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']) vm.set_boot_order(['Hard Disk', 'CD-ROM', 'Network']) logging.info('[{}] VM successfully provisioned.'.format(name)) set_job_status(job, 'complete')
def set_boot_order(vmid): user = User(session['userinfo']['preferred_username']) connect_proxmox() if user.rtp or int(vmid) in user.allowed_vms: boot_order = [] for key in sorted(request.form): boot_order.append(request.form[key]) vm = VM(vmid) vm.set_boot_order(boot_order) return '', 200 else: return '', 403