yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/hcs/instancenic.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 hcs 16 17 import ( 18 "yunion.io/x/cloudmux/pkg/cloudprovider" 19 ) 20 21 // =========================================== 22 type Interface struct { 23 PortState string `json:"port_state"` 24 FixedIPS []FixedIP `json:"fixed_ips"` 25 NetId string `json:"net_id"` // 网络Id. 与 SNetwork里的Id对应。统一使用这个Id 26 PortId string `json:"port_id"` 27 MACAddr string `json:"mac_addr"` 28 } 29 30 type FixedIP struct { 31 SubnetId string `json:"subnet_id"` // 子网Id, 与SNetwork中的 neutron_subnet_id对应. 注意!!! 并不是SNetwork Id。 32 IPAddress string `json:"ip_address"` 33 } 34 35 type SInstanceNic struct { 36 instance *SInstance 37 ipAddr string 38 macAddr string 39 40 cloudprovider.DummyICloudNic 41 } 42 43 func (self *SInstanceNic) GetId() string { 44 return "" 45 } 46 47 func (self *SInstanceNic) GetIP() string { 48 return self.ipAddr 49 } 50 51 func (self *SInstanceNic) GetMAC() string { 52 return self.macAddr 53 } 54 55 func (self *SInstanceNic) GetDriver() string { 56 return "virtio" 57 } 58 59 func (self *SInstanceNic) InClassicNetwork() bool { 60 return false 61 } 62 63 func (self *SInstanceNic) GetINetworkId() string { 64 instanceId := self.instance.GetId() 65 subnets, _ := self.instance.host.zone.region.GetInstanceInterfaces(instanceId) 66 for i := range subnets { 67 return subnets[i].NetId 68 } 69 return "" 70 } 71 72 type SInstanceInterface struct { 73 NetId string 74 PortId string 75 MacAddr string 76 PortState string 77 FixedIps []struct { 78 SubnetId string 79 IpAddress string 80 } 81 } 82 83 func (self *SRegion) GetInstanceInterfaces(instanceId string) ([]SInstanceInterface, error) { 84 ret := []SInstanceInterface{} 85 return ret, self.get("ecs", "v2.1", "servers/"+instanceId+"/os-interface", &ret) 86 }