Skip to content

Instantly share code, notes, and snippets.

@zaibon
Created July 27, 2016 12:29
Show Gist options
  • Save zaibon/9c4fbb250ee0170abf8ff84cfde64427 to your computer and use it in GitHub Desktop.
Save zaibon/9c4fbb250ee0170abf8ff84cfde64427 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/jspython
from JumpScale import j
g8_address = 'be-g8-3.demo.greenitglobe.com'
login = 'zaibon'
password = '***'
account = 'zaibon'
location = 'be-g8-3'
ocl = j.clients.openvcloud.get(g8_address, login, password)
acc_choice = j.tools.console.askChoice([acc.model['name'] for acc in ocl.accounts], "Choose which account to use")
print("Account %s selected" % acc_choice)
acc = ocl.account_get(acc_choice)
vdc_list = [space.model['name'] for space in acc.spaces]
vdc_list.append("Create new vdc")
vdc_choice = j.tools.console.askChoice(vdc_list, "Choose which vdc to use")
if vdc_choice == 'Create new vdc':
name = j.tools.console.askString('Choose a name for the new vdc')
location = j.tools.console.askChoice([l['name'] for l in ocl.locations], "Choose the location where to create the vdc")
vdc = acc.space_get(name=name, location=location, create=True)
print("VDC %s created" % vdc.model['name'])
else:
vdc = [s for s in acc.spaces if s.model['name'] == vdc_choice][0]
print("VDC %s selected" % vdc.model['name'])
action_choice = ['Create VM', 'inspect VMs', 'Enter IPython']
action_choice = j.tools.console.askChoice(action_choice, "Choose what to do next")
if action_choice == 'Create VM':
name = j.tools.console.askString("Name of the VM to create")
disksize = j.tools.console.askChoice([10, 20], "Choose disk size")
image_choices = [i['name'] for i in vdc.images]
image = j.tools.console.askChoice(image_choices, "Choose image")
print('Start creation of the VMS')
machine = vdc.machine_create(name=name, memsize=2, vcpus=1, disksize=disksize, datadisks=[], image=image)
print('Machine %s name created' % machine.name)
elif action_choice == 'inspect VMs':
vms = list(vdc.machines.keys())
if len(vms) <= 0:
print("no VM in this VDC")
else:
vm_choice = j.tools.console.askChoice(vms, "Choose the vm to inspect")
machine = vdc.machines[vm_choice]
print(j.data.serializer.json.dumps(machine.model, indent=True))
elif action_choice == 'Enter IPython':
from IPython import embed;embed()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment