NAME

VMware::API::vCloud - The VMware vCloud API

SYNOPSIS

  my $api = new VMware::API::vCloud (
    $hostname, $username, $password, $orgname
  );
  
  my $raw_login_data = $vcd->login;

DESCRIPTION

This module provides a bare interface to VMware's vCloud REST API.

VMware::vCloud is designed for high level usage with vCloud Director. This module, however, provides a more low-level access to the REST interface.

Responses received from vCloud are in XML. They are translated via XML::Simple with ForceArray set for consistency in nesting. This is the object returned.

Aside from the translation of XML into a perl data structure, no further alteration is performed on the data.

HTTP errors are automatically parsed and die() is called. If you need to perform a dangerous action, do so in an eval block and evaluate $@.

OBJECT METHODS

These methods are not API calls. They represent the methods that create this module as a "wrapper" for the vCloud API.

new()

This method creates the vCloud object.

Arguments

  • hostname

  • username

  • password

  • organization

config()

  $vcd->config( debug => 1 );
debug
  0 for no debugging.
  1 to turn on basic debug messages. 
  2 to display learned variables on exit.
  3 to show all XML transactions.
die_on_fault - 1 to cause the program to die verbosely on a soap fault. 0 for the fault object to be returned on the call and for die() to not be called. Defaults to 1. If you choose not to die_on_fault (for example, if you are writing a CGI) you will want to check all return objects to see if they are fault objects or not.
ssl_timeout - seconds to wait for timeout. Defaults to 3600. (1hr) This is how long a transaction response will be waited for once submitted. For slow storage systems and full clones, you may want to up this higher. If you find yourself setting this to more than 6 hours, your vCloud setup is probably not in the best shape.
hostname, orgname, username and password - All of these values can be changed from the original settings on new(). This is handing for performing multiple transactions across organizations.

REST METHODS

These are direct access to the REST web methods.

delete($url)

Performs a DELETE action on the given URL, and returns the parsed XML response.

get($url)

Performs a GET action on the given URL, and returns the parsed XML response.

get_raw($url)

Performs a GET action on the given URL, and returns the unparsed HTTP::Request object.

post($url,$type,$content)

Performs a POST action on the given URL, and returns the parsed XML response.

The optional value for $type is set as the Content Type for the transaction.

The optional value for $content is used as the content of the post.

put($url,$type,$content)

Performs a PUT action on the given URL, and returns the parsed XML response.

The optional value for $type is set as the Content Type for the transaction.

The optional value for $content is used as the content of the post.

API SHORTHAND METHODS

api_version

* Relative URL: /api/versions

This call queries the server for the current version of the API supported. It is implicitly called when library is instanced.

login

* Relative URL: dynamic, but usually: /login/

This call takes the username and password provided in the config() and creates an authentication token from the server. If successful, it returns the login data returned by the server.

In the 5.1 version of the API, this is a list of several access URLs.

logout()

Removes the current login session on the server.

admin()

* Relative URL: dynamic admin URL, usually /api/admin/

Parses the admin API URL to build and return a hash reference of key URLs for the API.

admin_extension_get()

* Relative URL: dynamic admin URL followed by "/extension"

admin_extension_vimServer_get()

admin_extension_vimServerReferences_get()

catalog_create($org_href,$conf)

$conf is a hashref that can contain:

  • name

  • description

  • is_published

Org HREF example: http://example.vcd.server/api/admin/org/{id}

catalog_get($catid or $caturl)

As a parameter, this method thakes the raw numeric id of the catalog or the full URL detailed for the catalog from the login catalog.

It returns the requested catalog.

catalog_get_access($cat_href,$org_href)

HREF example: http://example.vcd.server/api/org/{id}/catalog/{catalogId}/action/controlAccess

catalog_set_access($cat_href,$org_href,$is_shared,$level)

The sets the "organizational" sharing for a catalog.

  • is_shared - 1 or 0

  • level - one of: FullControl, Change, ReadOnly

HREF example: http://example.vcd.server/api/org/{id}/catalog/{catalogId}/action/controlAccess

org_create($name,$desc,$fullname,$is_enabled)

Create an organization.

  • name

  • desc

  • fullname

  • is_enabled

  • can_publish

  • deployed

  • stored

  • ldap_mode: NONE, SYSTEM or CUSTOM - Custom requires further parameters not implemented yet. Default is NONE

org_get($orgid or $orgurl)

As a parameter, this method takes the raw numeric id of the organization or the full URL detailed for the organization from the login catalog.

It returns the requested organization.

org_list()

Returns the full list of available organizations.

org_network_create($url,$conf)

Create an org network

The conf hash reference can contain:

  • name

  • desc

  • gateway

  • netmask

  • dns1

  • dns2

  • dnssuffix

  • is_enabled

  • is_shared

  • start_ip

  • end_ip

org_vdc_create($url,$conf)

