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 f4c5efe
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 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
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 f4c5efe

Please sign in to comment.