summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-10-27 15:24:42 +0900
committerISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-10-27 15:24:42 +0900
commit38755839c3e153dbaaec666a74c4392e8ef2c5e3 (patch)
tree357c44c12e5d26c5c560a36c83190e35842d9a24
parentad412e6502010a6f16587b63fba642b6368d7fb4 (diff)
cli: show all types of policy assignment when policy type is omitted
$ gobgp global policy Import policy: Default: ACCEPT Export policy: Default: ACCEPT Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r--gobgp/cmd/global.go11
-rw-r--r--gobgp/cmd/neighbor.go27
2 files changed, 31 insertions, 7 deletions
diff --git a/gobgp/cmd/global.go b/gobgp/cmd/global.go
index d3a35b49..e9333d81 100644
--- a/gobgp/cmd/global.go
+++ b/gobgp/cmd/global.go
@@ -657,13 +657,22 @@ func NewGlobalCmd() *cobra.Command {
policyCmd := &cobra.Command{
Use: CMD_POLICY,
+ Run: func(cmd *cobra.Command, args []string) {
+ for _, v := range []string{CMD_IMPORT, CMD_EXPORT} {
+ fmt.Printf("%s policy:\n", strings.Title(v))
+ if err := showNeighborPolicy(nil, v, 4); err != nil {
+ fmt.Println(err)
+ os.Exit(1)
+ }
+ }
+ },
}
for _, v := range []string{CMD_IN, CMD_IMPORT, CMD_EXPORT} {
cmd := &cobra.Command{
Use: v,
Run: func(cmd *cobra.Command, args []string) {
- if err := showNeighborPolicy(nil, cmd.Use); err != nil {
+ if err := showNeighborPolicy(nil, cmd.Use, 0); err != nil {
fmt.Println(err)
os.Exit(1)
}
diff --git a/gobgp/cmd/neighbor.go b/gobgp/cmd/neighbor.go
index 9b068c33..bbb524bc 100644
--- a/gobgp/cmd/neighbor.go
+++ b/gobgp/cmd/neighbor.go
@@ -610,7 +610,7 @@ func stateChangeNeighbor(cmd string, remoteIP string, args []string) error {
return err
}
-func showNeighborPolicy(remoteIP net.IP, policyType string) error {
+func showNeighborPolicy(remoteIP net.IP, policyType string, indent int) error {
var typ api.PolicyType
switch strings.ToLower(policyType) {
case "in":
@@ -641,10 +641,10 @@ func showNeighborPolicy(remoteIP net.IP, policyType string) error {
return nil
}
- fmt.Printf("Default: %s\n", ap.Default)
+ fmt.Printf("%sDefault: %s\n", strings.Repeat(" ", indent), ap.Default)
for _, p := range ap.Policies {
- fmt.Printf("Name %s:\n", p.Name)
- printPolicy(4, p)
+ fmt.Printf("%sName %s:\n", strings.Repeat(" ", indent), p.Name)
+ printPolicy(indent+4, p)
}
return nil
}
@@ -656,7 +656,7 @@ func extractDefaultAction(args []string) ([]string, api.RouteAction, error) {
return nil, api.RouteAction_NONE, fmt.Errorf("specify default action [accept|reject]")
}
typ := args[idx+1]
- switch typ {
+ switch strings.ToLower(typ) {
case "accept":
return append(args[:idx], args[idx+2:]...), api.RouteAction_ACCEPT, nil
case "reject":
@@ -774,6 +774,21 @@ func NewNeighborCmd() *cobra.Command {
policyCmd := &cobra.Command{
Use: CMD_POLICY,
+ Run: func(cmd *cobra.Command, args []string) {
+ remoteIP := net.ParseIP(args[0])
+ if remoteIP == nil {
+ fmt.Println("invalid ip address:", args[0])
+ os.Exit(1)
+ }
+
+ for _, v := range []string{CMD_IN, CMD_IMPORT, CMD_EXPORT} {
+ fmt.Printf("%s policy:\n", strings.Title(v))
+ if err := showNeighborPolicy(remoteIP, v, 4); err != nil {
+ fmt.Println(err)
+ os.Exit(1)
+ }
+ }
+ },
}
for _, v := range []string{CMD_IN, CMD_IMPORT, CMD_EXPORT} {
@@ -785,7 +800,7 @@ func NewNeighborCmd() *cobra.Command {
if remoteIP == nil {
err = fmt.Errorf("invalid ip address: %s", args[0])
} else {
- err = showNeighborPolicy(remoteIP, cmd.Use)
+ err = showNeighborPolicy(remoteIP, cmd.Use, 0)
}
if err != nil {
fmt.Println(err)