Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Deploying a virtual machine interacting directly with thee EIS Virtual Cloud RESTful API could somehow be overwhelming due to its multiple resources to check such as networks, folders, disks, etc. In order to simplify the interaction with the API we created a Python Client named pyvss with many self-descriptive methods  and available in the Python Package Index. 

This tutorial uses pyvss to create a virtual machine with no operating system and which will be installed manually by mounting an ISO image from the VSS Catalog. The full specification is listed below:

  • name: VMfromPyVss
  • built process: os install
  • billing department: VSS
  • description: virtual machine created from vss
  • usage: QA
  • cpu and memory: 2 
  • disks: 1GB, 2GB and 3GB
  • networks: any available network in your account
  • folders: any folder available in your account
  • iso: ubuntu 12.04 i386
  • os: ubuntuGues

Pre-requirements

  • python 2.7.10+
  • access to the EIS Virtual Cloud RESTful API 
  • Python client for the EIS Virtual Cloud RESTful API: pyvss

    pip install pyvss
  • ptpython (optional) - usual python console can be used

    pip install ptpython
  • httpie (optional) - curl or wget can be used as well

    pip install httpie

Step-by-step guide

  1. Generate an API access token and save it to tk.json file:

    http POST https://vss-api.eis.utoronto.ca:8001/auth/request-token -a jm > tk.json
    http: password for jm@vss-api.eis.utoronto.ca:8001:
  2. Start ptpython or python console:

    ptpython
  3. Import VssManager and json libraries and load tk.json into a variable

     

    from pyvss.manager import VssManager
    import json 
     
    token = json.load(open('tk.json')) 
  4. Create a VssManager instance with the previously loaded token:

     

    vss = VssManager(tk=token.get('token'))
  5.  Refer to the official docs or use the help built in function to display what parameters are required by the create_vm function:

     

    help(vss.create_vm)
  6. Define the following variables

    name = 'VMfromPyVss'
    built = 'os_install' # it could be either clone or image as well
    bill_dept = 'VSS'
    description = 'Virtual machine created from pyVss'
    usage = 'QA' # could be either Prod, Test, QA or Dev
    cpu = 2
    memory = 2 # this value is in GB
    disks = [1, 2, 3]  # three disks of 1GB, 2GB and 3GB
  7. Get target folder, networks, operating system and iso image to mount for the installation

    networks = vss.get_networks(name='1102') # filtering by name
    networks = [net.get('moref') for net in networks] # we need only a moref and networks has to be a list
     
    folders = vss.get_folders(name='APIDemo') # filtering by name
    folder = folders[0].get('moref')
    
    isos = vss.get_isos(name='ubuntu') # filtering by name
    iso = isos[0].get('path')
    
    os_list = vss.get_os(name='ubuntu') # filtering by name
    os = os_list[0].get('id')
     
  8. Create new vm request 

    r = vss.create_vm(name=name, os=os, built=built, bill_dept=bill_dept, description=description, 
    				  folder=folder, networks=networks, disks=disks, usage=usage, 
    				  cpu=cpu, memoryGB=memory, iso=iso)
  9. We will use wait_for_request function to get new virtual machine Uuid when provisioned:

    uuid = vss.wait_for_request(r.get('_links').get('request'), 'vm_uuid', 'Processed')
  10. Once you get the uuid, get a summary of the VM:

    vm = vss.get_vm(uuid)
    vm.get('state').get('powerState')
    u'poweredOff'
  11. Power on VM

    vss.power_on_vm(uuid)
  12. Validate new VM state:

    vss.get_vm_state(uuid).get('powerState')
    u'poweredOn'
  13. Generate a one-time VM console link to start the OS installation

    link = vss.get_vm_console()

AsciiCast

 

  • No labels