def login_to_ci(username, password, datacenter, **kwargs): try: print u"Logging to ArubaCloud DC{}".format(datacenter) ci = CloudInterface(dc=int(datacenter)) ci.login(username=username, password=password, load=False) return ci except RequestFailed as e: raise click.ClickException( u'Error while trying to connect to ArubaCloud. More info: \n{}'. format(e))
def aruba(cls, dc, username, password, netname, attach=None, servername=None): global token if dc in range(1, 6, 1): token = CloudInterface(dc=dc) token.login(username=username, password=password, load=True) vlan = token.purchase_vlan(vlan_name=netname) if attach: vmid = token.vmlist.find(servername)[0] netif = token.get_server_detail(server_id=vmid)['NetworkAdapters'][1] token.attach_vlan(network_adapter_id=netif['id'], vlan_resource_id=vlan.resource_id)
import argparse from ArubaCloud.PyArubaAPI import CloudInterface from ArubaCloud.objects.VmTypes import * if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('-d', '--datacenter', help='Specify datacenter to login.', action='store', type=int, dest='dc') parser.add_argument('-p', '--pattern', help='Specify pattern to search.', action='store', dest='pattern') parser.add_argument('-u', '--username', help='Specify username.', action='store', dest='username') parser.add_argument('-w', '--password', help='Specify password.', action='store', dest='password') p = parser.parse_args() i = CloudInterface(dc=p.dc) i.login(username=p.username, password=p.password, load=True) i.get_servers() for vm in i.vmlist: print("VM Name: {}".format(vm.vm_name)) print("VM Type: {}".format(type(vm))) if isinstance(vm, Smart): print("VM IP: {}".format(vm.ip_addr)) elif isinstance(vm, Pro): print("VM IP: {}".format(vm.ip_addr.ip_addr)) print("############################")
parser.add_argument('-w', '--password', help='Specify password.', action='store', dest='password') parser.add_argument('--vlan-name', help='Specify vSwitch Name.', action='store', dest='vlan_name') parser.add_argument('--vm-name', help='Name of the VM to attach the new VLAN.', action='store', dest='vm_name') p = parser.parse_args() i = CloudInterface(dc=p.dc) i.login(username=p.username, password=p.password, load=True) # create new vlan (virtual switch) vlan = i.purchase_vlan(p.vlan_name) # find the vm object vm = i.vmlist.find(p.vm_name)[0] # find the network adapter object network_adapter = i.get_server_detail( server_id=vm.sid)['NetworkAdapters'][0] # attach the network adapter to the created vlan i.attach_vlan(network_adapter_id=network_adapter['Id'], vlan_resource_id=vlan.resource_id) # retrieve every vlan in the datacenter and remove them
help='Specify pattern to search.', action='store', dest='pattern') parser.add_argument('-u', '--username', help='Specify username.', action='store', dest='username') parser.add_argument('-w', '--password', help='Specify password.', action='store', dest='password') p = parser.parse_args() i = CloudInterface(dc=p.dc) i.login(username=p.username, password=p.password, load=True) i.get_servers() poweroff_check = 0 maxretries = 5 sleep_for = 5 attempts = 0 for vm in i.vmlist.find(name=p.pattern): if vm.status == 3: print('Turn off VM: %s' % vm.vm_name) vm.poweroff() poweroff_check = 1 time.sleep(sleep_for) for w in range(maxretries):
action='store', dest='vmname') parser.add_argument('--vmpassword', help='Specify VM admin password.', action='store', dest='vmpassword', default='ArubaCloud2015') parser.add_argument( '--pkg', help='Specify package: [small|medium|large|extralarge]', action='store', dest='pkg', default='small') p = parser.parse_args() i = CloudInterface(dc=p.dc) i.login(username=p.username, password=p.password, load=True) packageID = i.get_package_id(p.pkg) from ArubaCloud.objects import SmartVmCreator c = SmartVmCreator(name=p.vmname, admin_password=p.vmpassword, template_id=p.template, auth_obj=i.auth) c.set_type(packageID) pprint(c.get_json()) print(c.commit(url=i.wcf_baseurl, debug=True))
dest='dc') parser.add_argument('-p', '--pattern', help='Specify pattern to search.', action='store', dest='pattern') parser.add_argument('-u', '--username', help='Specify username.', action='store', dest='username') parser.add_argument('-w', '--password', help='Specify password.', action='store', dest='password') parser.add_argument('--new-admin-password', action='store', dest='new_admin_passwd') p = parser.parse_args() i = CloudInterface(p.dc) i.login(p.username, p.password, False) for vm in i.get_vm(pattern=p.pattern): print('Reinitialize: %s' % vm.vm_name) if vm.status == 3: vm.poweroff() while len(i.get_jobs()['Value']) > 0: time.sleep(1) vm.reinitialize(admin_password=p.new_admin_passwd)
import argparse from ArubaCloud.PyArubaAPI import CloudInterface if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('-d', '--datacenter', help='Specify datacenter to login.', action='store', type=int, dest='dc') parser.add_argument('-p', '--pattern', help='Specify pattern to search.', action='store', dest='pattern') parser.add_argument('-u', '--username', help='Specify username.', action='store', dest='username') parser.add_argument('-w', '--password', help='Specify password.', action='store', dest='password') p = parser.parse_args() i = CloudInterface(dc=p.dc) i.login(username=p.username, password=p.password, load=True) i.get_servers() vm = i.vmlist.find(name=p.pattern)[0] vm.upgrade_vm(package_id=3)
from ArubaCloud.PyArubaAPI import CloudInterface if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('-d', '--datacenter', help='Specify datacenter to login.', action='store', type=int, dest='dc') parser.add_argument('-u', '--username', help='Specify username.', action='store', dest='username') parser.add_argument('-w', '--password', help='Specify password.', action='store', dest='password') p = parser.parse_args() i = CloudInterface(dc=p.dc) i.login(username=p.username, password=p.password, load=True) i.get_hypervisors() from pprint import pprint pprint(i.find_template(name='Windows', hv=2))
import argparse import time from ArubaCloud.PyArubaAPI import CloudInterface if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('-d', '--datacenter', help='Specify datacenter to login.', action='store', type=int, dest='dc') parser.add_argument('-p', '--pattern', help='Specify pattern to search.', action='store', dest='pattern') parser.add_argument('-u', '--username', help='Specify username.', action='store', dest='username') parser.add_argument('-w', '--password', help='Specify password.', action='store', dest='password') parser.add_argument('--new-admin-password', action='store', dest='new_admin_passwd') p = parser.parse_args() i = CloudInterface(p.dc) i.login(p.username, p.password, False) for vm in i.get_vm(pattern=p.pattern): print('Reinitialize: %s' % vm.vm_name) if vm.status == 3: vm.poweroff() while len(i.get_jobs()['Value']) > 0: time.sleep(1) vm.reinitialize(admin_password=p.new_admin_passwd)
import argparse import time from ArubaCloud.PyArubaAPI import CloudInterface if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('-d', '--datacenter', help='Specify datacenter to login.', action='store', dest='dc') parser.add_argument('-p', '--pattern', help='Specify pattern to search.', action='store', dest='pattern') parser.add_argument('-u', '--username', help='Specify username.', action='store', dest='username') parser.add_argument('-w', '--password', help='Specify password.', action='store', dest='password') parser.add_argument('--new-admin-password', action='store', dest='new_admin_passwd') p = parser.parse_args() o = CloudInterface(p.dc) o.login(p.username, p.password, False) for vm in o.find_vm(pattern=p.pattern): print('Reinitialize: %s' % vm.vm_name) vm.poweroff() while len(o.get_jobs()['Value']) > 0: time.sleep(1) vm.reinitialize(admin_password=p.new_admin_passwd)
help='Specify template.', action='store', dest='template') parser.add_argument('-n', '--name', help='Specify VM name', action='store', dest='vmname') parser.add_argument('--vmpassword', help='Specify VM admin password.', action='store', dest='vmpassword', default='ArubaCloud2015') p = parser.parse_args() i = CloudInterface(dc=p.dc, debug_level=logging.DEBUG) i.login(username=p.username, password=p.password, load=False) ip = i.purchase_ip(debug=True) from ArubaCloud.objects import ProVmCreator c = ProVmCreator(name=p.vmname, admin_password=p.vmpassword, template_id=p.template, auth_obj=i.auth) c.set_cpu_qty(2) c.set_ram_qty(6) c.add_public_ip(public_ip_address_resource_id=ip.resid) c.add_virtual_disk(40) c.add_virtual_disk(40)
import argparse import time from ArubaCloud.PyArubaAPI import CloudInterface from ArubaCloud.objects.VmTypes import * from ArubaCloud.base.vm import * if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('-p', '--pattern', help='Specify pattern to search.', action='store', dest='pattern') p = parser.parse_args() i = CloudInterface(dc=3) i.login(username="******", password="******", load=True) for vm in i.get_vm(pattern=p.pattern): print('Reinitialize: %s' % vm.vm_name) if vm.status == 3: vm.poweroff() while len(i.get_jobs()['Value']) > 0: time.sleep(1) vm.reinitialize(admin_password="******", OSTemplateID="406")
import argparse import time from ArubaCloud.PyArubaAPI import CloudInterface if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("-d", "--datacenter", help="Specify datacenter to login.", action="store", type=int, dest="dc") parser.add_argument("-p", "--pattern", help="Specify pattern to search.", action="store", dest="pattern") parser.add_argument("-u", "--username", help="Specify username.", action="store", dest="username") parser.add_argument("-w", "--password", help="Specify password.", action="store", dest="password") p = parser.parse_args() i = CloudInterface(dc=p.dc) i.login(username=p.username, password=p.password, load=True) i.get_servers() maxretries = 5 for vm in i.vmlist.find(name=p.pattern): if vm.status == 3: vm.poweroff() for w in range(maxretries): server_detail = i.get_server_detail(server_id=vm.sid) if server_detail["ServerStatus"] == 2: break else: print("Waiting shutdown") time.sleep(5) i.delete_vm(server_id=vm.sid)
import argparse from ArubaCloud.PyArubaAPI import CloudInterface from ArubaCloud.objects import VirtualDisk if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('-d', '--datacenter', help='Specify datacenter to login.', action='store', dest='dc', required=True) parser.add_argument('-u', '--username', help='Specify username.', action='store', dest='username', required=True) parser.add_argument('-w', '--password', help='Specify password.', action='store', dest='password', required=True) parser.add_argument('--vm_name', help='Specify VM Name.', action='store', dest='vm_name', required=True) p = parser.parse_args() i = CloudInterface(dc='2') i.login(username=p.username, password=p.password, load=True) vm = i.find_vm(pattern=p.vm_name)[0] # vm.poweroff() # Set the amount of CPU cores # vm.edit_cpu(cpu_qty=1, debug=True) # Set the amount of RAM GB # vm.edit_ram(ram_qty=2, debug=True) # Add a new Virtual Disk # vm.add_virtual_disk(size=10) # Delete a Virtual Disk vm.remove_virtual_disk(virtual_disk_id=VirtualDisk.additional_disk2_id)
import argparse from ArubaCloud.PyArubaAPI import CloudInterface if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('-d', '--datacenter', help='Specify datacenter to login.', action='store', dest='dc') parser.add_argument('-u', '--username', help='Specify username.', action='store', dest='username') parser.add_argument('-w', '--password', help='Specify password.', action='store', dest='password') parser.add_argument('-t', '--template', help='Specify template.', action='store', dest='template') parser.add_argument('--vlan-name', help='Specify vSwitch Name.', action='store', dest='vlan_name') parser.add_argument('--vm-name', help='Name of the VM to attach the new VLAN.', action='store', dest='vm_name') p = parser.parse_args() i = CloudInterface(dc=p.dc) i.login(username=p.username, password=p.password, load=True) # create new vlan (virtual switch) vlan = i.purchase_vlan(p.vlan_name) # find the vm object vm = i.vmlist.find(p.vm_name)[0] # find the network adapter object network_adapter = i.get_server_detail(server_id=vm.sid)['NetworkAdapters'][1] # attach the network adapter to the created vlan i.attach_vlan(network_adapter_id=network_adapter['Id'], vlan_resource_id=vlan.resource_id) # retrieve every vlan in the datacenter and remove them raw_input( "You are going to delete every VLAN in Datacenter: {}, press any key to continue (CTRL+C to abort)".format( p.dc
def check_login(): data = request.form ci = CloudInterface(1) ci.login(username=str(data['username']), password=str(data['password']), load=False) ci.get_servers() return Response(response="ok", status=200, mimetype="application/json")
import argparse from ArubaCloud.PyArubaAPI import CloudInterface if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('-d', '--datacenter', help='Specify datacenter to login.', action='store', dest='dc') parser.add_argument('-u', '--username', help='Specify username.', action='store', dest='username') parser.add_argument('-w', '--password', help='Specify password.', action='store', dest='password') p = parser.parse_args() i = CloudInterface(dc=p.dc) i.login(username=p.username, password=p.password, load=True) i.get_hypervisors() from pprint import pprint pprint(i.find_template(name='Debian', hv=4))
import argparse from pprint import pprint from ArubaCloud.PyArubaAPI import CloudInterface if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('-d', '--datacenter', help='Specify datacenter to login.', action='store', type=int, dest='dc') parser.add_argument('-u', '--username', help='Specify username.', action='store', dest='username') parser.add_argument('-w', '--password', help='Specify password.', action='store', dest='password') parser.add_argument('-t', '--template', help='Specify template.', action='store', dest='template') parser.add_argument('-n', '--name', help='Specify VM name', action='store', dest='vmname') parser.add_argument('--vmpassword', help='Specify VM admin password.', action='store', dest='vmpassword', default='ArubaCloud2015') parser.add_argument('--pkg', help='Specify package: [small|medium|large|extralarge]', action='store', dest='pkg', default='small') p = parser.parse_args() i = CloudInterface(dc=p.dc) i.login(username=p.username, password=p.password, load=True) from ArubaCloud.objects import SmartVmCreator c = SmartVmCreator(name=p.vmname, admin_password=p.vmpassword, template_id=p.template, auth_obj=i.auth) c.set_type(size=p.pkg) pprint(c.get_json()) print(c.commit(url=i.wcf_baseurl, debug=True))
from pprint import pprint from ArubaCloud.PyArubaAPI import CloudInterface if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('-d', '--datacenter', help='Specify datacenter to login.', action='store', type=int, dest='dc') parser.add_argument('-u', '--username', help='Specify username.', action='store', dest='username') parser.add_argument('-w', '--password', help='Specify password.', action='store', dest='password') parser.add_argument('-t', '--template', help='Specify template.', action='store', dest='template') parser.add_argument('-n', '--name', help='Specify VM name', action='store', dest='vmname') parser.add_argument('--vmpassword', help='Specify VM admin password.', action='store', dest='vmpassword', default='ArubaCloud2015') p = parser.parse_args() i = CloudInterface(dc=p.dc, debug_level=logging.DEBUG) i.login(username=p.username, password=p.password, load=False) ip = i.purchase_ip(debug=True) from ArubaCloud.objects import ProVmCreator c = ProVmCreator(name=p.vmname, admin_password=p.vmpassword, template_id=p.template, auth_obj=i.auth) c.set_cpu_qty(2) c.set_ram_qty(6) c.add_public_ip(public_ip_address_resource_id=ip.resid) c.add_virtual_disk(40) c.add_virtual_disk(40) pprint(c.get_json()) print(c.commit(url=i.wcf_baseurl, debug=True))
def aruba(cls, dc, username, password, servertype=None, flavor=None, servername=None, servpass=None, image=None, number=None, serverid=None, cpu=None, ram=None, disk=None, token=None, insert=None, reboot=None, remove=None, rebuild=None): if insert: global templ, image_id, i if dc in range(1, 6, 1): token = CloudInterface(dc=dc) if None in servertype: templ = token.find_template(hv=4) elif "lowcost" in servertype: templ = token.find_template(hv=3) elif "vmware" in servertype: templ = token.find_template(hv=2) elif "hyperv" in servertype: templ = token.find_template(hv=1) for t in templ: if image in t.id_code and "True" in t.enabled: image_id = t.template_id return image_id size = {"small", 'medium', 'large', 'extra large'} for i in size: if flavor not in i: Exception("size error") else: return i token.login(username=username, password=password, load=True) if servertype is None: if number is None: c = SmartVmCreator(name=servername, admin_password=servpass, template_id=image_id, auth_obj=token.auth) c.set_type(size=i) c.commit(url=token.wcf_baseurl, debug=True) else: a = 0 while a < int(number): a += 1 c = SmartVmCreator(name=servername + a, admin_password=servpass, template_id=image_id, auth_obj=token.auth) c.set_type(size=i) c.commit(url=token.wcf_baseurl, debug=True) else: if number is None: ip = token.purchase_ip() pvm = ProVmCreator(name=servername, admin_password=servpass, template_id=image_id, auth_obj=token.auth) pvm.set_cpu_qty(int(cpu)) pvm.set_ram_qty(int(ram)) pvm.add_virtual_disk(int(disk)) pvm.add_public_ip(public_ip_address_resource_id=ip.resid, primary_ip_address=True) pvm.commit(url=token.wcf_baseurl, debug=True) time.sleep(60) else: a = 0 while a < int(number): a += 1 ip = token.purchase_ip() pvm = ProVmCreator(name=servername + a, admin_password=servpass, template_id=image_id, auth_obj=token.auth) pvm.set_cpu_qty(int(cpu)) pvm.set_ram_qty(int(ram)) pvm.add_virtual_disk(int(disk)) pvm.add_public_ip(public_ip_address_resource_id=ip.resid, primary_ip_address=True) pvm.commit(url=token.wcf_baseurl, debug=True) time.sleep(60) elif reboot: token = CloudInterface(dc=dc) token.login(username=username, password=password, load=True) token.poweroff_server(server_id=serverid) time.sleep(60) token.poweron_server(server_id=serverid) elif remove: token = CloudInterface(dc=dc) token.login(username=username, password=password, load=True) token.poweroff_server(server_id=serverid) time.sleep(60) token.delete_vm(server_id=serverid) elif rebuild: token = CloudInterface(dc=dc) token.login(username=username, password=password, load=True) for vm in token.get_vm(pattern=serverid): vm.poweroff() time.sleep(60) vm.reinitialize(admin_password=servpass)