Reader small image

You're reading from  Learning PowerCLI - Second Edition

Product typeBook
Published inFeb 2017
Publisher
ISBN-139781786468017
Edition2nd Edition
Right arrow
Author (1)
Robert van den Nieuwendijk
Robert van den Nieuwendijk
author image
Robert van den Nieuwendijk

Robert van den Nieuwendijk is an IT veteran from the Netherlands with over thirty years of experience in Information Technology. He holds a bachelor degree in software engineering. After working a few years as a programmer of air traffic control and vessel traffic management systems, he started his own company Van den Nieuwendijk Informatica in 1988. Since then he has worked as a freelance systems administrator of OpenVMS, Windows Server, Linux, and VMware vSphere systems, for Dutch governmental organizations and cloud providers. During winter he is also a ski and snowboard instructor at an indoor ski school. With his background as a programmer, he always tries to make his job easier by writing programs or scripts to perform repeating tasks. In the past, he used the C programming language, OpenVMS DCL, Visual Basic Script and KiXtart to do this. Now, he uses Microsoft PowerShell and VMware PowerCLI for all of his scripting work. Robert is a frequent contributor and moderator at the VMware VMTN Communities. Since 2012 VMware awarded him the vExpert title for his significant contributions to the community and a willingness to share his expertise with others. He has a blog at http://rvdnieuwendijk.com where he writes mainly about VMware PowerCLI, Microsoft PowerShell, and VMware vSphere. If you want to get in touch with Robert, then you can find him on Twitter. His username is @rvdnieuwendijk. Robert is also the author of Learning PowerCLI, Packt Publishing.
Read more about Robert van den Nieuwendijk

Right arrow

Chapter 11.  Managing VMware vCloud Director and vCloud Air

VMware vCloud Director (vCD) is VMware's product for cloud service providers to build multitenant cloud services. VMware vCloud Air is VMware's public cloud platform built on vCD. Virtual machines managed by vCloud Director should not be modified in VMware vSphere. Both products can be managed using PowerCLI. The PowerCLI modules VMware.VimAutomation.Cloud and  VMware.VimAutomation.PCloud provides cmdlets to use vCD and vCloud Air. In this chapter, you will learn to how to manage vCD and vCloud Air virtual appliances as well as virtual machines using PowerCLI.

This chapter covers the following topics:

  • Connecting to vCloud Air servers and vCloud Director servers

  • Retrieving organizations

  • Retrieving organization virtual data centers

  • Retrieving organization networks

  • Retrieving vCloud users

  • Using vCloud virtual appliances

  • Managing vCloud virtual machines

  • Using the vCloud Director API with Get-CIView

  • Disconnecting from vCloud Director servers...

Connecting to vCloud Air servers and vCloud Director servers


Before you can start to use PowerCLI cmdlets to manage a vCloud Air or a vCD environment, you have to establish a connection to a vCloud Air or vCD server.

Tip

You can start any of the VMware Hands-on Labs for vCloud Air, to get a temporary vCloud Air account. Such a temporary vCloud Air account can be used to try the examples in this chapter. The temporary account will be reset after exiting the lab. You can find the VMware Hands-on Labs at http://labs.hol.vmware.com/ . While writing this chapter, I used HOL-1782-HBD-1 - VMware vCloud Air - Data Center Extension for testing. After starting the lab, you have to go to http://checkin.vcahol.com and enter your e-mail address to get your student account.

In the following image, you will see the temporary credentials we received from the Hands-on Lab.

The Connect-CIServer cmdlet establishes a connection to the specified vCD servers.

The syntax of the Connect-CIServer cmdlet is as follows...

Retrieving organizations


An organization in vCloud Director is a container that contains users, vApps, Organization Virtual Data Centers (Org vDCs), and Catalog entities. For every tenant in vCloud Director, there is an organization.

To retrieve organizations, you can use the Get-Org cmdlet. This cmdlet has the following syntax. The first parameter set is the default:

Get-Org [[-Name] <String[]>] [-Server <CIServer[]>]
    [<CommonParameters>]

The second parameter set is to retrieve organizations by ID:

Get-Org -Id <String[]> [-Server <CIServer[]>] [<CommonParameters>]

The -Id parameter is required.

If you use the Get-Org cmdlet without parameters, it will retrieve all of the organizations in your cloud. In the following example, we will retrieve the organization we are connected to in vCloud Air:

PowerCLI C:\> Get-Org


    Name       FullName   Enabled Description
