yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/zstack/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 zstack 16 17 import ( 18 "yunion.io/x/jsonutils" 19 "yunion.io/x/log" 20 21 "yunion.io/x/cloudmux/pkg/cloudprovider" 22 ) 23 24 type SInstanceNic struct { 25 instance *SInstance 26 27 UUID string `json:"uuid"` 28 VMInstanceUUID string `json:"vmInstanceUuid"` 29 L3NetworkUUID string `json:"l3NetworkUuid"` 30 IP string `json:"ip"` 31 Mac string `json:"mac"` 32 HypervisorType string `json:"hypervisorType"` 33 IPVersion int `json:"ipVersion"` 34 UsedIps []string `json:"usedIps"` 35 InternalName string `json:"internalName"` 36 DeviceID int `json:"deviceId"` 37 ZStackTime 38 39 cloudprovider.DummyICloudNic 40 } 41 42 func (nic *SInstanceNic) GetId() string { 43 return "" 44 } 45 46 func (nic *SInstanceNic) GetIP() string { 47 return nic.IP 48 } 49 50 func (nic *SInstanceNic) GetMAC() string { 51 return nic.Mac 52 } 53 54 func (nic *SInstanceNic) GetDriver() string { 55 return "virtio" 56 } 57 58 func (nic *SInstanceNic) InClassicNetwork() bool { 59 return false 60 } 61 62 func (nic *SInstanceNic) GetINetworkId() string { 63 networks, err := nic.instance.host.zone.region.GetNetworks(nic.instance.host.zone.UUID, "", nic.L3NetworkUUID, "") 64 if err != nil { 65 log.Errorf("failed to found networks for nic %v error: %v", jsonutils.Marshal(nic).String(), err) 66 return "" 67 } 68 for i := 0; i < len(networks); i++ { 69 if networks[i].Contains(nic.IP) { 70 return networks[i].L3NetworkUUID 71 } 72 } 73 return "" 74 }