VMware Cloud Community
jvm2016
Hot Shot
Hot Shot
Jump to solution

creating vmkernel port group_powercli

Hi luc,

good morning .

there is a requirement of

1:creating two distributed port groups

2:and two vmkernel adapters (for vmotion and replication) per esxi in three node cluster.

i thought of doing as below .could you modify orange code so that we can iterate over ips of vmotion and replication .

function create-vmkernelport

{

    [cmdletbinding()]

    param(

        [Parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]

        [string]$clustername,

        [Parameter(Mandatory=$true)]

        [string]$distributedswitch,

        [Parameter(Mandatory=$true)]

        [string]$vlanvmotion,

        [Parameter(Mandatory=$true)]

        [string]$vlanreplication,

        [Parameter(Mandatory=$true)]

        [string]$subnetmask

    )

    $cluster=Get-Cluster $clustername

   

    $vmhosts=get-vmhost -Location $cluster

    $ipvmotion = "172.16.8.21","172.16.8.22","172.16.8.23"

    $ipreplication = "172.16.9.21","172.16.9.22","172.16.9.21"

   

    $vmotion=New-VDPortgroup -name "vmotion_112" -VDSwitch $distributedswitch -VlanId 112 -PortBinding Static -NumPorts 8

     $replication=New-VDPortgroup -name "replication_113" -VDSwitch $distributedswitch -VlanId 113 -PortBinding Static -NumPorts 8

   

  

    foreach($vmhost in $vmhosts)

    {

  

  New-VMHostNetworkAdapter -VMHost $vmhost -PortGroup $vmotion

  -VirtualSwitch $distributedswitch -IP $ipvmotion[$i] -SubnetMask $subnetmask

  New-VMHostNetworkAdapter -VMHost $vmhost -PortGroup $replication

  -VirtualSwitch $distributedswitch -IP $ipreplication [$i] -SubnetMask $subnetmask

 

           

           

           

        

        

     }  

     }   

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try something like this

function create-vmkernelport {

   [cmdletbinding()]

   param(

   [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]

   [string]$clustername,

   [Parameter(Mandatory = $true)]

   [string]$distributedswitch,

   [Parameter(Mandatory = $true)]

   [string]$vlanvmotion,

   [Parameter(Mandatory = $true)]

   [string]$vlanreplication,

   [Parameter(Mandatory = $true)]

   [string]$subnetmask

   )


   $cluster = Get-Cluster $clustername


   $vmhosts = Get-VMHost -Location $cluster

   $ipvmotion = "172.16.8.21", "172.16.8.22", "172.16.8.23"

   $ipreplication = "172.16.9.21", "172.16.9.22", "172.16.9.21"


   if($vmhosts.Count -ne $ipvmotion.Count -or $vmhosts.Count -ne $ipreplication.Count){

   Write-Error "Number of IPs does not match number of ESXi nodes"

   return

   }


   $vmotion = New-VDPortgroup -name "vmotion_112" -VDSwitch $distributedswitch -VlanId 112 -PortBinding Static -NumPorts 8

   $replication = New-VDPortgroup -name "replication_113" -VDSwitch $distributedswitch -VlanId 113 -PortBinding Static -NumPorts 8


   $i = 0

   foreach ($vmhost in $vmhosts) {

   New-VMHostNetworkAdapter -VMHost $vmhost -PortGroup $vmotion `

   -VirtualSwitch $distributedswitch -IP $ipvmotion[$i] -SubnetMask $subnetmask


   New-VMHostNetworkAdapter -VMHost $vmhost -PortGroup $replication `

   -VirtualSwitch $distributedswitch -IP $ipreplication [$i] -SubnetMask $subnetmask


   $i++

   }

}


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

View solution in original post

0 Kudos
25 Replies
LucD
Leadership
Leadership
Jump to solution

Is there a requirement to have a specific IP assigned to a specific ESXi node?


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

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

no it can be random .

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try something like this

