From 6f02a8fe55687346dc138d1023b53c448033c686 Mon Sep 17 00:00:00 2001 From: Heinz Knutzen Date: Wed, 1 Nov 2023 15:42:01 +0100 Subject: [PATCH] Paremeter "TYPE:" selects all nodes of that type e.g. "service:" selects all services --- go/pkg/exportsyntax/export-netspoc-syntax.go | 6 +-- go/testdata/export-netspoc-syntax/export.t | 46 +++++++++++++++++--- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/go/pkg/exportsyntax/export-netspoc-syntax.go b/go/pkg/exportsyntax/export-netspoc-syntax.go index 6e366814..093b67c0 100644 --- a/go/pkg/exportsyntax/export-netspoc-syntax.go +++ b/go/pkg/exportsyntax/export-netspoc-syntax.go @@ -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") @@ -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)) } } diff --git a/go/testdata/export-netspoc-syntax/export.t b/go/testdata/export-netspoc-syntax/export.t index 98c1c93e..bb517e88 100644 --- a/go/testdata/export-netspoc-syntax/export.t +++ b/go/testdata/export-netspoc-syntax/export.t @@ -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= @@ -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= @@ -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; } @@ -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": [{ @@ -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: