Reader small image

You're reading from  Mastering PowerCLI

Product typeBook
Published inOct 2015
Reading LevelIntermediate
PublisherPackt
ISBN-139781785286858
Edition1st Edition
Languages
Right arrow
Author (1)
Sajal Debnath
Sajal Debnath
author image
Sajal Debnath

Sajal Debnath is a highly certified Cloud computing technocrat with more than 12 years of experience in virtualized data center design, Cloud computing, and BC/DR solutions. He is an EMCISA, VCAP-DCD/DCA, VCAP-CID/CIA, RHCE 4/5/6, RHCVA, Openstack, and ITIL certified person. He is presently associated with VMware Software India Pvt. Ltd. as a senior system engineer. Previously, he worked with France Telecom, Hewlett Packard, and many more in multiple roles. He is involved in prestigious Indian government projects, such as National Cloud, Digital Locker, and so on.
Read more about Sajal Debnath

Right arrow

Chapter 4. Managing Networks

In the previous chapter, we saw how to configure a customized image using the image profile, automatically configure hosts using the host profile, and finally, how to automatically deploy ESXi servers using Auto Deploy. Since we deployed the server, we will learn how to configure and manage networking in the vSphere environment using PowerCLI. In this chapter, we will discuss the following topics:

  • Managing vSphere standard switches

  • Managing host network adapters

  • Using port groups

  • Managing vSphere distributed switches

  • Configuring vSphere network I/O control

  • Creating private VLANs

  • Configuring Netflow

  • Configuring VMware DirectPath IO

We will start with the creation and configuration of standard switches. Next, we will go into the details of distributed switches and then move on to the advanced configurations.

Managing vSphere standard switches


To manage complete vSphere networking, we need two different components. All the cmdlets for standard switches and other one come with the VMware.VimAutomation.Core snap-in/module, and all the cmdlets related to distributed switches are included in the VMware.VimAutomation.Vds module. In this section, we will discuss standard switches; in the next section, we will discuss distributed switches. For all the cmdlets to run successfully, we need to connect to a vCenter server. So, let's connect to a vCenter server and get started.

As you already know, whenever you install an ESXi server, by default a standard vSwitch with the name vSwitch0 is created.

The first thing that we need to do is to get accustomed to the vSwitch in an ESXi host using the PowerCLI cmdlets. For this, we can use the following cmdlets:

  • Get-VirtualSwitch

  • New-VirtualSwitch

  • Remove-VirtualSwitch

  • Set-VirtualSwitch

First, let's try to get a list of virtual switches available in the entire environment...

Managing networking for ESXi


Cmdlets available for managing ESXi hosts can be categorized in different categories, such as managing the physical NIC and related parameters, managing HBAs, setting the ntp server and snmp, and so on.

The first set of cmdlets is used to check the networking parameters of an ESXi host and the cmdlets are as follows:

  • Get-VMHostNetwork

  • Set-VMHostNetwork

With the help of the preceding two cmdlets, we can get the details of the configured network setting for an ESXi host, though many of the parameters of these two cmdlets are outdated and will soon be deprecated.

The Set-VMHostNetwork cmdlet is used to update the different parameters of the specified virtual network. For example, the following cmdlets will enable the IPv6 network in the host and then the host must be restarted for any changes to take effect:

We can further control the finer aspects of ESXi host networking with the following set of cmdlets:

  • Get-VMHostNetworkAdapter

  • New-VMHostNetworkAdapter

  • Remove...

Managing vSphere distributed switches


After discussing the different aspects of a standard vSwitch, we will now move on to discus distributed virtual switches. The following is a list of available cmdlets for managing the different aspects of distributed virtual switches:

  • Add-VDSwitchPhysicalNetworkAdapter

  • Add-VDSwitchVMHost

  • Export-VDPortGroup

  • Export-VDSwitch

  • Get-VDBlockedPolicy

  • Get-VDPort

  • Get-VDPortgroup

  • Get-VDPortgroupOverridePolicy

  • Get-VDSecurityPolicy

  • Get-VDSwitch

  • Get-VDSwitchPrivateVlan

  • Get-VDTrafficShapingPolicy

  • Get-VDUplinkLacpPolicy

  • Get-VDUplinkTeamingPolicy

  • New-VDPortgroup

  • New-VDSwitch

  • New-VDSwitchPrivateVlan

  • Remove-VDPortGroup

  • Remove-VDSwitch

  • Remove-VDSwitchPhysicalNetworkAdapter

  • Remove-VDSwitchPrivateVlan

  • Remove-VDSwitchVMHost

  • Set-VDBlockedPolicy

  • Set-VDPort

  • Set-VDPortgroup

  • Set-VDPortgroupOverridePolicy

  • Set-VDSecurityPolicy

  • Set-VDSwitch

  • Set-VDTrafficShapingPolicy

  • Set-VDUplinkLacpPolicy

  • Set-VDUplinkTeamingPolicy

  • Set-VDVlanConfiguration

We will start...

Managing port groups


