yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/nutanix/wire.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 nutanix 16 17 import ( 18 "yunion.io/x/pkg/errors" 19 20 api "yunion.io/x/cloudmux/pkg/apis/compute" 21 "yunion.io/x/cloudmux/pkg/cloudprovider" 22 "yunion.io/x/cloudmux/pkg/multicloud" 23 ) 24 25 type SWire struct { 26 multicloud.SResourceBase 27 multicloud.STagBase 28 29 vpc *SVpc 30 } 31 32 func (self *SWire) GetName() string { 33 return self.vpc.GetName() 34 } 35 36 func (self *SWire) GetId() string { 37 return self.vpc.GetId() 38 } 39 40 func (self *SWire) GetGlobalId() string { 41 return self.vpc.GetGlobalId() 42 } 43 44 func (self *SWire) IsEmulated() bool { 45 return true 46 } 47 48 func (self *SWire) CreateINetwork(opts *cloudprovider.SNetworkCreateOptions) (cloudprovider.ICloudNetwork, error) { 49 network, err := self.vpc.region.CreateNetwork(self.vpc.UUID, opts) 50 if err != nil { 51 return nil, errors.Wrapf(err, "CreateNetwork") 52 } 53 return network, nil 54 } 55 56 func (self *SWire) GetBandwidth() int { 57 return 10000 58 } 59 60 func (self *SWire) GetINetworks() ([]cloudprovider.ICloudNetwork, error) { 61 ret := []cloudprovider.ICloudNetwork{} 62 if len(self.vpc.IPConfig.Pool) == 0 { 63 network := &SNetwork{wire: self} 64 ret = append(ret, network) 65 } 66 for _, pool := range self.vpc.IPConfig.Pool { 67 network := &SNetwork{wire: self} 68 network.Range = pool.Range 69 ret = append(ret, network) 70 } 71 return ret, nil 72 } 73 74 func (self *SWire) GetINetworkById(netid string) (cloudprovider.ICloudNetwork, error) { 75 networks, err := self.GetINetworks() 76 if err != nil { 77 return nil, err 78 } 79 80 for i := range networks { 81 if networks[i].GetGlobalId() == netid { 82 return networks[i], nil 83 } 84 } 85 return nil, cloudprovider.ErrNotFound 86 } 87 88 func (self *SWire) GetIVpc() cloudprovider.ICloudVpc { 89 return self.vpc 90 } 91 92 func (self *SWire) GetIZone() cloudprovider.ICloudZone { 93 cluster := SCluster{} 94 err := self.vpc.region.get("cluster", "", nil, &cluster) 95 if err != nil { 96 return nil 97 } 98 return &SZone{SCluster: cluster, region: self.vpc.region} 99 } 100 101 func (self *SWire) GetStatus() string { 102 return api.WIRE_STATUS_AVAILABLE 103 }