Introduction
Scheduling changes provides flexibility to execute API actions at any given time. For instance, scheduling to automatically upgrade VMware Tools, or to Shutdown VM and then increase memory or CPU can be accomplished by just adding the schedule attribute to any PUT request in any virutal machine resource /vm/<resource>. This guide, will exemplify how to schedule the following actions:
- Power Off VM
- Add CPU
- Add Memory
- Power On VM
Table of Contents
Prerequisites
- Valid access token.
- Access to Virtual Machine.
Step-by-step guide with PyVSS
This section assumes, you have already set up both VSS_API_USER and VSS_API_USER_PASS environment variables and installed PyVss.
Create an instance of VssManager, generate token via get_token, and create an instance of the webdavclient using get_vskey_stor method as follows:
from pyvss.manager import VssManager vss = VssManager(None) vss.get_token() # generates token vss.get_vskey_stor() # creates a WebDav Client instance to interact with VSKEY-STOR
Get Virtual Machine to change
# get target vm uuid vms = vss.get_vms(name='vm-testing') uuid = vms[0].get('uuid')
Using schedule in the in the method will make this change request scheduled:
r = vss.update_vm_state(uuid=uuid, state='poweredOff', schedule='2016-07-13 04:00')
Check request scheduled status:
request = vss.get_change_request(r.get('id')) request.get('scheduled') True request.get('scheduled_datetime') u'2016-07-13 04:00'
- At this point just wait for the email confirmation or check periodically the status of the request.
Step-by-step guide with API Calls
Get virtual machine UUID using the search feature in the /vm resource:
Requesthttp GET "https://vss-api.eis.utoronto.ca:8001/v2/vm?name=coreos0&summary" "Authorization: Bearer $TK"
This would be a simple VM State change via a PUT request to /vm/<uuid>/state with the attribute value set to poweredOff but, by adding the schedule attribute will be added as a scheduled change. The following example will schedule its execution at 4:00am on 2016-07-13:
http PUT "https://vss-api.eis.utoronto.ca:8001/v2/vm/5012abcb-a9f3-e112-c1ea-de2fa9dab90a/state" "Authorization: Bearer $TK" value=poweredOff schedule='2016-07-13 04:00'
The schedule attribute is expected to be in the following format: yyyy-mm-dd HH:MM
Response from the API will provide feedback upon request. Please, make sure it state is Scheduled:
Then, memory and CPU updates could be executed five and seven minutes later:
http PUT "https://vss-api.eis.utoronto.ca:8001/v2/vm/5012abcb-a9f3-e112-c1ea-de2fa9dab90a/memory" "Authorization: Bearer $TK" value=3 schedule='2016-07-13 04:05' http PUT "https://vss-api.eis.utoronto.ca:8001/v2/vm/5012abcb-a9f3-e112-c1ea-de2fa9dab90a/cpu" "Authorization: Bearer $TK" value=2 schedule='2016-07-13 04:07'
Verifying your request has been successfully scheduled is also possible using the /request/change/<id> resource, for instance:
- At this point just wait for the email confirmation or check periodically the status of the request.
Related articles