Versions Compared

Key

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

...

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

    Code Block
    http POST https://vss-api.eis.utoronto.ca/auth/request-token -a jm > tk.json
    http: password for jm@vss-api.eis.utoronto.ca:


  2. Start ptpython or python console:

    Code Block
    ptpython


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


    Code Block
    from pyvss.manager import VssManager
    import json 
     
    token = json.load(open('tk.json')) 


  4. Create a VssManager instance with the previously loaded token:


    Code Block
    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:


    Code Block
    help(vss.create_vm)


  6. Define the following variables

    Code Block
    name = 'VMfromPyVss'
    built = 'os_install' # it could be either clone or image as well
    client = '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

    Code Block
    networks = vss.get_networks(name='1102') # filtering by name
    networks = [{'network': net.get('moref')} for net in networks]
     
    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('guestFullName')
     


  8. Create new vm request 

    Code Block
    r = vss.create_vm(name=name, os=os, built=built, client=client, description=description, 
    				  folder=folder, networks=networks, disks=disks, usage=usage, 
    				  cpu=cpu, memoryGB=memory, iso=iso, power_on=True)


  9. We will use wait_for_request function to get new virtual machine Uuid when provisioned:

    Code Block
    uuidvm_id = vss.wait_for_request(r.get('_links').get('request'), 'vm_uuidmoref', 'Processed')


  10. Once you get the uuididget a summary of the VM:

    Code Block
    vm = vss.get_vm(uuidvm_id)
    vm.get('state').get('powerState')
    u'poweredOff'

    Power on VM

    Code Block
    vss.power_on_vm(uuid)

    Validate new VM state:

    Code Block
    vss.get_vm_state(uuid).get('powerState')
    u'poweredOn'


  11. Generate a one-time VM console vSphere client link to start the OS installation

    Code Block
    link = vss.get_vm_console()

AsciiCast

...

  1. vsphere_link(vm_id)


Filter by label (Content by label)
showLabelsfalse
max5
spacesAPI
showSpacefalse
sortmodified
reversetrue
typepage
cqllabel in ("rest","new","vm","pyvss") and type = "page" and space = "API"
labelspyvss rest vm new

...