Skip to content

Commit

Permalink
Merge pull request #864 from srl-labs/revisit-gen-cmd
Browse files Browse the repository at this point in the history
revistited generation command
  • Loading branch information
hellt authored May 3, 2022
2 parents 1fe9604 + 3ab41c9 commit da46ebe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 29 deletions.
41 changes: 19 additions & 22 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ var interfaceFormat = map[string]string{
"bridge": "veth%d",
"vr-sros": "eth%d",
"vr-vmx": "eth%d",
"vr-vqfx": "eth%d",
"vr-xrv9k": "eth%d",
"vr-veos": "eth%d",
}
var supportedKinds = []string{"srl", "ceos", "linux", "bridge", "sonic-vs", "crpd", "vr-sros", "vr-vmx", "vr-xrv9k"}
var supportedKinds = []string{"srl", "ceos", "linux", "bridge", "sonic-vs", "crpd", "vr-sros", "vr-vmx", "vr-vqfx", "vr-xrv9k"}

const (
defaultSRLType = "ixrd2"
Expand Down Expand Up @@ -130,7 +131,7 @@ func init() {
generateCmd.Flags().UintVarP(&maxWorkers, "max-workers", "", 0, "limit the maximum number of workers creating nodes and virtual wires")
}

func generateTopologyConfig(name, network, ipv4range, ipv6range string, images map[string]string, licenses map[string]string, nodes ...nodesDef) ([]byte, error) {
func generateTopologyConfig(name, network, ipv4range, ipv6range string, images, licenses map[string]string, nodes ...nodesDef) ([]byte, error) {
numStages := len(nodes)
config := &clab.Config{
Name: name,
Expand Down Expand Up @@ -257,35 +258,31 @@ func parseNodesFlag(kind string, nodes ...string) ([]nodesDef, error) {
}
def.numNodes = uint(i)
switch len(items) {
// num_nodes notation
// kind is assumed to be `srl` or set with --kind
case 1:
if kind == "" {
log.Errorf("no kind specified for nodes '%s'", n)
return nil, errSyntax
}
def.kind = kind
if kind == "srl" {
def.typ = defaultSRLType
}
// num_nodes:kind notation
case 2:
switch items[1] {
case "ceos", "linux", "bridge", "sonic", "crpd":
def.kind = items[1]
case "srl":
def.kind = items[1]
def.typ = defaultSRLType
default:
// assume second item is a type if kind set using --kind
if kind == "" {
log.Errorf("no kind specified for nodes '%s'", n)
return nil, errSyntax
}
def.kind = kind
def.typ = items[1]
if kind == "" {
log.Errorf("no kind specified for nodes '%s'", n)
return nil, errSyntax
}
def.kind = items[1]

// num_nodes:kind:type notation
case 3:
// srl with #nodes, kind and type
def.numNodes = uint(i)
def.kind = items[1]
def.kind = kind

if items[1] != "" {
def.kind = items[1]
}

def.typ = items[2]
}
result[idx] = def
Expand All @@ -294,7 +291,7 @@ func parseNodesFlag(kind string, nodes ...string) ([]nodesDef, error) {
}

func saveTopoFile(path string, data []byte) error {
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666)
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666) // skipcq: GSC-G302
if err != nil {
return err
}
Expand Down
14 changes: 7 additions & 7 deletions cmd/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ var nodesTestSet = map[string]struct {
},
out: nodesOutput{
out: []nodesDef{
{numNodes: 1, kind: "srl", typ: "ixrd2"},
{numNodes: 2, kind: "srl", typ: "ixrd2"},
{numNodes: 3, kind: "srl", typ: "ixrd2"},
{numNodes: 1, kind: "srl", typ: ""},
{numNodes: 2, kind: "srl", typ: ""},
{numNodes: 3, kind: "srl", typ: ""},
},
err: nil,
},
Expand All @@ -142,7 +142,7 @@ var nodesTestSet = map[string]struct {
out: nodesOutput{
out: []nodesDef{
{numNodes: 1, kind: "linux", typ: ""},
{numNodes: 2, kind: "srl", typ: "ixrd2"},
{numNodes: 2, kind: "srl", typ: ""},
{numNodes: 3, kind: "ceos", typ: ""},
},
err: nil,
Expand All @@ -151,12 +151,12 @@ var nodesTestSet = map[string]struct {
"kind_nodes_with_kind_and_type": {
in: nodesInput{
kind: "srl",
nodes: []string{"1:ixrd", "2", "3:ceos"},
nodes: []string{"1::ixrd", "2", "3:ceos"},
},
out: nodesOutput{
out: []nodesDef{
{numNodes: 1, kind: "srl", typ: "ixrd"},
{numNodes: 2, kind: "srl", typ: "ixrd2"},
{numNodes: 2, kind: "srl"},
{numNodes: 3, kind: "ceos", typ: ""},
},
err: nil,
Expand All @@ -169,7 +169,7 @@ var nodesTestSet = map[string]struct {
},
out: nodesOutput{
out: []nodesDef{
{numNodes: 2, kind: "srl", typ: "ixrd2"},
{numNodes: 2, kind: "srl", typ: ""},
},
err: nil,
},
Expand Down

0 comments on commit da46ebe

Please sign in to comment.