Step-by-step guide with PyVss
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:
Code Block from pyvss.manager import VssManager vss = VssManager(None) vss.get_token() # generates token
Get target VM UUID by first searching by its name
Code Block vms = vss.get_vms(name='vm-testing') # get target vm uuid vm = vms[0].get('uuid')
Look for the target network:
Code Block networks = vss.get_networks(name='1072') network = networks[0].get('moref')
Submit change:
Code Block r = vss.update_vm_nic_network(uuid=vm, nic=1, network=network)
Wait for request to be processed:
Code Block completed = vss.wait_for_request(request_url=r.get('_links').get('request'), request_attr='status', required_status='Processed')
Validate changes
Code Block nic = vss.get_vm_nic(vm, 1)
Step-by-step guide with API Calls
Set the access token environment variable (TK):
Code Block language bash set TK <really_long_string>
Get virtual machine UUID using the search feature in the /vm resource:
Code Block language bash title Request http GET "https://vss-api.eis.utoronto.ca:8001/v2/vm?name=vm-testing&summary" "Authorization: Bearer $TK"
Display virtual machine network adapters:
Code Block language bash title Request http GET "https://vss-api.eis.utoronto.ca:8001/v2/vm/<vm_uuid>/nic" "Authorization: Bearer $TK"
Code Block title Response Body collapse true { "_links": { "self": "https://vss-api.eis.utoronto.ca:8001/v2/vm/<vm_uuid>/nic", "vm": "https://vss-api.eis.utoronto.ca:8001/v2/vm/<vm_uuid>" }, "data": [ { "_links": { "network": "https://vss-api.eis.utoronto.ca:8001/v2/network/dvportgroup-92", "self": "https://vss-api.eis.utoronto.ca:8001/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:
Code Block language bash title Request http GET "https://vss-api.eis.utoronto.ca:8001/v2/network?name=VL-000-TEST" "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/network" }, "data": [ { "_links": { "self": "https://vss-api.eis.utoronto.ca:8001/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:
Code Block language bash http PUT "https://vss-api.eis.utoronto.ca:8001/v2/vm/<vm_uuid>/nic/1" "Authorization: Bearer $TK" attribute='network' value='dvportgroup-00'
Display virtual machine network adapters:
Code Block language bash title Request http GET "https://vss-api.eis.utoronto.ca:8001/v2/vm/<vm_uuid>/nic" "Authorization: Bearer $TK"
Code Block title Response Body collapse true { "_links": { "self": "https://vss-api.eis.utoronto.ca:8001/v2/vm/<vm_uuid>/nic", "vm": "https://vss-api.eis.utoronto.ca:8001/v2/vm/<vm_uuid>" }, "data": [ { "_links": { "network": "https://vss-api.eis.utoronto.ca:8001/v2/network/dvportgroup-92", "self": "https://vss-api.eis.utoronto.ca:8001/v2/vm/<vm_uuid>/nic/1" }, "label": "Network adapter 1", "network": "VL-0000-TEST" } ], "meta": { "count": 1, "time": "0.21006s", "user": "jm" } }
Note |
---|
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
Filter by label (Content by label) | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Page Properties | ||
---|---|---|
| ||
|