zone.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 cloudpods
  15. import (
  16. "yunion.io/x/cloudmux/pkg/cloudprovider"
  17. "yunion.io/x/cloudmux/pkg/multicloud"
  18. "yunion.io/x/pkg/errors"
  19. api "yunion.io/x/onecloud/pkg/apis/compute"
  20. modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
  21. )
  22. type SZone struct {
  23. multicloud.SResourceBase
  24. CloudpodsTags
  25. region *SRegion
  26. api.ZoneDetails
  27. }
  28. func (self *SZone) GetId() string {
  29. return self.Id
  30. }
  31. func (self *SZone) GetGlobalId() string {
  32. return self.Id
  33. }
  34. func (self *SZone) GetName() string {
  35. return self.Name
  36. }
  37. func (self *SZone) GetStatus() string {
  38. return self.Status
  39. }
  40. func (self *SZone) GetIRegion() cloudprovider.ICloudRegion {
  41. return self.region
  42. }
  43. func (self *SZone) GetI18n() cloudprovider.SModelI18nTable {
  44. table := cloudprovider.SModelI18nTable{}
  45. table["name"] = cloudprovider.NewSModelI18nEntry(self.GetName()).CN(self.GetName())
  46. return table
  47. }
  48. func (self *SRegion) GetZones() ([]SZone, error) {
  49. zones := []SZone{}
  50. return zones, self.list(&modules.Zones, nil, &zones)
  51. }
  52. func (self *SRegion) GetZone(id string) (*SZone, error) {
  53. zone := &SZone{region: self}
  54. return zone, self.cli.get(&modules.Zones, id, nil, &zone)
  55. }
  56. func (self *SRegion) GetIZoneById(id string) (cloudprovider.ICloudZone, error) {
  57. zone, err := self.GetZone(id)
  58. if err != nil {
  59. return nil, err
  60. }
  61. return zone, nil
  62. }
  63. func (self *SRegion) GetIZones() ([]cloudprovider.ICloudZone, error) {
  64. zones, err := self.GetZones()
  65. if err != nil {
  66. return nil, errors.Wrapf(err, "GetZones")
  67. }
  68. ret := []cloudprovider.ICloudZone{}
  69. for i := range zones {
  70. zones[i].region = self
  71. ret = append(ret, &zones[i])
  72. }
  73. return ret, nil
  74. }