Introduction to vSphere Distributed switches

0
149
9 min read

(For more resources related to this topic, see here.)

Using vSphere Distributed Switches

The vSphere Distributed Switches are virtual switches that span across multiple hosts. This makes it easier to configure hosts that need similar network configurations. It also ensures that virtual machines will get the same network configuration when they migrate to another host. You need a vSphere Enterprise Plus license and a vCenter Server to be able to use vSphere Distributed Switches.

In vSphere PowerCLI, there are separate sets of cmdlets for working with vSphere Standard Switches and vSphere Distributed Switches. In the past, the VMware PowerCLI team tried to integrate both types of switches into one set of cmdlets. This is why, for example, the Get-VirtualSwitch cmdlet has a –Distributed parameter. However, this parameter is now obsolete, and VMware made a new set of cmdlets specific for vSphere Distributed Switches. The vSphere PowerCLI VDS snap-in that provides support for managing Distributed Switches and port groups was introduced in PowerCLI 5.1 Release 2. In this section, you will learn more about these new cmdlets.

In the following diagram, you see a vSphere Distributed Switch that spans two hosts:

Creating vSphere Distributed Switches

The New-VDSwitch cmdlet creates new vSphere Distributed Switches. This cmdlet has the following syntax:

New-VDSwitch [-ContactDetails <String>] [-ContactName <String>] [-LinkDiscoveryProtocol <LinkDiscoveryProtocol>] [-LinkDiscoveryProtocolOperation <LinkDiscoveryOperation>] [-MaxPorts <Int32>] [-Mtu <Int32>] [-Notes <String>] [-NumUplinkPorts <Int32>] [-Version <String>] -Name <String> -Location <VIContainer> [-RunAsync] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>] New-VDSwitch -ReferenceVDSwitch <VDSwitch> -Name <String> -Location <VIContainer> [-WithoutPortGroups] [-RunAsync] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>] New-VDSwitch -BackupPath <String> [-KeepIdentifiers] [-Name <String>] -Location <VIContainer> [-WithoutPortGroups] [-RunAsync] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

If you compare the preceding syntax with the syntax of the New-VirtualSwitch cmdlet, then you will see that the New-VDSwitch cmdlet has many more possibilities to configure the virtual switch during creation. In vSphere 5.1 and later versions, you can even specify a reference vSphere Distributed Switch or a backup profile from where a new switch can be created.

Creating a new vSphere Distributed Switch from scratch.

To create a new vSphere Distributed Switch from scratch, you have to specify at least the -Name and the –Location parameters. The location can be a datacenter or a folder.

In the next example. we will create a new vSphere Distributed Switch named VDSwitch1 in datacenter New York:

PowerCLI C:> $Datacenter = Get-Datacenter -Name "New York" PowerCLI C:> New-VDSwitch -Name "VDSwitch1" -Location $Datacenter Name NumPorts Mtu Version Vendor ------------------------------------------------------------------------ VDSwitch2 0 1500 5.5.0 VMware

Cloning a vSphere Distributed Switch

We can now clone the VDSwitch1 to a new switch VDSwitch2. Of course, this is not very useful because VDSwitch1 is not configured yet. We will clone the switch just to show you how to do it:

PowerCLI C:> New-VDSwitch -Name "VDSwitch2" `
>> -ReferenceVDSwitch "VDSwitch1" -Location $Datacenter
>>
Name NumPorts Mtu Version Vendor
---- -------- --- ------- ------
VDSwitch2 0 1500 5.5.0 VMware

If you want to clone a vSpheredistributed switch without cloning the port groups, then you can use the –WithoutPortGroups parameter.

Cloning a vSphere Distributed Switch and the New-VDSwitch-ReferenceVDSwitch parameter are only supported in VMware vSphere 5.1 and later versions.

Creating a vSphere Distributed Switch from an export

Later in this article, we will see how to create an export of the configuration of a vSphere Distributed Switch. If you have an export, then you can use it to recreate a switch or to create a new one. The next example will create a new vSphere Distributed Switch named VDSwitch3 in the datacenter New York from an export of the configuration of VDSwitch1:

PowerCLI C:> New-VDSwitch -BackupPath C:VDSwitch1Config.zip ` >> -Name VDSwitch3 -Location (Get-Datacenter –Name "New York") Importing vSphere distributed switch - Switch name: 'VDSwitch1', Switch version: 5.5.0, Number of port groups: 1, Number of resource pools: 8, Number of uplinks: 1, Notes: VDSwitch1 Configuration Name NumPorts Mtu Version Vendor ------------------------------------------------------------------------ VDSwitch3 0 1500 5.5.0 VMware

