fix(climc): add version list command

This commit is contained in:
Qu Xuan
2021-07-28 17:58:46 +08:00
parent 705d7a0076
commit 1f87214bb9
2 changed files with 43 additions and 1 deletions

View File

@@ -14,5 +14,5 @@ assignees: ''
- OS (e.g. `cat /etc/os-release`):
- Kernel (e.g. `uname -a`):
<!--
- Version (e.g. `kubectl get oc -n onecloud -o yaml | grep -C 3 version`):
- Version (e.g. `climc version-list`):
-->

View File

@@ -17,6 +17,11 @@ package misc
import (
"fmt"
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/errors"
"yunion.io/x/pkg/utils"
"yunion.io/x/onecloud/pkg/cloudprovider"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
@@ -35,6 +40,43 @@ func init() {
return nil
})
type VersionListOptions struct {
}
R(&VersionListOptions{}, "version-list", "query all backend service version", func(s *mcclient.ClientSession, args *VersionListOptions) error {
services := []jsonutils.JSONObject{}
params := map[string]interface{}{}
for {
params["offset"] = len(services)
resp, err := modules.ServicesV3.List(s, jsonutils.Marshal(params))
if err != nil {
return err
}
services = append(services, resp.Data...)
if len(services) >= resp.Total {
break
}
}
vers := map[string]string{}
for _, service := range services {
serviceType, _ := service.GetString("type")
if utils.IsInStringArray(serviceType, []string{"offlinecloudmeta"}) {
continue
}
ver, err := modules.GetVersion(s, serviceType)
if err != nil {
if errors.Cause(err) == cloudprovider.ErrNotFound || errors.Cause(err) == errors.ErrConnectRefused {
continue
}
vers[serviceType] = err.Error()
} else {
vers[serviceType] = ver
}
}
printObject(jsonutils.Marshal(vers))
return nil
})
R(&options.VersionListOptions{}, "yunionagent-version-list", "show versions of backend services", func(s *mcclient.ClientSession, opts *options.VersionListOptions) error {
if len(opts.Region) == 0 {
opts.Region = s.GetRegion()