current.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 misc
  15. import (
  16. "yunion.io/x/pkg/errors"
  17. "yunion.io/x/onecloud/pkg/mcclient"
  18. "yunion.io/x/onecloud/pkg/mcclient/modulebase"
  19. )
  20. func init() {
  21. type CurrentUserOptions struct {
  22. }
  23. R(&CurrentUserOptions{}, "session-show", "show information of current account", func(s *mcclient.ClientSession, args *CurrentUserOptions) error {
  24. printObject(s.ToJson())
  25. return nil
  26. })
  27. type FreezeResrouceOptions struct {
  28. ID string `help:"ID of resource"`
  29. Module string `help:"Resource module type, eg: servers, disks, networks"`
  30. }
  31. R(&FreezeResrouceOptions{}, "freeze-resource", "Freeze resource operation update and perform action except for unfreeze", func(s *mcclient.ClientSession, args *FreezeResrouceOptions) error {
  32. mod, err := modulebase.GetModule(s, args.Module)
  33. if err != nil {
  34. return errors.Wrap(err, "failed get module")
  35. }
  36. obj, err := mod.PerformAction(s, args.ID, "freeze", nil)
  37. if err != nil {
  38. return err
  39. }
  40. printObject(obj)
  41. return nil
  42. })
  43. type UnfreezeResrouceOptions struct {
  44. ID string `help:"ID of resource"`
  45. Module string `help:"Resource module type, eg: servers, disks, networks"`
  46. }
  47. R(&UnfreezeResrouceOptions{}, "unfreeze-resource", "Unfreeze resource", func(s *mcclient.ClientSession, args *UnfreezeResrouceOptions) error {
  48. mod, err := modulebase.GetModule(s, args.Module)
  49. if err != nil {
  50. return errors.Wrap(err, "failed get module")
  51. }
  52. obj, err := mod.PerformAction(s, args.ID, "unfreeze", nil)
  53. if err != nil {
  54. return err
  55. }
  56. printObject(obj)
  57. return nil
  58. })
  59. }