From 5288c9f3ef7cf2f6daac5ed3c2d2b6c5ed56e98f Mon Sep 17 00:00:00 2001 From: Philippe Caseiro Date: Wed, 20 Apr 2016 14:12:28 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20du=20script=20opennebula.js=20qui=20cor?= =?UTF-8?q?rige=20le=20probl=C3=A8me=20d'upload=20d'images?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bugfix/opennebula.js | 1824 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1824 insertions(+) create mode 100644 bugfix/opennebula.js diff --git a/bugfix/opennebula.js b/bugfix/opennebula.js new file mode 100644 index 0000000..f365299 --- /dev/null +++ b/bugfix/opennebula.js @@ -0,0 +1,1824 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs */ +/* */ +/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ +/* not use this file except in compliance with the License. You may obtain */ +/* a copy of the License at */ +/* */ +/* http://www.apache.org/licenses/LICENSE-2.0 */ +/* */ +/* Unless required by applicable law or agreed to in writing, software */ +/* distributed under the License is distributed on an "AS IS" BASIS, */ +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ +/* See the License for the specific language governing permissions and */ +/* limitations under the License. */ +/* -------------------------------------------------------------------------- */ + +if (typeof(csrftoken) != "undefined") +{ + $.ajaxPrefilter(function(options, originalOptions, jqXHR) { + var params = originalOptions.data; + + if (typeof(params)=="string") + { + params = JSON.parse(params); + params["csrftoken"] = csrftoken; + options.data = JSON.stringify(params); + } + else + { + params = params || {}; + params["csrftoken"] = csrftoken; + options.data = $.param(params); + } + }); +} + +$.ajaxSetup({ + converters: { + "text json": function( textValue ) { + return jQuery.parseJSON(jQuery('
').text(textValue).html()); + } + } +}); + +var list_cache = {}; +var list_waiting = {}; +var list_callbacks = {}; +var cache_expire = 60000; //ms + + +var OpenNebula = { + + "Error": function(resp) + { + var error = {}; + if (resp.responseText) + { + try { + error = JSON.parse(resp.responseText); + } + catch (e) { + error.error = {message: "It appears there was a server exception. Please check server's log."}; + }; + } + else + { + error.error = {}; + } + error.error.http_status = resp.status; + return error; + }, + + "is_error": function(obj) + { + return obj.error ? true : false; + }, + + "Helper": { + "resource_state": function(type, value) + { + var state; + switch(type) + { + case "HOST": + case "host": + state = tr(["INIT", + "MONITORING_MONITORED", + "MONITORED", + "ERROR", + "DISABLED", + "MONITORING_ERROR", + "MONITORING_INIT", + "MONITORING_DISABLED"][value]); + break; + case "HOST_SIMPLE": + case "host_simple": + state = tr(["INIT", + "UPDATE", + "ON", + "ERROR", + "OFF", + "RETRY", + "INIT", + "OFF"][value]); + break; + case "VM": + case "vm": + state = tr(["INIT", + "PENDING", + "HOLD", + "ACTIVE", + "STOPPED", + "SUSPENDED", + "DONE", + "FAILED", + "POWEROFF", + "UNDEPLOYED"][value]); + break; + case "VM_LCM": + case "vm_lcm": + state = tr(["LCM_INIT", + "PROLOG", + "BOOT", + "RUNNING", + "MIGRATE", + "SAVE", + "SAVE", + "SAVE", + "MIGRATE", + "PROLOG", + "EPILOG", + "EPILOG", + "SHUTDOWN", + "SHUTDOWN", + "FAILURE", + "CLEANUP", + "UNKNOWN", + "HOTPLUG", + "SHUTDOWN", + "BOOT", + "BOOT", + "BOOT", + "BOOT", + "CLEANUP", + "SNAPSHOT", + "HOTPLUG", + "HOTPLUG", + "HOTPLUG", + "HOTPLUG", + "SHUTDOWN", + "EPILOG", + "PROLOG", + "BOOT"][value]); + break; + case "IMAGE": + case "image": + state = tr(["INIT", + "READY", + "USED", + "DISABLED", + "LOCKED", + "ERROR", + "CLONE", + "DELETE", + "USED_PERS"][value]); + break; + case "VM_MIGRATE_REASON": + case "vm_migrate_reason": + state = tr(["NONE", + "ERROR", + "USER"][value]); + break; + case "VM_MIGRATE_ACTION": + case "vm_migrate_action": + state = tr(["none", + "migrate", + "live-migrate", + "shutdown", + "shutdown-hard", + "undeploy", + "undeploy-hard", + "hold", + "release", + "stop", + "suspend", + "resume", + "boot", + "delete", + "delete-recreate", + "reboot", + "reboot-hard", + "resched", + "unresched", + "poweroff", + "poweroff-hard"][value]); + break; + default: + return value; + } + if (!state) state = value + return state; + }, + + "image_type": function(value) + { + return ["OS", "CDROM", "DATABLOCK", "KERNEL", "RAMDISK", "CONTEXT"][value]; + }, + + "action": function(action, params) + { + obj = { + "action": { + "perform": action + } + } + if (params) + { + obj.action.params = params; + } + return obj; + }, + + "request": function(resource, method, data) { + var r = { + "request": { + "resource" : resource, + "method" : method + } + } + if (data) + { + if (typeof(data) != "array") + { + data = [data]; + } + r.request.data = data; + } + return r; + }, + + "pool": function(resource, response) + { + var pool_name = resource + "_POOL"; + var type = resource; + var pool; + + if (typeof(pool_name) == "undefined") + { + return Error('Incorrect Pool'); + } + + var p_pool = []; + + if (response[pool_name]) { + pool = response[pool_name][type]; + } else { + pool = null; + } + + if (pool == null) + { + return p_pool; + } + else if (pool.length) + { + for (i=0;i new Date().getTime()){ + + //console.log(cache_name+" list. Cache used"); + + return callback ? + callback(request, list_cache[cache_name]["data"]) : null; + } + + // TODO: Because callbacks are queued, we may need to force a + // timeout. Otherwise a blocked call cannot be retried. + + if (!list_callbacks[cache_name]){ + list_callbacks[cache_name] = []; + } + + list_callbacks[cache_name].push({ + success : callback, + error : callback_error + }); + + //console.log(cache_name+" list. Callback queued"); + + if (list_waiting[cache_name]){ + return; + } + + list_waiting[cache_name] = true; + + //console.log(cache_name+" list. NO cache, calling ajax"); + + $.ajax({ + url: req_path, + type: "GET", + data: {timeout: timeout}, + dataType: "json", + success: function(response){ + var list = OpenNebula.Helper.pool(resource,response) + + list_cache[cache_name] = { + timestamp : new Date().getTime(), + data : list + }; + + list_waiting[cache_name] = false; + + for (var i=0; i