yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/esxi/fakeregion.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 esxi 16 17 import ( 18 "yunion.io/x/pkg/errors" 19 "yunion.io/x/pkg/utils" 20 21 api "yunion.io/x/cloudmux/pkg/apis/compute" 22 "yunion.io/x/cloudmux/pkg/cloudprovider" 23 ) 24 25 func (cli *SESXiClient) GetISnapshots() ([]cloudprovider.ICloudSnapshot, error) { 26 return nil, cloudprovider.ErrNotSupported 27 } 28 29 func (cli *SESXiClient) GetISnapshotById(snapshotId string) (cloudprovider.ICloudSnapshot, error) { 30 return nil, cloudprovider.ErrNotSupported 31 } 32 33 func (cli *SESXiClient) GetIHosts() ([]cloudprovider.ICloudHost, error) { 34 dcs, err := cli.GetDatacenters() 35 if err != nil { 36 return nil, err 37 } 38 39 ihosts := make([]cloudprovider.ICloudHost, 0) 40 for i := 0; i < len(dcs); i += 1 { 41 dcIHosts, err := dcs[i].GetIHosts() 42 if err != nil { 43 return nil, err 44 } 45 ihosts = append(ihosts, dcIHosts...) 46 } 47 return ihosts, nil 48 } 49 50 func (cli *SESXiClient) GetIVMById(id string) (cloudprovider.ICloudVM, error) { 51 hosts, err := cli.GetIHosts() 52 if err != nil { 53 return nil, err 54 } 55 for _, host := range hosts { 56 vm, err := host.GetIVMById(id) 57 if errors.Cause(err) != cloudprovider.ErrNotFound { 58 return vm, err 59 } 60 } 61 return nil, cloudprovider.ErrNotFound 62 } 63 64 func (self *SESXiClient) GetIDiskById(id string) (cloudprovider.ICloudDisk, error) { 65 storages, err := self.GetIStorages() 66 if err != nil { 67 return nil, err 68 } 69 for _, storage := range storages { 70 disk, err := storage.GetIDiskById(id) 71 if errors.Cause(err) != cloudprovider.ErrNotFound { 72 return disk, err 73 } 74 } 75 return nil, cloudprovider.ErrNotFound 76 } 77 78 func (cli *SESXiClient) GetIHostById(id string) (cloudprovider.ICloudHost, error) { 79 return cli.FindHostByIp(id) 80 } 81 82 func (cli *SESXiClient) GetIStorages() ([]cloudprovider.ICloudStorage, error) { 83 dcs, err := cli.GetDatacenters() 84 if err != nil { 85 return nil, err 86 } 87 88 iStorages := make([]cloudprovider.ICloudStorage, 0) 89 for i := 0; i < len(dcs); i += 1 { 90 dcIStorages, err := dcs[i].GetIStorages() 91 if err != nil { 92 return nil, err 93 } 94 iStorages = append(iStorages, dcIStorages...) 95 } 96 return iStorages, nil 97 } 98 99 func (cli *SESXiClient) GetIStorageById(id string) (cloudprovider.ICloudStorage, error) { 100 iStorages, err := cli.GetIStorages() 101 if err != nil { 102 return nil, err 103 } 104 for i := 0; i < len(iStorages); i += 1 { 105 if iStorages[i].GetGlobalId() == id { 106 return iStorages[i], nil 107 } 108 } 109 return nil, cloudprovider.ErrNotFound 110 } 111 112 func (cli *SESXiClient) GetProvider() string { 113 return api.CLOUD_PROVIDER_VMWARE 114 } 115 116 func (cli *SESXiClient) GetIStoragecaches() ([]cloudprovider.ICloudStoragecache, error) { 117 storages, err := cli.GetIStorages() 118 if err != nil { 119 return nil, err 120 } 121 caches := make([]cloudprovider.ICloudStoragecache, 0) 122 cacheIds := make([]string, 0) 123 for i := range storages { 124 iCache := storages[i].GetIStoragecache() 125 if !utils.IsInStringArray(iCache.GetGlobalId(), cacheIds) { 126 caches = append(caches, iCache) 127 cacheIds = append(cacheIds, iCache.GetGlobalId()) 128 } 129 } 130 return caches, nil 131 } 132 133 func (cli *SESXiClient) GetIStoragecacheById(idstr string) (cloudprovider.ICloudStoragecache, error) { 134 caches, err := cli.GetIStoragecaches() 135 if err != nil { 136 return nil, err 137 } 138 for i := range caches { 139 if caches[i].GetGlobalId() == idstr { 140 return caches[i], nil 141 } 142 } 143 return nil, cloudprovider.ErrNotFound 144 } 145 146 func (cli *SESXiClient) GetISkus() ([]cloudprovider.ICloudSku, error) { 147 return nil, cloudprovider.ErrNotSupported 148 } 149 150 func (cli *SESXiClient) GetILoadBalancerBackendGroups() ([]cloudprovider.ICloudLoadbalancerBackendGroup, error) { 151 return nil, cloudprovider.ErrNotImplemented 152 }