VMware {code} Community
iamnkd
Contributor
Contributor

Is there any web service to create a VMkernel port on a vSphere Distributed Switch?

I am looking for web service for creating a VMkernel port and setting its properties like vMotion, Fault Tolerance logging, Management Traffic on a vSphere Distributed Switch. There are various vSphere PowerCLI cmdlets available for this (New-VMHostNetworkAdapter) but I need a web service to accomplish this task.

Your help would be appreciated.

Thank you.

0 Kudos
4 Replies
RanjnaAggarwal
VMware Employee
VMware Employee

Can you please explain the meaning of web service? vSphere Web client can be used to create vmkernel port.

Regards, Ranjna Aggarwal
0 Kudos
iamnkd
Contributor
Contributor

Thanks for the reply. By web service I mean, programming interface or any API present in vSphere SDK. I tried MOB but couldn't find any method/property to manipulate VMkernel ports.

0 Kudos
vThinkBeyondVM
VMware Employee
VMware Employee

# ------- UpdateNetworkConfig -------  :: To Create new Vmkernel port

# ------- SelectVnicForNicType ------- :: to enable vMotion, Management network.


Below is the PowerCLi code but  it will work for you as reference. Note that PowerCLi code is not using any cmdlet, it is using Get-Object (.Net) and its equivalent to APIs. Just map each line with API reference: vSphere 6.0 Documentation Center

# ------- UpdateNetworkConfig -------

$config = New-Object VMware.Vim.HostNetworkConfig

$config.vnic = New-Object VMware.Vim.HostVirtualNicConfig[] (1)

$config.vnic[0] = New-Object VMware.Vim.HostVirtualNicConfig

$config.vnic[0].spec = New-Object VMware.Vim.HostVirtualNicSpec

$config.vnic[0].spec.mtu = 0

$config.vnic[0].spec.netStackInstanceKey = 'defaultTcpipStack'

$config.vnic[0].spec.ip = New-Object VMware.Vim.HostIpConfig

$config.vnic[0].spec.ip.subnetMask = ''

$config.vnic[0].spec.ip.dhcp = $true

$config.vnic[0].spec.ip.ipV6Config = New-Object VMware.Vim.HostIpConfigIpV6AddressConfiguration

$config.vnic[0].spec.ip.ipV6Config.ipV6Address = New-Object VMware.Vim.HostIpConfigIpV6Address[] (0)

$config.vnic[0].spec.ip.ipV6Config.dhcpV6Enabled = $false

$config.vnic[0].spec.ip.ipV6Config.autoConfigurationEnabled = $false

$config.vnic[0].spec.ip.ipAddress = ''

$config.vnic[0].portgroup = 'VMkernel'

$config.vnic[0].changeOperation = 'add'

$config.portgroup = New-Object VMware.Vim.HostPortGroupConfig[] (1)

$config.portgroup[0] = New-Object VMware.Vim.HostPortGroupConfig

$config.portgroup[0].spec = New-Object VMware.Vim.HostPortGroupSpec

$config.portgroup[0].spec.name = 'VMkernel'

$config.portgroup[0].spec.vswitchName = 'vSwitch0'

$config.portgroup[0].spec.policy = New-Object VMware.Vim.HostNetworkPolicy

$config.portgroup[0].spec.vlanId = 0

$config.portgroup[0].changeOperation = 'add'

$changeMode = 'modify'

$_this = Get-View -Id 'HostNetworkSystem-networkSystem-21'

$_this.UpdateNetworkConfig($config, $changeMode)

# ------- SelectVnicForNicType -------

$nicType = 'vmotion'

$device = 'vmk1'

$_this = Get-View -Id 'HostVirtualNicManager-virtualNicManager-21'

$_this.SelectVnicForNicType($nicType, $device)

# ------- SelectVnicForNicType -------

$nicType = 'management'

$device = 'vmk1'

$_this = Get-View -Id 'HostVirtualNicManager-virtualNicManager-21'

$_this.SelectVnicForNicType($nicType, $device)

I am not sure whether you are using http://vthinkbeyondvm.com/getting-started-with-yavi-java-opensource-java-sdk-for-vmware-vsphere-step...

Let me know if you need any help on vmkernel port creation/configuration


----------------------------------------------------------------
Thanks & Regards
Vikas, VCP70, MCTS on AD, SCJP6.0, VCF, vSphere with Tanzu specialist.
https://vThinkBeyondVM.com/about
-----------------------------------------------------------------
Disclaimer: Any views or opinions expressed here are strictly my own. I am solely responsible for all content published here. Content published here is not read, reviewed or approved in advance by VMware and does not necessarily represent or reflect the views or opinions of VMware.

0 Kudos
doskiran
Enthusiast
Enthusiast

Here is the Java API to "Adds the VMkernel network adapter for all the hosts in the dvSwitch and assign them to dvPortgroup ports and also enable vMotion service in vmkernel "

Add VMkernel nic in all hosts in the dvSwitch and enable vMotion. - Samples - VMware {code}

0 Kudos