[Kimchi-devel] [PATCH 4/4] Remove storage volume creation from file

Aline Manera alinefm at linux.vnet.ibm.com
Mon May 11 18:34:32 UTC 2015


Now the upload process will be a sequence of POST and several PUT
requests to the storage volume to avoid browser crashing.
So remove the former way to upload a file to Kimchi server which used
'file' parameter to POST request.

Signed-off-by: Aline Manera <alinefm at linux.vnet.ibm.com>
---
 docs/API.md                        |  3 +--
 src/kimchi/mockmodel.py            | 16 +++++-----------
 src/kimchi/model/storagevolumes.py | 36 ++----------------------------------
 3 files changed, 8 insertions(+), 47 deletions(-)

diff --git a/docs/API.md b/docs/API.md
index 88c5fec..71f2539 100644
--- a/docs/API.md
+++ b/docs/API.md
@@ -481,7 +481,7 @@ A interface represents available network interface on VM.
            in the defined Storage Pool
 * **POST**: Create a new Storage Volume in the Storage Pool
             The return resource is a task resource * See Resource: Task *
-            Only one of 'file', 'capacity', 'url' can be specified.
+            Only one of 'capacity', 'url' can be specified.
     * name: The name of the Storage Volume
     * capacity: The total space which can be used to store volumes
                 The unit is bytes
@@ -490,7 +490,6 @@ A interface represents available network interface on VM.
     * upload: True to start an upload process. False, otherwise.
               Only used when creating a storage volume 'capacity' parameter.
     * file: File to be uploaded, passed through form data
-    * url: URL to be downloaded
 
 ### Resource: Storage Volume
 
diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
index 4395883..b205608 100644
--- a/src/kimchi/mockmodel.py
+++ b/src/kimchi/mockmodel.py
@@ -282,21 +282,15 @@ class MockModel(Model):
         kimchi_log.info("The host system will be rebooted")
 
     def _mock_storagevolumes_create(self, pool, params):
-        vol_source = ['file', 'url', 'capacity']
+        vol_source = ['url', 'capacity']
         index_list = list(i for i in range(len(vol_source))
                           if vol_source[i] in params)
         create_param = vol_source[index_list[0]]
         name = params.get('name')
-        if name is None:
-            if create_param == 'file':
-                name = os.path.basename(params['file'].filename)
-                del params['file']
-                params['capacity'] = 1024
-            elif create_param == 'url':
-                name = os.path.basename(params['url'])
-                del params['url']
-                params['capacity'] = 1024
-            params['name'] = name
+        if name is None and create_param == 'url':
+            params['name'] = os.path.basename(params['url'])
+            del params['url']
+            params['capacity'] = 1024
 
         return self._model_storagevolumes_create(pool, params)
 
diff --git a/src/kimchi/model/storagevolumes.py b/src/kimchi/model/storagevolumes.py
index 0afc74b..e2128f1 100644
--- a/src/kimchi/model/storagevolumes.py
+++ b/src/kimchi/model/storagevolumes.py
@@ -58,7 +58,7 @@ class StorageVolumesModel(object):
         self.task = TaskModel(**kargs)
 
     def create(self, pool_name, params):
-        vol_source = ['file', 'url', 'capacity']
+        vol_source = ['url', 'capacity']
 
         name = params.get('name')
 
@@ -89,9 +89,7 @@ class StorageVolumesModel(object):
             # if 'name' is omitted - except for the methods listed in
             # 'REQUIRE_NAME_PARAMS' - the default volume name will be the
             # file/URL basename.
-            if create_param == 'file':
-                name = os.path.basename(params['file'].filename)
-            elif create_param == 'url':
+            if create_param == 'url':
                 name = os.path.basename(params['url'])
             else:
                 name = 'upload-%s' % int(time.time())
@@ -120,36 +118,6 @@ class StorageVolumesModel(object):
         taskid = add_task(targeturi, create_func, self.objstore, params)
         return self.task.lookup(taskid)
 
-    def _create_volume_with_file(self, cb, params):
-        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']
-        f_len = upload_file.fp.length
-        try:
-            size = 0
-            with open(file_path, 'wb') as f:
-                while True:
-                    data = upload_file.file.read(READ_CHUNK_SIZE)
-                    if not data:
-                        break
-                    size += len(data)
-                    f.write(data)
-                    cb('%s/%s' % (size, f_len))
-        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
-        StoragePoolModel.get_storagepool(pool_name, self.conn).refresh(0)
-        cb('OK', True)
-
     def _create_volume_with_capacity(self, cb, params):
         pool_name = params.pop('pool')
         vol_xml = """
-- 
2.1.0




More information about the Kimchi-devel mailing list