instance.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 shell
  15. import (
  16. "yunion.io/x/cloudmux/pkg/cloudprovider"
  17. "yunion.io/x/pkg/util/shellutils"
  18. "yunion.io/x/onecloud/pkg/mcclient/cloudpods"
  19. )
  20. func init() {
  21. type InstanceListOptions struct {
  22. HostId string
  23. }
  24. shellutils.R(&InstanceListOptions{}, "instance-list", "List instances", func(cli *cloudpods.SRegion, args *InstanceListOptions) error {
  25. instances, err := cli.GetInstances(args.HostId)
  26. if err != nil {
  27. return err
  28. }
  29. printList(instances, 0, 0, 0, nil)
  30. return nil
  31. })
  32. type InstanceIdOptions struct {
  33. ID string
  34. }
  35. shellutils.R(&InstanceIdOptions{}, "instance-show", "Show instance", func(cli *cloudpods.SRegion, args *InstanceIdOptions) error {
  36. instance, err := cli.GetInstance(args.ID)
  37. if err != nil {
  38. return err
  39. }
  40. printObject(instance)
  41. return nil
  42. })
  43. shellutils.R(&InstanceIdOptions{}, "instance-vnc", "Show instance vnc", func(cli *cloudpods.SRegion, args *InstanceIdOptions) error {
  44. vnc, err := cli.GetInstanceVnc(args.ID, "")
  45. if err != nil {
  46. return err
  47. }
  48. printObject(vnc)
  49. return nil
  50. })
  51. type InstanceSaveImageOptions struct {
  52. ID string
  53. NAME string
  54. Note string
  55. }
  56. shellutils.R(&InstanceSaveImageOptions{}, "instance-save-image", "Save instance image", func(cli *cloudpods.SRegion, args *InstanceSaveImageOptions) error {
  57. image, err := cli.SaveImage(args.ID, args.NAME, args.Note)
  58. if err != nil {
  59. return err
  60. }
  61. printObject(image)
  62. return nil
  63. })
  64. shellutils.R(&cloudprovider.MetricListOptions{}, "instance-monitor-list", "Instance Monitor List", func(cli *cloudpods.SRegion, opts *cloudprovider.MetricListOptions) error {
  65. metrics, err := cli.GetClient().GetMetrics(opts)
  66. if err != nil {
  67. return err
  68. }
  69. printList(metrics, len(metrics), 0, 0, []string{})
  70. return nil
  71. })
  72. }