Grant1525
Contributor
Contributor

Configure default gateway on vmotion TCP/IP stack

Jump to solution

Hoping this one is easy. I'm trying this, from one of LucD's scripts I found:

    $stackName = 'vmotion'

    $ipGateway = '192.168.0.1'

    $ipDevice = 'vmk2'

        

    $esx = Get-VMHost -Name $VMHost

    $netSys = Get-View -Id $esx.ExtensionData.ConfigManager.NetworkSystem

    $stack = $esx.ExtensionData.Config.Network.NetStackInstance | where{$_.Key -eq 'vmotion'}

    

   

    $config = New-Object VMware.Vim.HostNetworkConfig

    $spec = New-Object VMware.Vim.HostNetworkConfigNetStackSpec

    $spec.Operation = [VMware.Vim.ConfigSpecOperation]::edit

    $spec.NetStackInstance = $stack

    $spec.NetStackInstance.RouteTableConfig = New-Object VMware.Vim.HostIpRouteTableConfig

    $route = New-Object VMware.vim.HostIpRouteConfig

    $route.defaultGateway = $ipGateway

    $route.gatewayDevice = $ipDevice

    $spec.NetStackInstance.ipRouteConfig = $route

    $config.NetStackSpec += $spec

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

Getting this error:

Exception calling "UpdateNetworkConfig" with "2" argument(s): "A specified parameter was not correct:

Vim.Host.IpRouteConfig.DefaultGateway"

+     $netsys.UpdateNetworkConfig($config,[VMware.Vim.HostConfigChangeM ...

+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : VimException

vmk2 is already created and moved to a VDS, with the IP configured and vMotion tcp/ip stack selected. All I'm trying to do is stuff the default gateway into the vMotion tcp/ip stack.  Any ideas?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Can you try with this?

$stackName = 'vmotion'

$ipGateway = '192.168.0.1'

$ipDevice = 'vmk2'

 

$esx = Get-VMHost -Name $VMHost

$netSys = Get-View -Id $esx.ExtensionData.ConfigManager.NetworkSystem

$stack = $esx.ExtensionData.Config.Network.NetStackInstance | where{$_.Key -eq 'vmotion'}


$config = New-Object VMware.Vim.HostNetworkConfig

$spec = New-Object VMware.Vim.HostNetworkConfigNetStackSpec

$spec.Operation = [VMware.Vim.ConfigSpecOperation]::edit

$spec.NetStackInstance = $stack

$spec.NetStackInstance.ipRouteConfig.defaultGateway = $ipGateway

$spec.NetStackInstance.ipRouteConfig.gatewayDevice = $ipDevice

$config.NetStackSpec += $spec

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

And if it still shows errors, have a look at the vpxd log.
There might be more clues in there.


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership

Can you try with this?

$stackName = 'vmotion'

$ipGateway = '192.168.0.1'

$ipDevice = 'vmk2'

 

$esx = Get-VMHost -Name $VMHost

$netSys = Get-View -Id $esx.ExtensionData.ConfigManager.NetworkSystem

$stack = $esx.ExtensionData.Config.Network.NetStackInstance | where{$_.Key -eq 'vmotion'}


$config = New-Object VMware.Vim.HostNetworkConfig

$spec = New-Object VMware.Vim.HostNetworkConfigNetStackSpec

$spec.Operation = [VMware.Vim.ConfigSpecOperation]::edit

$spec.NetStackInstance = $stack

$spec.NetStackInstance.ipRouteConfig.defaultGateway = $ipGateway

$spec.NetStackInstance.ipRouteConfig.gatewayDevice = $ipDevice

$config.NetStackSpec += $spec

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

And if it still shows errors, have a look at the vpxd log.
There might be more clues in there.


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

0 Kudos
Grant1525
Contributor
Contributor

Ahh yep that did it!  Didn't realize the route stuff was in there from the last post.  Thanks for this!

0 Kudos