cluster.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 bingocloud
  15. import (
  16. "yunion.io/x/pkg/errors"
  17. api "yunion.io/x/cloudmux/pkg/apis/compute"
  18. "yunion.io/x/cloudmux/pkg/cloudprovider"
  19. "yunion.io/x/cloudmux/pkg/multicloud"
  20. )
  21. type SCluster struct {
  22. multicloud.SResourceBase
  23. multicloud.STagBase
  24. region *SRegion
  25. ClusterControllerSet []struct {
  26. Address string
  27. Role string
  28. }
  29. ClusterId string
  30. ClusterName string
  31. CreateVolumeMode string
  32. ExtendDiskMode string
  33. Hypervisor string
  34. MaxVolumeStorage string
  35. SchedPolicy string
  36. Status string
  37. }
  38. func (self *SCluster) GetGlobalId() string {
  39. return self.ClusterId
  40. }
  41. func (self *SCluster) GetId() string {
  42. return self.ClusterId
  43. }
  44. func (self *SCluster) GetName() string {
  45. return self.ClusterName
  46. }
  47. func (self *SCluster) GetStatus() string {
  48. if self.Status == "available" {
  49. return api.ZONE_ENABLE
  50. }
  51. return api.ZONE_DISABLE
  52. }
  53. func (self *SCluster) GetI18n() cloudprovider.SModelI18nTable {
  54. return cloudprovider.SModelI18nTable{}
  55. }
  56. func (self *SCluster) GetIRegion() cloudprovider.ICloudRegion {
  57. return self.region
  58. }
  59. func (self *SRegion) GetIZones() ([]cloudprovider.ICloudZone, error) {
  60. clusters, err := self.GetClusters()
  61. if err != nil {
  62. return nil, errors.Wrapf(err, "GetClusters")
  63. }
  64. var ret []cloudprovider.ICloudZone
  65. for i := range clusters {
  66. clusters[i].region = self
  67. ret = append(ret, &clusters[i])
  68. }
  69. return ret, nil
  70. }
  71. func (self *SRegion) GetIZoneById(id string) (cloudprovider.ICloudZone, error) {
  72. zones, err := self.GetIZones()
  73. if err != nil {
  74. return nil, err
  75. }
  76. for i := range zones {
  77. if zones[i].GetGlobalId() == id {
  78. return zones[i], nil
  79. }
  80. }
  81. return nil, errors.Wrapf(cloudprovider.ErrNotFound, "%s", id)
  82. }
  83. func (self *SRegion) GetClusters() ([]SCluster, error) {
  84. resp, err := self.invoke("DescribeClusters", nil)
  85. if err != nil {
  86. return nil, err
  87. }
  88. var ret []SCluster
  89. return ret, resp.Unmarshal(&ret, "clusterSet")
  90. }