host.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  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 nutanix
  15. import (
  16. "strconv"
  17. "yunion.io/x/jsonutils"
  18. "yunion.io/x/pkg/errors"
  19. api "yunion.io/x/cloudmux/pkg/apis/compute"
  20. "yunion.io/x/cloudmux/pkg/cloudprovider"
  21. "yunion.io/x/cloudmux/pkg/multicloud"
  22. )
  23. type SHost struct {
  24. multicloud.STagBase
  25. multicloud.SHostBase
  26. firstHost bool
  27. zone *SZone
  28. ServiceVmid string `json:"service_vmid"`
  29. UUID string `json:"uuid"`
  30. DiskHardwareConfigs DiskHardwareConfigs `json:"disk_hardware_configs"`
  31. Name string `json:"name"`
  32. ServiceVmexternalIP string `json:"service_vmexternal_ip"`
  33. ServiceVmnatIP string `json:"service_vmnat_ip"`
  34. ServiceVmnatPort string `json:"service_vmnat_port"`
  35. OplogDiskPct float64 `json:"oplog_disk_pct"`
  36. OplogDiskSize int64 `json:"oplog_disk_size"`
  37. HypervisorKey string `json:"hypervisor_key"`
  38. HypervisorAddress string `json:"hypervisor_address"`
  39. HypervisorUsername string `json:"hypervisor_username"`
  40. HypervisorPassword string `json:"hypervisor_password"`
  41. BackplaneIP string `json:"backplane_ip"`
  42. ControllerVMBackplaneIP string `json:"controller_vm_backplane_ip"`
  43. RdmaBackplaneIps string `json:"rdma_backplane_ips"`
  44. ManagementServerName string `json:"management_server_name"`
  45. IpmiAddress string `json:"ipmi_address"`
  46. IpmiUsername string `json:"ipmi_username"`
  47. IpmiPassword string `json:"ipmi_password"`
  48. Monitored bool `json:"monitored"`
  49. Position Position `json:"position"`
  50. Serial string `json:"serial"`
  51. BlockSerial string `json:"block_serial"`
  52. BlockModel string `json:"block_model"`
  53. BlockModelName string `json:"block_model_name"`
  54. BlockLocation string `json:"block_location"`
  55. HostMaintenanceModeReason string `json:"host_maintenance_mode_reason"`
  56. HypervisorState string `json:"hypervisor_state"`
  57. AcropolisConnectionState string `json:"acropolis_connection_state"`
  58. MetadataStoreStatus string `json:"metadata_store_status"`
  59. MetadataStoreStatusMessage string `json:"metadata_store_status_message"`
  60. State string `json:"state"`
  61. DynamicRingChangingNode string `json:"dynamic_ring_changing_node"`
  62. RemovalStatus []string `json:"removal_status"`
  63. VzoneName string `json:"vzone_name"`
  64. CPUModel string `json:"cpu_model"`
  65. NumCPUCores int `json:"num_cpu_cores"`
  66. NumCPUThreads int `json:"num_cpu_threads"`
  67. NumCPUSockets int `json:"num_cpu_sockets"`
  68. CPUFrequencyInHz int64 `json:"cpu_frequency_in_hz"`
  69. CPUCapacityInHz int64 `json:"cpu_capacity_in_hz"`
  70. MemoryCapacityInBytes int64 `json:"memory_capacity_in_bytes"`
  71. HypervisorFullName string `json:"hypervisor_full_name"`
  72. HypervisorType string `json:"hypervisor_type"`
  73. NumVms int `json:"num_vms"`
  74. BootTimeInUsecs int64 `json:"boot_time_in_usecs"`
  75. IsDegraded bool `json:"is_degraded"`
  76. IsSecureBooted bool `json:"is_secure_booted"`
  77. IsHardwareVirtualized bool `json:"is_hardware_virtualized"`
  78. FailoverClusterFqdn string `json:"failover_cluster_fqdn"`
  79. FailoverClusterNodeState string `json:"failover_cluster_node_state"`
  80. RebootPending bool `json:"reboot_pending"`
  81. DefaultVMLocation string `json:"default_vm_location"`
  82. DefaultVMStorageContainerID string `json:"default_vm_storage_container_id"`
  83. DefaultVMStorageContainerUUID string `json:"default_vm_storage_container_uuid"`
  84. DefaultVhdLocation string `json:"default_vhd_location"`
  85. DefaultVhdStorageContainerID string `json:"default_vhd_storage_container_id"`
  86. DefaultVhdStorageContainerUUID string `json:"default_vhd_storage_container_uuid"`
  87. BiosVersion string `json:"bios_version"`
  88. BiosModel string `json:"bios_model"`
  89. BmcVersion string `json:"bmc_version"`
  90. BmcModel string `json:"bmc_model"`
  91. HbaFirmwaresList string `json:"hba_firmwares_list"`
  92. ClusterUUID string `json:"cluster_uuid"`
  93. Stats Stats `json:"stats"`
  94. UsageStats UsageStats `json:"usage_stats"`
  95. HasCsr bool `json:"has_csr"`
  96. HostNicIds []string `json:"host_nic_ids"`
  97. HostGpus string `json:"host_gpus"`
  98. GpuDriverVersion string `json:"gpu_driver_version"`
  99. HostType string `json:"host_type"`
  100. KeyManagementDeviceToCertificateStatus KeyManagementDeviceToCertificateStatus `json:"key_management_device_to_certificate_status"`
  101. HostInMaintenanceMode string `json:"host_in_maintenance_mode"`
  102. }
  103. type Num1 struct {
  104. SerialNumber string `json:"serial_number"`
  105. DiskID string `json:"disk_id"`
  106. DiskUUID string `json:"disk_uuid"`
  107. Location int `json:"location"`
  108. Bad bool `json:"bad"`
  109. Mounted bool `json:"mounted"`
  110. MountPath string `json:"mount_path"`
  111. Model string `json:"model"`
  112. Vendor string `json:"vendor"`
  113. BootDisk bool `json:"boot_disk"`
  114. OnlyBootDisk bool `json:"only_boot_disk"`
  115. UnderDiagnosis bool `json:"under_diagnosis"`
  116. BackgroundOperation string `json:"background_operation"`
  117. CurrentFirmwareVersion string `json:"current_firmware_version"`
  118. TargetFirmwareVersion string `json:"target_firmware_version"`
  119. CanAddAsNewDisk bool `json:"can_add_as_new_disk"`
  120. CanAddAsOldDisk bool `json:"can_add_as_old_disk"`
  121. }
  122. type Num2 struct {
  123. SerialNumber string `json:"serial_number"`
  124. DiskID string `json:"disk_id"`
  125. DiskUUID string `json:"disk_uuid"`
  126. Location int `json:"location"`
  127. Bad bool `json:"bad"`
  128. Mounted bool `json:"mounted"`
  129. MountPath string `json:"mount_path"`
  130. Model string `json:"model"`
  131. Vendor string `json:"vendor"`
  132. BootDisk bool `json:"boot_disk"`
  133. OnlyBootDisk bool `json:"only_boot_disk"`
  134. UnderDiagnosis bool `json:"under_diagnosis"`
  135. BackgroundOperation string `json:"background_operation"`
  136. CurrentFirmwareVersion string `json:"current_firmware_version"`
  137. TargetFirmwareVersion string `json:"target_firmware_version"`
  138. CanAddAsNewDisk bool `json:"can_add_as_new_disk"`
  139. CanAddAsOldDisk bool `json:"can_add_as_old_disk"`
  140. }
  141. type DiskHardwareConfigs struct {
  142. Num1 Num1 `json:"1"`
  143. Num2 Num2 `json:"2"`
  144. }
  145. type Position struct {
  146. Ordinal int `json:"ordinal"`
  147. Name string `json:"name"`
  148. PhysicalPosition string `json:"physical_position"`
  149. }
  150. type Stats struct {
  151. HypervisorAvgIoLatencyUsecs string `json:"hypervisor_avg_io_latency_usecs"`
  152. NumReadIops string `json:"num_read_iops"`
  153. HypervisorWriteIoBandwidthKBps string `json:"hypervisor_write_io_bandwidth_kBps"`
  154. TimespanUsecs string `json:"timespan_usecs"`
  155. ControllerNumReadIops string `json:"controller_num_read_iops"`
  156. ReadIoPpm string `json:"read_io_ppm"`
  157. ControllerNumIops string `json:"controller_num_iops"`
  158. TotalReadIoTimeUsecs string `json:"total_read_io_time_usecs"`
  159. ControllerTotalReadIoTimeUsecs string `json:"controller_total_read_io_time_usecs"`
  160. HypervisorNumIo string `json:"hypervisor_num_io"`
  161. ControllerTotalTransformedUsageBytes string `json:"controller_total_transformed_usage_bytes"`
  162. HypervisorCPUUsagePpm string `json:"hypervisor_cpu_usage_ppm"`
  163. ControllerNumWriteIo string `json:"controller_num_write_io"`
  164. AvgReadIoLatencyUsecs string `json:"avg_read_io_latency_usecs"`
  165. ContentCacheLogicalSsdUsageBytes string `json:"content_cache_logical_ssd_usage_bytes"`
  166. ControllerTotalIoTimeUsecs string `json:"controller_total_io_time_usecs"`
  167. ControllerTotalReadIoSizeKbytes string `json:"controller_total_read_io_size_kbytes"`
  168. ControllerNumSeqIo string `json:"controller_num_seq_io"`
  169. ControllerReadIoPpm string `json:"controller_read_io_ppm"`
  170. ContentCacheNumLookups string `json:"content_cache_num_lookups"`
  171. ControllerTotalIoSizeKbytes string `json:"controller_total_io_size_kbytes"`
  172. ContentCacheHitPpm string `json:"content_cache_hit_ppm"`
  173. ControllerNumIo string `json:"controller_num_io"`
  174. HypervisorAvgReadIoLatencyUsecs string `json:"hypervisor_avg_read_io_latency_usecs"`
  175. ContentCacheNumDedupRefCountPph string `json:"content_cache_num_dedup_ref_count_pph"`
  176. NumWriteIops string `json:"num_write_iops"`
  177. ControllerNumRandomIo string `json:"controller_num_random_io"`
  178. NumIops string `json:"num_iops"`
  179. HypervisorNumReadIo string `json:"hypervisor_num_read_io"`
  180. HypervisorTotalReadIoTimeUsecs string `json:"hypervisor_total_read_io_time_usecs"`
  181. ControllerAvgIoLatencyUsecs string `json:"controller_avg_io_latency_usecs"`
  182. NumIo string `json:"num_io"`
  183. ControllerNumReadIo string `json:"controller_num_read_io"`
  184. HypervisorNumWriteIo string `json:"hypervisor_num_write_io"`
  185. ControllerSeqIoPpm string `json:"controller_seq_io_ppm"`
  186. ControllerReadIoBandwidthKBps string `json:"controller_read_io_bandwidth_kBps"`
  187. ControllerIoBandwidthKBps string `json:"controller_io_bandwidth_kBps"`
  188. HypervisorNumReceivedBytes string `json:"hypervisor_num_received_bytes"`
  189. HypervisorTimespanUsecs string `json:"hypervisor_timespan_usecs"`
  190. HypervisorNumWriteIops string `json:"hypervisor_num_write_iops"`
  191. TotalReadIoSizeKbytes string `json:"total_read_io_size_kbytes"`
  192. HypervisorTotalIoSizeKbytes string `json:"hypervisor_total_io_size_kbytes"`
  193. AvgIoLatencyUsecs string `json:"avg_io_latency_usecs"`
  194. HypervisorNumReadIops string `json:"hypervisor_num_read_iops"`
  195. ContentCacheSavedSsdUsageBytes string `json:"content_cache_saved_ssd_usage_bytes"`
  196. ControllerWriteIoBandwidthKBps string `json:"controller_write_io_bandwidth_kBps"`
  197. ControllerWriteIoPpm string `json:"controller_write_io_ppm"`
  198. HypervisorAvgWriteIoLatencyUsecs string `json:"hypervisor_avg_write_io_latency_usecs"`
  199. HypervisorNumTransmittedBytes string `json:"hypervisor_num_transmitted_bytes"`
  200. HypervisorTotalReadIoSizeKbytes string `json:"hypervisor_total_read_io_size_kbytes"`
  201. ReadIoBandwidthKBps string `json:"read_io_bandwidth_kBps"`
  202. HypervisorMemoryUsagePpm string `json:"hypervisor_memory_usage_ppm"`
  203. HypervisorNumIops string `json:"hypervisor_num_iops"`
  204. HypervisorIoBandwidthKBps string `json:"hypervisor_io_bandwidth_kBps"`
  205. ControllerNumWriteIops string `json:"controller_num_write_iops"`
  206. TotalIoTimeUsecs string `json:"total_io_time_usecs"`
  207. ContentCachePhysicalSsdUsageBytes string `json:"content_cache_physical_ssd_usage_bytes"`
  208. ControllerRandomIoPpm string `json:"controller_random_io_ppm"`
  209. ControllerAvgReadIoSizeKbytes string `json:"controller_avg_read_io_size_kbytes"`
  210. TotalTransformedUsageBytes string `json:"total_transformed_usage_bytes"`
  211. AvgWriteIoLatencyUsecs string `json:"avg_write_io_latency_usecs"`
  212. NumReadIo string `json:"num_read_io"`
  213. WriteIoBandwidthKBps string `json:"write_io_bandwidth_kBps"`
  214. HypervisorReadIoBandwidthKBps string `json:"hypervisor_read_io_bandwidth_kBps"`
  215. RandomIoPpm string `json:"random_io_ppm"`
  216. TotalUntransformedUsageBytes string `json:"total_untransformed_usage_bytes"`
  217. HypervisorTotalIoTimeUsecs string `json:"hypervisor_total_io_time_usecs"`
  218. NumRandomIo string `json:"num_random_io"`
  219. ControllerAvgWriteIoSizeKbytes string `json:"controller_avg_write_io_size_kbytes"`
  220. ControllerAvgReadIoLatencyUsecs string `json:"controller_avg_read_io_latency_usecs"`
  221. NumWriteIo string `json:"num_write_io"`
  222. TotalIoSizeKbytes string `json:"total_io_size_kbytes"`
  223. IoBandwidthKBps string `json:"io_bandwidth_kBps"`
  224. ContentCachePhysicalMemoryUsageBytes string `json:"content_cache_physical_memory_usage_bytes"`
  225. ControllerTimespanUsecs string `json:"controller_timespan_usecs"`
  226. NumSeqIo string `json:"num_seq_io"`
  227. ContentCacheSavedMemoryUsageBytes string `json:"content_cache_saved_memory_usage_bytes"`
  228. SeqIoPpm string `json:"seq_io_ppm"`
  229. WriteIoPpm string `json:"write_io_ppm"`
  230. ControllerAvgWriteIoLatencyUsecs string `json:"controller_avg_write_io_latency_usecs"`
  231. ContentCacheLogicalMemoryUsageBytes string `json:"content_cache_logical_memory_usage_bytes"`
  232. }
  233. type UsageStats struct {
  234. StorageTierDasSataUsageBytes string `json:"storage_tier.das-sata.usage_bytes"`
  235. StorageCapacityBytes string `json:"storage.capacity_bytes"`
  236. StorageLogicalUsageBytes string `json:"storage.logical_usage_bytes"`
  237. StorageTierDasSataCapacityBytes string `json:"storage_tier.das-sata.capacity_bytes"`
  238. StorageFreeBytes string `json:"storage.free_bytes"`
  239. StorageTierSsdUsageBytes string `json:"storage_tier.ssd.usage_bytes"`
  240. StorageTierSsdCapacityBytes string `json:"storage_tier.ssd.capacity_bytes"`
  241. StorageTierDasSataFreeBytes string `json:"storage_tier.das-sata.free_bytes"`
  242. StorageUsageBytes string `json:"storage.usage_bytes"`
  243. StorageTierSsdFreeBytes string `json:"storage_tier.ssd.free_bytes"`
  244. }
  245. type KeyManagementDeviceToCertificateStatus struct {
  246. }
  247. func (self *SRegion) GetHosts() ([]SHost, error) {
  248. hosts := []SHost{}
  249. return hosts, self.listAll("hosts", nil, &hosts)
  250. }
  251. func (self *SRegion) GetHost(id string) (*SHost, error) {
  252. host := &SHost{}
  253. return host, self.cli.get("hosts", id, nil, host)
  254. }
  255. func (self *SHost) GetName() string {
  256. return self.Name
  257. }
  258. func (self *SHost) GetId() string {
  259. return self.UUID
  260. }
  261. func (self *SHost) GetGlobalId() string {
  262. return self.UUID
  263. }
  264. func (self *SHost) CreateVM(opts *cloudprovider.SManagedVMCreateConfig) (cloudprovider.ICloudVM, error) {
  265. image, err := self.zone.region.GetImage(opts.ExternalImageId)
  266. if err != nil {
  267. return nil, errors.Wrapf(err, "GetImage")
  268. }
  269. disks := []map[string]interface{}{
  270. {
  271. "disk_address": map[string]interface{}{
  272. "device_bus": "ide",
  273. "device_index": 0,
  274. },
  275. "is_cdrom": true,
  276. "is_empty": true,
  277. },
  278. {
  279. "disk_address": map[string]interface{}{
  280. "device_bus": "scsi",
  281. "device_index": 0,
  282. },
  283. "is_cdrom": false,
  284. "vm_disk_clone": map[string]interface{}{
  285. "disk_address": map[string]string{
  286. "vmdisk_uuid": image.VMDiskID,
  287. },
  288. "minimum_size": opts.SysDisk.SizeGB * 1024 * 1024 * 1024,
  289. },
  290. },
  291. }
  292. for i, disk := range opts.DataDisks {
  293. disks = append(disks, map[string]interface{}{
  294. "disk_address": map[string]interface{}{
  295. "device_bus": "scsi",
  296. "device_index": i + 1,
  297. },
  298. "is_cdrom": false,
  299. "vm_disk_create": map[string]interface{}{
  300. "size": disk.SizeGB * 1024 * 1024 * 1024,
  301. "storage_container_uuid": disk.StorageExternalId,
  302. },
  303. })
  304. }
  305. nic := map[string]interface{}{
  306. "network_uuid": opts.ExternalVpcId,
  307. }
  308. if len(opts.IpAddr) > 0 {
  309. nic["requested_ip_address"] = opts.IpAddr
  310. }
  311. params := map[string]interface{}{
  312. "boot": map[string]interface{}{
  313. "boot_device_order": []string{"CDROM", "DISK", "NIC"},
  314. "uefi_boot": false,
  315. },
  316. "description": opts.Description,
  317. "hypervisor_type": "ACROPOLIS",
  318. "memory_mb": opts.MemoryMB,
  319. "name": opts.Name,
  320. "num_cores_per_vcpu": 1,
  321. "num_vcpus": opts.Cpu,
  322. "timezone": "UTC",
  323. "vm_customization_config": map[string]interface{}{
  324. "files_to_inject_list": []string{},
  325. "userdata": opts.UserData,
  326. },
  327. "vm_disks": disks,
  328. "vm_features": map[string]interface{}{
  329. "AGENT_VM": false,
  330. },
  331. "vm_nics": []map[string]interface{}{
  332. nic,
  333. },
  334. }
  335. ret := struct {
  336. TaskUUID string
  337. }{}
  338. err = self.zone.region.post("vms", jsonutils.Marshal(params), &ret)
  339. if err != nil {
  340. return nil, err
  341. }
  342. resId, err := self.zone.region.cli.wait(ret.TaskUUID)
  343. if err != nil {
  344. return nil, err
  345. }
  346. vm, err := self.zone.region.GetInstance(resId)
  347. if err != nil {
  348. return nil, err
  349. }
  350. vm.host = self
  351. return vm, nil
  352. }
  353. func (self *SHost) GetAccessIp() string {
  354. return self.HypervisorAddress
  355. }
  356. func (self *SHost) GetAccessMac() string {
  357. return ""
  358. }
  359. func (self *SHost) GetCpuCmtbound() float32 {
  360. return 16.0
  361. }
  362. func (self *SHost) GetMemCmtbound() float32 {
  363. return 1.5
  364. }
  365. func (self *SHost) GetCpuCount() int {
  366. return self.NumCPUCores * self.NumCPUSockets
  367. }
  368. func (self *SHost) GetNodeCount() int8 {
  369. return int8(self.NumCPUSockets)
  370. }
  371. func (self *SHost) GetEnabled() bool {
  372. return true
  373. }
  374. func (self *SHost) GetCpuDesc() string {
  375. return self.CPUModel
  376. }
  377. func (self *SHost) GetCpuMhz() int {
  378. return int(self.CPUCapacityInHz / 1000 / 1000)
  379. }
  380. func (self *SHost) GetMemSizeMB() int {
  381. return int(self.MemoryCapacityInBytes / 1024 / 1024)
  382. }
  383. func (self *SHost) GetStorageSizeMB() int64 {
  384. sizeBytes, _ := strconv.Atoi(self.UsageStats.StorageCapacityBytes)
  385. return int64(sizeBytes) / 1024 / 1024
  386. }
  387. func (self *SHost) GetStorageType() string {
  388. return api.DISK_TYPE_HYBRID
  389. }
  390. func (self *SHost) GetHostType() string {
  391. return api.HOST_TYPE_NUTANIX
  392. }
  393. func (self *SHost) GetHostStatus() string {
  394. return api.HOST_ONLINE
  395. }
  396. func (host *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
  397. wires, err := host.getIWires()
  398. if err != nil {
  399. return nil, errors.Wrap(err, "GetIWires")
  400. }
  401. return cloudprovider.GetHostNetifs(host, wires), nil
  402. }
  403. func (self *SHost) GetIsMaintenance() bool {
  404. return false
  405. }
  406. func (self *SHost) GetVersion() string {
  407. return ""
  408. }
  409. func (self *SHost) GetStatus() string {
  410. return api.HOST_STATUS_RUNNING
  411. }
  412. func (self *SHost) GetSN() string {
  413. return ""
  414. }
  415. func (self *SHost) GetSysInfo() jsonutils.JSONObject {
  416. info := jsonutils.NewDict()
  417. info.Add(jsonutils.NewString(CLOUD_PROVIDER_NUTANIX), "manufacture")
  418. return info
  419. }
  420. func (self *SHost) IsEmulated() bool {
  421. return false
  422. }
  423. func (self *SHost) Refresh() error {
  424. host, err := self.zone.region.GetHost(self.UUID)
  425. if err != nil {
  426. return err
  427. }
  428. return jsonutils.Update(self, host)
  429. }
  430. func (self *SHost) GetIStorages() ([]cloudprovider.ICloudStorage, error) {
  431. return self.zone.GetIStorages()
  432. }
  433. func (self *SHost) GetIStorageById(id string) (cloudprovider.ICloudStorage, error) {
  434. return self.zone.GetIStorageById(id)
  435. }
  436. func (self *SHost) GetIVMs() ([]cloudprovider.ICloudVM, error) {
  437. vms, err := self.zone.region.GetInstances()
  438. if err != nil {
  439. return nil, errors.Wrapf(err, "GetInstances")
  440. }
  441. ret := []cloudprovider.ICloudVM{}
  442. for i := range vms {
  443. if vms[i].HostUUID == self.UUID || (self.firstHost && len(vms[i].HostUUID) == 0) {
  444. vms[i].host = self
  445. ret = append(ret, &vms[i])
  446. }
  447. }
  448. return ret, nil
  449. }
  450. func (self *SHost) GetIVMById(id string) (cloudprovider.ICloudVM, error) {
  451. vm, err := self.zone.region.GetInstance(id)
  452. if err != nil {
  453. return nil, errors.Wrapf(err, "GetInstance")
  454. }
  455. if len(vm.HostUUID) > 0 && vm.HostUUID != self.UUID {
  456. return nil, errors.Wrapf(cloudprovider.ErrNotFound, "vm not locate host %s, it locate host %s", self.Name, vm.HostUUID)
  457. }
  458. vm.host = self
  459. return vm, nil
  460. }
  461. func (self *SHost) getIWires() ([]cloudprovider.ICloudWire, error) {
  462. vpcs, err := self.zone.region.GetIVpcs()
  463. if err != nil {
  464. return nil, err
  465. }
  466. ret := []cloudprovider.ICloudWire{}
  467. for i := range vpcs {
  468. wires, err := vpcs[i].GetIWires()
  469. if err != nil {
  470. return nil, errors.Wrapf(err, "GetIWires")
  471. }
  472. ret = append(ret, wires...)
  473. }
  474. return ret, nil
  475. }