So far, we have created standard and distributed virtual switches as well as checked how to configure the different aspects of networking ESXi hosts. Now, we will take a look at how we can configure port groups in virtual switches. We will start with the different cmdlets that we can use to configure port groups for standard switches, and then we will check the port groups of distributed switches.

The cmdlets related to standard switches are as follows:

  • Get-VirtualPortGroup

  • New-VirtualPortGroup

  • Remove-VirtualPortGroup

  • Set-VirtualPortGroup

As the name suggests, we can get details of the Get-VirtualPortGroup cmdlet and create a new one with the New-VirtualPortGroup cmdlet. We will start with creating a new port group.

We can add a VLAN ID to a port group of a virtual switch using the New-VirtualPortGroup cmdlet, using the VLanId switch.

We can remove a port group using the Remove-VirtualPortGroup cmdlet and change the properties of an existing virtual switch using the...

Creating private VLANs


In this section, we will discuss how to create a private VLAN in a distributed switch. We will first use the Get-VDSwitchPrivateVlan cmdlet to check whether there are any private VLANs configured or not. As can be seen, there is no PVLAN. Next, we created three different types of PVLAN and again checked the status.

We can remove a private VLAN using the Remove-VDSwitchPrivateVlan cmdlet.

Configuring vSphere network I/O control


Configuring network I/O control in the vSphere environment is a great way to control and ensure quality of service for different types of traffic. Though there is no direct cmdlet available to enable and disable network I/O control using PowerCLI, we can do so using the vSphere APIs using PowerCLI. We can get a list of all the methods and properties available in the VDSwitch object by inspecting the ExtensionData option of the object. In the following screenshot, we can see that there is an EnableNetworkResourceManagement method associated with the object that takes a $true or $false Boolean input, which decides whether NetworkResourceManagement will be turned on or off.

Tip

We will see how we can access APIs using PowerCLI in the upcoming chapter in detail. For now, we will just touch upon the subject.

So, we can enable or disable network I/O control by simply using the following method:

PS C:\> (Get-VDSwitch -Name Test1).ExtensionData.EnableNetworkResourceManagement...

Configuring Netflow


To configure Netflow, we need to access APIs. To do this, we will access the ReconfigureDVPortgroup_Task method. Alan Renouf has a very good blog and description for this (http://www.virtu-al.net/2013/07/23/disabling-netflow-with-powercli/):

PS C:\> (Get-VDPortgroup -Name TestPortGroup).Extensiondata.Config.defaultPortConfig.ipfixEnabled.Value
False

Next, we will change the value. As seen in the following output, it takes a VMware.Vim.DVPortgroupConfigSpec type specification:

PS C:\> (Get-VDPortgroup -Name "TestPortGroup") Extensiondata.ReconfigureDVPortgroup_Task

OverloadDefinitions                                                                                   
-------------------                                                                                   
VMware.Vim.ManagedObjectReference ReconfigureDVPortgroup_Task(VMware.Vim.DVPortgroupConfigSpec spec)

To do this, we will first create a specification and then pass the value to the method in order to...

Working with ports


So far, we have worked with host, switch, and port groups; now, let's explore how we can get details of a port and modify it. To manage a port, we will use the following two cmdlets:

  • Get-VDPort

  • Set-VDPort

We can get the details of the port using the Get-VDPort cmdlet and set details via the Set-VDPort cmdlet.

Configuring traffic shaping

We can use PowerCLI to configure traffic shaping in distributed ports, and we can use the following two cmdlets to configure it:

  • Get-VDTrafficShapingPolicy

  • Set-VDTrafficShapingPolicy

Obviously, Get-VDTrafficShapingPolicy will provide you with the details of the current policy set and Set-VDTrafficShapingPolicy will allow us to change the existing settings.

Next, let's set the parameters for traffic shaping.

Configuring port blocking

Next, we will check port blocking options using PowerCLI. The following are the cmdlets available for this purpose:

  • Get-VDBlockedPolicy

  • Set-VDBlockedPolicy

Configuring the security policy

To configure the security...

Summary


In this chapter, we covered the different aspects of networking in the vSphere environment, starting with how to manage standard switches using PowerCLI. Next, we covered how to manage ESXi hosts and distributed switches. After this, we covered the different parameters and aspects of distributed switches that we can configure using PowerCLI.

In the next chapter, we will cover how to configure the different aspects of storage in the vSphere environment. For example, how we can add different types of storage in an ESXi host, create a new data store, and so on, and how we can create and configure VSAN using PowerCLI.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering PowerCLI
Published in: Oct 2015Publisher: PacktISBN-13: 9781785286858
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Sajal Debnath

Sajal Debnath is a highly certified Cloud computing technocrat with more than 12 years of experience in virtualized data center design, Cloud computing, and BC/DR solutions. He is an EMCISA, VCAP-DCD/DCA, VCAP-CID/CIA, RHCE 4/5/6, RHCVA, Openstack, and ITIL certified person. He is presently associated with VMware Software India Pvt. Ltd. as a senior system engineer. Previously, he worked with France Telecom, Hewlett Packard, and many more in multiple roles. He is involved in prestigious Indian government projects, such as National Cloud, Digital Locker, and so on.
Read more about Sajal Debnath