[Kimchi-devel] [WIP][PATCH 3/4] Storage volume upload: add model function of upload

lvroyce0210 at gmail.com lvroyce0210 at gmail.com
Thu Aug 21 14:43:00 UTC 2014


From: Royce Lv <lvroyce at linux.vnet.ibm.com>

Add model function to upload file

Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
---
 src/kimchi/model/storagevolumes.py | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/src/kimchi/model/storagevolumes.py b/src/kimchi/model/storagevolumes.py
index a7823c2..0b9d96a 100644
--- a/src/kimchi/model/storagevolumes.py
+++ b/src/kimchi/model/storagevolumes.py
@@ -54,6 +54,29 @@ class StorageVolumesModel(object):
             if create_func and p in params:
                 return create_func(pool_name, params)
 
+    def _create_volume_with_file(self, pool_name, params):
+        pool = StoragePoolModel.get_storagepool(pool_name, self.conn)
+        dir_path = StoragePoolModel(conn=self.conn,
+                objstore=self.objstore).lookup(pool_name)['path']
+        upload_file = params['file']
+        file_name = params['resumableFilename']
+        size = 0
+        allData=''
+        while True:
+            data = upload_file.file.read(8192)
+            allData += data
+            if not data:
+                    break
+            size += len(data)
+
+        file_path = os.path.join(dir_path, file_name)
+        f = open(file_path, 'wb')
+        f.write(allData)
+        f.close()
+        # Refresh to make sure volume can be found in following lookup
+        pool.refresh()
+        return file_name
+
     def _create_volume_with_capacity(self, pool_name, params):
         vol_xml = """
         <volume>
-- 
1.8.3.2




More information about the Kimchi-devel mailing list