Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Introduction

When you have multiple Virtual Networks available in our environment, you can easily update any virtual machine NIC backend using the REST API.

A common use case is when virtual machines have been deployed in our public Network, and you have requested a new network subnet (Network Admin Tools) for your department which has been already presented and defined throughout the network core to our environment. 

This guide demonstrates how to update the virtual network attached to any given network interface controller.

Prerequisites

  1. Valid access token
  2. Access to Virtual Machine
  3. Virtual Machine name and network interface card to update.

Table of Contents

Table of Contents

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.

  1. 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
  2. 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')
  3. Look for the target network:

    Code Block
    networks = vss.get_networks(name='1072')
    network = networks[0].get('moref')  
  4. Submit change:

    Code Block
    r =  vss.update_vm_nic_network(uuid=vm, nic=1, network=network)
  5. 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')
  6. Validate changes

    Code Block
    nic = vss.get_vm_nic(vm, 1)

Step-by-step guide with API Calls

  1. Set the access token environment variable (TK):

    Code Block
    languagebash
    set TK <really_long_string>
  2. Get virtual machine UUID using the search feature in the /vm resource:

    Code Block
    languagebash
    titleRequest
    http GET "https://vss-api.eis.utoronto.ca:8001/v2/vm?name=vm-testing&summary" "Authorization: Bearer $TK"
  3. Display virtual machine network adapters:

    Code Block
    languagebash
    titleRequest
    http GET "https://vss-api.eis.utoronto.ca:8001/v2/vm/<vm_uuid>/nic" "Authorization: Bearer $TK"
    Code Block
    titleResponse Body
    collapsetrue
    {
        "_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"
        }
    }
  4. Get the network MOR using the network resource from the API:

    Code Block
    languagebash
    titleRequest
    http GET "https://vss-api.eis.utoronto.ca:8001/v2/network?name=VL-000-TEST" "Authorization: Bearer $TK"
    Code Block
    languagepy
    titleResponse Body
    collapsetrue
    {
        "_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"
        }
    }
  5. Make a PUT request to the virtual machine nic number endpoint update virtual network using attribute network and value dvportgroup-00:

    Code Block
    languagebash
    http PUT "https://vss-api.eis.utoronto.ca:8001/v2/vm/<vm_uuid>/nic/1" "Authorization: Bearer $TK" attribute='network' value='dvportgroup-00'
  6. Display virtual machine network adapters:

    Code Block
    languagebash
    titleRequest
    http GET "https://vss-api.eis.utoronto.ca:8001/v2/vm/<vm_uuid>/nic" "Authorization: Bearer $TK"
    Code Block
    titleResponse Body
    collapsetrue
    {
        "_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.

 

Filter by label (Content by label)
showLabelsfalse
max5
spacesAPI
showSpacefalse
sortmodified
reversetrue
typepage
cqllabel in ("vlan","nic","network") and type = "page" and space = "API"
labelsnic network vlan

Page Properties
hiddentrue
Related issues