Пример #1
0
def delete_vm_task(vmid):
    with app.app_context():
        db = connect_db()
        starrs = connect_starrs()
        vm = VM(vmid)
        # do this before deleting the VM since it is hard to reconcile later
        retry = 0
        while retry < 3:
            try:
                delete_starrs(starrs, vm.name)
                break
            except:
                retry += 1
                time.sleep(3)
                continue
        if vm.status != 'stopped':
            vm.stop()
            retry = 0
            while retry < 10:
                time.sleep(3)
                if vm.status == 'stopped':
                    break
                retry += 1
        vm.delete()
        delete_vm_expire(db, vmid)
Пример #2
0
def clone_vm(proxmox, template_id, name, pool):
    node = proxmox.nodes(get_vm_node(proxmox, template_id))
    vmid = get_free_vmid(proxmox)
    # Make sure lingering expirations are deleted
    delete_vm_expire(db, vmid)
    target = get_node_least_mem(proxmox)
    node.qemu(template_id).clone.post(newid=vmid,
                                      name=name,
                                      pool=pool,
                                      full=1,
                                      description='Managed by Proxstar',
                                      target=target)
    return vmid
Пример #3
0
def create_vm(proxmox, user, name, cores, memory, disk, iso):
    node = proxmox.nodes(get_node_least_mem(proxmox))
    vmid = get_free_vmid(proxmox)
    # Make sure lingering expirations are deleted
    delete_vm_expire(db, vmid)
    node.qemu.create(
        vmid=vmid,
        name=name,
        cores=cores,
        memory=memory,
        storage='ceph',
        virtio0="ceph:{}".format(disk),
        ide2="{},media=cdrom".format(iso),
        net0='virtio,bridge=vmbr0',
        pool=user,
        description='Managed by Proxstar')
    return vmid
Пример #4
0
def create_vm(proxmox, user, name, cores, memory, disk, iso):
    node = proxmox.nodes(get_node_least_mem(proxmox))
    vmid = get_free_vmid(proxmox)
    # Make sure lingering expirations are deleted
    delete_vm_expire(db, vmid)
    node.qemu.create(
        vmid=vmid,
        name=name,
        cores=cores,
        memory=memory,
        storage=app.config['PROXMOX_VM_STORAGE'],
        virtio0='{}:{}'.format(app.config['PROXMOX_VM_STORAGE'], disk),
        ide2='{},media=cdrom'.format(iso),
        net0='virtio,bridge=vmbr0',
        pool=user,
        description='Managed by Proxstar',
    )
    return vmid