cloudproviders.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. "fmt"
  17. "yunion.io/x/jsonutils"
  18. "yunion.io/x/log"
  19. "yunion.io/x/onecloud/cmd/climc/shell"
  20. modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
  21. "yunion.io/x/onecloud/pkg/mcclient/options"
  22. "yunion.io/x/onecloud/pkg/mcclient/options/compute"
  23. )
  24. type ClircShowOpt struct {
  25. options.BaseIdOptions
  26. FollowOutputFormat bool `help:"follow output format"`
  27. }
  28. func init() {
  29. cmd := shell.NewResourceCmd(&modules.Cloudproviders).WithKeyword("cloud-provider")
  30. cmd.List(&compute.CloudproviderListOptions{})
  31. cmd.Update(&compute.CloudproviderUpdateOptions{})
  32. cmd.Show(&options.BaseIdOptions{})
  33. cmd.Delete(&options.BaseIdOptions{})
  34. cmd.Perform("change-project", &compute.CloudproviderChangeProjectOptions{})
  35. cmd.Perform("enable", &options.BaseIdOptions{})
  36. cmd.Perform("disable", &options.BaseIdOptions{})
  37. cmd.Perform("sync", &compute.CloudproviderSyncOptions{})
  38. cmd.Perform("project-mapping", &compute.ClouproviderProjectMappingOptions{})
  39. cmd.Perform("set-syncing", &compute.ClouproviderSetSyncingOptions{})
  40. cmd.GetWithCustomOptionShow("clirc", func(result jsonutils.JSONObject, opt shell.IGetOpt) {
  41. rc := make(map[string]string)
  42. err := result.Unmarshal(&rc)
  43. if err != nil {
  44. log.Errorf("Unmarshal error: %v", err)
  45. return
  46. }
  47. if opt.(*ClircShowOpt).FollowOutputFormat {
  48. shell.PrintObject(result)
  49. } else {
  50. for k, v := range rc {
  51. fmt.Printf(`export %s='%s'`+"\n", k, v)
  52. }
  53. }
  54. }, &ClircShowOpt{})
  55. cmd.Get("storage-classes", &compute.CloudproviderStorageClassesOptions{})
  56. cmd.Get("change-owner-candidate-domains", &options.BaseIdOptions{})
  57. cmd.Get("balance", &options.BaseIdOptions{})
  58. }