Esempio n. 1
0
def storage(pool, volume, val: VolumeAction):
    try:
        conn = libvrt.wvmStorage(pool)
        vol = conn.get_volume(volume)
    except libvirtError as err:
        error_msg(err)

    if val.action not in ['resize', 'clone']:
        error_msg('Action not exist.')

    if val.action == 'resize':
        if not val.size:
            error_msg('Size required for resize ation.')
        try:
            conn.resize_volume(val.size)
        except libvirtError as err:
            error_msg(err)

    if val.action == 'clone':
        if not val.name:
            error_msg('Name required for clone ation.')
        try:
            conn.clone_volume(volume, val.name)
        except libvirtError as err:
            error_msg(err)

    conn.close()
    return val
Esempio n. 2
0
def storage(pool, volume):
    try:
        conn = libvrt.wvmStorage(pool)
        vol = conn.del_volume(volume)
    except libvirtError as err:
        error_msg(err)
    conn.close()
Esempio n. 3
0
def storage(pool):
    try:
        conn = libvrt.wvmStorage(pool)
        conn.stop()
        conn.delete()
    except libvirtError as err:
        error_msg(err)
    conn.close()
Esempio n. 4
0
def storage(pool, volume):
    try:
        conn = libvrt.wvmStorage(pool)
        vol = conn.get_volume_info(volume)
    except libvirtError as err:
        error_msg(err)

    conn.close()
    return {'volume': vol}
Esempio n. 5
0
def storage(pool):
    try:
        conn = libvrt.wvmStorage(pool)
    except libvirtError as err:
        error_msg(err)

    volumes = conn.get_volumes_info()
    conn.close()
    return {'volumes': volumes}
Esempio n. 6
0
def storage(pool, volume: VolumeCreate):
    try:
        conn = libvrt.wvmStorage(pool)
        conn.create_volume(name=volume.name,
                           size=volume.size * (1024**3),
                           fmt=volume.format)
    except libvirtError as err:
        error_msg(err)

    conn.close()
    return volume
Esempio n. 7
0
def instance(name):
    try:
        conn = libvrt.wvmInstance(name)
        drivers = conn.get_disk_device()
        for drive in drivers:
            if drive.get('dev') == 'vda' or drive.get('dev') == 'sda':
                sconn = libvrt.wvmStorage(drive.get('pool'))
                vol = sconn.get_volume(drive.get('name'))
                vol.delete()
                sconn.refresh()
                sconn.close()
        conn.delete()
        conn.close()
    except libvirtError as err:
        error_msg(err)
Esempio n. 8
0
def instance(name, resize: InstanceResize):
    try:
        conn = libvrt.wvmInstance(name)
        if conn.get_state() != 'shutoff':
            error_msg('Please shutoff the virtual machine.')
        conn.resize_resources(resize.vcpu, resize.memory)
        if resize.disk_size:
            drivers = conn.get_disk_device()
            for drive in drivers:
                if drive.get('dev') == 'vda' or drive.get('dev') == 'sda':
                    sconn = libvrt.wvmStorage(drive.get('pool'))
                    sconn.resize_volume(drive.get('name'), resize.disk_size)
                    sconn.close()
        conn.close()
    except libvirtError as err:
        error_msg(err)

    return resize
Esempio n. 9
0
def instance(instance: InstanceCreate):
    # Download and deploy images template
    for img in instance.images:
        if img.get('primary') is True:
            template = images.Template(img.get('name'), img.get('md5sum'))
            err_msg, template_path = template.download(img.get('url'))
            if err_msg is None:
                image = images.Image(img.get('name'), img.get('pool'))
                err_msg = image.deploy_template(
                    template=template,
                    disk_size=img.get('size'),
                    networks=instance.network,
                    public_key=instance.public_keys,
                    hostname=instance.name,
                    root_password=instance.root_password)
        else:
            try:
                conn = libvrt.wvmStorage(img.get('pool'))
                conn.create_volume(img.get('name'), img.get('size'), fmt='raw')
                conn.close()
            except libvirtError as err:
                error_msg(err)

    if err_msg is not None:
        error_msg(err_msg)

    # Create XML
    try:
        conn = libvrt.wvmCreate()
        conn.create_xml(instance.name, instance.vcpu, instance.memory,
                        instance.images, instance.network)
        conn.close()
    except libvirtError as err:
        error_msg(err)

    # Run Instance
    try:
        conn = libvrt.wvmInstance(instance.name)
        conn.start()
        conn.close()
    except libvirtError as err:
        error_msg(err)

    return instance
Esempio n. 10
0
def storage(pool, val: StorageAction):
    try:
        conn = libvrt.wvmStorage(pool)
    except libvirtError as err:
        error_msg(err)

    if val.action not in ['start', 'stop', 'autostart', 'manualstart']:
        error_msg('Action not exist.')

    if val.action == 'start':
        conn.start()
    if val.action == 'stop':
        conn.stop()
    if val.action == 'autostart':
        conn.set_autostart(True)
    if val.action == 'manualstart':
        conn.set_autostart(False)

    conn.close()
    return val
Esempio n. 11
0
def storage(pool):
    try:
        conn = libvrt.wvmStorage(pool)
    except libvirtError as err:
        error_msg(err)

    storage = {
        'name': pool,
        'active': conn.get_active(),
        'type': conn.get_type(),
        'volumes': conn.get_volumes_info(),
        'size': {
            'total': conn.get_total_size(),
            'used': conn.get_used_size(),
            'free': conn.get_free_size()
        },
        'autostart': conn.get_autostart()
    }
    conn.close()
    return {'storage': storage}