How-To create backups of running vApps in VMware vCloud version 5.1 and earlier

With vCloud version 5.5 the Director (web GUI) got a bunch of useful features. One of them is Cloning Running vApps: http://www.vmware.com/files/pdf/products/vCloud/Whats-New-VMware-vCloud-Director-55-Technical-Whitepaper.pdf page 9 – 2.2.3 Clone vApp with Memory State

With older deployments of vCloud administrators still have to use the REST API to create these hot-clones. From the vCloud Director the only option to clone a vApp is to stop that first, which method is simply unacceptable in production environments.

When developing automated backups, or auto deploying vApps/networks the REST API-based scripts come handy even with newer versions.

Let’s take a look at the API through a few simple examples.

Examples

Login to the vCloud

POST https://%5Bvcloud-url%5D/api/sessions

Headers:

Authorization: Basic <encripted auth>
Accept: application/*+xml;version=5.1

Response:

<?xml version="1.0" encoding="UTF-8"?>
<Session xmlns="http://www.vmware.com/vcloud/v1.5" user="test-user" org="test-org" type="application/vnd.vmware.vcloud.session+xml" href="https://url.to.vcloud/api/session/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://url.to.vcloud/api/v1.5/schema/master.xsd">
   <Link rel="down" type="application/vnd.vmware.vcloud.orgList+xml" href="https://url.to.vcloud/api/org/"/>
   <Link rel="remove" href="https://url.to.vcloud/api/session/"/>
   <Link rel="down" type="application/vnd.vmware.admin.vcloud+xml" href="https://url.to.vcloud/api/admin/"/>
   <Link rel="down" type="application/vnd.vmware.vcloud.org+xml" name="test-org" href="https://url.to.vcloud/api/org/adsfkjasdf-asdfasdio8d-asdf3ef"/>
   <Link rel="down" type="application/vnd.vmware.vcloud.query.queryList+xml" href="https://url.to.vcloud/api/query"/>
   <Link rel="entityResolver" type="application/vnd.vmware.vcloud.entity+xml" href="https://url.to.vcloud/api/entity/"/>
   <Link rel="down:extensibility" type="application/vnd.vmware.vcloud.apiextensibility+xml" href="https://url.to.vcloud/api/extensibility"/>
</Session>

Getting schema of elements – next is the vOrg:

GET https://url.to.vcloud/api/org/adsfkjasdf-asdfasdio8d-asdf3ef

Headers:

Authorization: Basic <encripted auth>
Accept: application/*+xml;version=5.1

Response:

…
<Link rel="down" type="application/vnd.vmware.vcloud.vdc+xml" name="test-vdc" href= "https://url.to.vcloud/api/vdc/jkghuighke-sgjkdbgui-rfse" />
…

And so on – getting the schemas of the vDc (-> vApp -> VM/network)

GET https://url.to.vcloud/api/vdc/jkghuighke-sgjkdbgui-rfse

Cloning

POST https://url.to.vcloud/api/vdc/<vdc ID>/action/cloneVApp

Headers:

Authorization: Basic <encripted auth>
Accept: application/*+xml;version=5.1

Body:

<?xml version="1.0" encoding="UTF-8"?>
<CloneVAppParams
   xmlns="http://www.vmware.com/vcloud/v1.5"
   xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"
   name="<name of the clone>"
   deploy="true"
   powerOn="false">
   <Description>Cloned vApp Example</Description>
   <InstantiationParams>
     <NetworkConfigSection>
         <ovf:Info>Configuration parameters for logical networks</ovf:Info>
     </NetworkConfigSection>
   </InstantiationParams>
   <Source
     href="https://url.to.vcloud/api/vApp/<source vapp ID>" />
   <IsSourceDelete>false</IsSourceDelete>
</CloneVAppParams>

The response contains the ID of the clone.

Capturing Template

POST https://url.to.vcloud/api/vdc/<vdc ID>/action/captureVApp

Headers:

Authorization: Basic <encripted auth>
Accept: application/*+xml;version=5.1

Body:

<?xml version="1.0" encoding="UTF-8"?><vcloud:CaptureVAppParams
xmlns:vcloud="http://www.vmware.com/vcloud/v1.5"
name="<name of the template">
<vcloud:Description>Template captured from vapp.</vcloud:Description>
<vcloud:Source
href="https://url.to.vcloud/api/vApp/<vapp ID of the previous clone>" />
</vcloud:CaptureVAppParams>

The response contains the ID of the template.

Cataloging the template

POST https://url.to.vcloud/api/catalog/<catalog ID>/catalogItems

Headers:

Authorization: Basic <encripted auth>
Accept: application/*+xml;version=5.1

Body:

<?xml version="1.0" encoding="UTF-8"?>
<CatalogItem
name="<name of the template>"
type="application/vnd.vmware.vcloud.catalogItem+xml"
xmlns="http://www.vmware.com/vcloud/v1.5">
<Description>backed up template</Description>
<Entity
href="https://url.to.vcloud/api/vAppTemplate/<ID of the template created in previous step>"/>
</CatalogItem>

Creating the Hot-Clone

You noticed for sure, that executing the steps above in that order, it’s quite easy to create a cataloged template of a running vApp. The “extra” clone before the template-capture is necessary, because it’s not possible (was not before 5.5) to capture a template of a running vApp (even with the REST API).

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s