serverisolatedevices.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package compute
  15. import (
  16. "yunion.io/x/jsonutils"
  17. "yunion.io/x/onecloud/pkg/mcclient"
  18. modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
  19. )
  20. func init() {
  21. type ServerAttachDeviceOptions struct {
  22. SERVER string `help:"ID or name of server"`
  23. DEVICE string `help:"ID of isolated device to attach"`
  24. Type string `help:"Device type" choices:"GPU-HPC|GPU-VGA|PCI"`
  25. }
  26. R(&ServerAttachDeviceOptions{}, "server-attach-isolated-device", "Attach an existing isolated device to a virtual server", func(s *mcclient.ClientSession, args *ServerAttachDeviceOptions) error {
  27. params := jsonutils.NewDict()
  28. params.Add(jsonutils.NewString(args.DEVICE), "device")
  29. if len(args.Type) > 0 {
  30. params.Add(jsonutils.NewString(args.Type), "dev_type")
  31. }
  32. srv, err := modules.Servers.PerformAction(s, args.SERVER, "attach-isolated-device", params)
  33. if err != nil {
  34. return err
  35. }
  36. printObject(srv)
  37. return nil
  38. })
  39. type ServerDetachDeviceOptions struct {
  40. SERVER string `help:"ID or name of server"`
  41. DEVICE string `help:"ID of isolated device to attach"`
  42. }
  43. R(&ServerDetachDeviceOptions{}, "server-detach-isolated-device", "Detach a isolated device from a virtual server", func(s *mcclient.ClientSession, args *ServerDetachDeviceOptions) error {
  44. params := jsonutils.NewDict()
  45. params.Add(jsonutils.NewString(args.DEVICE), "device")
  46. srv, err := modules.Servers.PerformAction(s, args.SERVER, "detach-isolated-device", params)
  47. if err != nil {
  48. return err
  49. }
  50. printObject(srv)
  51. return nil
  52. })
  53. }