def create_vm_task(user, name, cores, memory, disk, iso): with app.app_context(): job = get_current_job() proxmox = connect_proxmox() db = connect_db() starrs = connect_starrs() logging.info('[{}] Creating VM.'.format(name)) set_job_status(job, 'creating VM') vmid = create_vm(proxmox, user, name, cores, memory, disk, iso) logging.info( '[{}] Waiting until Proxmox is done provisioning.'.format(name)) set_job_status(job, 'waiting for Proxmox') timeout = 20 retry = 0 while retry < timeout: if not VM(vmid).is_provisioned(): retry += 1 time.sleep(3) continue break if retry == timeout: logging.info('[{}] Failed to provision, deleting.'.format(name)) set_job_status(job, 'failed to provision') delete_vm_task(vmid) return logging.info('[{}] Registering in STARRS.'.format(name)) set_job_status(job, 'registering in STARRS') vm = VM(vmid) ip = get_next_ip(starrs, app.config['STARRS_IP_RANGE']) register_starrs(starrs, name, app.config['STARRS_USER'], vm.get_mac(), ip) set_job_status(job, 'setting VM expiration') get_vm_expire(db, vmid, app.config['VM_EXPIRE_MONTHS']) logging.info('[{}] VM successfully provisioned.'.format(name)) set_job_status(job, 'complete')
def create_vm_task(user, name, cores, memory, disk, iso): with app.app_context(): job = get_current_job() proxmox = connect_proxmox() db = connect_db() starrs = connect_starrs() job.meta['status'] = 'creating VM' job.save_meta() vmid, mac = create_vm(proxmox, user, name, cores, memory, disk, iso) job.meta['status'] = 'registering in STARRS' job.save_meta() register_starrs(starrs, name, app.config['STARRS_USER'], mac, get_next_ip(starrs, app.config['STARRS_IP_RANGE'])) job.meta['status'] = 'setting VM expiration' job.save_meta() get_vm_expire(db, vmid, app.config['VM_EXPIRE_MONTHS']) job.meta['status'] = 'complete' job.save_meta()