mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 02:37:24 +08:00
feat(esxi): do not specify portkey in NewVNIC
This commit is contained in:
@@ -158,18 +158,23 @@ func NewVNICDev(host *SHost, mac, driver string, vlanId int32, key, ctlKey, inde
|
||||
var backing types.BaseVirtualDeviceBackingInfo
|
||||
switch inet.(type) {
|
||||
case *SDistributedVirtualPortgroup:
|
||||
// net := inet.(*SDistributedVirtualPortgroup)
|
||||
// port, err := net.FindPort()
|
||||
//if err != nil {
|
||||
// return nil, errors.Wrap(err, "net.FindPort")
|
||||
// }
|
||||
// if port == nil {
|
||||
// return nil, fmt.Errorf("no active port for dvportgroup %q", net.GetName())
|
||||
// }
|
||||
net := inet.(*SDistributedVirtualPortgroup)
|
||||
port, err := net.FindPort()
|
||||
dvpg := net.getMODVPortgroup()
|
||||
uuid, err := net.GetDVSUuid()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "net.FindPort")
|
||||
}
|
||||
if port == nil {
|
||||
return nil, errors.Error("no valid port on DVS, exhausted")
|
||||
return nil, errors.Wrap(err, "GetDVSUuid")
|
||||
}
|
||||
portCon := types.DistributedVirtualSwitchPortConnection{
|
||||
PortgroupKey: port.PortgroupKey,
|
||||
SwitchUuid: port.DvsUuid,
|
||||
PortKey: port.Key,
|
||||
PortgroupKey: dvpg.Key,
|
||||
SwitchUuid: uuid,
|
||||
}
|
||||
backing = &types.VirtualEthernetCardDistributedVirtualPortBackingInfo{Port: portCon}
|
||||
case *SNetwork:
|
||||
|
||||
@@ -43,7 +43,7 @@ const (
|
||||
)
|
||||
|
||||
var NETWORK_PROPS = []string{"name", "parent", "summary", "host", "vm"}
|
||||
var DVPORTGROUP_PROPS = []string{"name", "parent", "summary", "host", "vm", "config"}
|
||||
var DVPORTGROUP_PROPS = []string{"name", "parent", "summary", "host", "vm", "config", "key"}
|
||||
|
||||
type SNetwork struct {
|
||||
SManagedObject
|
||||
@@ -175,6 +175,16 @@ func (net *SDistributedVirtualPortgroup) Uplink() bool {
|
||||
return *dvpg.Config.Uplink
|
||||
}
|
||||
|
||||
func (net *SDistributedVirtualPortgroup) GetDVSUuid() (string, error) {
|
||||
dvgp := net.getMODVPortgroup()
|
||||
var dvs mo.DistributedVirtualSwitch
|
||||
err := net.manager.reference2Object(*dvgp.Config.DistributedVirtualSwitch, []string{"uuid"}, &dvs)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "reference2Object")
|
||||
}
|
||||
return dvs.Uuid, nil
|
||||
}
|
||||
|
||||
func (net *SDistributedVirtualPortgroup) FindPort() (*types.DistributedVirtualPort, error) {
|
||||
dvgp := net.getMODVPortgroup()
|
||||
odvs := object.NewDistributedVirtualSwitch(net.manager.client.Client, *dvgp.Config.DistributedVirtualSwitch)
|
||||
|
||||
Reference in New Issue
Block a user