yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/cloudpods/region.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 "fmt" 19 20 "yunion.io/x/jsonutils" 21 22 api "yunion.io/x/onecloud/pkg/apis/compute" 23 24 "yunion.io/x/cloudmux/pkg/cloudprovider" 25 "yunion.io/x/cloudmux/pkg/multicloud" 26 ) 27 28 type SRegion struct { 29 multicloud.SRegion 30 multicloud.SRegionOssBase 31 multicloud.SRegionLbBase 32 multicloud.SRegionSecurityGroupBase 33 cli *SCloudpodsClient 34 35 api.CloudregionDetails 36 } 37 38 func (self *SRegion) GetClient() *SCloudpodsClient { 39 return self.cli 40 } 41 42 func (self *SRegion) GetId() string { 43 return self.Id 44 } 45 46 func (self *SRegion) GetName() string { 47 return fmt.Sprintf("%s-%s", self.cli.cpcfg.Name, self.Name) 48 } 49 50 func (self *SRegion) GetGlobalId() string { 51 return fmt.Sprintf("%s/%s/%s", CLOUD_PROVIDER_CLOUDPODS, self.cli.cpcfg.Id, self.Name) 52 } 53 54 func (self *SRegion) GetStatus() string { 55 return self.Status 56 } 57 58 func (self *SRegion) GetI18n() cloudprovider.SModelI18nTable { 59 table := cloudprovider.SModelI18nTable{} 60 table["name"] = cloudprovider.NewSModelI18nEntry(self.GetName()).CN(self.GetName()) 61 return table 62 } 63 64 func (self *SRegion) GetCapabilities() []string { 65 return self.cli.GetCapabilities() 66 } 67 68 func (self *SRegion) GetCloudEnv() string { 69 return api.CLOUD_ENV_PRIVATE_CLOUD 70 } 71 72 func (self *SRegion) GetProvider() string { 73 return api.CLOUD_PROVIDER_CLOUDPODS 74 } 75 76 func (self *SRegion) GetGeographicInfo() cloudprovider.SGeographicInfo { 77 return cloudprovider.SGeographicInfo{ 78 Latitude: self.Latitude, 79 Longitude: self.Longitude, 80 City: self.City, 81 CountryCode: self.CountryCode, 82 } 83 } 84 85 func (self *SRegion) GetIVMById(id string) (cloudprovider.ICloudVM, error) { 86 ins, err := self.GetInstance(id) 87 if err != nil { 88 return nil, err 89 } 90 return ins, nil 91 } 92 93 func (self *SRegion) GetIDiskById(id string) (cloudprovider.ICloudDisk, error) { 94 disk, err := self.GetDisk(id) 95 if err != nil { 96 return nil, err 97 } 98 return disk, nil 99 } 100 101 func (self *SRegion) GetIHostById(id string) (cloudprovider.ICloudHost, error) { 102 host, err := self.GetHost(id) 103 if err != nil { 104 return nil, err 105 } 106 if host.CloudregionId != self.Id { 107 return nil, cloudprovider.ErrNotFound 108 } 109 zone, err := self.GetZone(host.ZoneId) 110 if err != nil { 111 return nil, err 112 } 113 host.zone = zone 114 return host, nil 115 } 116 117 func (self *SRegion) create(manager ModelManager, params interface{}, retVal interface{}) error { 118 return self.cli.create(manager, params, retVal) 119 } 120 121 func (self *SRegion) perform(manager ModelManager, id, action string, params interface{}) (jsonutils.JSONObject, error) { 122 return self.cli.perform(manager, id, action, params) 123 } 124 125 func (self *SRegion) list(manager ModelManager, params map[string]interface{}, retVal interface{}) error { 126 if params == nil { 127 params = map[string]interface{}{} 128 } 129 params["cloudregion_id"] = self.Id 130 return self.cli.list(manager, params, retVal) 131 }