yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/incloudsphere/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 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 SWire struct { 27 multicloud.SResourceBase 28 InCloudSphereTags 29 30 region *SRegion 31 32 Id string `json:"id"` 33 Name string `json:"name"` 34 ResourceId string `json:"resourceId"` 35 ControllerIP string `json:"controllerIP"` 36 DataCenterDto SZone `json:"dataCenterDto"` 37 HostDtos []SHost `json:"hostDtos"` 38 SwitchType string `json:"switchType"` 39 AppType string `json:"appType"` 40 Description string `json:"description"` 41 NetworkDtos string `json:"networkDtos"` 42 SdnNetworkDtos string `json:"sdnNetworkDtos"` 43 VMDtos string `json:"vmDtos"` 44 HostNum int `json:"hostNum"` 45 PnicNum int `json:"pnicNum"` 46 NetworkNum int `json:"networkNum"` 47 VMNum int `json:"vmNum"` 48 Maxvfs int `json:"maxvfs"` 49 ThirdPartySDN bool `json:"thirdPartySDN"` 50 Hierarchy bool `json:"hierarchy"` 51 ConnectStorage bool `json:"connectStorage"` 52 ConnectManage bool `json:"connectManage"` 53 ConnectSwitches string `json:"connectSwitches"` 54 DhcpProtection bool `json:"dhcpProtection"` 55 NeutronName string `json:"neutronName"` 56 NeutronPassword string `json:"neutronPassword"` 57 ConnectScvm bool `json:"connectScvm"` 58 SwitchUplinkType string `json:"switchUplinkType"` 59 ComputerNetNum int `json:"computerNetNum"` 60 DataNetNum int `json:"dataNetNum"` 61 MigrateNetNum int `json:"migrateNetNum"` 62 VMMigBandWidth string `json:"vmMigBandWidth"` 63 EnableDpdk bool `json:"enableDpdk"` 64 SflowStatus bool `json:"sflowStatus"` 65 NetflowStatus bool `json:"netflowStatus"` 66 MulticastStatus bool `json:"multicastStatus"` 67 MirrorStatus bool `json:"mirrorStatus"` 68 BrLimitStatus bool `json:"brLimitStatus"` 69 Hidden bool `json:"hidden"` 70 NetworkTopoly bool `json:"networkTopoly"` 71 } 72 73 func (self *SWire) GetName() string { 74 return self.Name 75 } 76 77 func (self *SWire) GetId() string { 78 return self.Id 79 } 80 81 func (self *SWire) GetGlobalId() string { 82 return self.GetId() 83 } 84 85 func (self *SWire) CreateINetwork(opts *cloudprovider.SNetworkCreateOptions) (cloudprovider.ICloudNetwork, error) { 86 return nil, cloudprovider.ErrNotSupported 87 } 88 89 func (self *SWire) GetBandwidth() int { 90 return 10000 91 } 92 93 func (self *SWire) GetINetworks() ([]cloudprovider.ICloudNetwork, error) { 94 nets, err := self.region.GetNetworks(self.Id) 95 if err != nil { 96 return nil, err 97 } 98 ret := []cloudprovider.ICloudNetwork{} 99 for i := range nets { 100 nets[i].wire = self 101 ret = append(ret, &nets[i]) 102 } 103 return ret, nil 104 } 105 106 func (self *SWire) GetINetworkById(id string) (cloudprovider.ICloudNetwork, error) { 107 net, err := self.region.GetNetwork(id) 108 if err != nil { 109 return nil, err 110 } 111 net.wire = self 112 if net.VswitchDto.Id != self.Id { 113 return nil, cloudprovider.ErrNotFound 114 } 115 return net, nil 116 } 117 118 func (self *SWire) GetIVpc() cloudprovider.ICloudVpc { 119 return self.region.getVpc() 120 } 121 122 func (self *SWire) GetIZone() cloudprovider.ICloudZone { 123 zone, _ := self.region.GetZone(self.DataCenterDto.Id) 124 return zone 125 } 126 127 func (self *SWire) GetStatus() string { 128 return api.WIRE_STATUS_AVAILABLE 129 } 130 131 func (self *SRegion) GetWires() ([]SWire, error) { 132 ret := []SWire{} 133 return ret, self.list("/vswitchs", url.Values{}, &ret) 134 } 135 136 func (self *SRegion) GetWiresByDs(dsId string) ([]SWire, error) { 137 ret := []SWire{} 138 res := fmt.Sprintf("/datacenters/%s/vswitchs", dsId) 139 return ret, self.list(res, url.Values{}, &ret) 140 } 141 142 func (self *SRegion) GetWire(id string) (*SWire, error) { 143 ret := &SWire{region: self} 144 res := fmt.Sprintf("/vswitchs/%s", id) 145 return ret, self.get(res, url.Values{}, ret) 146 }