Skip to content
This repository has been archived by the owner on Nov 9, 2020. It is now read-only.
/ vchs Public archive

VMware OnDemand REST API Java Samples

License

Notifications You must be signed in to change notification settings

vmware-archive/vchs

Repository files navigation

VMware has ended active development of this project, this repository will no longer be updated.

VMware OnDemand REST API Java Samples

Requirements

  • Java 7 or later
  • Maven 3

Clone repository

git clone https://github.com/vmware/vchs.git

Change directory

cd vchs

Install required libraries

mvn install:install-file -Dfile=./lib/vchs-rest-apis-1.0.0.jar -DgroupId=com.vmware.vchs -DartifactId=vchs-rest-apis -Dversion=1.0.0 -Dpackaging=jar
mvn install:install-file -Dfile=./lib/rest-api-schemas-1.0.0.jar -DgroupId=com.vmware.vcloud -DartifactId=rest-api-schemas -Dversion=1.0.0 -Dpackaging=jar

Compile

mvn compile

Run examples

mvn exec:java -Dexec.mainClass=com.vmware.vchs.api.samples.ondemand.endtoend.ListPlansAndInstances -Dexec.args="--username <your account username here> --password <your account password here> --hostname https://vchs.vmware.com --version 5.7"

The list below will detail each sample you can run and what it does. You can then look at the source code to see how it uses the API for your own purposes.

Helper samples

ListVdcAndVmIds

This helper class can be executed to list all the VDCs and VMs of your organization. It's purpose is to list the name and IDs of each VDC and VM. The IDs can be utilized in various API calls, including but not limited to the Metering and Billing APIs where the L1 and L2 IDs represent VM and VDC IDs respectively. It also can be used after creating a new VDC, for example, to verify the VDC was indeed created.

mvn exec:java -Dexec.mainClass=com.vmware.vchs.api.samples.ondemand.details.ListVdcAndVmIds -Dexec.args="--username <your account username here> --password <your account password here> --hostname https://vchs.vmware.com --version 5.7"

ListVdcTemplates

This helper class can be executed to list all the VDCs and VDC Templates of your organization. This is primarily to help identify VDC Templates you can use to create additional VDCs with.

mvn exec:java -Dexec.mainClass=com.vmware.vchs.api.samples.ondemand.details.ListVdcTemplates -Dexec.args="--username <your account username here> --password <your account password here> --hostname https://vchs.vmware.com --version 5.7"

ListVmTemplates

This helper class can be executed to list all the VM templates available for your organization. The results of this call can then be used in the CreateVmFromTemplate end to end sample to create a new VM from one of the listed templates.

mvn exec:java -Dexec.mainClass=com.vmware.vchs.api.samples.ondemand.details.ListVmTemplates -Dexec.args="--username <your account username here> --password <your account password here> --hostname https://vchs.vmware.com --version 5.7"

OnDemand End to End Samples

CreateVdcFromTemplate

This end to end sample will create an additional VDC for your organization from a VDC Template you specify as part of the command line.

mvn exec:java -Dexec.mainClass=com.vmware.vchs.api.samples.ondemand.endtoend.CreateVdcFromTemplate -Dexec.args="--username <your account username here> --password <your account password here> --hostname https://vchs.vmware.com --version 5.7 --region <region identifier> --vdctemplatename <name of VDC template>"

CreateVmFromTemplate

This end to end sample will create a new VM within a VDC of your organization using a VM template you specify. Using the ListVmTemplates helper class will provide the list of templates you can use to create a VM from.

mvn exec:java -Dexec.mainClass=com.vmware.vchs.api.samples.ondemand.endtoend.CreateVmFromTemplate -Dexec.args="--username <your account username here> --password <your account password here> --hostname https://vchs.vmware.com --version 5.7 --region <region identifier> --vdcname <name of the VDC to create VM in> --vmname <display name of VM> --vmtemplatename <the name of the VM template to create the VM from>"

ListPlansAndServices

This is a simple end to end sample, which will log in to IAM, then list all available service plans, then list all available service instances. Each list will contain helpful details such as the plan ID, serviceName property and so on.

mvn exec:java -Dexec.mainClass=com.vmware.vchs.api.samples.ondemand.endtoend.ListPlansAndInstances -Dexec.args="--username <your account username here> --password <your account password here> --hostname https://vchs.vmware.com --version 5.7"

UserManagement

This end to end sample will use the IAM user management APIs to display a list of all users in your organization that are accessible by the provided credentials, create a new user, update the user's Family Name value, then delete the new user.

mvn exec:java -Dexec.mainClass=com.vmware.vchs.api.samples.ondemand.endtoend.UserManagement -Dexec.args="--username <your account username here> --password <your account password here> --hostname https://vchs.vmware.com --version 5.7"

MeteringAndBilling

This end to end sample will display some billing and metering details for the specified VM and VDC IDs provided. Using the ListVdcAndVmIds helper will list the VDC and VM ids that can be used in this sample. Also, to get the service instance id (sid) execute the ListPlansAndInstances sample.

mvn exec:java -Dexec.mainClass=com.vmware.vchs.api.samples.ondemand.endtoend.MeteringAndBilling -Dexec.args="--username <your account username here> --password <your account password here> --hostname https://vchs.vmware.com --version 5.7 --l2 <the id of L2 (e.g. VDC ID for compute) to retrieve metering data for> --l1 <the id of L1 (e.g. VM ID for compute service) to retrieve metering data for> --serviceGroupId <the service group id to retrieve metering data for> --serviceInstanceId <the service instance id to retrieve metering data for >"