After you define a resource class, you can specify the actions that are permitted on resources of that class.

A ResourceClassAction object defines an HTTP method that is allowed on a specific UrlPattern. The UrlPattern can be any of the following URL forms:
  • An explicit URL like/backup/restore/vm/27. A UrlPattern of this form defines an action for a resource that has a specific URL.
  • A URL that contains a regular expression, like /backup/restore/vm[-,a-z,0-9]*. A UrlPattern of this form defines an action for any resource in the class that matches the regular expression.
  • A URL that contains a service resource id, which is expressed as <id>. In a UrlPattern, the delimiters must be written as the XML entities &lt; and &gt;. The id can stand alone, as in /backup/restore/vm/&lt;id&gt;, or appear as part of a regular expression like/backup/restore/vm/?&lt;id&gt;[-,a-z,0-9]*). A UrlPattern of this form targets a specific ServiceResource, which must the service must define and register.

Prerequisites

This operation is restricted to system administrators.

Procedure

  1. Retrieve the XML representation of the service.
    Use a request like this one:
    GET https://vcloud.example.com/api/admin/extension/service/45
  2. Examine the response to find the Link for specifying resource class actions.
    This Link has the following form:
    <vcloud:Link
          rel="add"
          type="application/vnd.vmware.admin.resourceClassAction+xml"
          href="https://vcloud.example.com/api/admin/extension/service/45/resourceclassactions" />
  3. Construct a ResourceClassAction element.
    For information about the contents of this element, see the request portion of Define an Action for a Resource Class.
  4. POST the ResourceClassAction element to the URL described in Step 2.

Example: Define an Action for a Resource Class

This example defines a resource class action for a GET request to a UrlPattern that could match URLs including https://vcloud.example.com/api/backup/27 or https://vcloud.example.com/api/backup/vm-27-backup-2013-04-25T01:17:00.000Z.

Request:
POST https://vcloud.example.com/api/admin/extension/service/45/resourceclassactions
Content-type:application/vnd.vmware.admin.resourceClassAction+xml
<?xml version="1.0" encoding="UTF-8"?>
<vmext:ResourceClassAction
   xmlns:vmext="http://www.vmware.com/vcloud/extension/v1.5"
   xmlns:vcloud="http://www.vmware.com/vcloud/v1.5"
   name="Read backups">
   <vmext:HttpMethod>GET</vmext:HttpMethod>
   <vmext:UrlPattern>/api/backup/[-,a-z,0-9]*)</vmext:UrlPattern>
</vmext:ResourceClassAction>

The response is a ResourceClassAction element that includes information derived from the contents you POSTed , along with a set of Link elements that you can use to remove the ResourceClassAction or add ACL rules that control access to the resource class through the action.

Response:
201 Created
Content-Type: application/vnd.vmware.admin.resourceClassAction+xml
...
<vmext:ResourceClassAction
   xmlns:vmext="http://www.vmware.com/vcloud/extension/v1.5"
   xmlns:vcloud="http://www.vmware.com/vcloud/v1.5"
   name="Read backups"
   id="urn:vcloud:resourceClassAction:268"
   type="application/vnd.vmware.admin.resourceClassAction+xml"
   href="https://vcloud.example.com/api/admin/extension/service/resourceclassaction/268"
   ... >
   <vcloud:Link
      rel="remove"
      href="https://vcloud.example.com/api/admin/extension/service/resourceclassaction/268" />
   <vcloud:Link
      rel="up"
      type="application/vnd.vmware.admin.resourceClass+xml"
      href="https://vcloud.example.com/api/admin/extension/service/resourceclass/83" />
   <vcloud:Link
      rel="down:aclRules"
      type="application/vnd.vmware.vcloud.query.records+xml"
      href="https://vcloud.example.com/api/admin/extension/service/resourceclassaction/268/aclrules" />
   <vmext:HttpMethod>GET</vmext:HttpMethod>
   <vmext:UrlPattern>/api/backup/[-,a-g,0-9]*)</vmext:UrlPattern>
</vmext:ResourceClassAction>