[Kimchi-devel] [PATCHv3 2/3] Prevent volume create and delete for certain pool types
Sheldon
shaohef at linux.vnet.ibm.com
Thu Feb 27 08:44:43 UTC 2014
Reviewed-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
On 02/27/2014 04:25 PM, lvroyce at linux.vnet.ibm.com wrote:
> From: Royce Lv <lvroyce at linux.vnet.ibm.com>
>
> As iscsi, scsi, mpath pools do not support create/delete
> storage volumes, when creating and deleting volumes,
> these pool types should be eleminated.
> REF:
> http://libvirt.org/storage.html
>
> Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
> ---
> src/kimchi/control/base.py | 2 ++
> src/kimchi/i18n.py | 1 +
> src/kimchi/model/storagevolumes.py | 18 +++++++++++++++---
> 3 files changed, 18 insertions(+), 3 deletions(-)
>
> diff --git a/src/kimchi/control/base.py b/src/kimchi/control/base.py
> index 61b4341..005acec 100644
> --- a/src/kimchi/control/base.py
> +++ b/src/kimchi/control/base.py
> @@ -130,6 +130,8 @@ class Resource(object):
> return self.delete()
> except NotFoundError, e:
> raise cherrypy.HTTPError(404, e.message)
> + except InvalidParameter, e:
> + raise cherrypy.HTTPError(400, e.message)
> elif method == 'PUT':
> try:
> return self.update()
> diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py
> index e22bb4b..558490a 100644
> --- a/src/kimchi/i18n.py
> +++ b/src/kimchi/i18n.py
> @@ -149,6 +149,7 @@ messages = {
> "KCHVOL0009E": _("Unable to wipe storage volumes %(name)s. Details: %(err)s"),
> "KCHVOL0010E": _("Unable to delete storage volume %(name)s. Details: %(err)s"),
> "KCHVOL0011E": _("Unable to resize storage volume %(name)s. Details: %(err)s"),
> + "KCHVOL0012E": _("Storage type %(type)s does not support volume create and delete"),
>
> "KCHIFACE0001E": _("Interface %(name)s does not exist"),
>
> diff --git a/src/kimchi/model/storagevolumes.py b/src/kimchi/model/storagevolumes.py
> index 8defdb7..98b6864 100644
> --- a/src/kimchi/model/storagevolumes.py
> +++ b/src/kimchi/model/storagevolumes.py
> @@ -22,7 +22,8 @@ import os
> import libvirt
>
> from kimchi import xmlutils
> -from kimchi.exception import InvalidOperation, IsoFormatError
> +from kimchi.config import READONLY_POOL_TYPE
> +from kimchi.exception import InvalidOperation, InvalidParameter, IsoFormatError
> from kimchi.exception import MissingParameter, NotFoundError, OperationFailed
> from kimchi.isoinfo import IsoImage
> from kimchi.model.storagepools import StoragePoolModel
> @@ -37,8 +38,9 @@ VOLUME_TYPE_MAP = {0: 'file',
> class StorageVolumesModel(object):
> def __init__(self, **kargs):
> self.conn = kargs['conn']
> + self.objstore = kargs['objstore']
>
> - def create(self, pool, params):
> + def create(self, pool_name, params):
> vol_xml = """
> <volume>
> <name>%(name)s</name>
> @@ -56,12 +58,16 @@ class StorageVolumesModel(object):
>
> name = params['name']
> try:
> - pool = StoragePoolModel.get_storagepool(pool, self.conn)
> + pool = StoragePoolModel.get_storagepool(pool_name, self.conn)
> xml = vol_xml % params
> except KeyError, item:
> raise MissingParameter("KCHVOL0004E", {'item': str(item),
> 'volume': name})
>
> + pool_info = StoragePoolModel(conn=self.conn,
> + objstore=self.objstore).lookup(pool_name)
> + if pool_info['type'] in READONLY_POOL_TYPE:
> + raise InvalidParameter("KCHVOL0012E", {'type': pool_info['type']})
> try:
> pool.createXML(xml, 0)
> except libvirt.libvirtError as e:
> @@ -86,6 +92,7 @@ class StorageVolumesModel(object):
> class StorageVolumeModel(object):
> def __init__(self, **kargs):
> self.conn = kargs['conn']
> + self.objstore = kargs['objstore']
>
> def _get_storagevolume(self, pool, name):
> pool = StoragePoolModel.get_storagepool(pool, self.conn)
> @@ -136,6 +143,11 @@ class StorageVolumeModel(object):
> {'name': name, 'err': e.get_error_message()})
>
> def delete(self, pool, name):
> + pool_info = StoragePoolModel(conn=self.conn,
> + objstore=self.objstore).lookup(pool)
> + if pool_info['type'] in READONLY_POOL_TYPE:
> + raise InvalidParameter("KCHVOL0012E", {'type': pool_info['type']})
> +
> volume = self._get_storagevolume(pool, name)
> try:
> volume.delete(0)
--
Thanks and best regards!
Sheldon Feng(冯少合)<shaohef at linux.vnet.ibm.com>
IBM Linux Technology Center
More information about the Kimchi-devel
mailing list