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
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:
Code Block 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
Code Block # 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:
Code Block r = vss.update_vm_state(uuid=uuid, state='poweredOff', schedule='2016-07-13 04:00')
Check request scheduled status:
Code Block 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:
Code Block language bash title Request http -a $TK GET "https://vss-api.eis.utoronto.ca:8001/v2/vm?name=coreos0&summary" "Authorization: Bearer $TK"
Code Block language py title Response Body collapse true { "_links": { "api": "https://vss-api.eis.utoronto.ca:8001/v2/", "self": "https://vss-api.eis.utoronto.ca:8001/v2/vm" }, "data": [ { "_links": { "self": "https://vss-api.eis.utoronto.ca:8001/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:
Code Block http -a $TK 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'
Note 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:
Code Block language py title Response Body collapse true { "data": { "_links": { "request": "https://vss-api.eis.utoronto.ca:8001/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:
Code Block http -a $TK 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 -a $TK 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:
Code Block language py title Response Body collapse true { "_link": { "request": "https://vss-api.eis.utoronto.ca:8001/v2/request/change", "self": "https://vss-api.eis.utoronto.ca:8001/v2/request/change/116" }, "data": { "_links": { "vm": "https://vss-api.eis.utoronto.ca:8001/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:8001/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" } }
- At this point just wait for the email confirmation or check periodically the status of the request.
Related articles
Filter by label (Content by label) | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Page Properties | ||
---|---|---|
| ||
|