function create-vmkernelport {

   [cmdletbinding()]

   param(

   [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]

   [string]$clustername,

   [Parameter(Mandatory = $true)]

   [string]$distributedswitch,

   [Parameter(Mandatory = $true)]

   [string]$vlanvmotion,

   [Parameter(Mandatory = $true)]

   [string]$vlanreplication,

   [Parameter(Mandatory = $true)]

   [string]$subnetmask

   )


   $cluster = Get-Cluster $clustername


   $vmhosts = Get-VMHost -Location $cluster

   $ipvmotion = "172.16.8.21", "172.16.8.22", "172.16.8.23"

   $ipreplication = "172.16.9.21", "172.16.9.22", "172.16.9.21"


   if($vmhosts.Count -ne $ipvmotion.Count -or $vmhosts.Count -ne $ipreplication.Count){

   Write-Error "Number of IPs does not match number of ESXi nodes"

   return

   }


   $vmotion = New-VDPortgroup -name "vmotion_112" -VDSwitch $distributedswitch -VlanId 112 -PortBinding Static -NumPorts 8

   $replication = New-VDPortgroup -name "replication_113" -VDSwitch $distributedswitch -VlanId 113 -PortBinding Static -NumPorts 8


   $i = 0

   foreach ($vmhost in $vmhosts) {

   New-VMHostNetworkAdapter -VMHost $vmhost -PortGroup $vmotion `

   -VirtualSwitch $distributedswitch -IP $ipvmotion[$i] -SubnetMask $subnetmask


   New-VMHostNetworkAdapter -VMHost $vmhost -PortGroup $replication `

   -VirtualSwitch $distributedswitch -IP $ipreplication [$i] -SubnetMask $subnetmask


   $i++

   }

}


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

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

thanks Luc.for somereasons new-vdportgroup command is not present in powershell .do i need to import module

i see following

pastedImage_0.png

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That cmdlet comes from the VMware.VimAutomation.Vds module.
But when the folder under which that module is living is present in $env:PSModulePath, the module should autoload.

You can check where your PowerCLI modules are living with

Get-Module -Name VMware* -ListAvailable


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

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

it should autoload

but i run import-module vmware.vimautomation.vds and its available now .

also

pastedImage_0.png

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You seem to still be on a quite old PowerCLI version (and a MSI based installation I think).

Once again, I would strongly advise to go for a more recent PowerCLI version.


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

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

thnaks Luc,

I am checking this again .thoughtof instaling all mangenet utilitiles(including  powercli) on separate vm .

0 Kudos
jack_watson
Contributor
Contributor
Jump to solution

Thank you. it was very helpful and kinda reminded me of this: https://www.techwhoop.com/update-straight-talk-phone-signal/. The resemblance is uncanny and it did throw me off guard.

Regards,

Jack.

Hi
0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

for some reasons its not creation vmk2 the replication adapter .i know i need to enable  replication traffic manually as there is no option in powercli but it should create adapter.

this is how iam running this function.

pastedImage_0.png

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Remove that blank between $ipreplication and [$i].

The cmdlet thinks you are passing 2 values to the -IP parameter


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

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

thnaksLuc.I am going to configure again .

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

that worked .however how it is taking default gateway as i dont see any parameter in

New-VMHostNetworkAdapter command

right now we have enabled management ,vmotion and replication in on same vmk0 .

the whole idea to create this is to create additional port for vmotion and replication .

script worked fine but for someresons default gateway is assigned from vmk0 only.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That is correct, setting the default gateway is doen with the Set-VMHostNetwork cmdlet.

But be aware, there can only be 1 default gateway per network stack.
That means you will have to create a new TCPIPStack for a vmk for which you want to have a different default gateway.

See for example Re: Configure default gateway on vmotion TCP/IP stack


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

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

Thanks I m checking this again.

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

currently I have three subnet (x,y,z) assigned to mgmt,vmtion,replication respectively.

and each subnet gateway is given by network team and normally the first ip of that subnet.and these three gateway ips will be connected to layer 3 device .

by stack you mean subnet?

so  is it not enough to use  only set-vmhostnetwork to  assign gateway ?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

No, I mean the TCP/IP STacks

vmk.jpg

You have a default gateway per stack.
All the vmk on that stack use the same gateway.

stack.jpg


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

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

Ohh ...thanks .i m going to configure again.thankks for this.

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

Hi Luc,

good morning ,

i have following three vmkernel as shown below . its from one of the hosts of three node cluster.

pastedImage_0.png

i tried following  where $esxi is "172.16.7.16"   also creating  vmotion network stack is also failing.

pastedImage_1.png

0 Kudos