/* -------------------------------------------------------------------------- */ /* 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