multicloud: ICloudNic: fix GetMAC()

This commit is contained in:
Yousong Zhou
2020-11-26 21:18:58 +08:00
parent 9f31365416
commit 1569966aa3
12 changed files with 51 additions and 38 deletions
+10 -3
View File
@@ -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
+2 -4
View File
@@ -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 {
+10 -3
View File
@@ -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
+2 -4
View File
@@ -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 {
+10 -3
View File
@@ -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
+2 -4
View File
@@ -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 {
-4
View File
@@ -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)
}
+1 -4
View File
@@ -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 {
+5 -1
View File
@@ -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)
}
}
+2 -3
View File
@@ -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 {
+5 -1
View File
@@ -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)
}
+2 -4
View File
@@ -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 {