diff --git a/cmd/climc/shell/loadbalancerlistenerrules.go b/cmd/climc/shell/loadbalancerlistenerrules.go index 1d82eaa5f8..ac0832d50e 100644 --- a/cmd/climc/shell/loadbalancerlistenerrules.go +++ b/cmd/climc/shell/loadbalancerlistenerrules.go @@ -89,4 +89,11 @@ func init() { printObject(lblistenerrule) return nil }) + R(&options.LoadbalancerListenerRuleGetBackendStatusOptions{}, "lblistenerrule-backend-status", "Get lblistenerrule backend status", func(s *mcclient.ClientSession, opts *options.LoadbalancerListenerRuleGetBackendStatusOptions) error { + backendStatus, err := modules.LoadbalancerListenerRules.GetSpecific(s, opts.ID, "backend-status", nil) + if err != nil { + return err + } + return printLbBackendStatus(backendStatus) + }) } diff --git a/cmd/climc/shell/loadbalancerlisteners.go b/cmd/climc/shell/loadbalancerlisteners.go index 7b54c3b94c..7e9eedfa99 100644 --- a/cmd/climc/shell/loadbalancerlisteners.go +++ b/cmd/climc/shell/loadbalancerlisteners.go @@ -15,13 +15,44 @@ package shell import ( + "fmt" + "yunion.io/x/jsonutils" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" ) +func printLbBackendStatus(backendStatus jsonutils.JSONObject) error { + arr, ok := backendStatus.(*jsonutils.JSONArray) + if !ok { + return fmt.Errorf("want json array, got %s", backendStatus.String()) + } + objList, err := arr.GetArray() + if err != nil { + return err + } + listResult := &modulebase.ListResult{ + Data: objList, + } + columns := []string{ + "id", + "name", + "backend_type", + "backend_id", + "address", + "port", + "weight", + "check_time", + "check_status", + "check_code", + } + printList(listResult, columns) + return nil +} + func init() { R(&options.LoadbalancerListenerCreateOptions{}, "lblistener-create", "Create lblistener", func(s *mcclient.ClientSession, opts *options.LoadbalancerListenerCreateOptions) error { @@ -99,4 +130,11 @@ func init() { printObject(lblistener) return nil }) + R(&options.LoadbalancerListenerGetBackendStatusOptions{}, "lblistener-backend-status", "Get lblistene backend status", func(s *mcclient.ClientSession, opts *options.LoadbalancerListenerGetBackendStatusOptions) error { + backendStatus, err := modules.LoadbalancerListeners.GetSpecific(s, opts.ID, "backend-status", nil) + if err != nil { + return err + } + return printLbBackendStatus(backendStatus) + }) } diff --git a/pkg/mcclient/options/loadbalancerlistenerrules.go b/pkg/mcclient/options/loadbalancerlistenerrules.go index c5f41c51d0..10975f428f 100644 --- a/pkg/mcclient/options/loadbalancerlistenerrules.go +++ b/pkg/mcclient/options/loadbalancerlistenerrules.go @@ -46,6 +46,10 @@ type LoadbalancerListenerRuleDeleteOptions struct { ID string `json:"-"` } +type LoadbalancerListenerRuleGetBackendStatusOptions struct { + ID string `json:"-"` +} + type LoadbalancerListenerRuleActionStatusOptions struct { ID string `json:"-"` Status string `choices:"enabled|disabled"` diff --git a/pkg/mcclient/options/loadbalancerlisteners.go b/pkg/mcclient/options/loadbalancerlisteners.go index 93ce2322a5..850ffb7964 100644 --- a/pkg/mcclient/options/loadbalancerlisteners.go +++ b/pkg/mcclient/options/loadbalancerlisteners.go @@ -184,6 +184,10 @@ type LoadbalancerListenerActionStatusOptions struct { Status string `choices:"enabled|disabled"` } +type LoadbalancerListenerGetBackendStatusOptions struct { + ID string `json:"-"` +} + type LoadbalancerListenerActionSyncStatusOptions struct { ID string `json:"-"` }