Commit 61d19ac2 authored by Thibault VINCENT's avatar Thibault VINCENT
Browse files

Storage implementation: add_volume del_volume

+ fixed interface docstring for add_volume
parent 6a3ff54c
Loading
Loading
Loading
Loading
+13 −13
Original line number Diff line number Diff line
@@ -217,7 +217,7 @@ class HVStorage(object):
        '''
        Adds a volume to the specified pool

        :param pool: name of the pool
        :param pool: the pool in which to create the volume
        :type pool: :class:`str`
        :param name: name of the new volume
        :type name: :class:`str`
+56 −14
Original line number Diff line number Diff line
@@ -363,6 +363,48 @@ class LibvirtHVStorage(HVStorage):
        '''
        return POOL_STATE[pool.info()[0]]

    def add_volume(self, pool, name, space):
        '''
        Adds a volume to the specified pool

        :param pool: the pool in which to create the volume
        :type pool: :class:`str`
        :param name: name of the new volume
        :type name: :class:`str`
        :param space: size of the new volume in gigabytes
        :type space: :class:`int`
        '''
        xml_desc = """
            <volume>
                <name>%(vol_name)s</name>
                <capacity>%(vol_size)u</capacity>
            </volume>
        """ % {
            "vol_name" : name,
            "vol_size" : space * GIGABYTE_DIV,
            }
        try:
            pool.createXML(xml_desc, 0);
        except libvirt.libvirtError as e:
            raise StorageError("Failed to create the volume (%s)" % e)

    def del_volume(self, pool, name):
        '''
        Deletes a volume in the specified pool

        :param pool: the pool in which delete the volume
        :type pool: :class:`str`
        :param name: the name of the volume
        :type name: :class:`str`
        '''
        try:
            vol = pool.storageVolLookupByName(name)
        except libvirt.libvirtError as e:
            raise StorageError("Volume not found (%s)" % e)
        try:
            vol.delete(0)
        except libvirt.libvirtError as e:
            raise StorageError("Failed to delete the volume (%s)" % e)


#### Helper functions