Skip to content
Snippets Groups Projects
node.go 816 B
Newer Older
  • Learn to ignore specific revisions
  • package node
    
    import (
    	"regexp"
    
    	"code.fbi.h-da.de/danet/gosdn/models/generated/openconfig"
    )
    
    // Node is a representation of a network element.
    type Node struct {
    	ID       string
    	Name     string
    	Kind     string
    	Image    string
    	MgmtIpv4 string
    	YangData openconfig.Device
    }
    
    // GetID gets the id.
    func (n Node) GetID() string {
    	return n.ID
    }
    
    // FillAllFields fills all remaining fields of object with data from YangData.
    func (n *Node) FillAllFields(containerRegistryURL string) {
    	// make switch case here to differentialte between linux, arista, etc
    
    	// specific to arista
    	regex := regexp.MustCompile(`[0-9]+\.[0-9]+\.[0-9][A-Z]`)
    	dockerTag := string(regex.FindAll([]byte(*n.YangData.Lldp.Config.SystemDescription), 1)[0])
    
    	n.Kind = "ceos"
    	n.Image = containerRegistryURL + n.Kind + ":" + dockerTag
    }