----       --------   ------- -----------
student501 student501 True

As you can see in...

Retrieving organization virtual datacenters


An organization virtual data center or organization vDC is a group of computing, memory, and storage resources from one vCenter Server allocated to an organization. The Get-OrgVdc cmdlet retrieves organization vDCs. The syntax of the Get-OrgVdc cmdlet is as follows. The first parameter set is the default.

Get-OrgVdc [[-Name] <String[]>] [-Org <Org[]>] [-ProviderVdc
    <ProviderVdc[]>] [-Server <CIServer[]>] [<CommonParameters>]

The second parameter set is to retrieve organization virtual data centers by ID:

Get-OrgVdc -Id <String[]> [-Server <CIServer[]>] [<CommonParameters>]

The -Id parameter is required.

In the following example, we will retrieve the organization vDC for our vCloud Air connection:

PowerCLI C:\> Get-OrgVdc


    Name       Enabled CpuUsedGHz MemoryUsedGB StorageUsedGB Allocation Model
----       ------- ---------- ------------ ------------- -----------
student501 True    1.00...

Retrieving organization networks


If you create virtual appliances or virtual machines, you probably want to connect them to a network. The Get-OrgVdcNetwork cmdlet will retrieve available organization vDC networks. The syntax of the Get-OrgVdcNetwork cmdlet is given here. The first parameter set is the default:

Get-OrgVdcNetwork [[-Name] <String[]>] [-OrgVdc <OrgVdc[]>]
    [-Server <CIServer[]>] [<CommonParameters>]

The second parameter set is to retrieve organization vDC networks by ID:

Get-OrgVdcNetwork -Id <String[]> [-Server <CIServer[]>]
    [<CommonParameters>]

The -Id parameter is required.

The Get-OrgVdcNetwork cmdlet without parameters will retrieve all of the organization vDC networks, as shown in the following example:

PowerCLI C:\> Get-OrgVdcNetwork


    Name                       OrgVdc     DefaultGateway NetworkType
----                       ------     -------------- -----------
student501-IsolatedNetwork student501 192.16.50.1...

Retrieving vCloud users


You can use the Get-CIUser cmdlet to retrieve vCloud users. The Get-CIUser cmdlet has an alias Get-PIUser.

The syntax of the Get-CIUser cmdlet is as follows and the first parameter set is the default:

Get-CIUser [[-Name] <String[]>] [-Org <Org[]>] [-Role <CIRole[]>]
    [-Server <CIServer[]>] [<CommonParameters>]

The second parameter set is to retrieve vCloud users by ID:

Get-CIUser -Id <String[]> [-Server <CIServer[]>] [<CommonParameters>]

The -Id parameter is required.

In the following example, we will retrieve the user student501@vcahol.com and format the output in a list view:

PowerCLI C:\> Get-CIUser -Name student501@vcahol.com | Format-List


    WARNING: PowerCLI scripts should not use the 'Client' property. The
property will be removed in a future release.
WARNING: PowerCLI scripts should not use the 'Uid' property. The
property will be removed in a future release.
Href            : https://p13v37-vcd.vchs.vmware...

Using vCloud virtual appliances


A virtual appliance (vApp) is a container that contains one or more virtual machines. These virtual machines together make an application. For example, if you have a three-tier application, you can have a vApp that contains the database server, the application server, and the web server. In vCloud Director every virtual machine has to be part of a vApp.

In the following sections Retrieving vApp templates, Creating vCloud vApps, Retrieving vCloud vApps, Starting vCloud vApps, and Stopping vCloud vApps , we will show you how to use the PowerCLI cmdlets to retrieve vApp templates, create vApps, retrieve vApps, start vApps, and stop vApps.

Retrieving vApp templates

In vCloud Air, there are some predefined vApp templates available for use in your tenant environment. You can use the vApp templates to create your vApps. The Get-CIVAppTemplate cmdlet retrieves these vApp templates. The syntax of this cmdlet is as follows, and the first parameter set is the default:

Get...

Managing vCloud virtual machines


In the following sections Creating vCloud virtual machines, Retrieving vCloud virtual machines, Starting vCloud virtual machines, and Stopping vCloud virtual machines, we will show you how to use PowerCLI to create VMware vCloud Director or VMware vCloud Air virtual machines, retrieve vCloud virtual machines, start vCloud virtual machines, and stop vCloud virtual machines.

Creating vCloud virtual machines

