Sample Code

The following section provides sample code to perform common scenarios or tasks with the Commander API.

Authenticate

  1. Logging in with JWT and renewing the token for subsequent API calls.

Add users to an organization

In this scenario, you create an organization and a user, and then add the user as a member of the organization.

  1. Create an organization named myNewOrganization.
  2. Create a user with username mynewuser and password secret.
  3. Add the user to the organization.
  4. The user mynewuser is added as a member of the organization myNewOrganization. The user is given a role of CUSTOMER in the organization.

Apply custom attributes to virtual machines

In this scenario, you look up a virtual machine by name and apply a custom attribute.

  1. Filter the collection of virtual machines by name to find the virtual machine ID.
  2. Apply the custom attribute to the virtual machine.
  3. The custom attribute named SLA is applied to the virtual machine. The custom attribute is given a value of Gold.

Assign an organizational owner to a virtual machine

In this scenario, you look up a virtual machine by name and assign it an organizational owner.

  1. Filter the collection of virtual machines by name to find the virtual machine ID.
  2. Assign the virtual machine to the organization.
  3. The organization myNewOrganization is assigned as the owner of the virtual machine centos-vm.

Deploy a virtual machine

In this scenario, you select a service from the catalog and generate its request form. Reconfigure the request form by increasing the number of CPUs, then submit it. Because there is a deployment destination and an approval workflow, the virtual machine auto-deploys when the service request is submitted.

  1. Find the ID of the service named VMware from the service catalog.
  2. Generate the request form for the service.
  3. The request form is a JSON document that contains the configurable attributes of the service. The administrator controls which attributes of each service are configurable, so the request form varies by service.

  4. Reconfigure the request form to increase the number of CPUs.
  5. In this scenario, the administrator has made the CPU Count a configurable property of the service. The CPU Count may be reconfigured, but it isn't required.

  6. Submit the complete service request.

Create an AWS deployment destination

In this scenario, you create an AWS deployment destination.

To create a deployment destination, you find the supporting resources for the cloud account type, and reference those resources in the creation request.

  1. Find the cloud account that the target of the deployment destination belongs to, filtering by cloud account type.
  2. Find the region that the target belongs to, filtering by cloud account and region name.
  3. Find the virtual cloud that's the target of the destination, filtering by cloud account and region.
  4. Find the subnets applicable to the destination, filtering by the target virtual cloud.
  5. Optionally, add a key pair to the destination. To find key pairs applicable to the destination, filter by the cloud account.
  6. Optionally, add security groups to the destination. To find security groups applicable to the target, filter by the virtual cloud.
  7. In the common section of the deployment destination creation request, configure the cloud account, the target virtual cloud, and a unique name for the destination. Configure the AWS specific resource references in the aws property, and submit the request. Because users and organizations weren't configured, the deployment destination is globally accessible.

Create a VMware deployment destination

In this scenario, you create a VMware deployment destination.

To create a deployment destination, you find the supporting resources for the cloud account type, and reference those resources in the creation request. In this scenario, the destination targets a host, and you use both datastores and datastore clusters as storage. You assign both standard networks and distributed portgroups to the destination.

  1. Find the cloud account that the target of the deployment destination belongs to, filtering by cloud account type.
  2. Find the datacenter that the target belongs to, filtering by cloud account and datacenter name.
  3. Find the host that's the target of the destination, filtering by cloud account and datacenter.
  4. Find the storage to use for the destination. You can use any combination of datastores and datastore clusters as storage. To find storage that's valid for the destination, filter the datastores and datastore clusters by the target host.
  5. Since you're not connecting to the same network as the source, find the networks to use for the destination. You can use any combination of standard networks and distributed portgroups, both of which are available in the networks collection. To find networks that are valid for the destination, filter by the target host.
  6. In the common section of the deployment destination create request, reference the cloud account, the target host, and configure a unique name for the destination. In the vmware_vcenter property, configure the datacenter as the location, and reference the storage resources. Configure the destination to not use the same networks as the source, and configure the networks. Don't assign NICs a static IP address. Disable fenced networking, and submit the request. Because users and organizations weren't configured for the destination, the destination is globally accessible.

Add users and organizations to a deployment destination

In this scenario, you modify a deployment destination to make it accessible to a limited set of users and organizations. You update the users and organizations by replacing the existing sets with new sets.

  1. Get the current set of users and organizations the destination is accessible to.
  2. Replace the existing set of users and organizations with new sets, and submit the update request. The destination is accessible only to the configured users and organizations. It isn't globally accessible.

Add placement attributes to a deployment destination

In this scenario, you update a deployment destination by adding placement attributes. You add one provided placement attribute, and one selectable placement attribute. To update placement attributes, you replace the existing set with a new set.

  1. Get the current set of placement attributes associated with the destination.
  2. Add the new placement attributes to the set, and submit the update request. Because the attribute fixed-placement-attribute is a provided placement attribute, it has no value. The selectable-placement-attribute has a value of some value.

Configure per-destination quotas for organizations

In this scenario, you configure a destination quota for an organization. The organization is named myOrganization and the deployment destination is named VMWare-dest. You assign the organization to the deployment destination, and update the organization with a quota for the destination. Like global quotas, a destination can have either a cost quota or a resource quota, but not both. In this example, you configure a cost quota for the organization.

  1. Filter the collection of deployment destinations by name to find the deployment destination ID.
  2. Assign the organization to the deployment destination.
  3. Update the organization with a cost quota for the deployment destination. Reference the deployment destination ID, and configure a quota limit of $2000.00 for the organization.

Configure per-destination quotas for organization members

In this scenario, you configure a destination quota for an organization member. You assign the organization to the deployment destination, and update the organization member with a quota for the destination. Because the organization has a destination cost quota, the organization member can either have a destination cost quota, or no quota.

 

In this example, the user myOrgMember is a member of organization myOrganization. The deployment destination is named VMware-dest.

  1. Filter the collection of deployment destinations by name to find the deployment destination ID.
  2. Assign the organization to the deployment destination.
  3. Update the organization member with a cost quota for the deployment destination. Reference the deployment destination ID, and configure a quota limit of $100.00 for the organization member.