yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/incloudsphere/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 incloudsphere 16 17 import ( 18 "fmt" 19 "net/url" 20 21 api "yunion.io/x/cloudmux/pkg/apis/compute" 22 "yunion.io/x/cloudmux/pkg/cloudprovider" 23 "yunion.io/x/cloudmux/pkg/multicloud" 24 ) 25 26 type SZone struct { 27 multicloud.SResourceBase 28 InCloudSphereTags 29 30 region *SRegion 31 32 Id string `json:"id"` 33 Name string `json:"name"` 34 NFSPath string `json:"nfsPath"` 35 Type string `json:"type"` 36 Description string `json:"description"` 37 HostNum int64 `json:"hostNum"` 38 VMNum int64 `json:"vmNum"` 39 ClusterNum int64 `json:"clusterNum"` 40 CfsDomainNum int64 `json:"cfsDomainNum"` 41 StorageNum int64 `json:"storageNum"` 42 ImageISONum int64 `json:"imageIsoNum"` 43 NetNum int64 `json:"netNum"` 44 NeutronNetNum int64 `json:"neutronNetNum"` 45 CPUCapacity string `json:"cpuCapacity"` 46 CPUAvailable string `json:"cpuAvailable"` 47 CPUUsed string `json:"cpuUsed"` 48 CPUUtilization string `json:"cpuUtilization"` 49 MemoryCapacity string `json:"memoryCapacity"` 50 MemoryAvailable string `json:"memoryAvailable"` 51 MemoryUsed string `json:"memoryUsed"` 52 MemoryUtilization string `json:"memoryUtilization"` 53 StorageCapacity string `json:"storageCapacity"` 54 StorageAvailable string `json:"storageAvailable"` 55 StorageUsed string `json:"storageUsed"` 56 StorageUtilization string `json:"storageUtilization"` 57 DatastoreNum int64 `json:"datastoreNum"` 58 LocalstoreNum int64 `json:"localstoreNum"` 59 CfsstoreNum int64 `json:"cfsstoreNum"` 60 RawstoreNum int64 `json:"rawstoreNum"` 61 NfsstoreNum int64 `json:"nfsstoreNum"` 62 XactivestoreNum int64 `json:"xactivestoreNum"` 63 NetworkType string `json:"networkType"` 64 VswitchDtos string `json:"vswitchDtos"` 65 //SDNNetworkDtos []interface{} `json:"sdnNetworkDtos"` 66 SDNInit bool `json:"sdnInit"` 67 SDNSpeedUp bool `json:"sdnSpeedUp"` 68 SDNConfigDto string `json:"sdnConfigDto"` 69 } 70 71 func (self *SZone) GetId() string { 72 return self.Id 73 } 74 75 func (self *SZone) GetGlobalId() string { 76 return self.Id 77 } 78 79 func (self *SZone) GetName() string { 80 return self.Name 81 } 82 83 func (self *SZone) GetIRegion() cloudprovider.ICloudRegion { 84 return self.region 85 } 86 87 func (self *SZone) GetStatus() string { 88 return api.ZONE_ENABLE 89 } 90 91 func (self *SZone) GetI18n() cloudprovider.SModelI18nTable { 92 table := cloudprovider.SModelI18nTable{} 93 table["name"] = cloudprovider.NewSModelI18nEntry(self.GetName()).CN(self.GetName()) 94 return table 95 } 96 97 func (self *SZone) GetIHostById(id string) (cloudprovider.ICloudHost, error) { 98 host, err := self.region.GetHost(id) 99 if err != nil { 100 return nil, err 101 } 102 host.zone = self 103 if host.DataCenterId != self.Id { 104 return nil, cloudprovider.ErrNotFound 105 } 106 return host, nil 107 } 108 109 func (self *SZone) GetIHosts() ([]cloudprovider.ICloudHost, error) { 110 hosts, err := self.region.GetHosts(self.Id) 111 if err != nil { 112 return nil, err 113 } 114 ret := []cloudprovider.ICloudHost{} 115 for i := range hosts { 116 hosts[i].zone = self 117 ret = append(ret, &hosts[i]) 118 } 119 return ret, nil 120 } 121 122 func (self *SZone) GetIStorages() ([]cloudprovider.ICloudStorage, error) { 123 storages, err := self.region.GetStoragesByDc(self.Id) 124 if err != nil { 125 return nil, err 126 } 127 ret := []cloudprovider.ICloudStorage{} 128 for i := range storages { 129 storages[i].zone = self 130 ret = append(ret, &storages[i]) 131 } 132 return ret, nil 133 } 134 135 func (self *SZone) GetIStorageById(id string) (cloudprovider.ICloudStorage, error) { 136 storage, err := self.region.GetStorage(id) 137 if err != nil { 138 return nil, err 139 } 140 if storage.DataCenterId != self.Id { 141 return nil, cloudprovider.ErrNotFound 142 } 143 storage.zone = self 144 return storage, nil 145 } 146 147 func (self *SRegion) GetZones() ([]SZone, error) { 148 ret := []SZone{} 149 return ret, self.list("/datacenters", url.Values{}, &ret) 150 } 151 152 func (self *SRegion) GetZone(id string) (*SZone, error) { 153 ret := &SZone{region: self} 154 res := fmt.Sprintf("/datacenters/%s", id) 155 return ret, self.get(res, url.Values{}, ret) 156 }