yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/bingocloud/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 bingocloud 16 17 import "yunion.io/x/cloudmux/pkg/cloudprovider" 18 19 type SInstanceNic struct { 20 Association string `json:"association"` 21 Attachment struct { 22 AttachTime string `json:"attachTime"` 23 AttachmentId string `json:"attachmentId"` 24 DeleteOnTermination string `json:"deleteOnTermination"` 25 DeviceIndex string `json:"deviceIndex"` 26 InstanceId string `json:"instanceId"` 27 InstanceOwnerId string `json:"instanceOwnerId"` 28 Status string `json:"status"` 29 } `json:"attachment"` 30 AvailabilityZone string `json:"availabilityZone"` 31 Description string `json:"description"` 32 FirstPacketLimit string `json:"firstPacketLimit"` 33 MACAddress string `json:"macAddress"` 34 Model string `json:"model"` 35 NetworkInterfaceId string `json:"networkInterfaceId"` 36 NoMatchPort string `json:"noMatchPort"` 37 OwnerId string `json:"ownerId"` 38 PrivateDNSName string `json:"privateDnsName"` 39 PrivateIPAddress string `json:"privateIpAddress"` 40 PrivateIPAddressesSet []struct { 41 Association string `json:"association"` 42 Primary string `json:"primary"` 43 PrivateDNSName string `json:"privateDnsName"` 44 PrivateIPAddress string `json:"privateIpAddress"` 45 } `json:"privateIpAddressesSet"` 46 RequesterManaged string `json:"requesterManaged"` 47 SourceDestCheck string `json:"sourceDestCheck"` 48 Status string `json:"status"` 49 SubnetId string `json:"subnetId"` 50 VpcId string `json:"vpcId"` 51 } 52 53 func (self *SInstanceNic) GetId() string { 54 return self.NetworkInterfaceId 55 } 56 57 func (self *SInstanceNic) GetIP() string { 58 return self.PrivateIPAddress 59 } 60 61 func (self *SInstanceNic) GetMAC() string { 62 return self.MACAddress 63 } 64 65 func (self *SInstanceNic) InClassicNetwork() bool { 66 return false 67 } 68 69 func (self *SInstanceNic) GetDriver() string { 70 return self.Model 71 } 72 73 func (self *SInstanceNic) GetINetworkId() string { 74 return self.SubnetId 75 } 76 77 func (self *SInstanceNic) GetSubAddress() ([]string, error) { 78 ret := []string{} 79 for _, ip := range self.PrivateIPAddressesSet { 80 if ip.PrivateIPAddress != self.PrivateIPAddress { 81 ret = append(ret, ip.PrivateIPAddress) 82 } 83 } 84 return ret, nil 85 } 86 87 func (self *SInstanceNic) AssignNAddress(count int) ([]string, error) { 88 return nil, cloudprovider.ErrNotImplemented 89 } 90 91 func (self *SInstanceNic) AssignAddress(ipAddrs []string) error { 92 return cloudprovider.ErrNotImplemented 93 } 94 95 func (self *SInstanceNic) UnassignAddress(ipAddrs []string) error { 96 return cloudprovider.ErrNotImplemented 97 } 98 99 func (self *SRegion) GetInstanceNics(insId string) ([]SInstanceNic, error) { 100 params := map[string]string{} 101 if len(insId) > 0 { 102 params["instanceId"] = insId 103 } 104 resp, err := self.invoke("DescribeNetworkInterfaces", params) 105 if err != nil { 106 return nil, err 107 } 108 ret := struct { 109 NetworkInterfaceSet []SInstanceNic 110 }{} 111 resp.Unmarshal(&ret) 112 return ret.NetworkInterfaceSet, nil 113 }