This section assumes, you have already set up both VSS_API_USER and VSS_API_USER_PASS or VSS_API_TOKEN environment variables and installed PyVss.
Create an instance of VssManager and generate token via get_token as follows:
from pyvss.manager import VssManager vss = VssManager(None) vss.get_token() # generates token |
Get target VM UUID by first searching by its name
vms = vss.get_vms(name='vm-testing') # get target vm uuid vm = vms[0].get('uuid') |
Look for the target network:
networks = vss.get_networks(name='1072') network = networks[0].get('moref') |
Submit change:
r = vss.update_vm_nic_network(uuid=vm, nic=1, network=network) |
Wait for request to be processed:
completed = vss.wait_for_request(request_url=r.get('_links').get('request'), request_attr='status', required_status='Processed') |
Validate changes
nic = vss.get_vm_nic(vm, 1) |
Add the steps involved:
Set the access token environment variable (TK):
set TK <really_long_string> |
Get virtual machine UUID using the search feature in the /vm resource:
http GET "https://vss-api.eis.utoronto.ca/v2/vm?name=vm-testing&summary" "Authorization: Bearer $TK" |
Display virtual machine network adapters:
http GET "https://vss-api.eis.utoronto.ca/v2/vm/<vm_uuid>/nic" "Authorization: Bearer $TK" |
{ "_links": { "self": "https://vss-api.eis.utoronto.ca/v2/vm/<vm_uuid>/nic", "vm": "https://vss-api.eis.utoronto.ca/v2/vm/<vm_uuid>" }, "data": [ { "_links": { "network": "https://vss-api.eis.utoronto.ca/v2/network/dvportgroup-92", "self": "https://vss-api.eis.utoronto.ca/v2/vm/<vm_uuid>/nic/1" }, "label": "Network adapter 1", "network": "VL-1072-VSGAN" } ], "meta": { "count": 1, "time": "0.21006s", "user": "jm" } } |
Get the network MOR using the network resource from the API:
http GET "https://vss-api.eis.utoronto.ca/v2/network?name=VL-000-TEST" "Authorization: Bearer $TK" |
{ "_links": { "api": "https://vss-api.eis.utoronto.ca/v2/", "self": "https://vss-api.eis.utoronto.ca/v2/network" }, "data": [ { "_links": { "self": "https://vss-api.eis.utoronto.ca/v2/network/dvportgroup-00" }, "accessible": true, "moref": "dvportgroup-00", "name": "VL-0000-TEST" } ], "meta": { "count": 1, "time": "0.15235s", "user": "jm" } } |
Make a PUT request to the virtual machine nic number endpoint update virtual network using attribute network and value dvportgroup-00:
http PUT "https://vss-api.eis.utoronto.ca/v2/vm/<vm_uuid>/nic/1" "Authorization: Bearer $TK" attribute='network' value='dvportgroup-00' |
Display virtual machine network adapters:
http GET "https://vss-api.eis.utoronto.ca/v2/vm/<vm_uuid>/nic" "Authorization: Bearer $TK" |
{ "_links": { "self": "https://vss-api.eis.utoronto.ca/v2/vm/<vm_uuid>/nic", "vm": "https://vss-api.eis.utoronto.ca/v2/vm/<vm_uuid>" }, "data": [ { "_links": { "network": "https://vss-api.eis.utoronto.ca/v2/network/dvportgroup-92", "self": "https://vss-api.eis.utoronto.ca/v2/vm/<vm_uuid>/nic/1" }, "label": "Network adapter 1", "network": "VL-0000-TEST" } ], "meta": { "count": 1, "time": "0.21006s", "user": "jm" } } |
Using the /vm/<vm_uuid>/nic resource you can also update NIC type (VMXNET3, VMXNET2, E1000, etc.) and state (connect, disconnect). For more information, please refer to this KB Article. |
Related articles appear here based on the labels you select. Click to edit the macro and add or change labels.
|