diff --git a/pkg/multicloud/aliyun/instance.go b/pkg/multicloud/aliyun/instance.go index ac70bac3ec..067e6b279e 100644 --- a/pkg/multicloud/aliyun/instance.go +++ b/pkg/multicloud/aliyun/instance.go @@ -334,9 +334,16 @@ func (self *SInstance) GetIDisks() ([]cloudprovider.ICloudDisk, error) { } func (self *SInstance) GetINics() ([]cloudprovider.ICloudNic, error) { - nics := make([]cloudprovider.ICloudNic, 0) - for _, ip := range self.VpcAttributes.PrivateIpAddress.IpAddress { - nic := SInstanceNic{instance: self, ipAddr: ip} + var ( + networkInterfaces = self.NetworkInterfaces.NetworkInterface + nics []cloudprovider.ICloudNic + ) + for _, networkInterface := range networkInterfaces { + nic := SInstanceNic{ + instance: self, + ipAddr: networkInterface.PrimaryIpAddress, + macAddr: networkInterface.MacAddress, + } nics = append(nics, &nic) } return nics, nil diff --git a/pkg/multicloud/aliyun/instancenic.go b/pkg/multicloud/aliyun/instancenic.go index e8d2cd7b85..aa99b1f65c 100644 --- a/pkg/multicloud/aliyun/instancenic.go +++ b/pkg/multicloud/aliyun/instancenic.go @@ -15,14 +15,13 @@ package aliyun import ( - "yunion.io/x/pkg/util/netutils" - "yunion.io/x/onecloud/pkg/cloudprovider" ) type SInstanceNic struct { instance *SInstance ipAddr string + macAddr string } func (self *SInstanceNic) GetIP() string { @@ -30,8 +29,7 @@ func (self *SInstanceNic) GetIP() string { } func (self *SInstanceNic) GetMAC() string { - ip, _ := netutils.NewIPV4Addr(self.ipAddr) - return ip.ToMac("00:16:") + return self.macAddr } func (self *SInstanceNic) InClassicNetwork() bool { diff --git a/pkg/multicloud/apsara/instance.go b/pkg/multicloud/apsara/instance.go index 2b32661872..9ff6fc116b 100644 --- a/pkg/multicloud/apsara/instance.go +++ b/pkg/multicloud/apsara/instance.go @@ -334,9 +334,16 @@ func (self *SInstance) GetIDisks() ([]cloudprovider.ICloudDisk, error) { } func (self *SInstance) GetINics() ([]cloudprovider.ICloudNic, error) { - nics := make([]cloudprovider.ICloudNic, 0) - for _, ip := range self.VpcAttributes.PrivateIpAddress.IpAddress { - nic := SInstanceNic{instance: self, ipAddr: ip} + var ( + networkInterfaces = self.NetworkInterfaces.NetworkInterface + nics []cloudprovider.ICloudNic + ) + for _, networkInterface := range networkInterfaces { + nic := SInstanceNic{ + instance: self, + ipAddr: networkInterface.PrimaryIpAddress, + macAddr: networkInterface.MacAddress, + } nics = append(nics, &nic) } return nics, nil diff --git a/pkg/multicloud/apsara/instancenic.go b/pkg/multicloud/apsara/instancenic.go index 539a3da126..d84ea5400c 100644 --- a/pkg/multicloud/apsara/instancenic.go +++ b/pkg/multicloud/apsara/instancenic.go @@ -15,14 +15,13 @@ package apsara import ( - "yunion.io/x/pkg/util/netutils" - "yunion.io/x/onecloud/pkg/cloudprovider" ) type SInstanceNic struct { instance *SInstance ipAddr string + macAddr string } func (self *SInstanceNic) GetIP() string { @@ -30,8 +29,7 @@ func (self *SInstanceNic) GetIP() string { } func (self *SInstanceNic) GetMAC() string { - ip, _ := netutils.NewIPV4Addr(self.ipAddr) - return ip.ToMac("00:16:") + return self.macAddr } func (self *SInstanceNic) InClassicNetwork() bool { diff --git a/pkg/multicloud/aws/instance.go b/pkg/multicloud/aws/instance.go index c75b6352e0..a7e577722a 100644 --- a/pkg/multicloud/aws/instance.go +++ b/pkg/multicloud/aws/instance.go @@ -277,9 +277,16 @@ func (self *SInstance) GetIDisks() ([]cloudprovider.ICloudDisk, error) { } func (self *SInstance) GetINics() ([]cloudprovider.ICloudNic, error) { - nics := make([]cloudprovider.ICloudNic, 0) - for _, ip := range self.VpcAttributes.PrivateIpAddress.IpAddress { - nic := SInstanceNic{instance: self, ipAddr: ip} + var ( + networkInterfaces = self.NetworkInterfaces.NetworkInterface + nics = make([]cloudprovider.ICloudNic, 0) + ) + for _, networkInterface := range networkInterfaces { + nic := SInstanceNic{ + instance: self, + ipAddr: networkInterface.PrivateIpAddress, + macAddr: networkInterface.MacAddress, + } nics = append(nics, &nic) } return nics, nil diff --git a/pkg/multicloud/aws/instancenic.go b/pkg/multicloud/aws/instancenic.go index 5ebe2b7b11..ea22499f20 100644 --- a/pkg/multicloud/aws/instancenic.go +++ b/pkg/multicloud/aws/instancenic.go @@ -15,14 +15,13 @@ package aws import ( - "yunion.io/x/pkg/util/netutils" - "yunion.io/x/onecloud/pkg/cloudprovider" ) type SInstanceNic struct { instance *SInstance ipAddr string + macAddr string } func (self *SInstanceNic) GetIP() string { @@ -30,8 +29,7 @@ func (self *SInstanceNic) GetIP() string { } func (self *SInstanceNic) GetMAC() string { - ip, _ := netutils.NewIPV4Addr(self.ipAddr) - return ip.ToMac("00:16:") + return self.macAddr } func (self *SInstanceNic) InClassicNetwork() bool { diff --git a/pkg/multicloud/azure/instancenic.go b/pkg/multicloud/azure/instancenic.go index a1d9abc450..6470ec053a 100644 --- a/pkg/multicloud/azure/instancenic.go +++ b/pkg/multicloud/azure/instancenic.go @@ -85,10 +85,6 @@ func (self *SInstanceNic) Delete() error { func (self *SInstanceNic) GetMAC() string { mac := self.Properties.MacAddress - if len(mac) == 0 { - ip, _ := netutils.NewIPV4Addr(self.GetIP()) - return ip.ToMac("00:16:") - } return strings.Replace(strings.ToLower(mac), "-", ":", -1) } diff --git a/pkg/multicloud/ctyun/instancenic.go b/pkg/multicloud/ctyun/instancenic.go index d376939bc3..2ab7c4336c 100644 --- a/pkg/multicloud/ctyun/instancenic.go +++ b/pkg/multicloud/ctyun/instancenic.go @@ -17,7 +17,6 @@ package ctyun import ( "yunion.io/x/log" "yunion.io/x/pkg/errors" - "yunion.io/x/pkg/util/netutils" "yunion.io/x/onecloud/pkg/cloudprovider" ) @@ -45,9 +44,7 @@ func (self *SInstanceNic) GetIP() string { } func (self *SInstanceNic) GetMAC() string { - ipAddr := self.GetIP() - ip, _ := netutils.NewIPV4Addr(ipAddr) - return ip.ToMac("00:16:") + return self.MACAddr } func (self *SInstanceNic) GetDriver() string { diff --git a/pkg/multicloud/huawei/instance.go b/pkg/multicloud/huawei/instance.go index 0a00736aae..aa0ad21ea3 100644 --- a/pkg/multicloud/huawei/instance.go +++ b/pkg/multicloud/huawei/instance.go @@ -345,7 +345,11 @@ func (self *SInstance) GetINics() ([]cloudprovider.ICloudNic, error) { for _, ipAddresses := range self.Addresses { for _, ipAddress := range ipAddresses { if ipAddress.OSEXTIPSType == "fixed" { - nic := SInstanceNic{instance: self, ipAddr: ipAddress.Addr} + nic := SInstanceNic{ + instance: self, + ipAddr: ipAddress.Addr, + macAddr: ipAddress.OSEXTIPSMACMACAddr, + } nics = append(nics, &nic) } } diff --git a/pkg/multicloud/huawei/instancenic.go b/pkg/multicloud/huawei/instancenic.go index 3965da8cbe..047f3be3ff 100644 --- a/pkg/multicloud/huawei/instancenic.go +++ b/pkg/multicloud/huawei/instancenic.go @@ -16,7 +16,6 @@ package huawei import ( "yunion.io/x/log" - "yunion.io/x/pkg/util/netutils" "yunion.io/x/onecloud/pkg/cloudprovider" "yunion.io/x/onecloud/pkg/multicloud/huawei/client/modules" @@ -59,6 +58,7 @@ type FixedIP struct { type SInstanceNic struct { instance *SInstance ipAddr string + macAddr string } func (self *SInstanceNic) GetIP() string { @@ -66,8 +66,7 @@ func (self *SInstanceNic) GetIP() string { } func (self *SInstanceNic) GetMAC() string { - ip, _ := netutils.NewIPV4Addr(self.ipAddr) - return ip.ToMac("00:16:") + return self.macAddr } func (self *SInstanceNic) GetDriver() string { diff --git a/pkg/multicloud/ucloud/instance.go b/pkg/multicloud/ucloud/instance.go index 8c1e189fbd..f84758f766 100644 --- a/pkg/multicloud/ucloud/instance.go +++ b/pkg/multicloud/ucloud/instance.go @@ -300,7 +300,11 @@ func (self *SInstance) GetINics() ([]cloudprovider.ICloudNic, error) { continue } - nic := SInstanceNic{instance: self, ipAddr: ip.IP} + nic := SInstanceNic{ + instance: self, + ipAddr: ip.IP, + macAddr: ip.MAC, + } nics = append(nics, &nic) } diff --git a/pkg/multicloud/ucloud/instancenic.go b/pkg/multicloud/ucloud/instancenic.go index e1b1e994ea..7cbb126bc7 100644 --- a/pkg/multicloud/ucloud/instancenic.go +++ b/pkg/multicloud/ucloud/instancenic.go @@ -15,14 +15,13 @@ package ucloud import ( - "yunion.io/x/pkg/util/netutils" - "yunion.io/x/onecloud/pkg/cloudprovider" ) type SInstanceNic struct { instance *SInstance ipAddr string + macAddr string } func (self *SInstanceNic) GetIP() string { @@ -30,8 +29,7 @@ func (self *SInstanceNic) GetIP() string { } func (self *SInstanceNic) GetMAC() string { - ip, _ := netutils.NewIPV4Addr(self.ipAddr) - return ip.ToMac("00:16:") + return self.macAddr } func (self *SInstanceNic) GetDriver() string {