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