VMware Cloud Community
kmzimm
Enthusiast
Enthusiast
Jump to solution

Attempting to move VMK NICs during vDS migration produces an error

I'm attempting to write some code that moves both physical NICs and VMK NICs to a vDS that replicates the "Add-VDSwitchPhysicalNetworkAdapter" cmdlet, but with specific uplinks chosen (LAG in use).
 
So far, this is what I have (with code borrowed from lucD):
 
$esxName = 'host01'
$vdsName = 'cluster01-mgmt'
 
$uplinkmapping = @(
("vmnic5","cluster01-mgmt-0"),
("vmnic7","cluster01-mgmt-1")
)
 
$esxiClusterName = "cluster01"
 
$vmkNics = @(
    ("vmk0","$esxiClusterName-esxmgmt-pri" ),
    ("vmk1","$esxiClusterName-iSCSI-1"),
    ("vmk2","$esxiClusterName-iSCSI-2"),
    ("vmk3","$esxiClusterName-vmotion-pri")
)
 
$esx = Get-VMHost -Name $esxName
$vds = Get-VDSwitch -Name $vdsName -VMHost $esx
$uplinks = Get-VDPort -VDSwitch $vds -Uplink | Where-Object {$_.ProxyHost -like $esxName}
$portgroups = Get-VDPortgroup -VDSwitch $vds
$netSys = Get-View -Id $esx.ExtensionData.ConfigManager.NetworkSystem
$config = New-Object VMware.Vim.HostNetworkConfig
$proxy = New-Object VMware.Vim.HostProxySwitchConfig
$proxy.Uuid = $vds.ExtensionData.Uuid
$proxy.ChangeOperation = [VMware.Vim.HostConfigChangeOperation]::edit
$proxy.Spec = New-Object VMware.Vim.HostProxySwitchSpec
$proxy.Spec.Backing = New-Object VMware.Vim.DistributedVirtualSwitchHostMemberPnicBacking
 
# Migrate Physical NICs.
 
foreach($uplink in $uplinkmapping){
 
    $pnic = New-Object VMware.Vim.DistributedVirtualSwitchHostMemberPnicSpec
    $pnic.PnicDevice = $uplink[0]
    $pnic.UplinkPortKey = $uplinks | Where-Object {$_.Name -eq $uplink[1]} | Select-Object -ExpandProperty Key
    $proxy.Spec.Backing.PnicSpec += $pnic
}
 
$config.ProxySwitch += $proxy
 
# Migrate vmk NICs.
 
foreach($vmkNic in $vmkNics){
    $vnic = New-Object VMware.Vim.HostVirtualNicConfig
    $vnic.ChangeOperation = [VMware.Vim.HostConfigChangeOperation]::edit
    $vnic.Device = $vmkNic[0]
    $vnic.Spec = New-Object VMware.Vim.HostVirtualNicSpec
    $vnic.Spec.DistributedVirtualPort = New-Object VMware.Vim.DistributedVirtualSwitchPortConnection
    $vnic.Spec.DistributedVirtualPort.SwitchUuid = $vds.ExtensionData.Uuid
    $vnic.Spec.DistributedVirtualPort.PortgroupKey = $portgroups | Where-Object {$_.Name -eq $vmkNic[1] } | Select-Object -ExpandProperty Key
    $config.Vnic += $vnic
}
 
 
$netSys.UpdateNetworkConfig($config,[VMware.Vim.HostConfigChangeMode]::modify)
 
The object I get back looks right, but I receive the following error back:
 
