diff --git a/examples/multivendor/multivendor.pb.txt b/examples/multivendor/multivendor.pb.txt index 23d74f03..1bf97da4 100644 --- a/examples/multivendor/multivendor.pb.txt +++ b/examples/multivendor/multivendor.pb.txt @@ -5,11 +5,18 @@ nodes: { config: { file: "ceos.cfg" } + interfaces: { + key: "eth0" + value: { + name: "Management1" + } + } } nodes: { name: "ncptx" vendor: JUNIPER config: { + image: "ncptx:ga" file: "ncptx.cfg" } interfaces: { diff --git a/exec/fake/fake.go b/exec/fake/fake.go index 888e4e26..8574db08 100644 --- a/exec/fake/fake.go +++ b/exec/fake/fake.go @@ -165,10 +165,10 @@ func (c *Command) Run() error { call.Optional = r.Optional if c.stdout != nil && r.Stdout != "" { - fmt.Fprintf(c.stdout, r.Stdout) + fmt.Fprint(c.stdout, r.Stdout) } if c.stderr != nil && r.Stderr != "" { - fmt.Fprintf(c.stderr, r.Stderr) + fmt.Fprint(c.stderr, r.Stderr) } switch e := r.Err.(type) { case string: diff --git a/topo/node/arista/arista.go b/topo/node/arista/arista.go index b2ac04b2..2666b1b0 100644 --- a/topo/node/arista/arista.go +++ b/topo/node/arista/arista.go @@ -160,6 +160,10 @@ func (n *Node) CreateCRD(ctx context.Context) error { log.Infof("Creating new CEosLabDevice CRD for node: %v", n.Name()) proto := n.GetProto() config := proto.GetConfig() + links, err := node.GetNodeLinks(proto) + if err != nil { + return err + } device := &ceos.CEosLabDevice{ TypeMeta: metav1.TypeMeta{ APIVersion: "ceoslab.arista.com/v1alpha1", @@ -179,7 +183,7 @@ func (n *Node) CreateCRD(ctx context.Context) error { InitContainerImage: config.GetInitImage(), Args: config.GetArgs(), Resources: proto.GetConstraints(), - NumInterfaces: int32(len(proto.GetInterfaces())), + NumInterfaces: int32(len(links)), Sleep: int32(config.GetSleep()), }, } diff --git a/topo/node/arista/arista_test.go b/topo/node/arista/arista_test.go index 359b6a91..a939f14d 100644 --- a/topo/node/arista/arista_test.go +++ b/topo/node/arista/arista_test.go @@ -378,11 +378,18 @@ func TestCRD(t *testing.T) { Version: "version-test", Os: "os-test", Interfaces: map[string]*topopb.Interface{ + "eth0": { + Name: "Management1", + }, "eth1": { - Name: "Ethernet1/1", + Name: "Ethernet1/1", + PeerIntName: "eth1", + PeerName: "foo", }, "eth2": { - Name: "Ethernet1/2", + Name: "Ethernet1/2", + PeerIntName: "eth2", + PeerName: "foo", }, }, }, @@ -423,6 +430,7 @@ func TestCRD(t *testing.T) { }}, }, IntfMapping: map[string]string{ + "eth0": "Management1", "eth1": "Ethernet1/1", "eth2": "Ethernet1/2", }, diff --git a/topo/node/node.go b/topo/node/node.go index ba00407f..bb875ad4 100644 --- a/topo/node/node.go +++ b/topo/node/node.go @@ -172,24 +172,9 @@ func (n *Impl) String() string { } func (n *Impl) TopologySpecs(context.Context) ([]*topologyv1.Topology, error) { - proto := n.GetProto() - - var links []topologyv1.Link - for ifcName, ifc := range proto.Interfaces { - if ifc.PeerIntName == "" { - return nil, fmt.Errorf("interface %q PeerIntName canot be empty", ifcName) - } - if ifc.PeerName == "" { - return nil, fmt.Errorf("interface %q PeerName canot be empty", ifcName) - } - links = append(links, topologyv1.Link{ - UID: int(ifc.Uid), - LocalIntf: ifcName, - PeerIntf: ifc.PeerIntName, - PeerPod: ifc.PeerName, - LocalIP: "", - PeerIP: "", - }) + links, err := GetNodeLinks(n.Proto) + if err != nil { + return nil, err } // by default each node will result in exactly one topology resource @@ -197,7 +182,7 @@ func (n *Impl) TopologySpecs(context.Context) ([]*topologyv1.Topology, error) { return []*topologyv1.Topology{ { ObjectMeta: metav1.ObjectMeta{ - Name: proto.Name, + Name: n.Proto.Name, }, Spec: topologyv1.TopologySpec{ Links: links, @@ -393,6 +378,10 @@ func (n *Impl) CreateConfig(ctx context.Context) (*corev1.Volume, error) { // CreatePod creates a Pod for the Node based on the underlying proto. func (n *Impl) CreatePod(ctx context.Context) error { pb := n.Proto + links, err := GetNodeLinks(pb) + if err != nil { + return err + } log.Infof("Creating Pod:\n %+v", pb) initContainerImage := pb.Config.InitImage if initContainerImage == "" { @@ -411,7 +400,7 @@ func (n *Impl) CreatePod(ctx context.Context) error { Name: fmt.Sprintf("init-%s", pb.Name), Image: initContainerImage, Args: []string{ - fmt.Sprintf("%d", len(n.Proto.Interfaces)+1), + fmt.Sprintf("%d", len(links)+1), fmt.Sprintf("%d", pb.Config.Sleep), }, ImagePullPolicy: "IfNotPresent", @@ -753,3 +742,28 @@ func (n *Impl) GetCLIConn(platform string, opts []scrapliutil.Option) (*scraplin func (n *Impl) BackToBackLoop() bool { return false } + +func GetNodeLinks(n *tpb.Node) ([]topologyv1.Link, error) { + var links []topologyv1.Link + for ifcName, ifc := range n.Interfaces { + if ifcName == "eth0" { + log.Infof("Found mgmt interface ignoring for Meshnet: %q", ifcName) + continue + } + if ifc.PeerIntName == "" { + return nil, fmt.Errorf("interface %q PeerIntName canot be empty", ifcName) + } + if ifc.PeerName == "" { + return nil, fmt.Errorf("interface %q PeerName canot be empty", ifcName) + } + links = append(links, topologyv1.Link{ + UID: int(ifc.Uid), + LocalIntf: ifcName, + PeerIntf: ifc.PeerIntName, + PeerPod: ifc.PeerName, + LocalIP: "", + PeerIP: "", + }) + } + return links, nil +} diff --git a/topo/topo_test.go b/topo/topo_test.go index bde0f538..b4004fd5 100644 --- a/topo/topo_test.go +++ b/topo/topo_test.go @@ -123,7 +123,7 @@ type resettable struct { func (r *resettable) ResetCfg(_ context.Context) error { if r.rErr != "" { - return fmt.Errorf(r.rErr) + return fmt.Errorf("%s", r.rErr) } return nil } @@ -144,7 +144,7 @@ func (c *certable) GetProto() *tpb.Node { func (c *certable) GenerateSelfSigned(_ context.Context) error { if c.gErr != "" { - return fmt.Errorf(c.gErr) + return fmt.Errorf("%s", c.gErr) } return nil }