cloudproviderregions.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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/pkg/util/printutils"
  18. "yunion.io/x/onecloud/pkg/mcclient"
  19. modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
  20. "yunion.io/x/onecloud/pkg/mcclient/options"
  21. )
  22. func init() {
  23. type CloudproviderRegionListOptions struct {
  24. options.BaseListOptions
  25. Region string `help:"ID or Name of Host"`
  26. Capability []string `help:"capability filter" choices:"project|compute|network|loadbalancer|objectstore|rds|cache|event"`
  27. }
  28. R(&CloudproviderRegionListOptions{}, "cloud-provider-region-list", "List cloudprovider region synchronization status", func(s *mcclient.ClientSession, args *CloudproviderRegionListOptions) error {
  29. var params *jsonutils.JSONDict
  30. {
  31. var err error
  32. params, err = args.BaseListOptions.Params()
  33. if err != nil {
  34. return err
  35. }
  36. }
  37. var result *printutils.ListResult
  38. var err error
  39. if len(args.Manager) == 1 {
  40. result, err = modules.CloudproviderregionManager.ListDescendent(s, args.Manager[0], params)
  41. } else if len(args.Region) > 0 {
  42. result, err = modules.CloudproviderregionManager.ListDescendent2(s, args.Region, params)
  43. } else {
  44. result, err = modules.CloudproviderregionManager.List(s, params)
  45. }
  46. if err != nil {
  47. return err
  48. }
  49. printList(result, modules.CloudproviderregionManager.GetColumns(s))
  50. return nil
  51. })
  52. type CloudproviderRegionOpsOptions struct {
  53. PROVIDER string `help:"ID or name of cloud provider"`
  54. REGION string `help:"ID or name of cloud region"`
  55. }
  56. R(&CloudproviderRegionOpsOptions{}, "cloud-provider-region-enable", "Enable automatic synchronization for cloudprovider/region pair", func(s *mcclient.ClientSession, args *CloudproviderRegionOpsOptions) error {
  57. params := jsonutils.NewDict()
  58. params.Add(jsonutils.JSONTrue, "enabled")
  59. result, err := modules.CloudproviderregionManager.Update(s, args.PROVIDER, args.REGION, nil, params)
  60. if err != nil {
  61. return err
  62. }
  63. printObject(result)
  64. return nil
  65. })
  66. R(&CloudproviderRegionOpsOptions{}, "cloud-provider-region-disable", "Disable automatic synchronization for cloudprovider/region pair", func(s *mcclient.ClientSession, args *CloudproviderRegionOpsOptions) error {
  67. params := jsonutils.NewDict()
  68. params.Add(jsonutils.JSONFalse, "enabled")
  69. result, err := modules.CloudproviderregionManager.Update(s, args.PROVIDER, args.REGION, nil, params)
  70. if err != nil {
  71. return err
  72. }
  73. printObject(result)
  74. return nil
  75. })
  76. }