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:
Prerequisites
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' |
Add the steps involved:
Get virtual machine UUID using the search feature in the /vm resource:
http GET "https://vss-api.eis.utoronto.ca/v2/vm?name=coreos0&summary" "Authorization: Bearer $TK" |
{ "_links": { "api": "https://vss-api.eis.utoronto.ca/v2/", "self": "https://vss-api.eis.utoronto.ca/v2/vm" }, "data": [ { "_links": { "self": "https://vss-api.eis.utoronto.ca/v2/vm/<vm_uuid>" }, "name": "1606T-coreos0", "uuid": "<vm_uuid>" } ], "meta": { "count": 1, "time": "1.13983s", "user": "jm" } } |
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/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:
{ "data": { "_links": { "request": "https://vss-api.eis.utoronto.ca/v2/request/change/114" }, "message": "VM Change Request has been accepted for processing", "name": "Accepted", "state": "Scheduled", "status": 202 }, "meta": { "time": "0.86168s", "user": "jm" } } |
Then, memory and CPU updates could be executed five and seven minutes later:
http PUT "https://vss-api.eis.utoronto.ca/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/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:
{ "_link": { "request": "https://vss-api.eis.utoronto.ca/v2/request/change", "self": "https://vss-api.eis.utoronto.ca/v2/request/change/116" }, "data": { "_links": { "vm": "https://vss-api.eis.utoronto.ca/v2/vm/5012abcb-a9f3-e112-c1ea-de2fa9dab90a" }, "attribute": "cpu", "created_on": "2016-07-12 13:34:56 EDT", "id": 116, "message": {}, "scheduled": true, # scheduled OK "scheduled_datetime": "2016-07-13 04:07:00 EDT", # scheduled OK "status": "Scheduled", "task_id": null, # task not created yet "updated_on": "2016-07-12 13:34:56 EDT", "user": { "_links": { "self": "https://vss-api.eis.utoronto.ca/v2/user" }, "username": "jm" }, "user_id": 1, "value": { "cpu": 2 }, "vm_name": "1606T-coreos0", "vm_uuid": "5012abcb-a9f3-e112-c1ea-de2fa9dab90a" }, "meta": { "count": 15, "time": "0.01072s", "user": "jm" } } |
Related articles appear here based on the labels you select. Click to edit the macro and add or change labels.
|