Exception calling "UpdateNetworkConfig" with "2" argument(s): "
Required property portgroup is missing from data object of type HostVirtualNicConfig
while parsing serialized DataObject of type vim.host.VirtualNic.Config
at line 1, column 661
while parsing property "vnic" of static type ArrayOfHostVirtualNicConfig
while parsing serialized DataObject of type vim.host.NetworkConfig
at line 1, column 266
while parsing call information for method UpdateNetworkConfig
at line 1, column 171
while parsing SOAP body
at line 1, column 64
while parsing SOAP envelope
at line 1, column 0
while parsing HTTP request for method updateNetworkConfig
on object of type vim.host.NetworkSystem
at line 1, column 0"
At line:1 char:1
+ $netSys.UpdateNetworkConfig($config,[VMware.Vim.HostConfigChangeMode] ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : VimException
 
 
 
According to the API, portgroup gets ignored, so I tried setting it to a blank value, a real PG name on the vSS, the vDS PG name, and as a blank:
 
foreach($vmkNic in $vmkNics){
    $vnic = New-Object VMware.Vim.HostVirtualNicConfig
    $vnic.ChangeOperation = [VMware.Vim.HostConfigChangeOperation]::edit
    $vnic.Device = $vmkNic[0]
$vnic.Portgroup = $vmkNic[1]
    $vnic.Spec = New-Object VMware.Vim.HostVirtualNicSpec
    $vnic.Spec.DistributedVirtualPort = New-Object VMware.Vim.DistributedVirtualSwitchPortConnection
    $vnic.Spec.DistributedVirtualPort.SwitchUuid = $vds.ExtensionData.Uuid
    $vnic.Spec.DistributedVirtualPort.PortgroupKey = $portgroups | Where-Object {$_.Name -eq $vmkNic[1] } | Select-Object -ExpandProperty Key
    $config.Vnic += $vnic
}
 
 
This returned the error:
 
Exception calling "UpdateNetworkConfig" with "2" argument(s): "A specified parameter was not correct: "
At line:1 char:1
+ $netSys.UpdateNetworkConfig($config,[VMware.Vim.HostConfigChangeMode] ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : VimException
 
At this point, I'm not sure if I'm way off track on how to do this, or if I'm missing something obvious. Any help would be appreciated.
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

See also Re: Assign vminc to Specific Uplink on VDS

That user seems to have experienced the same portgroup issue


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
12 Replies
kmzimm
Enthusiast
Enthusiast
Jump to solution

Sorry about the formatting. I fought the editor, and it won.
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did you check if there is actually anything in $uplinks?

$uplinks = Get-VDPort -VDSwitch $vds -Uplink | Where-Object {$_.ProxyHost -like $esxName}

If not, try replacing that line  with

$uplinks = Get-VDPort -VDSwitch $vds -Uplink | Where-Object {$_.ProxyHost.Name -like $esxName}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
kmzimm
Enthusiast
Enthusiast
Jump to solution

Thanks for the reply. Yes, we get data in $uplinks:

ExtensionData      : VMware.Vim.DistributedVirtualPort Key                : 800 Description        : IsBlocked          : False IsBlockedInherited : True IsLinkUp           : MacAddress         : VlanConfiguration  : VLAN Trunk [0-4094] ConnectedEntity    : ProxyHost          : host1 Portgroup          : cluster1-mgmt-DVUplinks-88 Switch             : cluster1-mgmt Name               : dvUplink1 Id                 : 800 Uid                : <removed>  ExtensionData      : VMware.Vim.DistributedVirtualPort Key                : 801 Description        : IsBlocked          : False IsBlockedInherited : True IsLinkUp           : MacAddress         : VlanConfiguration  : VLAN Trunk [0-4094] ConnectedEntity    : ProxyHost          : host1 Portgroup          : cluster1-mgmt-DVUplinks-88 Switch             : cluster1-mgmt Name               : dvUplink2 Id                 : 801 Uid                : <removed>  ExtensionData      : VMware.Vim.DistributedVirtualPort Key                : 802 Description        : IsBlocked          : False IsBlockedInherited : True IsLinkUp           : MacAddress         : VlanConfiguration  : VLAN Trunk [0-4094] ConnectedEntity    : ProxyHost          : host1 Portgroup          : cluster1-mgmt-DVUplinks-88 Switch             : cluster1-mgmt Name               : cluster1-mgmt-0 Id                 : 802 Uid                : <removed>  ExtensionData      : VMware.Vim.DistributedVirtualPort Key                : 803 Description        : IsBlocked          : False IsBlockedInherited : True IsLinkUp           : MacAddress         : VlanConfiguration  : VLAN Trunk [0-4094] ConnectedEntity    : ProxyHost          : host1 Portgroup          : cluster1-mgmt-DVUplinks-88 Switch             : cluster1-mgmt Name               : cluster1-mgmt-1 Id                 : 803 Uid                : <removed> 

 

And this is what ends up in $config.ProxySwitch[0].Spec.Backing:

PnicSpec : {802, 803}

You're right to zero in on that part of the code though. Just before you replied I commented out the VMK change portion and received the same error.

0 Kudos
kmzimm
Enthusiast
Enthusiast
Jump to solution

Well, that didn't work either, and I don't see any way to edit my post (what editor shows and what posts...not the same).

Here it is again in hopefully better format:

ExtensionData      : VMware.Vim.DistributedVirtualPort
Key                : 800
Description        :
IsBlocked          : False
IsBlockedInherited : True
IsLinkUp           :
MacAddress         :
VlanConfiguration  : VLAN Trunk [0-4094]
ConnectedEntity    :
ProxyHost          : host1
Portgroup          : cluster1-mgmt-DVUplinks-88
Switch             : cluster1-mgmt
Name               : dvUplink1
Id                 : 800
Uid                : <removed>

ExtensionData      : VMware.Vim.DistributedVirtualPort
Key                : 801
Description        :
IsBlocked          : False
IsBlockedInherited : True
IsLinkUp           :
MacAddress         :
VlanConfiguration  : VLAN Trunk [0-4094]
ConnectedEntity    :
ProxyHost          : host1
Portgroup          : cluster1-mgmt-DVUplinks-88
Switch             : cluster1-mgmt
Name               : dvUplink2
Id                 : 801
Uid                : <removed>

ExtensionData      : VMware.Vim.DistributedVirtualPort
Key                : 802
Description        :
IsBlocked          : False
IsBlockedInherited : True
IsLinkUp           :
MacAddress         :
VlanConfiguration  : VLAN Trunk [0-4094]
ConnectedEntity    :
ProxyHost          : host1
Portgroup          : cluster1-mgmt-DVUplinks-88
Switch             : cluster1-mgmt
Name               : cluster1-mgmt-0
Id                 : 802
Uid                : <removed>

ExtensionData      : VMware.Vim.DistributedVirtualPort
Key                : 803
Description        :
IsBlocked          : False
IsBlockedInherited : True
IsLinkUp           :
MacAddress         :
VlanConfiguration  : VLAN Trunk [0-4094]
ConnectedEntity    :
ProxyHost          : host1
Portgroup          : cluster1-mgmt-DVUplinks-88
Switch             : cluster1-mgmt
Name               : cluster1-mgmt-1
Id                 : 803
Uid                : <removed>

0 Kudos
LucD
Leadership
Leadership
Jump to solution

It could be useful to have a look at the vpxd log at the time of the error.

Sometimes there are more hints in there.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
LucD
Leadership
Leadership
Jump to solution

What would also help, is a formatted dump of the $config variable before the call.

Try with this at the end

$config | Format-Custom -Depth 4

#$netSys.UpdateNetworkConfig($config,[VMware.Vim.HostConfigChangeMode]::modify)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
kmzimm
Enthusiast
Enthusiast
Jump to solution

Here is what vCenter spits out when the operation is submitted:

2018-08-22T16:01:35.048-04:00 error vpxd[10316] [Originator@6876 sub=hostMethod] [HostMethodDispatcher::ProcessTaskResult] Host call [updateNetworkConfig]for host [host-15] failed with exception [vmodl.fault.InvalidArgument]
2018-08-22T16:01:35.056-04:00 verbose vpxd[12624] [Originator@6876 sub=Locale opID=7b62b85a] FormatField: Optional unset (vmodl.fault.InvalidArgument.invalidProperty)
2018-08-22T16:01:35.056-04:00 verbose vpxd[12624] [Originator@6876 sub=Locale opID=7b62b85a] FormatField: Optional unset (vmodl.fault.InvalidArgument.invalidProperty)
2018-08-22T16:01:35.056-04:00 verbose vpxd[12624] [Originator@6876 sub=Default opID=7b62b85a] [VpxVmomi] Invoke error: vim.host.NetworkSystem.updateNetworkConfig session: 52024164-cc8b-add4-ea65-6be6d1ea1bfa Throw: vmodl.fault.InvalidArgument 
2018-08-22T16:01:35.056-04:00 verbose vpxd[12624] [Originator@6876 sub=PropertyProvider opID=7b62b85a] RecordOp ASSIGN: info.state, task-284. Applied change to temp map.
2018-08-22T16:01:35.056-04:00 verbose vpxd[12624] [Originator@6876 sub=PropertyProvider opID=7b62b85a] RecordOp ASSIGN: info.cancelable, task-284. Applied change to temp map.
2018-08-22T16:01:35.056-04:00 verbose vpxd[12624] [Originator@6876 sub=PropertyProvider opID=7b62b85a] RecordOp ASSIGN: info.error, task-284. Applied change to temp map.
2018-08-22T16:01:35.056-04:00 verbose vpxd[12624] [Originator@6876 sub=PropertyProvider opID=7b62b85a] [CommitChangesAndNotify] Updating cached values
2018-08-22T16:01:35.056-04:00 info vpxd[12624] [Originator@6876 sub=vpxLro opID=7b62b85a] [VpxLRO] -- FINISH task-284
2018-08-22T16:01:35.056-04:00 info vpxd[12624] [Originator@6876 sub=Default opID=7b62b85a] [VpxLRO] -- ERROR task-284 -- networkSystem-15 -- vim.host.NetworkSystem.updateNetworkConfig: vmodl.fault.InvalidArgument:
--> Result:
--> (vmodl.fault.InvalidArgument) {
-->    faultCause = (vmodl.MethodFault) null, 
-->    invalidProperty = <unset>, 
-->    msg = "Received SOAP response fault from [<cs p:0000000008eb6e60, TCP:host1:443>]: invokeHostTransactionCall
--> Received SOAP response fault from [<cs p:1f3b16e8, TCP:localhost:8307>]: invokeHostTransactionCall
--> A specified parameter was not correct: "
--> }
--> Args:
--> 
--> Arg config:
--> (vim.host.NetworkConfig) {
-->    proxySwitch = (vim.host.HostProxySwitch.Config) [
-->       (vim.host.HostProxySwitch.Config) {
-->          changeOperation = "edit", 
-->          uuid = "a0 14 3f 50 1f 03 d6 50-78 6c 22 cc 2c e5 85 18", 
-->          spec = (vim.host.HostProxySwitch.Specification) {
-->             backing = (vim.dvs.HostMember.PnicBacking) {
-->                pnicSpec = (vim.dvs.HostMember.PnicSpec) [
-->                   (vim.dvs.HostMember.PnicSpec) {
-->                      pnicDevice = "vmnic5", 
-->                      uplinkPortKey = "802", 
-->                      uplinkPortgroupKey = <unset>, 
-->                      connectionCookie = 470509171
-->                   }, 
-->                   (vim.dvs.HostMember.PnicSpec) {
-->                      pnicDevice = "vmnic7", 
-->                      uplinkPortKey = "803", 
-->                      uplinkPortgroupKey = <unset>, 
-->                      connectionCookie = 470510171
-->                   }
-->                ]
-->             }
-->          }
-->       }
-->    ], 
-->    dnsConfig = (vim.host.DnsConfig) null, 
-->    ipRouteConfig = (vim.host.IpRouteConfig) null, 
-->    consoleIpRouteConfig = (vim.host.IpRouteConfig) null, 
-->    routeTableConfig = (vim.host.IpRouteTableConfig) null, 
-->    ipV6Enabled = <unset>, 
-->    ipSecConfig = (vim.host.IpSecConfig) null, 
-->    consoleIpSecConfig = (vim.host.IpSecConfig) null, 
--> }
--> Arg changeMode:
--> "modify"

 

This is the formatted $config object:

class HostNetworkConfig
{
  Vswitch =
  ProxySwitch =
    [
      class HostProxySwitchConfig
      {
        ChangeOperation = edit
        Uuid = a0 14 3f 50 1f 03 d6 50-78 6c 22 cc 2c e5 85 18
        Spec =
          class HostProxySwitchSpec
          {
            Backing =
              class DistributedVirtualSwitchHostMemberPnicBacking
              {
                PnicSpec =
                  [
                    VMware.Vim.DistributedVirtualSwitchHostMemberPnicSpec
                    VMware.Vim.DistributedVirtualSwitchHostMemberPnicSpec
                  ]

              }
          }
      }
    ]

  Portgroup =
  Pnic =
  Vnic =
  ConsoleVnic =
  DnsConfig =
  IpRouteConfig =
  ConsoleIpRouteConfig =
  RouteTableConfig =
  Dhcp =
  Nat =
  IpV6Enabled =
  NetStackSpec =
}

class HostNetworkConfig
{
  Vswitch =
  ProxySwitch =
    [
      class HostProxySwitchConfig
      {
        ChangeOperation = edit
        Uuid = a0 14 3f 50 1f 03 d6 50-78 6c 22 cc 2c e5 85 18
        Spec =
          class HostProxySwitchSpec
          {
            Backing =
              class DistributedVirtualSwitchHostMemberPnicBacking
              {
                PnicSpec =
                  [
                    VMware.Vim.DistributedVirtualSwitchHostMemberPnicSpec
                    VMware.Vim.DistributedVirtualSwitchHostMemberPnicSpec
                  ]
 
              }
          }
      }
    ]
 
  Portgroup =
  Pnic =
  Vnic =
  ConsoleVnic =
  DnsConfig =
  IpRouteConfig =
  ConsoleIpRouteConfig =
  RouteTableConfig =
  Dhcp =
  Nat =
  IpV6Enabled =
  NetStackSpec =
}
0 Kudos
kmzimm
Enthusiast
Enthusiast
Jump to solution

Digging into this further, I seem to have a smoking gun of sorts from the hostd.log on the server being changed:

2018-08-22T20:38:28.766Z info hostd[50F40B70] [Originator@6876 sub=Vimsvc.TaskManager opID=50edaf3f-aa-59fe user=vpxuser:thisguy] Task Created : haTask-ha-host-vim.host.NetworkSystem.invokeHostTransactionCall-339
2018-08-22T20:38:28.771Z info hostd[50F40B70] [Originator@6876 sub=Hostsvc.NetworkVmkSimulator opID=50edaf3f-aa-59fe user=vpxuser:thisguy] DvsAddNic:  pnic vmnic5 not free
2018-08-22T20:38:28.771Z info hostd[50F40B70] [Originator@6876 sub=Hostsvc opID=50edaf3f-aa-59fe user=vpxuser:thisguy] Simulate failed
2018-08-22T20:38:28.771Z info hostd[50F40B70] [Originator@6876 sub=Default opID=50edaf3f-aa-59fe user=vpxuser:thisguy] AdapterServer caught exception: vmodl.fault.InvalidArgument
2018-08-22T20:38:28.771Z info hostd[50F40B70] [Originator@6876 sub=Vimsvc.TaskManager opID=50edaf3f-aa-59fe user=vpxuser:thisguy] Task Completed : haTask-ha-host-vim.host.NetworkSystem.invokeHostTransactionCall-339 Status error
2018-08-22T20:38:28.771Z info hostd[50F40B70] [Originator@6876 sub=Solo.Vmomi opID=50edaf3f-aa-59fe user=vpxuser:thisguy] Activation [N5Vmomi10ActivationE:0x4f9d9f80] : Invoke done [invokeHostTransactionCall] on [vim.host.NetworkSystem:networkSystem]

 

 

Perhaps I've got a misunderstanding of what this function is supposed to be doing (the migrate operation). Do I need additional code to remove the pnic interfaces from the vSS first?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I find it strange that in the dump of the $config, the $config.vnic property seems to be empty.
Also, although the API Ref indeed says that the portgroup property is ignored, it is marked as a property that needs to be set.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
LucD
Leadership
Leadership
Jump to solution

See also Re: Assign vminc to Specific Uplink on VDS

That user seems to have experienced the same portgroup issue


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
kmzimm
Enthusiast
Enthusiast
Jump to solution

The $config.vnic being empty in this case is correct. I commented out that code to focus on the part that wasn't working.

0 Kudos
kmzimm
Enthusiast
Enthusiast
Jump to solution

Thank you for this. Sadly, I'll admit I started on that thread a couple days ago (which is where I found the original code snippet from you). I either failed to read the entire thing, or else did and forgot about it.

I had already gotten down to stripping the NICs out of the vSS bond, and having it explode on me. I don't think I would have ever guessed at adding a dummy NIC to it to fix the problem though.

Either way, sorry for the wild goose chase. At least I learned where to look for the right errors...

0 Kudos