Introduction
Logical Folders are containers for storing and organizing inventory objects, in this case virtual machines. Just like the network resource, a Folder has a Managed Object Reference (moref) which is required for either virtual machine deployment (where a virtual machine will be placed upon creation) or updating virtual machine containing folder (move).
The /v2/folder resource lists folders you are allowed to access in our environment. If by any chance you cannot see a folder and you add it to a new virtual machine creation request or a virtual machine change request, they will not be successfully processed. If you believe you need access to a specific folder, please let us know.
On this page:
The following table shows a brief description and HTTP methods allowed to interact with logical folders.
Resource | URI | Description | GET | POST | PUT | PATCH |
---|---|---|---|---|---|---|
Folder | /folder | Logical Folder Management resource. List permitted folders and their attributes | ||||
Folder Object | /folder/<moref> | Get logical folder attributes. | ||||
Folder Name | /folder/<moref>/name | Rename object. | ||||
Folder Children | /folder/<moref>/children | Get children folders if any. | ||||
Folder Parent | /folder/<moref>/parent | Get or move folder to a different parent. | ||||
Folder VMs | /folder/<moref>/vm | List children virtual machines. | ||||
Folder Permission | /folder/<moref>/permission | List object permission. |
TK stores the Cloud API Token generated as a result of the following POST request to the /auth/request-token resource:
curl -X POST https://vss-api.eis.utoronto.ca/auth/request-token -u <username>
For example, extracting the token with the jq command:
TK=$(curl -X POST https://vss-api.eis.utoronto.ca/auth/request-token -u <username> | jq -r '.token')
List
In order to list allowed Folders you should make a GET request to the endpoint /v2/folder, passing your access token. As a result, you will get a reference URI /v2/folder/<moref> to get detailed information about that folder.
http GET "https://vss-api.eis.utoronto.ca/v2/folder" "Authorization: Bearer $TK" curl -H "Authorization: Bearer $TK" -X GET "https://vss-api.eis.utoronto.ca/v2/folder"
The following examples implements HTTPie and CURL to list all folders a user have access to:
Paging
All requests to the /folder URL are paginated. The response body includes a 'meta.pages' key with everything to navigate through the results, for instance:
Key | Description |
---|---|
first_url | Contain the URLs to navigate through results. |
last_url | |
prev_url | |
next_url | |
page | Current page |
pages | Total number of pages |
per_page | Results per page. Maximum 250; Default 10. |
total | Total number of results |
Results per page can be set by including the parameter in the URL query, so we can get the desired number of elements per page, for example:
http GET "https://vss-api.eis.utoronto.ca/v2/folder?per_page=1" "Authorization: Bearer $TK" curl -H "Authorization: Bearer $TK" -X GET "https://vss-api.eis.utoronto.ca/v2/folder?per_page=1"
Filtering
Folders can be filtered by adding the filter argument to the query string in the following format:
filter=<field_name>,<operator>,<value>
Operators can be:
Operator | Description |
---|---|
eq | Equals |
ne | Not equal |
lt | Lower than |
le | Lower equal |
gt | Greater than |
ge | Greater equal |
like | Matching pattern |
in | Match value in many items separated by commas |
A resource can be filtered by as many attributes the request has, for instance /folder can be filtered by moref, path, created_on, name, etc. Thus, the following example will filter only by name=Prod
http GET "https://vss-api.eis.utoronto.ca/v2/folder?per_page=10&expand=1&filter=name,like,%Prod%" "Authorization: Bearer $TK"
Sorting
The resource provides also attribute sorting by adding the sort parameter in the URL query string in the following format:
sort=<field_name>,<asc|desc>
The following example shows how to filter by label:
http GET "https://vss-api.eis.utoronto.ca/v2/folder?per_page=10&expand=1&filter=name,like,%Prod%&sort=label,desc" "Authorization: Bearer $TK" curl -X GET -H "Authorization: Bearer $TK" "https://vss-api.eis.utoronto.ca/v2/network?per_page=10&expand=1&filter=name,like,%VL%&sort=label,desc"
Create
To create a new folder you just need to submit a request to /v2/folder/<moref> and provide the name of the new folder as a parameter. So, the folder <moref> will be parent of the new folder. For this example we will create a subfolder in APIDemo > APISubFolder, so request will be crafted as follows:
http -a $TK POST https://vss-api.eis.utoronto.ca/v2/folder/group-v6736 "Authorization: Bearer $TK" name=APISubFolder curl -H "Content-Type: application/json" -H "Authorization: Bearer $TK" -X POST https://vss-api.eis.utoronto.ca/v2/folder/group-v6736 -d '{"name": "APISubFolder"}'
HTTP/1.1 202 ACCEPTED Allow: POST, HEAD, OPTIONS, GET Connection: keep-alive Content-Length: 400 Content-Type: application/json Date: Wed, 11 May 2016 17:19:15 GMT Location: https://vss-api.eis.utoronto.ca/v2/request/task/fff43ba4-40c1-40df-bf5b-02f5424e091a Server: nginx X-RateLimit-Limit: 3000 X-RateLimit-Remaining: 2997 X-RateLimit-Reset: 1462989600
Listing folder
Listing folders with the API word in them, would show the folder has been successfully created:
Update
Renaming or moving folders between your folder tree is possible by making a PUT request to the URI folder in question sending both the attribute and value you wish to update. Currently, we support name and parent as supported attributes.
Attribute | Description |
---|---|
name | folder new name |
parent | managed object reference of new parent folder |
The following request illustrates how to update a folder's name (group-v6736) to NewAPIFolder:
http PUT https://vss-api.eis.utoronto.ca/v2/folder/group-v6736 "Authorization: Bearer $TK" attribute="name" value="NewAPIFolder" curl -H "Content-Type: application/json" -H "Authorization: Bearer $TK" -X PUT https://vss-api.eis.utoronto.ca/v2/folder/group-v6736 -d '{"attribute": "name", "value": "NewAPIFolder"}'
HTTP response would look something like:
HTTP/1.1 202 ACCEPTED Allow: HEAD, GET, PUT, POST, OPTIONS Connection: keep-alive Content-Length: 437 Content-Type: application/json Date: Mon, 27 Jun 2016 14:38:32 GMT Location: https://vss-api.eis.utoronto.ca/v2/request/task/d7eec47d-fd14-4958-a5ff-bfb93a191a01 Server: nginx X-RateLimit-Limit: 3000 X-RateLimit-Remaining: 2996 X-RateLimit-Reset: 1467039600
If you wish to update any parent folder, just select the new parent moref and include it in the PUT request attribute's value, i.e.
http PUT https://vss-api.eis.utoronto.ca/v2/folder/group-v6736 "Authorization: Bearer $TK" attribute="parent" value="group-v1234" curl -H "Content-Type: application/json" -H "Authorization: Bearer $TK" -X PUT https://vss-api.eis.utoronto.ca/v2/folder/group-v6736 -d '{"attribute": "parent", "value": "group-v1234""}'
Where group-v1234 would be new parent of group-v6736