Skip to content

Commit

Permalink
Add new handler for being able to map eth0 to management iterfaces and
Browse files Browse the repository at this point in the history
bypass meshnet
  • Loading branch information
marcushines committed Aug 15, 2024
1 parent 832274d commit b24ce00
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 4 deletions.
7 changes: 7 additions & 0 deletions examples/multivendor/multivendor.pb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
6 changes: 5 additions & 1 deletion topo/node/arista/arista.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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()),
},
}
Expand Down
12 changes: 10 additions & 2 deletions topo/node/arista/arista_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
},
Expand Down Expand Up @@ -423,6 +430,7 @@ func TestCRD(t *testing.T) {
}},
},
IntfMapping: map[string]string{
"eth0": "Management1",
"eth1": "Ethernet1/1",
"eth2": "Ethernet1/2",
},
Expand Down
35 changes: 34 additions & 1 deletion topo/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ func (n *Impl) TopologySpecs(context.Context) ([]*topologyv1.Topology, error) {

var links []topologyv1.Link
for ifcName, ifc := range proto.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)
}
Expand Down Expand Up @@ -393,6 +397,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 == "" {
Expand All @@ -411,7 +419,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",
Expand Down Expand Up @@ -753,3 +761,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
}

0 comments on commit b24ce00

Please sign in to comment.