mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-10-24 02:26:39 +08:00
54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
package openstack
|
|
|
|
import (
|
|
"yunion.io/x/onecloud/pkg/cloudprovider"
|
|
)
|
|
|
|
type SInstanceNic struct {
|
|
instance *SInstance
|
|
MacAddr string `json:"OS-EXT-IPS-MAC:mac_addr"`
|
|
Version int `json:"version"`
|
|
Addr string `json:"addr"`
|
|
Type string `json:"OS-EXT-IPS:type"`
|
|
}
|
|
|
|
func (nic *SInstanceNic) GetIP() string {
|
|
return nic.Addr
|
|
}
|
|
|
|
func (nic *SInstanceNic) GetMAC() string {
|
|
return nic.MacAddr
|
|
}
|
|
|
|
func (nic *SInstanceNic) GetDriver() string {
|
|
return "virtio"
|
|
}
|
|
|
|
func (nic *SInstanceNic) GetINetwork() cloudprovider.ICloudNetwork {
|
|
ports, err := nic.instance.host.zone.region.GetPorts(nic.MacAddr)
|
|
if err == nil {
|
|
for i := 0; i < len(ports); i++ {
|
|
for j := 0; j < len(ports[i].FixedIps); j++ {
|
|
if ports[i].FixedIps[j].IpAddress == nic.Addr {
|
|
network, err := nic.instance.host.zone.region.GetNetwork(ports[i].FixedIps[j].SubnetID)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
wires, err := nic.instance.host.zone.GetIWires()
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
for k := 0; k < len(wires); k++ {
|
|
wire := wires[k].(*SWire)
|
|
if net, _ := wire.GetINetworkById(network.ID); net != nil {
|
|
return net
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return nil
|
|
}
|