Example #1
0
 def run(self):
     while self.stop is False:
         try:
             if not creator_q.empty():
                 vm_type, params = creator_q.get(True, 10)
                 if params.number > 1:
                     rnd = ''.join(
                         random.choice(string.ascii_letters)
                         for _ in range(6))
                     vm_name = '%s-%s' % (params.vmname, rnd)
                 else:
                     vm_name = params.name
                 vm_creation_sem.acquire()
                 # create lock to avoid double creation
                 single_lock.acquire()
                 op = False
                 if vm_type is 'smart':
                     from ArubaCloud.objects import SmartVmCreator
                     creator = SmartVmCreator(
                         name=vm_name,
                         admin_password=params.admin_pwd,
                         template_id=params.template,
                         auth_obj=pool[params.dc].auth)
                     creator.set_type(size=params.pkg)
                     op = creator.commit(url=pool[params.dc].wcf_baseurl)
                 elif vm_type is 'pro':
                     from ArubaCloud.objects import ProVmCreator
                     creator = ProVmCreator(name=vm_name,
                                            admin_password=params.adminpwd,
                                            template_id=params.template,
                                            auth_obj=pool[params.dc].auth)
                     if params.buyip is True:
                         ip = pool[params.dc].purchase_ip()
                         creator.add_public_ip(ip.resid)
                     creator.add_virtual_disk(params.disk1)
                     if params.disk2 > 0:
                         creator.add_virtual_disk(params.disk2)
                     if params.disk3 > 0:
                         creator.add_virtual_disk(params.disk3)
                     if params.disk4 > 0:
                         creator.add_virtual_disk(params.disk4)
                     creator.set_cpu_qty(int(params.cpuqty))
                     creator.set_ram_qty(int(params.ramqty))
                     op = creator.commit(url=pool[params.dc].wcf_baseurl)
                 ret = True if op is True else False
                 single_lock.release()
                 if ret is False:
                     self.logger.warning('Cannot create VM.')
                 else:
                     while pool[params.dc].find_job(
                             vm_name) is not 'JOBNOTFOUND':
                         time.sleep(10)
                     cprint('Creation of VM: %s Done.' % vm_name, 'green')
                 creator_q.task_done()
                 vm_creation_sem.release()
             time.sleep(0.25)
         except Queue.Empty:
             pass
Example #2
0
                        '--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))