fix(climc): host-show hide long content sys_info nic_info metadata (#21850)

This commit is contained in:
wanyaoqi
2024-12-20 11:11:36 +08:00
committed by GitHub
parent 5496190609
commit 9b36b35b9f
2 changed files with 41 additions and 1 deletions
+28 -1
View File
@@ -37,7 +37,6 @@ import (
func init() {
cmd := shell.NewResourceCmd(&modules.Hosts)
cmd.List(&compute.HostListOptions{})
cmd.Show(&options.BaseShowOptions{})
cmd.GetMetadata(&options.BaseIdOptions{})
cmd.GetProperty(&compute.HostStatusStatisticsOptions{})
@@ -89,6 +88,34 @@ func init() {
}
}, &options.BaseIdOptions{})
R(&compute.HostShowOptions{}, "host-show", "Show details of a host", func(s *mcclient.ClientSession, args *compute.HostShowOptions) error {
params, err := args.Params()
if err != nil {
return err
}
result, err := modules.Hosts.Get(s, args.ID, params)
if err != nil {
return err
}
resultDict := result.(*jsonutils.JSONDict)
if !args.ShowAll {
if !args.ShowMetadata {
print("ShowMetadata\n")
resultDict.Remove("metadata")
}
if !args.ShowNicInfo {
print("ShowMetadata\n")
resultDict.Remove("nic_info")
}
if !args.ShowSysInfo {
print("ShowSysInfo\n")
resultDict.Remove("sys_info")
}
}
printObject(resultDict)
return nil
})
R(&options.BaseIdOptions{}, "host-logininfo", "Get SSH login information of a host", func(s *mcclient.ClientSession, args *options.BaseIdOptions) error {
i, e := modules.Hosts.PerformAction(s, args.ID, "login-info", nil)
if e != nil {
+13
View File
@@ -87,6 +87,19 @@ func (opts *HostListOptions) Params() (jsonutils.JSONObject, error) {
return params, nil
}
type HostShowOptions struct {
options.BaseShowOptions
ShowMetadata bool `help:"Show host metadata in details"`
ShowNicInfo bool `help:"Show host nic_info in details"`
ShowSysInfo bool `help:"Show host sys_info in details"`
ShowAll bool `help:"Show all of host details" short-token:"a"`
}
func (o *HostShowOptions) Params() (jsonutils.JSONObject, error) {
// NOTE: host show only request with base options
return jsonutils.Marshal(o.BaseShowOptions), nil
}
type HostReserveCpusOptions struct {
options.BaseIdsOptions
Cpus string