Files
cloudpods/cmd/climc/shell/isolatedevices.go
T
2018-08-01 14:13:23 +08:00

56 lines
1.6 KiB
Go

package shell
import (
"github.com/yunionio/jsonutils"
"github.com/yunionio/onecloud/pkg/mcclient"
"github.com/yunionio/onecloud/pkg/mcclient/modules"
)
func init() {
type DeviceListOptions struct {
BaseListOptions
Unused bool `help:"Only show unused devices"`
Gpu bool `help:"Only show gpu devices"`
Host string `help:"Host ID or Name"`
}
R(&DeviceListOptions{}, "isolated-device-list", "List isolated devices like GPU", func(s *mcclient.ClientSession, args *DeviceListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
if len(args.Host) > 0 {
params.Add(jsonutils.NewString(args.Host), "host")
}
if args.Unused {
params.Add(jsonutils.JSONTrue, "unused")
}
if args.Gpu {
params.Add(jsonutils.JSONTrue, "gpu")
}
result, err := modules.IsolatedDevices.List(s, params)
if err != nil {
return err
}
printList(result, modules.IsolatedDevices.GetColumns(s))
return nil
})
type DeviceShowOptions struct {
ID string `help:"ID of the isolated device"`
}
R(&DeviceShowOptions{}, "isolated-device-show", "Show isolated device details", func(s *mcclient.ClientSession, args *DeviceShowOptions) error {
result, err := modules.IsolatedDevices.Get(s, args.ID, nil)
if err != nil {
return err
}
printObject(result)
return nil
})
R(&DeviceShowOptions{}, "isolated-device-delete", "Delete a isolated device", func(s *mcclient.ClientSession, args *DeviceShowOptions) error {
result, err := modules.IsolatedDevices.Delete(s, args.ID, nil)
if err != nil {
return err
}
printObject(result)
return nil
})
}