Skip to content

Commit

Permalink
Paremeter "TYPE:" selects all nodes of that type
Browse files Browse the repository at this point in the history
e.g. "service:" selects all services
  • Loading branch information
hknutzen committed Nov 1, 2023
1 parent a3a8066 commit 6f02a8f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
6 changes: 3 additions & 3 deletions go/pkg/exportsyntax/export-netspoc-syntax.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func Main(d oslink.Data) int {
fs := pflag.NewFlagSet(d.Args[0], pflag.ContinueOnError)
fs.Usage = func() {
fmt.Fprintf(d.Stderr,
"Usage: %s [options] netspoc-data [typed-name ...]\n%s",
"Usage: %s [options] netspoc-data [TYPE:NAME|TYPE: ...]\n%s",
d.Args[0], fs.FlagUsages())
}
fs.BoolP("quiet", "q", false, "Flag is ignored")
Expand Down Expand Up @@ -53,8 +53,8 @@ func Main(d oslink.Data) int {
}
for _, node := range aF.Nodes {
name := node.GetName()
if len(filter) == 0 || filter[name] {
typ, _, _ := strings.Cut(name, ":")
typ, _, _ := strings.Cut(name, ":")
if len(filter) == 0 || filter[name] || filter[typ+":"] {
definitions[typ] = append(definitions[typ], convertToMap(node))
}
}
Expand Down
46 changes: 41 additions & 5 deletions go/testdata/export-netspoc-syntax/export.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
=INPUT=#
=PARAMS=-h
=ERROR=
Usage: PROGRAM [options] netspoc-data [typed-name ...]
Usage: PROGRAM [options] netspoc-data [TYPE:NAME|TYPE: ...]
-q, --quiet Flag is ignored
=END=

Expand All @@ -20,7 +20,7 @@ Error: unknown flag: --abc
=TITLE=No input file
=INPUT=NONE
=ERROR=
Usage: PROGRAM [options] netspoc-data [typed-name ...]
Usage: PROGRAM [options] netspoc-data [TYPE:NAME|TYPE: ...]
-q, --quiet Flag is ignored
=END=

Expand Down Expand Up @@ -272,7 +272,7 @@ router:r1 = {
=END=

############################################################
=TITLE=Filter objects
=TITLE=Filter objects by name
=INPUT=
network:n1 = { ip = 10.1.1.0/24; }
network:n2 = { ip = 10.1.2.0/24; }
Expand All @@ -284,7 +284,6 @@ area:a1 = {
inclusive_border = interface:r2.n2, interface:r3.n3;
router_attributes = { policy_distribution_point = host:netspoc; }
}
=PARAMS= network:n1 group:g2 area:a1
=OUTPUT=
{"area":
[{
Expand All @@ -306,4 +305,41 @@ area:a1 = {
"name":"network:n1",
"ip":["10.1.1.0/24"]}]
}
=END=
=PARAMS= network:n1 group:g2 area:a1


############################################################
=TITLE=Filter objects by type
=INPUT=
network:n1 = { ip = 10.1.1.0/24; }
network:n2 = { ip = 10.1.2.0/24; }
group:g1 = network:n1;
group:g2 = group:g1;
area:a1 = {
owner = o2;
border = interface:r1.n1;
inclusive_border = interface:r2.n2, interface:r3.n3;
router_attributes = { policy_distribution_point = host:netspoc; }
}
=OUTPUT=
{"area":
[{
"name": "area:a1",
"owner": [ "o2" ],
"router_attributes": {
"policy_distribution_point": [ "host:netspoc" ]
},
"border": [ "interface:r1.n1" ],
"inclusive_border": [ "interface:r2.n2", "interface:r3.n3" ]
}],
"group":
[{
"name": "group:g1",
"elements": [ "network:n1" ]
},
{
"name":"group:g2",
"elements": ["group:g1"]
}]
}
=PARAMS= group: area:

0 comments on commit 6f02a8f

Please sign in to comment.