[Kimchi-devel] [PATCH 1/4] Download Remote Image UI: Add Common API to kimchi.api.js

Aline Manera alinefm at linux.vnet.ibm.com
Thu Sep 11 01:12:36 UTC 2014


On 09/10/2014 09:02 AM, Hongliang Wang wrote:
> Added APIs to kimchi.api.js.
>
> Signed-off-by: Hongliang Wang <hlwang at linux.vnet.ibm.com>
> ---
>   ui/js/src/kimchi.api.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 49 insertions(+)
>
> diff --git a/ui/js/src/kimchi.api.js b/ui/js/src/kimchi.api.js
> index 5fc456d..393962b 100644
> --- a/ui/js/src/kimchi.api.js
> +++ b/ui/js/src/kimchi.api.js
> @@ -1130,5 +1130,54 @@ var kimchi = {
>                   kimchi.message.error(data.responseJSON.reason);
>               }
>           });
> +    },
> +
> +    /**
> +     * Add a volume to a given storage pool by URL.
> +     */
> +    downloadVolumeToSP: function(settings, suc, err) {

> +        var url = settings['url'];
> +        var name = settings['name'];

Why don't you pass settings direct to data? Seems a duplicated work here.

> +        var sp = encodeURIComponent(settings['sp']);
> +        kimchi.requestJSON({
> +            url : kimchi.url + 'storagepools/' + sp + '/storagevolumes',
> +            type : 'POST',
> +            data : JSON.stringify({
> +                name: name,
> +                url: url
> +            }),



> +            contentType : 'application/json',
> +            dataType : 'json',
> +            success : suc,
> +            error : err
> +        });
> +    },
> +
> +    makeTaskTrackFunc: function(task) {
> +        return function(suc, err, progress) {
> +            var onTaskResponse = function(result) {
> +                var taskStatus = result['status'];
> +                switch(taskStatus) {
> +                case 'running':
> +                    progress && progress(result);
> +                    setTimeout(trackTask, 200);
> +                    break;
> +                case 'finished':
> +                    suc(result);
> +                    break;
> +                case 'failed':
> +                    err(result);
> +                    break;
> +                default:
> +                    break;
> +                }
> +            };
> +
> +            var trackTask = function() {
> +                kimchi.getTask(task, onTaskResponse, err);
> +            };
> +
> +            trackTask();
> +        };
>       }
>   };




More information about the Kimchi-devel mailing list