Also, for importing an export you can use the –WithoutPortGroups parameter to prevent importing the port groups.

Retrieving vSphere Distributed Switches

You can retrieve vSphere Distributed Switches with the Get-VDSwitch cmdlet. The syntax of this cmdlet is as follows:

Get-VDSwitch [[-Name] <String[]>] [-Location <FolderContainer[]>] [-VMHost <VMHost[]>] [-VM <VirtualMachine[]>] [-Server <VIServer[]>] [<CommonParameters>] Get-VDSwitch -Id <String[]> [-Server <VIServer[]>] [<CommonParameters>] Get-VDSwitch -RelatedObject <VDSwitchRelatedObjectBase[]> [<CommonParameters>]

If you use the Get-VDSwitch cmdlet without parameters, then it will return all of the vSphere Distributed Switches in your environment. You can use the -Location parameter to specify a datacenter or folder in which you want to search for vSphere Distributed Switches.

The next example will retrieve all of the vSphere Distributed Switches in the datacenter New York:

PowerCLI C:> Get-Datacenter -Name "New York" | Get-VDSwitch Name NumPorts Mtu Version Vendor -------------------------------------------------------------- VDSwitch1 0 1500 5.5.0 VMware VDSwitch2 0 1500 5.5.0 VMware VDSwitch3 0 1500 5.5.0 VMware

You can specify a value for the –Name parameter to retrieve a specific vSphere Distributed Switch. In the following example, we will retrieve the vSphere Distributed Switch VDSwitch1:

PowerCLI C:> Get-VDSwitch -Name VDSwitch1 Name NumPorts Mtu Version Vendor ------------------------------------------------------------------------ VDSwitch1 0 1500 5.5.0 VMware

Configuring vSphere Distributed Switches

The selection you make using Get-VDSwitch can be used as an input of the SetVDSwitch cmdlet to modify the configuration or version of one or more vSphere Distributed Switches, to roll back the configuration to its previous state, or to import the configuration from a backup profile.

Rolling back the configuration of a vSphere Distributed Switch and importing the configuration of a vSphere Distributed Switch from a backup are available only on vSphere 5.1 and later versions.

The Set-VDSwitchcmdlet has the following syntax:

Set-VDSwitch [-Name <String>] [-ContactDetails <String>] [-ContactName <String>] [-LinkDiscoveryProtocol <LinkDiscoveryProtocol>] [-LinkDiscoveryProtocolOperation <LinkDiscoveryOperation>] [-MaxPorts <Int32>] [-Mtu <Int32>] [-Notes <String>] [-NumUplinkPorts <Int32>] [-Version <String>] [-VDSwitch] <VDSwitch[]> [-RunAsync] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>] Set-VDSwitch -BackupPath <String> [-WithoutPortGroups] [-VDSwitch] <VDSwitch[]> [-RunAsync] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>] Set-VDSwitch -RollBackConfiguration [-VDSwitch] <VDSwitch[]> [-RunAsync] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

In the next example, we will set almost every property for VDSwitch1 that you can set using PowerShell. We will use a PowerShell technique called splatting to create a parameter list for the Set-VDSwitch cmdlet. The parameter list will be a hash table called $Parameters. By using the splat operator @,you can add the parameters in the $Parameters hash table to the Set-VDSwitchcmdlet call.

When you use splatting, you have to use the name of the variable containing the parameter’s hash table without the dollar sign, that is, @Parameters and not @$Parameters.

PowerCLI C:> $VDSwitch = Get-VDSwitch -Name vDSWitch1 PowerCLI C:> $Parameters = @{ >> NumUplinkPorts = 2 >> MaxPorts = 1024 >> LinkDiscoveryProtocol = 'LLDP' >> LinkDiscoveryProtocolOperation = 'Both' >> ContactName = 'vsphereadmin@blackmilktea.com' >> ContactDetails = 'New York office' >> Notes = 'VDSwitch for New York datacenter' >> } >> $VDSwitch | Set-VDSwitch @Parameters >> Get-VDSwitch -Name vDSWitch1 | Format-List -Property * >> Name NumPorts Mtu Version Vendor ------------------------------------------------------------- VDSwitch1 0 1500 5.5.0 VMware LinkDiscoveryProtocol : LLDP LinkDiscoveryProtocolOperation : Both VlanConfiguration : Name : VDSwitch1 ExtensionData : VMware.Vim. VmwareDistributedVirtualSwitch NumPorts : 0 Key : 6c 48 12 50 ca 61 ec be-4d a8 bb 95 d0 0f bd a7 Mtu : 1500 Notes : VDSwitch for New York datacenter Datacenter : New York NumUplinkPorts : 4 ContactName : vsphereadmin@blackmilktea.com ContactDetails : New York office Version : 5.5.0 Vendor : VMware Folder : network MaxPorts : 1024 Id : VmwareDistributedVirtualSwitch-dvs-182 Uid : /VIServer=root@192.168.0.132:443/Distrib utedSwitch=VmwareDistributedVirtualSwitch-dvs-49/ Client : VMware.VimAutomation.Vds.Impl. V1.VDClientImpl

