VMware Cloud Community
geeko71
Enthusiast
Enthusiast

shutdown partially running vApps automaticly

Hi Folks

Within an particular organisation i have to automate the shutdown of all vApps

1. which are partially running and all VMs within the vAPP are Powered OFF or Suspended

2. count all running VMs within an entire ORG (many vCDs)

How can i realize this and how would be an API call using REST CLI script (using curl e.g.)?

For the action 2. i cannot see the posibility to call an vCD API call for VM state (running) can i realize this using VCD API or do i need access to vSphere API?

Thanks Dominik

Tags (3)
0 Kudos
2 Replies
IamTHEvilONE
Immortal
Immortal

You should be able to do this from REST API in vCD or PowerCLI (i think).  REST API pseudo code would look something like this:

start script (input is org name or ID)

login to REST API as System Admin

use the query service to get a list of all vApps for a specific organization (you might have to parse multiple pages of results depending on how many vApps there are)

for each vApp in the array

  • get a list of All VMs in the vApp (query service or get on the vApp reference should give you the list) ... again parsing for multiple pages
  • for each VM in the new array
    • do a get on the VM (obtains current configuration and state information)
    • if (power state != off) then issue power off API call to it
  • move to next VM

move to next vApp

Logout of REST API

end script

0 Kudos
IamTHEvilONE
Immortal
Immortal

shorter alternative is to just loop through each vApp and issue a power off command at the vApp level as well.

i guess it just depends on how you want to approach it.

0 Kudos