
From: Royce Lv <lvroyce@linux.vnet.ibm.com> As we are starting to support upload and download to create volume, they need to be distinguished from previous creating through libvirt api. Adding a dispatcher to support this. Also update the jsonschema to add capacity parameter. Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> Signed-off-by: CrÃstian Viana <vianac@linux.vnet.ibm.com> --- src/kimchi/API.json | 6 ++++++ src/kimchi/i18n.py | 3 +++ src/kimchi/mockmodel.py | 17 +++++++++++++++++ src/kimchi/model/storagevolumes.py | 17 +++++++++++++++++ 4 files changed, 43 insertions(+) diff --git a/src/kimchi/API.json b/src/kimchi/API.json index 67612f2..2e2f9b0 100644 --- a/src/kimchi/API.json +++ b/src/kimchi/API.json @@ -165,6 +165,12 @@ "required": true, "error": "KCHVOL0013E" }, + "capacity": { + "description": "The total size (MiB) of the storage volume", + "type": "number", + "minimum": 1, + "error": "KCHVOL0020E" + }, "allocation": { "description": "The size(MiB) of allocation when create the storage volume", "type": "number", diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py index c276b38..1e8b47a 100644 --- a/src/kimchi/i18n.py +++ b/src/kimchi/i18n.py @@ -185,6 +185,9 @@ messages = { "KCHVOL0015E": _("Storage volume format not supported"), "KCHVOL0016E": _("Storage volume requires a volume name"), "KCHVOL0017E": _("Unable to update database with storage volume information due error: %(err)s"), + "KCHVOL0018E": _("Only one of %(param)s can be specified"), + "KCHVOL0019E": _("Creating volume from %(param)s is not supported"), + "KCHVOL0020E": _("Storage volume capacity must be an integer number."), "KCHIFACE0001E": _("Interface %(name)s does not exist"), diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py index e23c21a..f15e6c9 100644 --- a/src/kimchi/mockmodel.py +++ b/src/kimchi/mockmodel.py @@ -478,6 +478,23 @@ class MockModel(object): raise NotFoundError("KCHPOOL0002E", {'name': name}) def storagevolumes_create(self, pool_name, params): + vol_source = ['file', 'url', 'capacity'] + + index_list = list(i for i in range(len(vol_source)) + if vol_source[i] in params) + if len(index_list) != 1: + raise InvalidParameter("KCHVOL0018E", + {'param': ",".join(vol_source)}) + + try: + create_func = getattr(self, "_create_volume_with_" + + vol_source[index_list[0]]) + except AttributeError: + raise InvalidParameter("KCHVOL0019E", + {'param': vol_source[index_list[0]]}) + return create_func(pool_name, params) + + def _create_volume_with_capacity(self, pool_name, params): pool = self._get_storagepool(pool_name) if pool.info['state'] == 'inactive': raise InvalidOperation("KCHVOL0003E", diff --git a/src/kimchi/model/storagevolumes.py b/src/kimchi/model/storagevolumes.py index b60884c..8e44cab 100644 --- a/src/kimchi/model/storagevolumes.py +++ b/src/kimchi/model/storagevolumes.py @@ -44,6 +44,23 @@ class StorageVolumesModel(object): self.objstore = kargs['objstore'] def create(self, pool_name, params): + vol_source = ['file', 'url', 'capacity'] + + index_list = list(i for i in range(len(vol_source)) + if vol_source[i] in params) + if len(index_list) != 1: + raise InvalidParameter("KCHVOL0018E", + {'param': ",".join(vol_source)}) + + try: + create_func = getattr(self, "_create_volume_with_" + + vol_source[index_list[0]]) + except AttributeError: + raise InvalidParameter("KCHVOL0019E", + {'param': vol_source[index_list[0]]}) + return create_func(pool_name, params) + + def _create_volume_with_capacity(self, pool_name, params): vol_xml = """ <volume> <name>%(name)s</name> -- 1.9.3