Create an org VDC

The conf hash reference can contain:

  • name

  • desc

  • np_href

  • sp_enabled

  • sp_units

  • sp_limit

  • sp_default

  • sp_href

  • allocation_model

  • cpu_unit

  • cpu_alloc

  • cpu_limit

  • mem_unit

  • mem_alloc

  • mem_limit

  • nic_quota

  • net_quota

  • ResourceGuaranteedMemory

  • ResourceGuaranteedCpu

  • VCpuInMhz

  • is_thin_provision

  • pvdc_name

  • pvdc_href

  • use_fast_provisioning

org_vdc_update($url,$conf)

Create an org VDC

The conf hash reference can contain:

  • name (required)

  • desc

  • np_href

  • sp_enabled

  • sp_units

  • sp_limit

  • sp_default

  • sp_href

  • allocation_model

  • cpu_unit

  • cpu_alloc

  • cpu_limit

  • mem_unit

  • mem_alloc

  • mem_limit

  • nic_quota

  • net_quota

  • ResourceGuaranteedMemory

  • ResourceGuaranteedCpu

  • VCpuInMhz

  • is_thin_provision

  • pvdc_name

  • pvdc_href

  • use_fast_provisioning

pdvc_get($href)

task_get($href)

Returns information on the task.

template_get($templateid or $templateurl)

As a parameter, this method thakes the raw numeric id of the template or the full URL.

It returns the requested template.

template_get_metadata($tmpl_href)

Returns the response for metadata for the given template href.

HREF example: http://example.vcd.server/api/vAppTemplate/{uuid}

vdc_get($vdcid or $vdcurl)

As a parameter, this method thakes the raw numeric id of the virtual data center or the full URL detailed a catalog.

It returns the requested VDC.

vdc_list()

Returns the full list of available VDCs.

vapp_get($vappid or $vapp_href)

As a parameter, this method thakes the raw numeric id of the vApp or the full URL.

It returns the requested vApp.

vapp_get_metadata($vapp_href)

Returns the response for metadata for the given vApp href.

HREF example: http://example.vcd.server/api/vApp/{uuid}

BUGS and LIMITATIONS

LoginUrl error.

In both version 1.5 and 5.1 of the API, the "LoginUrl" returned upon log has the value of 'https://HOSTNAME/api/sessions'

To actually succeed with an API log out, however, the URL has to be "session" - singular - 'https://HOSTNAME/api/session'

This module works around this issue.

Template name validation.

Most names in the GUI (for vApps, VMs, Templates, and Catalogs) are limited to 128 characters, and are restricted to being composed of alpha numerics and standard keyboard punctuations. Notably, spaces and tabs are NOT allowed to be entered in the GUI. However, you can upload a template in the API with a space in the name. It will only be visable or usable some of the time in the GUI. Apparently there is a bug in name validation via the API.

WISH LIST

If someone from VMware is reading this, and has control of the API, I would dearly love a few changes, that might help things:

Statistics & Dogfooding - There is an implied contract in the API. That is, anything I can see and do in the GUI I should also be able to do via the API. There are no per-VM statistics available in the API. But the statistics are shown in the GUI. Please offer per-VM statistics in the API. Crosswalking the VM name and trying to find the data in the vSphere API to do this is a pain.
System - It would really help if in the API guide it mentions early on that the organization to connect as an administrator account, IE: the macro organization to which all other orgs descend from is called "System." That helps a lot.
External vs External - When you have the concept of a "fenced" network for a vApp, one of the most confusing points is the local network that is natted to the outside is referred to as "External" as is the outside IPs that the network is routed to. Walk a new user through some of the Org creation wizards and watch the confusion. Bad choice of names.

VERSION

  Version: v2.32 (2013-03-29)

AUTHOR

  Phillip Pollard, <bennie@cpan.org>

CONTRIBUTIONS

A strong thanks to all people who have helped me with direction, ideas, patches and other such items.

  Dave Gress, <dgress@vmware.com> - Handling org admin issues and metadata
  Stuart Johnston, <sjohnston@cpan.org> - authentication and XML on API v1.0

DEPENDENCIES

  LWP
  XML::Simple

LICENSE AND COPYRIGHT

  Released under Perl Artistic License

SEE ALSO

 VMware vCloud Director Publications
  http://www.vmware.com/support/pubs/vcd_pubs.html
  http://pubs.vmware.com/vcd-51/index.jsp

 VMware vCloud API Programming Guide v5.1
  http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.doc_51/GUID-86CA32C2-3753-49B2-A471-1CE460109ADB.html
  
 vCloud API and Admin API v5.1 schema definition files
  http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/about.html
  
 VMware vCloud API Communities
  http://communities.vmware.com/community/vmtn/developer/forums/vcloudapi

 VMware vCloud API Specification v1.5
  http://www.vmware.com/support/vcd/doc/rest-api-doc-1.5-html/