Bug Reference & Branch

CLOUDSTACK-....

template-upload branch off master

Introduction

Currently CloudStack accepts only URL's to register a template/volume. If the user has a downloaded template/volume available, user has to host it either on dropbox etc. or run web server so as to get downloadable url. It is desirable to be able upload a volume or template directly through standard we browser.

This feature enables the users to directly upload the template/volume to CloudStack and eliminates the dependency on an external http server. This will be a complementary functionality and users can continue to register template/volume with URL as well.

use cases

  1. A user, who wants to upload a template and launch a vm with it on cludstack
  2. A user, who want to upload a volume and attach it to a vm on cloudstack

Design

This section will explain how the feature shall be implemented in CloudStack

process flow

The browser-based uploading process will have four main steps:

  1. Management Server generates a unique pre-shared key (PSK) and shares it with the SSVM agent. 
    1. key is saved in encrypted form in the configuration tables as hidden configuration with name upload.secret.key
    2. on start of management server, if the key doesnt exist, it generates one using sha1 and stores it in db
    3. when the management server sends StartCommand to SSVM agent, it shares this key with it. 
    4. SSVM agent stores this key in a file at /etc/cloudstack/agent/ms-psk.
  2. New API request "getUploadParams" encoded the usual CloudStack API way using api keys. Request parameters include format, hypervisor, md5 sum etc.
  3. Management Server response to (b) returns post url to upload the file, params to send to the url while uploading the file and a SHA1 signature generated using PSK and params json.  
  4. User should upload the file over https POST request to the url obtained in (c). The signature and params returned in (c) should be passed as is.
  5. The Apache web server on the SSVM matches the url, decrypts and passes on to the SSVM java agent as plain HTTP. The SSVM agent checks the signature against the params using the key PSK and SHA1. Once the params are verified, it writes to the NFS storage to the location encoded in the URL. 
  6. Once the upload completes, the MD5 checksum is compared (if available from step c). 

 

This is hypervisor agnostic and should work for all hypervisors. Multiple files for the same template/volume will not be supported for now. It will use the current resource limits for templates/volumes and would error on reaching the limits. 

 

To increase the number of parallel uploads, multiple SSVMs needs to be created. This will be handled automatically by the management server using the system.vm.auto.reserve.capacity, secstorage.capacity.standby and secstorage.session.max configuration variables.

API changes

A new API getUploadParams which takes all the params as the registertemplate/uploadvolume except for URL and  which returns all the required params plus a post URL to be used to uploadVolume/registerTemplate

POST url to post the data on to SSVM. This post url is returned from the getUploadParams api call Ex: https://ssvmpublicip/upload/key 

At any point while this post is active, the api user should be able to call the listtemplates/listvolumes api to get the upload status of it. 

Sequence Diagram

  1. failure at any point during the form upload to ssvm apache would return error to the user and DOWNLOAD_ERROR when the management server pings for download status.
  2. polling starts after the success of getUploadParams
  3. current polling interval is 10000 ms 
  4. currently it polls thrice to check the status. We may need to increase this. (is the current value 5 or 3?)

Agent Commands

  1. DownloadProgressCommand will be used the check the download progress (from Management server to Agent)
  2. DownloadCommand will be used to start the download(SSVM Apache to SSVM Agent)

State Diagram

Template/Volume go through below state machine state transitions, when it goes through the browser based upload.

States:

NOT_UPLOADED: getUploadParams API was successful and the template is registered. But, upload hasnt started yet

UPLOAD_IN_PROGRESS: User has initiated the POST request SSVM Apache and the validation/download is in progress

UPLOADED: SSVM Agent successfully Downloaded the template to secondary storage

UPLOAD_ERROR: Any Failure in between user initiating a post request and template being downloaded

ABANDONED: the post request isnt called in the stipulated time (check sequence diagram point 4)

State Transitions:

UI Changes

A new register template and upload volume UI which should be able to accept "browse and upload" file. 

UI flow:

  1. Browser UI requests the upload form by doing the getUploadParams api call. 
  2. Management Server returns a upload url, params json string which should be passed on to the upload url while doing the upload
  3. UI shows an upload dialog with a way to browse and upload file.
  4. User chooses a file and posts on the url.
  5. The post request completes once the template is downloaded/errored. 
  6. The user can close the dialog(Post request should still be active) and use list page to check the status of it.

DB Changes

No db changes.

Future

  1. Upload progress to the user (http://creativejs.com/tutorials/advanced-uploading-techniques-part-1/ )
  2. split upload and join in apache so as to not hit browser timeouts
  3. post url should be active only for one time call - return proper error message on subsequent calls - how do we determine if its already used?

  4. Admin to list all the uploads happening and cancel any if required?

  5. Partial data upload and template cleanup (can be due to SSVM to agent restart or network error)
  6. a new global param to limit the max upload size

Questions

  1. Multipart form data - Can this go in multiple connections? - NO

  2. Should there be an unencrypted HTTP version of the post?  No for now
  3. No. of parallel uploads SSVM can handle? - a default value should be provided to tune the apache to handle those many parallel connections. These should be determined based on the CPU RAM of SSVM - a proper error message to the user on reaching this limit

  4. cross zone template upload - file to be uploaded to one zone and then copied to all the other zones
  5. system vm template upload - same as the current. will be differentiated using the filename.
  6. default timeouts and configurable values - updated default values. There are no configurable values
  7. multiple management servers with the one monitoring the download crashed (How is the template status updated? A. when the download hasnt started yet. B. upload in progress C. upload done) - Template status wont be updated unless the SSVM is restarted and is connected to new management server
  8. How does the agent return template status for DownloadProgressCommand? - in memory hashmap of in progress items. during a restart or crash, its starts the wget download again.

OPEN

  1. SSVM storage issue. What should we tell the user? How can we notify the admin to recover from it?

  2. SSL CA certificates - what kind of certificates will be used?
  3. multiple SSVMs. Which agent should handle the upload?