The New-CIVM cmdlet can be used to create new cloud virtual machines. The syntax of the New-CIVM cmdlet is as follows:

New-CIVM -VApp <CIVApp> -VMTemplate <CIVMTemplate> [[-Name]
    <String>] [-ComputerName <String>] [-RunAsync] [-Server 
    <CIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

The -VApp and -VMTemplate parameters are required.

In the following example, we will create a new Windows Server 2012 R2 virtual machine named Server001 in vApp001:

PowerCLI C:\> New-CIVM -Name Server001 -VApp vApp001 
   ...

Using the vCloud Director API with Get-CIView


While writing this book, there is no Remove-CIVM cmdlet available in PowerCLI. To remove a vCloud Director or a vCloud Air virtual machine, or do anything else in vCloud Director or vCloud Air for which there is no PowerCLI cmdlet, you will have to use the vCloud API. PowerCLI provides us the Get-CIView cmdlet that gives access to the cloud view objects of the vCloud API. You can also use the ExtensionData property of the vCloud objects, to access the vCloud API, just like you can do with vSphere objects to access the vSphere API. The syntax of the Get-CIView cmdlet is as follows. The first parameter set is to retrieve cloud view objects from a cloud object:

Get-CIView [-CIObject] <CIObject[]> [-Server <CIServer[]>]  
    [<CommonParameters>]

The -CIObject parameter is required.

The second parameter set is to retrieve cloud view objects by ID:

Get-CIView -Id <String[]> [-ViewLevel <CIViewLevel>] 
    [-Server <...

Disconnecting from vCloud Director servers


To disconnect your session from the specified cloud servers, you can use the Disconnect-CIServer cmdlet. The syntax of the Disconnect-CIServer cmdlet is as follows:

Disconnect-CIServer [[-Server] <CIServer[]>] [-Force] 
    [-WhatIf] [-Confirm] [<CommonParameters>]

The Disconnect-CIServer cmdlet has no required parameters.

In the following example, we will disconnect from all default cloud servers without asking for confirmation:

PowerCLI C:\> Disconnect-CIServer * -Confirm:$false

The preceding command does not return any output.

Summary


In this chapter, you have seen how you can manage VMware vCloud Air and VMware vCloud Director servers from PowerCLI. We have used the VMware Hands-on Labs to get a temporary account to use VMware vCloud Air and connected to the vCloud Director servers used for vCloud Air.

You have learned how to retrieve organizations, organization virtual data centers, organization networks, and vCloud users. We showed how to create, retrieve, start, stop, and remove vCloud virtual machines and virtual appliances. Creating, retrieving, reverting to, and removing snapshots was discussed. Finally, we disconnected from the vCloud Director servers.

In the next chapter, you will learn how to use Site Recovery Manager from PowerCLI.

lock icon
The rest of the chapter is locked

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
You have been reading a chapter from
Learning PowerCLI - Second Edition
Published in: Feb 2017Publisher: ISBN-13: 9781786468017
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.
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 £13.99/month. Cancel anytime

Author (1)

author image
Robert van den Nieuwendijk

Robert van den Nieuwendijk is an IT veteran from the Netherlands with over thirty years of experience in Information Technology. He holds a bachelor degree in software engineering. After working a few years as a programmer of air traffic control and vessel traffic management systems, he started his own company Van den Nieuwendijk Informatica in 1988. Since then he has worked as a freelance systems administrator of OpenVMS, Windows Server, Linux, and VMware vSphere systems, for Dutch governmental organizations and cloud providers. During winter he is also a ski and snowboard instructor at an indoor ski school. With his background as a programmer, he always tries to make his job easier by writing programs or scripts to perform repeating tasks. In the past, he used the C programming language, OpenVMS DCL, Visual Basic Script and KiXtart to do this. Now, he uses Microsoft PowerShell and VMware PowerCLI for all of his scripting work. Robert is a frequent contributor and moderator at the VMware VMTN Communities. Since 2012 VMware awarded him the vExpert title for his significant contributions to the community and a willingness to share his expertise with others. He has a blog at&nbsp;http://rvdnieuwendijk.com where he writes mainly about VMware PowerCLI, Microsoft PowerShell, and VMware vSphere. If you want to get in touch with Robert, then you can find him on Twitter. His username is @rvdnieuwendijk. Robert is also the author of Learning PowerCLI, Packt Publishing.
Read more about Robert van den Nieuwendijk