VMware vSphere PowerCLI Reference. Graf Brian

Читать онлайн.
Название VMware vSphere PowerCLI Reference
Автор произведения Graf Brian
Жанр Зарубежная образовательная литература
Серия
Издательство Зарубежная образовательная литература
Год выпуска 0
isbn 9781118925140



Скачать книгу

running the sample script in Listing 1-1, we ensured that all prerequisites and installation requirements were completed. Listing 1-1 shows how you might automate an installation of vCenter Server.

Listing 1-1: Sample script for an automated installation of vCenter Server

      Not all vCenter Servers are installed on Windows machines. VMware has released a virtual appliance known as the vCenter Server Appliance (vCSA) that can be used in place of a Windows vCenter. This option is compelling to many users because it does not require a Microsoft Windows license, and with each new release it is continuing to increase the size of environment it can handle.

Previous versions of the vCSA could be deployed using the Deploy OVF Template button within the C# client. However, with vCSA 6 this option is no longer possible. Luckily, we still have a few other options for deploying it. Along with the installer files, vCSA 6 has a command-line tool packaged in the installation media. The command-line tool leverages the use of a JavaScript Object Notation (JSON) configuration file and the OVF Tool to deploy the virtual appliance. Listing 1-2 shows an example of how we can use PowerCLI to configure the JSON configuration file and deploy the vCenter Server appliance.

Leveraging features found in PowerShell version 3 and later, we are able to convert the vCSA configuration template JSON file and convert it into a PowerShell object that we can then manipulate for our deployment purposes. Once the JSON file is converted into a PowerShell object, we can easily go through each property of the object and set its value. Once we have finished setting all the properties necessary for deployment, we can convert the PowerShell object back into a JSON file and use it to deploy the vCenter Server appliance. Figure 1-1 shows what is returned during the import process.

Listing 1-2: Sample script for an automated installation of the vCenter Server appliance

Figure 1-1: Sample vCSA import progress

Additional components, such as the vCenter Client or Update Manager, can also be installed in an automated fashion. We can deploy Update Manager the same way we deployed the Windows vCenter Server (see Listing 1-3).

Listing 1-3: Sample script for a silent install of the vSphere Client

vSphere Update Manager (VUM) deployments can also be automated in a similar fashion as vCenter Server. Update Manager can leverage a local database, but to maintain consistency with how we deployed vCenter Server, we will be deploying to a remote SQL database. Listing 1-4 shows how you can automate the deployment of vSphere Update Manager 6.

Listing 1-4: Sample script for an automated installation of vSphere Update Manager

      VMware supports more automated installation options and parameters, such as installing a linked mode vCenter Server, and maintains an online installation document here:

      https://www.vmware.com/support/pubs/vsphere-esxi-vcenter-server-pubs.html

      Set Up Your vCenter Server Folder Structure

      Two types of folders are supported in vSphere. From within the Hosts and Clusters view, you are able to create folders at any point under the datacenter level. These are commonly known as yellow folders and can be used throughout the infrastructure to organize the clusters, hosts, and VMs in a logical view.

      Blue folders can be seen in the VMs and Templates view. Use these folders to more accurately reflect the layout of your VMs from a logical point of view. For example, you can create folders based on departments (such as Finance, Legal, and Customer Services) or by function (Internet, Active Directory, File Servers, Print Servers, Databases), or any other view that makes sense to your organization. Blue folders could also be used to reflect a security function and used to group the VMs into folders that only certain people can access. Once you create the folder, you can use it to grant access to various vCenter Server permissions.

      Creating a Folder Structure from Scratch

You can initially create your folder structure when you create your new VMs; create your templates and move them into the appropriate folder. Another way of creating the folder structure is to plan the layout in a comma-separated value (CSV) file. This type of plan can easily be created in an Excel document, as shown in Figure 1-2, and then exported to the CSV format needed to create the virtual folder structure.

Figure 1-2: Sample CSV layout

In the example CSV file we created, there are two columns. The first column, Name, is used to define the name of the folder that you wish to create. The second column, Path, is used to show the path to where this folder is to be created in vCenter Server. As seen in Figure 1-2, in the Path column all entries begin with vm\. This folder will not be created but is used by the underlying application programming interface (API). Once you have created the CSV file that contains the layout of your folder structure, a script can easily read your CSV file and create the structure using the code shown in Listing 1-5.

Listing 1-5: Using a CSV file to create a vCenter file structure

      Exporting a Folder Structure

      Both yellow and blue folder views can be exported to a CSV file. You will find this technique useful when you are rebuilding your vCenter Server from scratch or creating a DR replica of the current virtual infrastructure.

The script in Listing 1-6 can be used to export either a blue or a yellow folder structure to a CSV. It can also be used to export the location of the current VMs, ensuring a replicated location when you reimport the structure.

Listing 1-6: Exporting a vCenter structure to a CSV file

      Importing a Folder Structure

You can import an existing blue or yellow folder structure into vCenter Server using the Import-Folders function previously shown in Listing 1-5. You can also choose if you would like your VMs moved back into their correct blue folders by using the Import-VMLocation function, as shown in Listing 1-7.

Listing 1-7: Importing VMs to their blue folders

      Define Users and Their Privileges

      The authorization to perform tasks in your virtual infrastructure is controlled by a role-based access control (RBAC) system. A vCenter Server administrator can specify in great detail which users or groups can perform which tasks on which objects. RBAC systems are defined using three key concepts:

      Privilege A privilege is the ability to perform an action or read a property. Examples include powering on a VM