The following screenshot of the vSphere Web Client shows the settings of the Distributed Switch VDSwitch1 after executing the previous commands:

Rolling back the configuration of a vSphere Distributed Switch

If you made a mistake in the configuration of a vSphere Distributed Switch, then you can roll back the configuration to its previous state using the Set-VDSwitch –RollbackConfiguration parameter

In the following example, we will modify the MTU size of the switch VDSwitch1to 9,000, and then use the –RollbackConfigurationparameter to revert to the previous value of 1,500:

PowerCLI C:> Get-VDSwitch -Name VDSwitch1 | >> Set-VDSwitch -MTU 9000 >> Name NumPorts Mtu Version Vendor -------------------------------------------------------------- VDSwitch1 0 9000 5.5.0 VMware PowerCLI C:> Get-VDSwitch -Name VDSwitch1 | >> Set-VDSwitch –RollbackConfiguration >> Name NumPorts Mtu Version Vendor ------------------------------------------------------------ VDSwitch1 0 1500 5.5.0

Importing the configuration of a vSphere Distributed Switch from a backup

You can import the configuration of a vSphere Distributed Switch from a backup created with the Export-VDSwitch cmdlet. Later in this article, you will learn how to create a backup. In this section, we will show you how to restore the configuration from a backup.

You have to use the Set-VDSwitch -BackupPath parameter to specify the path to the configuration .zip file. You can also use the –WithoutPortGroups parameter if you don’t want to restore the port groups.

In the next example, we will import the configuration of VDSwitch1 from a backup file called ‘c:myVDSwitch1Config.zip’:

PowerCLI C:> Get-VDSwitch -Name 'VDSwitch1' | >> Set-VDSwitch -BackupPath 'c:myVDSwitch1Config.zip' >> Restoring vSphere distributed switch configuration - Switch name: 'VDSwitch1', Switch version: 5.5.0, Number of port groups: 0, Number of resource pools: 8, Number of uplinks: 1, Notes: My VDSwitch1 configuration Name NumPorts Mtu Version Vendor ------------------------------------------------------------- VDSwitch1 0 1500 5.5.0

Upgrading a vSphere Distributed Switch

In every new VMware vSphere version, VMware introduces new features to the vSphere Distributed Switch. To be able to use these new features, you have to upgrade your switches to the new version.

In the next example, we will upgrade the version of the VDSwitch4 switch to 5.5.0:

PS C:> $VDSwitch = Get-VDSwitch -Name VDSwitch4 PS C:> $VDSwitch Name NumPorts Mtu Version Vendor ---------------------------------------------------------------- VDSwitch4 0 1500 4.1.0 VMware PS C:> $VDSwitch | Set-VDSwitch -Version 5.5.0 Name NumPorts Mtu Version Vendor --------------------------------------------------------------- VDSwitch4 0 1500 5.5.0 VMware

Adding hosts to vSphere Distributed Switches

After creating a vSphere Distributed Switch, you have to add hosts to the switch. Normally, you add at least all of the hosts that are in the same cluster. Because a vSphere Distributed Switch is created in a datacenter or a folder, a vSphere Distributed Switch is not limited to one cluster. You can add hosts of multiple clusters to the same switch.

The Add-VDSwitchVMHost cmdlet will add hosts to a vSphere Distributed Switch. The syntax of this cmdlet is as follows:

Add-VDSwitchVMHost -VDSwitch <VDSwitch> -VMHost <VMHost[]> [-Server <VIServer[]>] [-RunAsync] [-WhatIf] [-Confirm] [<CommonParameters>]

In the next example, we will add all of the hosts of the cluster “Cluster01” to the vSphere Distributed Switch “VDSwitch1”:

PowerCLI C:> $VMHost = Get-Cluster Cluster01 | Get-VMHost PowerCLI C:> Add-VDSwitchVMHost -VDSwitch VDSwitch1 -VMHost $VMHost

LEAVE A REPLY

Please enter your comment!
Please enter your name here