VMware vSphere PowerCLI Reference. Graf Brian. Читать онлайн. Newlib. NEWLIB.NET

Автор: Graf Brian
Издательство: Автор
Серия:
Жанр произведения: Зарубежная образовательная литература
Год издания: 0
isbn: 9781118925140
Скачать книгу
A folder is a logical way to define how VMs or other vCenter Server objects are organized. Folders are often used to organize VMs into department owners or server functions.

      Creating Datacenters

      Datacenters are generally created as part of the initial setup process. The setup can be automated by using the following code, which will create a datacenter called Boston and store it in a variable. The Datacenter object held within the variable can then be referred to later in the code as you create clusters or folders:

      Creating Clusters

      Clusters are more complex than datacenters; there are many configurable items available for a new cluster. Consider the options the vSphere Web Client gives us: the normal cluster options as well as configuration options for VMware High Availability (HA), VMware Distributed Resource Scheduler (DRS), VMware Enhanced VMotion Compatibility (EVC), and VMware Distributed Power Management (DPM).

      To create a new cluster in the Boston datacenter you created earlier, you can use the following code:

      This code line gives you the basic settings. The sections that follow discuss the additional cluster settings available to you.

      Configuring High Availability

      When configured in a cluster, VMware HA gives you many advantages, including the following:

      • Proactive monitoring of all vSphere hosts and VMs

      • Automatic detection of vSphere host failure

      • Rapid restart of VMs affected by host failure

      • Optimal placement of VMs after server failure

Much like the configuration of a cluster through the vSphere Web Client, you can configure HA within a cluster either as part of the initial cluster setup or you can alter an existing cluster object. For example, to configure a new cluster named Production with HA enabled and an HA failover level of 1 physical host failure and the HA Restart Priority as Medium, you would use the code in Listing 1-11.

Listing 1-11: Enabling HA with a failover host level and restart priority on a new cluster

To complete this same action on an existing cluster, you first need to retrieve the cluster as an object and then push it down the pipeline into the Set-Cluster cmdlet, as shown in Listing 1-12.

Listing 1-12: Enabling HA with a failover host level and restart priority on an existing cluster

      Configuring Distributed Resource Scheduler

VMware DRS is a configuration made at the cluster level of the vCenter Server environment that balances VM workloads with available host resources. With VMware DRS, you are able to define the rules for allocation of physical resources among the VMs. DRS can be configured for manual or automatic control. If the workload on one or more VMs drastically changes, DRS redistributes the VMs among the physical servers to ensure the resources are available where needed. Much like HA, DRS can be configured as part of the initial cluster setup or as an alteration to an existing cluster object. For example, to configure a new Production cluster with DRS enabled and a DRS automation level of FullyAutomated with DRSMode set to FullyAutomated, you would use the code in Listing 1-13.

Listing 1-13: Configuring DRS on a new cluster

To complete this same action on an existing cluster, you would again need to retrieve the cluster object and push the object through the pipe into the Set-Cluster cmdlet, as shown in Listing 1-14.

Listing 1-14: Configuring DRS on an existing cluster

      Configuring Enhanced vMotion Compatibility

      EVC allows you to add multiple hosts with different CPU architectures to your cluster. EVC will, for example, allow you to add older hosts with Intel processors to a cluster that includes hosts with newer Intel processors. It does this by setting a mask on the VMs and ensuring the instruction sets are the same for both sets of hosts. Unfortunately, at this point in time VMware does not include either a PowerCLI cmdlet or a method to enable this feature programmatically. Therefore, configuring EVC is outside the scope of this book.

      Configuring Distributed Power Management

      DPM provides cost savings by dynamically consolidating VMs onto fewer hosts during periods of low usage. Once the VMs are consolidated onto fewer hosts, the remaining hosts that are no longer hosting any VMs are powered off to save power. Once utilization starts to increase, the vSphere Server will power these hosts back on as needed.

      While there are currently no options to enable DPM through the native cmdlets that are provided with PowerCLI, you can address the API and create your own function to enable DPM. For more information about using the SDK/API or Project Onyx, read Chapter 18, “The SDK.”

Listing 1-15 shows how you can enable DPM on a cluster.

Listing 1-15: Configuring DPM on a cluster

      Licensing

      Licensing is one of the first areas that will be critical to setting up a new host. Without a valid license, you can manage and use your host-to-host VMs for a maximum of 60 days.

      You may be surprised to learn that there are no cmdlets to help with licensing ESX hosts or even viewing the current license details. However, the licensing information is available through the Get-View cmdlet, and you can manipulate the SDK to perform the actions necessary to both view license information and set the license key for your hosts. You can write functions to help you deal with these cmdlets and make them a little friendlier than the SDK code.

      Viewing License Information

To make things easier, you can use the functions we’ll show you next to list all license keys registered on the vCenter Server and also to set a license key on a host. The Get-LicenseKey function in Listing 1-16 lists all existing license keys.

Listing 1-16: Retrieving license key information from vCenter Server

      Each of the existing license keys will be returned in an output listing like this:

      Licensing a Host

Once you have a list of the keys, you can use that information to license the ESX hosts attached to the vCenter Server. Listing 1-17 shows how you set the license key for a specific host. Once the license key is set, it will return the server and license key that were specified.

Listing 1-17: Adding a license key to a host

      Chapter 2

      Automating vSphere Hypervisor Deployment and Configuration

      In this chapter, you will learn to:

      • Prepare for an Installation

      •