Use¶
Create an instance of VssManager
passing your EIS Virtual Cloud REST API access token
and your are all set to start calling any of the self-descriptive methods included:
from pyvss.manager import VssManager
vss = VssManager(tk='api_token')
# list vms
vms = vss.get_vms()
# list folders
folders = vss.get_folders()
# networks
networks = vss.get_networks()
# domains
domains = vss.get_domains()
# power cycle vm
vss.power_cycle_vm(uuid='<uuid>')
# create vm
req = vss.create_vm(os='ubuntu64Guest', built='os_install',
description='Testing python wrapper',
folder='group-v6736', bill_dept='EIS', disks=[100, 100])
uuid = vss.wait_for_request(req['_links']['request'], 'vm_uuid', 'Processed')
# creating multiple vms
reqs = vss.create_vms(count=3, name='python', os='ubuntu64Guest', bill_dept='EIS',
description='Testing multiple deployment from python wrapper',
folder='group-v6736', built='os_install')
uuids = [vss.wait_for_request(r['_links']['request'], 'vm_uuid', 'Processed') for r in reqs]
# power on recently created vms
for uuid in uuids:
vss.power_on_vm(uuid)
# create snapshot
req = vss.create_vm_snapshot(uuid='5012abcb-a9f3-e112-c1ea-de2fa9dab90a',
desc='Snapshot description',
date_time='2016-08-04 15:30',
valid=1)
snap_id = vss.wait_for_request(req['_links']['request'], 'snap_id', 'Processed')
# revert to snapshot
req = vss.revert_vm_snapshot(uuid, snap_id)
An alternative is to generate a token from within the VssManager
class and this can be done
by setting the following environment variables
export VSS_API_USER='username'
export VSS_API_USER_PASS='username_password'
Then, from the VssManager
call the get_token
method as follows:
from pyvss.manager import VssManager
vss = VssManager()
vss.get_token()
It also supports command line execution by setting the VSS_API_TOKEN
environment variable
with the EIS Virtual Cloud REST API access token
python pyvss/manager.py get_vms 'summary=1&name=pm'
[{u'_links': {u'self': u'https://vss-api.eis.utoronto.ca/v2/vm/<vm_uuid>'},
u'cpuCount': 2,
u'folder': {u'_links': {u'self': u'https://vss-api.eis.utoronto.ca/v2/folder/group-v519'},
u'moref': u'group-v519',
u'name': u'Public',
u'parent': u'API'},
u'guestFullName': u'Ubuntu Linux (64-bit)',
u'ipAddress': u'<ip_addr>',
u'memoryMB': 4096,
u'name': u'1502P-pm',
u'overallStatus': u'green',
u'powerState': u'poweredOn',
u'storageB': 96637166467,
u'uuid': u'<vm_uuid>'}]
python pyvss/manager.py get_vm_console <vm_uuid>
{u'value': u'https://vctr5-1.dcb.eis.utoronto.ca:7343/console/?vmId=vm-4766
&vmName=1502P-pm&host=vctr5-1.dcb.eis.utoronto.ca:443&sessionTicket=<really-long-string>'}