[Kimchi-devel] [PATCHv1 4/5] Storage volume upload: Support file based upload
Aline Manera
alinefm at linux.vnet.ibm.com
Mon Sep 1 16:24:53 UTC 2014
On 09/01/2014 08:50 AM, lvroyce0210 at gmail.com wrote:
> From: Royce Lv <lvroyce at linux.vnet.ibm.com>
>
> Start a task to upload storage volume, limit the upload size to 4G.
The patch is OK for me.
I just would like to know what is needed to allow files larger than 4G.
Otherwise: Reviewed-by: Aline Manera <alinefm at linux.vnet.ibm.com>
>
> Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
> ---
> src/kimchi/i18n.py | 1 +
> src/kimchi/model/storagevolumes.py | 37 +++++++++++++++++++++++++++++++++++++
> 2 files changed, 38 insertions(+)
>
> diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py
> index bbec591..eded027 100644
> --- a/src/kimchi/i18n.py
> +++ b/src/kimchi/i18n.py
> @@ -187,6 +187,7 @@ messages = {
> "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": _("Upload volume can not be larger than 4G"),
>
> "KCHIFACE0001E": _("Interface %(name)s does not exist"),
>
> diff --git a/src/kimchi/model/storagevolumes.py b/src/kimchi/model/storagevolumes.py
> index 203d5e1..44279a2 100644
> --- a/src/kimchi/model/storagevolumes.py
> +++ b/src/kimchi/model/storagevolumes.py
> @@ -19,6 +19,7 @@
>
> import os
>
> +import cherrypy
> import libvirt
>
> from kimchi import xmlutils
> @@ -61,6 +62,42 @@ class StorageVolumesModel(object):
> taskid = add_task('', create_func, self.objstore, params)
> return self.task.lookup(taskid)
>
> + def _create_volume_with_file(self, cb, params):
> + lcHDRS = {}
> + for key, val in cherrypy.request.headers.iteritems():
> + lcHDRS[key.lower()] = val
> +
> + incomingBytes = int(lcHDRS['content-length'])
> + if incomingBytes > (2 << 31):
> + raise InvalidParameter("KCHVOL0020E")
> +
> + pool_name = params.pop('pool')
> + dir_path = StoragePoolModel(conn=self.conn,
> + objstore=self.objstore).lookup(pool_name)['path']
> + file_path = os.path.join(dir_path, params['name'])
> + if os.path.exists(file_path):
> + raise InvalidParameter('KCHVOL0001E', {'name': params['name']})
> +
> + upload_file = params['file']
> + try:
> + f = open(file_path, 'wb')
> + while True:
> + data = upload_file.file.read(8192)
> + if not data:
> + break
> + f.write(data)
> + f.close()
> + except Exception as e:
> + raise OperationFailed('KCHVOL0007E',
> + {'name': params['name'],
> + 'pool': pool_name,
> + 'err': e.message})
> +
> + # Refresh to make sure volume can be found in following lookup
> + pool = StoragePoolModel.get_storagepool(pool_name, self.conn)
> + pool.refresh()
> + cb('', True)
> +
> def _create_volume_with_capacity(self, cb, params):
> pool_name = params.pop('pool')
> vol_xml = """
More information about the Kimchi-devel
mailing list