Deploy VMs Using the Rest API

*Note that the credentials used in these API calls should have either Administrator or Automator permissions.

 

This tutorial provides an example of how to deploy VMs from a Bash command prompt. It also makes use of grep in order to filter out the API's response and only return relevant information. When you follow these steps, remember to replace the username, password, and server IP address in each step, as well as the UUIDs that are obtained in each step.

 

1) Find template you want to clone into new VMs. Note the “uuid” property (bolded). Note that some earlier versions of Operations Manager have different conventions for how the “name” property is set (e.g. They might start with "VirtualMachine::")
- You can use “grep” if you know the display name of the template that you want to use to avoid scanning through a lot of XML
- In this example, this is a discovered VCenter VM template. You can see the memory capacity (vMemSize) and the number of configured VCPUs (numVCPUs).

vmturbo:~ # curl -X GET http://username:password@1.2.3.4/vmturbo/api/templates | grep "TMP-linux"

Response:
<TopologyElement accessSpeedConsumed="0.0" cpuConsumedFactor="0.5" creationClassName="VirtualMachineProfile" displayName="10.10.10.2::TMP-linux" ioThroughputConsumed="0.0" memConsumedFactor="0.75" model="" name="vm-803" networkThroughputConsumed="0.0" numVCPUs="1" price="0.0" storageConsumedFactor="1.0" uuid="T421ebff3-350d-0cc9-4eb2-02982a8059c6" vMemSize="3072.0" vStorageSize="0" vendor="”/>

 

2) Get the deployment profiles that are associated with it. Note the “uuid” property (italicized and underlined), shown below.
- You can use “grep” to find only deployment profiles that are related to the template you chose below.

vmturbo:~ # curl -X GET http://username:password@1.2.3.4/vmturbo/api/deploymentprofiles | grep -B3 -A1 "T421ebff3-350d-0cc9-4eb2-02982a8059c6"

Response:
<TopologyElement creationClassName="ServiceCatalogItem" discovered="true" displayName="DEP-linux" name="linux" uuid="_kvPKccVrEeOOn73Mmc1_Hg">
  <scope>a4488f5d4067554d3bc2d63a4967bf218d1685ff</scope>   <scope>_kKQ1IMVrEeOOn73Mmc1_Hg</scope>
  <TopologyRelationship childrenUuids="T421ebff3-350d-0cc9-4eb2-02982a8059c6" name="RelatedProfiles"/>
</TopologyElement>

 

3) Request recommendations for where you should deploy the VMs that you want. The “deploy item” that is returned will be needed in the next two steps.
- The templateName is the uuid from step 1 (bolded)
- The serviceName is the uuid from step 2 (italicized and underlined)
- The count is the number of VMs you would like to deploy (maximum is 25). In this example, we chose 2.
- Although the API will return immediately, the server internally can take 30-60 seconds to make these decisions, depending on how many VMs you are attempting to place.

vmturbo:~ # curl -X POST http://username:password@1.2.3.4/vmturbo/api/markets/Market/virtualmachines/test_VM_deploy -d "templateName=T421ebff3-350d-0cc9-4eb2-02982a8059c6&serviceName=_kvPKccVrEeOOn73Mmc1_Hg&count=2"

Response:
_kKi8ccWAEeOOn73Mmc1_Hg 

4) Review the Deploy Recommendations to confirm the host and datastore where the VMs are being placed.
- This step is optional, and can be skipped if you trust the automated placement decisions of VMTurbo Operations Manager. 

vmturbo:~ # curl -X GET http://username:password@1.2.3.4/vmturbo/api/deployitems/_kKi8ccWAEeOOn73Mmc1_Hg

Response:
<?xml version="1.0" encoding="ISO-8859-1"?><ActionItems>
  <ActionItem datastore="Quantastor583:ESXDC2DS2" datastoreState="Recommended" host="hp-esx15.corp.vmturbo.com" hostState="Pending Accept" name="vm_Test_deploy_0" status="OK" user=“username" vdc="" vdcState=""/>
  <ActionItem datastore="Quantastor583:ESXDC2DS2" datastoreState="Recommended" host="hp-esx17.corp.vmturbo.com" hostState="Pending Accept" name="vm_Test_deploy_1" status="OK" user=“username" vdc="" vdcState=""/>
</ActionItems>

 

5) Accept the recommendations to execute this deployment. If you choose not to use these recommendations, you can also reject them by specifying "action=reject" instead of accept.

vmturbo:~ # curl -X POST http://username:password@1.2.3.4/vmturbo/api/deployitems/_kKi8ccWAEeOOn73Mmc1_Hg -d "action=accept"

Response:
True

 

You will now see these VMs being deployed in the hypervisor where this template was discovered from. First the template will be cloned and then the VMs will be powered on. After they are finished cloning, it can take 10-20 minutes for them to fully display in the VMTurbo Operations Manager interface.

Have more questions? Submit a request

Comments

  • Avatar
    Iddo Avneri

    The API changed a little bit and you need to run different APIs now:

    Get the VM template:
    curl -X GET http://username:password@1.2.3.4/vmturbo/api/templates | grep "TMP-linux"
    _QEv5AGtzEeWl9daU3mtgNQ

    Get the DeploymentPorfile:
    curl -X GET http://username:password@1.2.3.4/vmturbo/api/deploymentprofiles | grep -B3 -A1 "_QEv5AGtzEeWl9daU3mtgNQ"
    _Zx560GtzEeWl9daU3mtgNQ

    Exectute reservation:
    curl -X POST "http://administrator:administrator@localhost/vmturbo/api/reservations?
    reservationName=Test1&count=1&templateName=_QEv5AGtzEeWl9daU3mtgNQ&deploymentProfile=_Zx560GtzEeWl9daU3mtgNQ&deployDate=2015-10-16 12:00:00&reservationDate=2015-10-16 12:00:00"

    Returns UUID. For example: _iXadAHNTEeW9If4nySDVAA

    Check status field for success or fail
    Get call on reservations again:
    curl -X GET http://administrator:administrator@localhost/vmturbo/api/reservations

    Check placement:
    curl -X GET http://administrator:administrator@localhost/vmturbo/api/reservations/_iXadAHNTEeW9If4nySDVAA

    <?xml version="1.0" encoding="ISO-8859-1"?><VirtualMachines>
    <ActionItem datastore="3PAR.Cell-02.01" datastoreState="Recommended" host="usmdcvsh1423.us.kworld.kpmg.com" hostState="Recommended" name="Test1_C0" status="OK" user="administrator" vdc=""
    vdcState=""/>
    </VirtualMachines>

    Delele placement:
    curl -X DELETE http://administrator:administrator@localhost/vmturbo/api/reservations/_iXadAHNTEeW9If4nySDVAA