yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/zstack/image_server.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 zstack 16 17 import "net/url" 18 19 type ImageServers []SImageServer 20 21 type SImageServer struct { 22 ZStackBasic 23 24 Hostname string `json:"hostname"` 25 Username string `json:"username"` 26 SSHPort int `json:"sshPort"` 27 URL string `json:"url"` 28 TotalCapacity int `json:"totalCapacity"` 29 AvailableCapacity int `json:"availableCapacity"` 30 Type string `json:"type"` 31 State string `json:"state"` 32 Status string `json:"status"` 33 AttachedZoneUUIDs []string `json:"attachedZoneUuids"` 34 ZStackTime 35 } 36 37 func (v ImageServers) Len() int { 38 return len(v) 39 } 40 41 func (v ImageServers) Swap(i, j int) { 42 v[i], v[j] = v[j], v[i] 43 } 44 45 func (v ImageServers) Less(i, j int) bool { 46 if v[i].AvailableCapacity < v[j].AvailableCapacity { 47 return false 48 } 49 return true 50 } 51 52 func (region *SRegion) GetImageServers(zoneId, serverId string) ([]SImageServer, error) { 53 servers := []SImageServer{} 54 params := url.Values{} 55 params.Add("q", "state=Enabled") 56 params.Add("q", "status=Connected") 57 if SkipEsxi { 58 params.Add("q", "type!=VCenter") 59 } 60 if len(zoneId) > 0 { 61 params.Add("q", "zone.uuid="+zoneId) 62 } 63 if len(serverId) > 0 { 64 params.Add("q", "uuid="+serverId) 65 } 66 return servers, region.client.listAll("backup-storage", params, &servers) 67 }