How to update NIC backend network of a 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 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)
Step-by-step guide with API Calls
Set the access token environment variable (TK):
set TK <really_long_string>
Get virtual machine UUID using the search feature in the /vm resource:
Requesthttp GET "https://vss-api.eis.utoronto.ca/v2/vm?name=vm-testing&summary" "Authorization: Bearer $TK"
Display virtual machine network adapters:
Requesthttp GET "https://vss-api.eis.utoronto.ca/v2/vm/<vm_uuid>/nic" "Authorization: Bearer $TK"
Get the network MOR using the network resource from the API:
Requesthttp GET "https://vss-api.eis.utoronto.ca/v2/network?name=VL-000-TEST" "Authorization: Bearer $TK"
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:
Requesthttp GET "https://vss-api.eis.utoronto.ca/v2/vm/<vm_uuid>/nic" "Authorization: Bearer $TK"
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