From 2630d1c6a7a630b26646107f88c33e2ae1500671 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Tue, 14 Feb 2012 18:59:00 +0100 Subject: [PATCH] Improve Selfservice/OCCI upload. Wait until images have been successfully copied into the repository by opennebula to return from request. --- src/cloud/occi/lib/OCCIServer.rb | 11 ++++++++++- src/cloud/occi/lib/occi-server.rb | 6 +----- src/cloud/occi/lib/ui/public/js/plugins/storage.js | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/cloud/occi/lib/OCCIServer.rb b/src/cloud/occi/lib/OCCIServer.rb index f762fe1fbc..1a1a6357d1 100755 --- a/src/cloud/occi/lib/OCCIServer.rb +++ b/src/cloud/occi/lib/OCCIServer.rb @@ -45,6 +45,9 @@ COLLECTIONS = ["compute", "instance_type", "network", "storage"] # FLAG that will filter the elements retrieved from the Pools POOL_FILTER = Pool::INFO_ALL +# Secs to sleep between checks to see if image upload© to repo is finished +IMAGE_POLL_SLEEP_TIME = 1 + class OCCIServer < CloudServer # Server initializer # config_file:: _String_ path of the config file @@ -410,8 +413,14 @@ class OCCIServer < CloudServer return rc, CloudServer::HTTP_ERROR_CODE[rc.errno] end - # --- Prepare XML Response --- image.info + #wait until image is ready to return + while (image.state_str == 'LOCKED') && (image['RUNNING_VMS'] == '0') do + sleep IMAGE_POLL_SLEEP_TIME + image.info + end + + # --- Prepare XML Response --- return to_occi_xml(image, :status=>201) end diff --git a/src/cloud/occi/lib/occi-server.rb b/src/cloud/occi/lib/occi-server.rb index ad51901120..8bee03b296 100755 --- a/src/cloud/occi/lib/occi-server.rb +++ b/src/cloud/occi/lib/occi-server.rb @@ -366,13 +366,9 @@ get '/ui' do end post '/ui/upload' do - file = Tempfile.new('uploaded_image') - FileUtils.cp(request.env['rack.input'].path, file.path) - #so we can re-use occi post_storage() - request.params['file'] = {:tempfile => file} + request.params['file'] = {:tempfile => request.env['rack.input']} result,rc = @occi_server.post_storage(request) - treat_response(result,rc) end diff --git a/src/cloud/occi/lib/ui/public/js/plugins/storage.js b/src/cloud/occi/lib/ui/public/js/plugins/storage.js index 6e7b99d7fd..336a51d272 100644 --- a/src/cloud/occi/lib/ui/public/js/plugins/storage.js +++ b/src/cloud/occi/lib/ui/public/js/plugins/storage.js @@ -478,7 +478,7 @@ function popUpCreateImageDialog(){ multiple: false, params: {}, showMessage: function(message){ - notifyMessage(message); + //notifyMessage(message); }, onSubmit: function(id, fileName){ var xml = json2xml(img_obj,"STORAGE");