diff --git a/src/sunstone/public/js/locale.js b/src/sunstone/public/js/locale.js deleted file mode 100644 index a347d1bebc..0000000000 --- a/src/sunstone/public/js/locale.js +++ /dev/null @@ -1,17 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2002-2015, 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. */ -/* -------------------------------------------------------------------------- */ - - diff --git a/src/sunstone/public/js/login.js b/src/sunstone/public/js/login.js deleted file mode 100644 index 277024cf92..0000000000 --- a/src/sunstone/public/js/login.js +++ /dev/null @@ -1,101 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2002-2015, 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. */ -/* -------------------------------------------------------------------------- */ - -function auth_success(req, response){ - window.location.href = "."; -} - -function auth_error(req, error){ - - var status = error.error.http_status; - - switch (status){ - case 401: - $("#error_message").text("Invalid username or password"); - break; - case 500: - $("#error_message").text("OpenNebula is not running or there was a server exception. Please check the server logs."); - break; - case 0: - $("#error_message").text("No answer from server. Is it running?"); - break; - default: - $("#error_message").text("Unexpected error. Status "+status+". Check the server logs."); - }; - $("#error_box").fadeIn("slow"); - $("#login_spinner").hide(); -} - -function authenticate(){ - var username = $("#username").val(); - var password = $("#password").val(); - var remember = $("#check_remember").is(":checked"); - - $("#error_box").fadeOut("slow"); - $("#login_spinner").show(); - - OpenNebula.Auth.login({ data: {username: username - , password: password} - , remember: remember - , success: auth_success - , error: auth_error - }); -} - -function getInternetExplorerVersion(){ -// Returns the version of Internet Explorer or a -1 -// (indicating the use of another browser). - var rv = -1; // Return value assumes failure. - if (navigator.appName == 'Microsoft Internet Explorer') - { - var ua = navigator.userAgent; - var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); - if (re.exec(ua) != null) - rv = parseFloat( RegExp.$1 ); - } - return rv; -} - -function checkVersion(){ - var ver = getInternetExplorerVersion(); - - if ( ver > -1 ){ - msg = ver <= 7.0 ? "You are using an old version of IE. \ -Please upgrade or use Firefox or Chrome for full compatibility." : - "OpenNebula Sunstone is best seen with Chrome or Firefox"; - $("#error_box").text(msg); - $("#error_box").fadeIn('slow'); - } -} - -$(document).ready(function(){ - $("#login_form").submit(function (){ - authenticate(); - return false; - }); - - //compact login elements according to screen height - if (screen.height <= 600){ - $('div#logo_sunstone').css("top","15px"); - $('div#login').css("top","10px"); - $('.error_message').css("top","10px"); - }; - - $("input#username.box").focus(); - $("#login_spinner").hide(); - - checkVersion(); -}); diff --git a/src/sunstone/public/js/opennebula.js b/src/sunstone/public/js/opennebula.js deleted file mode 100644 index 7170973d5d..0000000000 --- a/src/sunstone/public/js/opennebula.js +++ /dev/null @@ -1,2224 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2002-2015, 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 "SHORT_VM_LCM": - case "short_vm_lcm": - state = tr(["LCM_INIT", // LCM_INIT - "PROLOG", // PROLOG - "BOOT", // BOOT - "RUNNING", // RUNNING - "MIGRATE", // MIGRATE - "SAVE", // SAVE_STOP - "SAVE", // SAVE_SUSPEND - "SAVE", // SAVE_MIGRATE - "MIGRATE", // PROLOG_MIGRATE - "PROLOG", // PROLOG_RESUME - "EPILOG", // EPILOG_STOP - "EPILOG", // EPILOG - "SHUTDOWN", // SHUTDOWN - "SHUTDOWN", // CANCEL - "FAILURE", // FAILURE - "CLEANUP", // CLEANUP_RESUBMIT - "UNKNOWN", // UNKNOWN - "HOTPLUG", // HOTPLUG - "SHUTDOWN", // SHUTDOWN_POWEROFF - "BOOT", // BOOT_UNKNOWN - "BOOT", // BOOT_POWEROFF - "BOOT", // BOOT_SUSPENDED - "BOOT", // BOOT_STOPPED - "CLEANUP", // CLEANUP_DELETE - "SNAPSHOT", // HOTPLUG_SNAPSHOT - "HOTPLUG", // HOTPLUG_NIC - "HOTPLUG", // HOTPLUG_SAVEAS - "HOTPLUG", // HOTPLUG_SAVEAS_POWEROFF - "HOTPLUG", // HOTPLUG_SAVEAS_SUSPENDED - "SHUTDOWN", // SHUTDOWN_UNDEPLOY - "EPILOG", // EPILOG_UNDEPLOY - "PROLOG", // PROLOG_UNDEPLOY - "BOOT", // BOOT_UNDEPLOY - "HOTPLUG", // HOTPLUG_PROLOG_POWEROFF - "HOTPLUG", // HOTPLUG_EPILOG_POWEROFF - "BOOT", // BOOT_MIGRATE - "FAILURE", // BOOT_FAILURE - "FAILURE", // BOOT_MIGRATE_FAILURE - "FAILURE", // PROLOG_MIGRATE_FAILURE - "FAILURE", // PROLOG_FAILURE - "FAILURE", // EPILOG_FAILURE - "FAILURE", // EPILOG_STOP_FAILURE - "FAILURE", // EPILOG_UNDEPLOY_FAILURE - "MIGRATE", // PROLOG_MIGRATE_POWEROFF - "FAILURE", // PROLOG_MIGRATE_POWEROFF_FAILURE - "MIGRATE", // PROLOG_MIGRATE_SUSPEND - "FAILURE", // PROLOG_MIGRATE_SUSPEND_FAILURE - "FAILURE", // BOOT_UNDEPLOY_FAILURE - "FAILURE", // BOOT_STOPPED_FAILURE - "FAILURE", // PROLOG_RESUME_FAILURE - "FAILURE" // PROLOG_UNDEPLOY_FAILURE - ][value]); - break; - case "VM_LCM": - case "vm_lcm": - state = tr(["LCM_INIT", - "PROLOG", - "BOOT", - "RUNNING", - "MIGRATE", - "SAVE_STOP", - "SAVE_SUSPEND", - "SAVE_MIGRATE", - "PROLOG_MIGRATE", - "PROLOG_RESUME", - "EPILOG_STOP", - "EPILOG", - "SHUTDOWN", - "CANCEL", - "FAILURE", - "CLEANUP_RESUBMIT", - "UNKNOWN", - "HOTPLUG", - "SHUTDOWN_POWEROFF", - "BOOT_UNKNOWN", - "BOOT_POWEROFF", - "BOOT_SUSPENDED", - "BOOT_STOPPED", - "CLEANUP_DELETE", - "HOTPLUG_SNAPSHOT", - "HOTPLUG_NIC", - "HOTPLUG_SAVEAS", - "HOTPLUG_SAVEAS_POWEROFF", - "HOTPLUG_SAVEAS_SUSPENDED", - "SHUTDOWN_UNDEPLOY", - "EPILOG_UNDEPLOY", - "PROLOG_UNDEPLOY", - "BOOT_UNDEPLOY", - "HOTPLUG_PROLOG_POWEROFF", - "HOTPLUG_EPILOG_POWEROFF", - "BOOT_MIGRATE", - "BOOT_FAILURE", - "BOOT_MIGRATE_FAILURE", - "PROLOG_MIGRATE_FAILURE", - "PROLOG_FAILURE", - "EPILOG_FAILURE", - "EPILOG_STOP_FAILURE", - "EPILOG_UNDEPLOY_FAILURE", - "PROLOG_MIGRATE_POWEROFF", - "PROLOG_MIGRATE_POWEROFF_FAILURE", - "PROLOG_MIGRATE_SUSPEND", - "PROLOG_MIGRATE_SUSPEND_FAILURE", - "BOOT_UNDEPLOY_FAILURE", - "BOOT_STOPPED_FAILURE", - "PROLOG_RESUME_FAILURE", - "PROLOG_UNDEPLOY_FAILURE" - ][value]); - break; - case "IMAGE": - case "image": - state = tr(["INIT", - "READY", - "USED", - "DISABLED", - "LOCKED", - "ERROR", - "CLONE", - "DELETE", - "USED_PERS"][value]); - break; - case "DATASTORE": - case "datastore": - state = tr(["ON", - "OFF"][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", - "disk-attach", - "disk-detach", - "nic-attach", - "nic-detach"][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\ -
\ -

'+tr("Create ACL")+'

\ -
\ -
\ -
\ -
\ -
\ -
\ - '+tr("This rule applies to")+'\ -
\ -
\ - \ -
\ -
\ - \ -
\ -
\ - \ -
\ -
\ -
\ -
\ -
\ - \ -
\ -
\ -
\ -
\ - \ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ - \ -
\ -
\ -
\ -
\ -
\ - '+tr("Affected resources")+'\ -
\ -
\ - \ -
\ -
\ - \ -
\ -
\ - \ -
\ -
\ - \ -
\ -
\ -
\ -
\ - \ -
\ -
\ - \ -
\ -
\ - \ -
\ -
\ - \ -
\ -
\ -
\ -
\ - \ -
\ -
\ - \ -
\ -
\ - \ -
\ -
\ - \ -
\ -
\ -
\ -
\ - \ -
\ -
\ -
\ -
\ - '+tr("Resource subset")+'\ -
\ -
\ - \ -
\ -
\ - \ -
\ -
\ - \ -
\ -
\ - \ -
\ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ - \ -
\ -
\ -
\ -
\ - \ -
\ -
\ -
\ -
\ -
\ -
\ -
\ - '+tr("Allowed operations")+'\ -
\ -
\ - \ -
\ -
\ - \ -
\ -
\ - \ -
\ -
\ - \ -
\ -
\ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ -
\ - \ - \ -
\ - ×\ -
\ - '; - -var acl_actions = { - "Acl.create" : { - type: "create", - call: OpenNebula.Acl.create, - callback: function(){ - $create_acl_dialog.foundation('reveal', 'close'); - $create_acl_dialog.empty(); - setupCreateAclDialog(); - - Sunstone.runAction("Acl.list"); - }, - error: onError, - notify: true - }, - - "Acl.create_dialog" : { - type: "custom", - call: popUpCreateAclDialog - }, - - "Acl.list" : { - type: "list", - call: OpenNebula.Acl.list, - callback: updateAclsView, - error: onError - }, - - "Acl.refresh" : { - type: "custom", - call: function () { - waitingNodes(dataTable_acls); - Sunstone.runAction("Acl.list", {force: true}); - } - }, - - "Acl.delete" : { - type: "multiple", - call: OpenNebula.Acl.del, - callback: deleteAclElement, - elements: aclElements, - error: onError, - notify: true - }, - - "Acl.help" : { - type: "custom", - call: function() { - hideDialog(); - $('div#acls_tab div.legend_div').slideToggle(); - } - } -} - -var acl_buttons = { - "Acl.refresh" : { - type: "action", - layout: "refresh", - alwaysActive: true - }, -// "Sunstone.toggle_top" : { -// type: "custom", -// layout: "top", -// alwaysActive: true -// }, - "Acl.create_dialog" : { - type: "create_dialog", - layout: "create" - }, - "Acl.delete" : { - type: "confirm", - layout: "del", - text: tr("Delete") - }, - //"Acl.help" : { - // type: "action", - // text: '?', - // alwaysActive: true - //} -} - -var acls_tab = { - title: tr("ACLs"), - resource: 'Acl', - buttons: acl_buttons, - tabClass: 'subTab', - parentTab: 'system-tab', - search_input: '', - list_header: ' '+tr("Access Control Lists"), - subheader: ' ', - table: '\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
'+tr("ID")+''+tr("Applies to")+''+tr("Affected resources")+''+tr("Resource ID / Owned by")+''+tr("Allowed operations")+''+tr("Zone")+''+tr("ACL String")+'
' -} - -Sunstone.addActions(acl_actions); -Sunstone.addMainTab('acls-tab',acls_tab); - -//Returns selected elements on the acl datatable -function aclElements(){ - return getSelectedNodes(dataTable_acls); -} - -//Receives a segment of an ACL and translates: -// * -> All -// @1 -> Group 1 (tries to translate "1" into group name) -// #1 -> User 1 (tries to translate "1" into username) -//Translation of usernames and groupnames depends on -//group and user plugins tables. -function parseUserAcl(user){ - var user_str=""; - if (user[0] == '*'){ - user_str = tr("All"); - } else { - if (user[0] == '#'){ - user_str=tr("User")+" "; - user_str+= getUserName(user.substring(1)); - } - else if (user[0] == '@'){ - user_str=tr("Group "); - user_str+= getGroupName(user.substring(1)); - }; - }; - return user_str; -} - -//Similar to above, but #1 means resource with "ID 1" -function parseResourceAcl(user){ - var user_str=""; - if (user[0] == '*'){ - user_str = tr("All"); - } else { - if (user[0] == '#'){ - user_str=tr("ID")+" "; - user_str+= user.substring(1); - } - else if (user[0] == '@'){ - user_str=tr("Group")+" "; - user_str+= getGroupName(user.substring(1)); - } - else if (user[0] == '%'){ - user_str=tr("Cluster ID")+" "; - user_str+= user.substring(1); - }; - }; - return user_str; -} - -//Receives a segment of an ACL and translates: -// * -> All -// #1 -> Zone 1 (tries to translate "1" into zone name) -//Translation of zone names depends on -//zone plugins tables. -function parseZoneAcl(zone){ - var zone_str = ""; - - if (zone[0] == '*'){ - zone_str = tr("All"); - } else if (zone[0] == '#'){ - zone_str = getZoneName(zone.substring(1)); - } - - return zone_str; -} - -//Parses a full ACL string, and translates it into -//a legible array -//to be put in the datatable fields. -function parseAclString(string) { - var space_split = string.split(' '); - var user = space_split[0]; - var resources = space_split[1]; - var rights = space_split[2]; - var zone = space_split[3]; - - //User - var user_str=parseUserAcl(user); - - - //Resources - var resources_str=""; - var resources_array = resources.split('/'); - var belonging_to = parseResourceAcl(resources_array[1]); - resources_array = resources_array[0].split('+'); - for (var i=0; i', - acl.ID, - acl_array[0], - acl_array[1], - acl_array[2], - acl_array[3], - tr(acl_array[4].charAt(0).toUpperCase()+acl_array[4].substring(1)), //capitalize 1st letter for translation - acl.STRING - ] -} - - -// Callback to delete a single element from the dataTable -function deleteAclElement(request){ - deleteElement(dataTable_acls,'#acl_'+request.request.data); -} - -//update the datatable with new data -function updateAclsView(request,list){ - var list_array = []; - $.each(list,function(){ - list_array.push(aclElementArray(this)); - }); - - updateView(list_array,dataTable_acls); -} - -function setupCreateAclDialog(){ - dialogs_context.append('
'); - $create_acl_dialog = $('#create_acl_dialog',dialogs_context); - var dialog = $create_acl_dialog; - dialog.html(create_acl_tmpl); - var height = Math.floor($(window).height()*0.8); //set height to a percentage of the window - //Prepare jquery dialog - //dialog.dialog({ - // autoOpen: false, - // modal:true, - // width: 650, - // height: height - //}); - dialog.addClass("reveal-modal large").attr("data-reveal", ""); - - //Default selected options - $('#applies_all',dialog).attr('checked','checked'); - $('.applies_to_user',dialog).hide(); - $('.applies_to_group',dialog).hide(); - - $('#res_subgroup_all',dialog).attr('checked','checked'); - $('.res_id',dialog).hide(); - $('.belonging_to',dialog).hide(); - $('.in_cluster',dialog).hide(); - - //$('button',dialog).button(); - - //Applies to subset radio buttons - $('.applies',dialog).click(function(){ - var value = $(this).val(); - switch (value) { - case "*": - $('.applies_to_user',dialog).hide(); - $('.applies_to_group',dialog).hide(); - break; - case "applies_to_user": - $('.applies_to_user',dialog).show(); - $('.applies_to_group',dialog).hide(); - break; - case "applies_to_group": - $('.applies_to_user',dialog).hide(); - $('.applies_to_group',dialog).show(); - break; - }; - }); - - //Resource subset radio buttons - $('.res_subgroup',dialog).click(function(){ - var value = $(this).val(); - switch (value) { - case "*": - $('.res_id',dialog).hide(); - $('.belonging_to',dialog).hide(); - $('.in_cluster',dialog).hide(); - break; - case "res_id": - $('.res_id',dialog).show(); - $('.belonging_to').hide(); - $('.in_cluster',dialog).hide(); - break; - case "belonging_to": - $('.res_id',dialog).hide(); - $('.belonging_to',dialog).show(); - $('.in_cluster',dialog).hide(); - break; - case "in_cluster": - $('.res_id',dialog).hide(); - $('.belonging_to',dialog).hide(); - $('.in_cluster',dialog).show(); - break; - }; - }); - - //trigger ACL string preview on keyup - $('input#res_id',dialog).keyup(function(){ - $(this).trigger("change"); - }); - - //update the rule preview every time some field changes - $(dialog).off('change', 'input,select'); - $(dialog).on('change', 'input,select', function(){ - var context = $('#create_acl_form',$create_acl_dialog); - - var user=""; - var mode = $('.applies:checked',context).val(); - switch (mode) { - case "*": - user="*"; - break; - case "applies_to_user": - user="#"+$('div#applies_to_user .resource_list_select',context).val(); - break; - case "applies_to_group": - user="@"+$('div#applies_to_group .resource_list_select',context).val(); - break; - } - - var resources = ""; - $('.resource_cb:checked',context).each(function(){ - resources+=$(this).val()+'+'; - }); - if (resources.length) { resources = resources.substring(0,resources.length-1) }; - - var belonging=""; - var mode = $('.res_subgroup:checked',context).val(); - switch (mode) { - case "*": - belonging="*"; - break; - case "res_id": - belonging="#"+$('#res_id',context).val(); - break; - case "belonging_to": - belonging="@"+$('div#belonging_to .resource_list_select',context).val(); - break; - case "in_cluster": - belonging="%"+$('#in_cluster .resource_list_select',context).val(); - break; - } - - - var rights = ""; - $('.right_cb:checked',context).each(function(){ - rights+=$(this).val()+'+'; - }); - if (rights.length) { rights = rights.substring(0,rights.length-1) }; - - var zone = $('#zones_applies .resource_list_select',context).val(); - - if (zone != "*"){ - zone = '#'+zone; - } - - var acl_string = user + ' ' + resources + '/' + belonging + ' ' - + rights + ' ' + zone; - $('#acl_preview',context).val(acl_string); - - }); - - $('#create_acl_form',dialog).submit(function(){ - var mode = $('.applies:checked',this).val(); - switch (mode) { - case "applies_to_user": - var l=$('#applies_to_user .resource_list_select',this).val().length; - if (!l){ - notifyError("Please select a user to whom the acl applies"); - return false; - } - break; - case "applies_to_group": - var l=$('#applies_to_group .resource_list_select',this).val().length; - if (!l){ - notifyError("Please select a group to whom the acl applies"); - return false; - } - break; - } - - var resources = $('.resource_cb:checked',this).length; - if (!resources) { - notifyError(tr("Please select at least one resource")); - return false; - } - - var mode = $('.res_subgroup:checked',this).val(); - switch (mode) { - case "res_id": - var l=$('#res_id',this).val().length; - if (!l){ - notifyError(tr("Please provide a resource ID for the resource(s) in this rule")); - return false; - } - break; - case "belonging_to": - var l=$('#belonging_to .resource_list_select',this).val().length; - if (!l){ - notifyError("Please select a group to which the selected resources belong to"); - return false; - } - break; - case "in_cluster": - var l=$('#in_cluster .resource_list_select',this).val().length; - if (!l){ - notifyError("Please select a cluster to which the selected resources belong to"); - return false; - } - break; - } - - var rights = $('.right_cb:checked',this).length; - if (!rights) { - notifyError("Please select at least one operation"); - return false; - } - - var acl_string = $('#acl_preview',this).val(); - - var acl_json = { "acl" : acl_string }; - Sunstone.runAction("Acl.create",acl_json); - return false; - }); -} - -// Before popping up the dialog, some prepartions are -// required: we have to put the right options in the -// selects. -function popUpCreateAclDialog(){ - var dialog = $create_acl_dialog; - - insertSelectOptions('div#applies_to_user', dialog, "User", null, true); - insertSelectOptions('div#applies_to_group', dialog, "Group", null, true); - - insertSelectOptions('div#belonging_to', dialog, "Group", null, true); - insertSelectOptions('#in_cluster',dialog, "Cluster", null, true); - - // Delete cluster -1 option - $('#in_cluster select option[value="-1"]',dialog).remove(); - - insertSelectOptions('div#zones_applies', dialog, "Zone", "*", false, - ''); - - dialog.foundation().foundation('reveal', 'open'); -} - -$(document).ready(function(){ - var tab_name = 'acls-tab'; - - if (Config.isTabEnabled(tab_name)) { - //if we are not oneadmin, our tab will not even be in the DOM. - dataTable_acls = $("#datatable_acls",main_tabs_context).dataTable({ - "aoColumnDefs": [ - { "bSortable": false, "aTargets": ["check",2,3,4,5,6,7] }, - { "sWidth": "35px", "aTargets": [0] }, - { "bVisible": true, "aTargets": Config.tabTableColumns(tab_name)}, - { "bVisible": false, "aTargets": ['_all']} - ], - "bSortClasses" : false, - "bDeferRender": true - }); - - - $('#acl_search').keyup(function(){ - dataTable_acls.fnFilter( $(this).val() ); - }) - - dataTable_acls.on('draw', function(){ - recountCheckboxes(dataTable_acls); - }) - - Sunstone.runAction("Acl.list"); - - setupCreateAclDialog(); - - initCheckAllBoxes(dataTable_acls); - tableCheckboxesListener(dataTable_acls); - //shortenedInfoFields('#datatable_acls'); - - infoListener(dataTable_acls); - - $('div#acls_tab div.legend_div').hide(); - - dataTable_acls.fnSort( [ [1,config['user_config']['table_order']] ] ); - } -}) diff --git a/src/sunstone/public/js/plugins/clusters-tab.js b/src/sunstone/public/js/plugins/clusters-tab.js deleted file mode 100644 index 45a9d2ef0a..0000000000 --- a/src/sunstone/public/js/plugins/clusters-tab.js +++ /dev/null @@ -1,831 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2002-2015, 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. */ -/* -------------------------------------------------------------------------- */ - -/* ---------------- Cluster tab plugin ---------------- */ - -/* ------------ Cluster creation dialog ------------ */ - -var create_cluster_tmpl ='
\ -
\ -

'+tr("Create Cluster")+'

\ -

'+tr("Update Cluster")+'

\ -
\ -
\ -
\ -
\ -
\ -
\ - \ - \ -
\ - \ -
\ -
\ -
\ - '+generateHostTableSelect("cluster_wizard_hosts")+'\ -
\ -
\ - '+generateVNetTableSelect("cluster_wizard_vnets")+'\ -
\ -
\ - '+generateDatastoreTableSelect("cluster_wizard_datastores")+'\ -
\ -
\ -
\ -
\ -\ -×'; - -// Prepares the cluster creation dialog -function setupCreateClusterDialog(){ - - $("#create_cluster_dialog").remove(); - dialogs_context.append('
'); - - $create_cluster_dialog = $('div#create_cluster_dialog'); - var dialog = $create_cluster_dialog; - - dialog.html(create_cluster_tmpl); - var height = Math.floor($(window).height()*0.8); //set height to a percentage of the window - - dialog.addClass("reveal-modal large max-height").attr("data-reveal", ""); - - setupHostTableSelect(dialog, "cluster_wizard_hosts", {multiple_choice: true}); - setupVNetTableSelect(dialog, "cluster_wizard_vnets", {multiple_choice: true}); - setupDatastoreTableSelect(dialog, "cluster_wizard_datastores", {multiple_choice: true}); - - // Handle the Create button - $('#create_cluster_submit').click(function(){ - - if (!($('input#name',dialog).val().length)){ - notifyError(tr("Cluster name missing!")); - return false; - } - - var selected_hosts_arr = retrieveHostTableSelect(dialog, "cluster_wizard_hosts"); - var selected_hosts_list = {}; - - $.each(selected_hosts_arr, function(i,e){ - selected_hosts_list[e] = 1; - }); - - var selected_vnets_arr = retrieveVNetTableSelect(dialog, "cluster_wizard_vnets"); - var selected_vnets_list = {}; - - $.each(selected_vnets_arr, function(i,e){ - selected_vnets_list[e] = 1; - }); - - var selected_datastores_arr = retrieveDatastoreTableSelect(dialog, "cluster_wizard_datastores"); - var selected_datastores_list = {}; - - $.each(selected_datastores_arr, function(i,e){ - selected_datastores_list[e] = 1; - }); - - var cluster_json = { - "cluster": { - "name": $('#name',dialog).val(), - "hosts": selected_hosts_list, - "vnets": selected_vnets_list, - "datastores": selected_datastores_list - } - }; - - // Create the OpenNebula.Cluster. - Sunstone.runAction("Cluster.create",cluster_json); - return false; - }); -} - -// Open creation dialogs -function popUpCreateClusterDialog(){ - if (!$create_cluster_dialog || $create_cluster_dialog.html() == "") { - setupCreateClusterDialog(); - } - - $create_cluster_dialog.die(); - - // Activate create button - $('#create_cluster_submit',$create_cluster_dialog).show(); - $('#update_cluster_submit',$create_cluster_dialog).hide(); - $('#create_cluster_header',$create_cluster_dialog).show(); - $('#update_cluster_header',$create_cluster_dialog).hide(); - - refreshHostTableSelect($create_cluster_dialog, "cluster_wizard_hosts"); - refreshVNetTableSelect($create_cluster_dialog, "cluster_wizard_vnets"); - refreshDatastoreTableSelect($create_cluster_dialog, "cluster_wizard_datastores"); - - $create_cluster_dialog.foundation().foundation('reveal', 'open'); - - $("input#name",$create_cluster_dialog).focus(); - - return false; -} - -// Open update dialog -function popUpUpdateClusterDialog(){ - - var selected_nodes = getSelectedNodes(dataTable_clusters); - - if ( selected_nodes.length != 1 ) - { - notifyError(tr("Please select one (and just one) cluster to update.")); - return false; - } - - var dialog = $create_cluster_dialog; - - if ($("#create_cluster_dialog")) { - dialog.html(""); - } - - setupCreateClusterDialog(); - - // Activate update button - $('#create_cluster_submit',$create_cluster_dialog).hide(); - $('#update_cluster_submit',$create_cluster_dialog).show(); - $('#create_cluster_header',$create_cluster_dialog).hide(); - $('#update_cluster_header',$create_cluster_dialog).show(); - - Sunstone.runAction("Cluster.show_to_update", selected_nodes[0]); - - $create_cluster_dialog.die(); - $create_cluster_dialog.live('closed', function () { - $("#create_cluster_dialog").html(""); - setupCreateClusterDialog(); - }); - - $create_cluster_dialog.foundation().foundation('reveal', 'open'); - - return false; -} - -// Fill update dialog with loaded properties -function fillPopPup(request,response){ - var dialog = $create_cluster_dialog; - - // Harvest variables - var name = response.CLUSTER.NAME; - var host_ids = response.CLUSTER.HOSTS.ID; - var vnet_ids = response.CLUSTER.VNETS.ID; - var ds_ids = response.CLUSTER.DATASTORES.ID; - - if (typeof host_ids == 'string') - { - host_ids = [host_ids]; - } - - if (typeof vnet_ids == 'string') - { - vnet_ids = [vnet_ids]; - } - - if (typeof ds_ids == 'string') - { - ds_ids = [ds_ids]; - } - - // Fill in the name - $('#name',dialog).val(name); - $('#name',dialog).attr("disabled", "disabled"); - - var original_hosts_list = []; - - // Select hosts belonging to the cluster - if (host_ids) - { - original_hosts_list = host_ids; - var opts = { - ids : host_ids - } - - selectHostTableSelect(dialog, "cluster_wizard_hosts", opts); - } - - var original_vnets_list = []; - - // Select vnets belonging to the cluster - if (vnet_ids) - { - original_vnets_list = vnet_ids; - var opts = { - ids : vnet_ids - } - - selectVNetTableSelect(dialog, "cluster_wizard_vnets", opts); - } - - var original_datastores_list = []; - - // Select datastores belonging to the cluster - if (ds_ids) - { - original_datastores_list = ds_ids; - var opts = { - ids : ds_ids - } - - selectDatastoreTableSelect(dialog, "cluster_wizard_datastores", opts); - } - - // Clone already existing resources (to keep track) - cluster_to_update_id = response.CLUSTER.ID; - - refreshHostTableSelect(dialog, "cluster_wizard_hosts"); - refreshVNetTableSelect(dialog, "cluster_wizard_vnets"); - refreshDatastoreTableSelect(dialog, "cluster_wizard_datastores"); - - // Define update button - $('#update_cluster_submit').click(function(){ - - // find out which ones are in and out - var selected_hosts_list = retrieveHostTableSelect(dialog, "cluster_wizard_hosts"); - - $.each(selected_hosts_list, function(i,host_id){ - if (original_hosts_list.indexOf(host_id) == -1) - { - Sunstone.runAction("Cluster.addhost",cluster_to_update_id,host_id); - } - }); - - $.each(original_hosts_list, function(i,host_id){ - if (selected_hosts_list.indexOf(host_id) == -1) - { - Sunstone.runAction("Cluster.delhost",cluster_to_update_id,host_id); - } - }); - - var selected_vnets_list = retrieveVNetTableSelect(dialog, "cluster_wizard_vnets"); - - $.each(selected_vnets_list, function(i,vnet_id){ - if (original_vnets_list.indexOf(vnet_id) == -1) - { - Sunstone.runAction("Cluster.addvnet",cluster_to_update_id,vnet_id); - } - }); - - $.each(original_vnets_list, function(i,vnet_id){ - if (selected_vnets_list.indexOf(vnet_id) == -1) - { - Sunstone.runAction("Cluster.delvnet",cluster_to_update_id,vnet_id); - } - }); - - var selected_datastores_list = retrieveDatastoreTableSelect(dialog, "cluster_wizard_datastores"); - - $.each(selected_datastores_list, function(i,datastore_id){ - if (original_datastores_list.indexOf(datastore_id) == -1) - { - Sunstone.runAction("Cluster.adddatastore",cluster_to_update_id,datastore_id); - } - }); - - $.each(original_datastores_list, function(i,datastore_id){ - if (selected_datastores_list.indexOf(datastore_id) == -1) - { - Sunstone.runAction("Cluster.deldatastore",cluster_to_update_id,datastore_id); - } - }); - - $create_cluster_dialog.foundation('reveal', 'close') - - Sunstone.runAction('Cluster.list'); - - return false; - }); -} - -var dataTable_clusters; -var $create_cluster_dialog; - - -//Setup actions -var cluster_actions = { - - "Cluster.create" : { - type: "create", - call: OpenNebula.Cluster.create, - callback: function(request, response){ - // Reset the create wizard - $create_cluster_dialog.foundation('reveal', 'close'); - $create_cluster_dialog.empty(); - setupCreateClusterDialog(); - - addClusterElement(request, response); -// Sunstone.runAction('Cluster.list'); - - for (var host in request.request.data[0].cluster.hosts) - if (request.request.data[0].cluster.hosts[host]) - Sunstone.runAction("Cluster.addhost",response.CLUSTER.ID,host); - for (var vnet in request.request.data[0].cluster.vnets) - if (request.request.data[0].cluster.vnets[vnet]) - Sunstone.runAction("Cluster.addvnet",response.CLUSTER.ID,vnet); - for (var datastore in request.request.data[0].cluster.datastores) - if (request.request.data[0].cluster.datastores[datastore]) - Sunstone.runAction("Cluster.adddatastore",response.CLUSTER.ID,datastore); - - //Sunstone.runAction('Cluster.list'); - // Sunstone.runAction('Cluster.show',response.CLUSTER.ID); - notifyCustom(tr("Cluster created"), " ID: " + response.CLUSTER.ID, false); - }, - error: onError - }, - - "Cluster.create_dialog" : { - type: "custom", - call: popUpCreateClusterDialog - }, - - "Cluster.list" : { - type: "list", - call: OpenNebula.Cluster.list, - callback: updateClustersView, - error: onError - }, - - "Cluster.show" : { - type: "single", - call: OpenNebula.Cluster.show, - callback: function(request, response) { - updateClusterElement(request, response); - if (Sunstone.rightInfoVisible($("#clusters-tab"))) { - updateClusterInfo(request, response); - } - }, - error: onError - }, - - "Cluster.show_to_update" : { - type: "single", - call: OpenNebula.Cluster.show, - callback: fillPopPup, - error: onError - }, - - "Cluster.refresh" : { - type: "custom", - call: function(){ - var tab = dataTable_clusters.parents(".tab"); - if (Sunstone.rightInfoVisible(tab)) { - Sunstone.runAction("Cluster.show", Sunstone.rightInfoResourceId(tab)) - } else { - waitingNodes(dataTable_clusters); - Sunstone.runAction("Cluster.list", {force: true}); - } - }, - error: onError - }, - - "Cluster.addhost" : { - type: "single", - call : OpenNebula.Cluster.addhost, - callback : function (req) { - OpenNebula.Helper.clear_cache("HOST"); - Sunstone.runAction('Cluster.show',req.request.data[0][0]); - }, - error : onError - }, - - "Cluster.delhost" : { - type: "single", - call : OpenNebula.Cluster.delhost, - callback : function (req) { - OpenNebula.Helper.clear_cache("HOST"); - Sunstone.runAction('Cluster.show',req.request.data[0][0]); - }, - error : onError - }, - - "Cluster.adddatastore" : { - type: "single", - call : OpenNebula.Cluster.adddatastore, - callback : function (req) { - OpenNebula.Helper.clear_cache("DATASTORE"); - Sunstone.runAction('Cluster.show',req.request.data[0][0]); - }, - error : onError - }, - - "Cluster.deldatastore" : { - type: "single", - call : OpenNebula.Cluster.deldatastore, - callback : function (req) { - OpenNebula.Helper.clear_cache("DATASTORE"); - Sunstone.runAction('Cluster.show',req.request.data[0][0]); - }, - error : onError - }, - - "Cluster.addvnet" : { - type: "single", - call : OpenNebula.Cluster.addvnet, - callback : function (req) { - OpenNebula.Helper.clear_cache("VNET"); - Sunstone.runAction('Cluster.show',req.request.data[0][0]); - }, - error : onError - }, - - "Cluster.delvnet" : { - type: "single", - call : OpenNebula.Cluster.delvnet, - callback : function (req) { - OpenNebula.Helper.clear_cache("VNET"); - Sunstone.runAction('Cluster.show',req.request.data[0][0]); - }, - error : onError - }, - - "Cluster.delete" : { - type: "multiple", - call : OpenNebula.Cluster.del, - callback : deleteClusterElement, - elements: clusterElements, - error : onError - }, - - "Cluster.update_template" : { // Update template - type: "single", - call: OpenNebula.Cluster.update, - callback: function(request,response){ - Sunstone.runAction('Cluster.show',request.request.data[0][0]); - }, - error: onError - }, - - "Cluster.fetch_template" : { - type: "single", - call: OpenNebula.Cluster.fetch_template, - callback: function(request,response){ - $('#template_update_dialog #template_update_textarea').val(response.template); - }, - error: onError - }, - - "Cluster.update_dialog" : { - type: "single", - call: popUpUpdateClusterDialog - }, - - "Cluster.rename" : { - type: "single", - call: OpenNebula.Cluster.rename, - callback: function(request) { - Sunstone.runAction('Cluster.show',request.request.data[0]); - }, - error: onError - } -}; - -var cluster_buttons = { - "Cluster.refresh" : { - type: "action", - layout: "refresh", - alwaysActive: true - }, -// "Sunstone.toggle_top" : { -// type: "custom", -// layout: "top", -// alwaysActive: true -// }, - "Cluster.create_dialog" : { - type: "create_dialog", - layout: "create" - }, - "Cluster.update_dialog" : { - type : "action", - layout: "main", - text : tr("Update") - }, - "Cluster.delete" : { - type: "confirm", - layout: "del", - text: tr("Delete") - } -}; - -var clusters_tab = { - title: tr("Clusters"), - resource: 'Cluster', - buttons: cluster_buttons, - showOnTopMenu: false, - tabClass: "subTab", - parentTab: "infra-tab", - search_input: '', - list_header: ' '+tr("Clusters"), - info_header: ' '+tr("Cluster"), - subheader: '  ', - table: '\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
' + tr("ID") + '' + tr("Name") + '' + tr("Hosts") + '' + tr("VNets") + '' + tr("Datastores") + '
' -}; - -var cluster_info_panel = { - "cluster_info_tab" : { - title: tr("Cluster information"), - content:"" - }, - - "cluster_host_tab" : { - title: tr("Cluster Hosts"), - content: "" - }, - "cluster_vnet_tab" : { - title: tr("Cluster Virtual Networks"), - content: "" - }, - "cluster_datastore_tab" : { - title: tr("Cluster Datastores"), - content: "" - } - -}; - -Sunstone.addActions(cluster_actions); -Sunstone.addMainTab('clusters-tab',clusters_tab); -Sunstone.addInfoPanel("cluster_info_panel",cluster_info_panel); - -//return lists of selected elements in cluster list -function clusterElements(){ - return getSelectedNodes(dataTable_clusters); -} - -function clusterElementArray(element_json){ - - var element = element_json.CLUSTER; - - var hosts = 0; - if ($.isArray(element.HOSTS.ID)) - hosts = element.HOSTS.ID.length; - else if (!$.isEmptyObject(element.HOSTS.ID)) - hosts = 1; - - var vnets = 0; - if ($.isArray(element.VNETS.ID)) - vnets = element.VNETS.ID.length; - else if (!$.isEmptyObject(element.VNETS.ID)) - vnets = 1; - - var dss = 0; - if ($.isArray(element.DATASTORES.ID)) - dss = element.DATASTORES.ID.length; - else if (!$.isEmptyObject(element.DATASTORES.ID)) - dss = 1; - - - return [ - '', - element.ID, - element.NAME, - hosts, - vnets, - dss - ]; -} - -//callback for an action affecting a cluster element -function updateClusterElement(request, element_json){ - var id = element_json.CLUSTER.ID; - var element = clusterElementArray(element_json); - updateSingleElement(element,dataTable_clusters,'#cluster_'+id); -} - -//callback for actions deleting a cluster element -function deleteClusterElement(req){ - deleteElement(dataTable_clusters,'#cluster_'+req.request.data); - $('div#cluster_tab_'+req.request.data,main_tabs_context).remove(); -} - -//call back for actions creating a cluster element -function addClusterElement(request,element_json){ - var id = element_json.CLUSTER.ID; - var element = clusterElementArray(element_json); - addElement(element,dataTable_clusters); -} - -//callback to update the list of clusters. -function updateClustersView (request,list){ - var list_array = []; - - $.each(list,function(){ - //Grab table data from the list - list_array.push(clusterElementArray(this)); - }); - - updateView(list_array,dataTable_clusters); -}; - - -// Updates the cluster info panel tab content and pops it up -function updateClusterInfo(request,cluster){ - cluster_info = cluster.CLUSTER; - cluster_template = cluster_info.TEMPLATE; - - $(".resource-info-header", $("#clusters-tab")).html(cluster_info.NAME); - - //Information tab - var info_tab = { - title : tr("Info"), - icon: "fa-info-circle", - content : - '
\ -
\ - \ - \ - \ - \ - \ - \ - \ - \ - '+ - insert_rename_tr( - 'clusters-tab', - "Cluster", - cluster_info.ID, - cluster_info.NAME)+ - '\ -
' +tr("Information") +'
' + tr("id") + ''+cluster_info.ID+'
\ -
\ -
' + - '
\ -
\ -
\ -
'+ - insert_extended_template_table(cluster_template, - "Cluster", - cluster_info.ID, - tr("Attributes")) + - '
\ -
' - } - - var cluster_host_tab = { - title: tr("Hosts"), - icon: "fa-hdd-o", - content : '
\ -
\ - '+generateHostTableSelect("cluster_info_hosts")+'\ -
\ -
' - } - - var cluster_vnet_tab = { - title: tr("VNets"), - icon: "fa-globe", - content : '
\ -
\ - '+generateVNetTableSelect("cluster_info_vnets")+'\ -
\ -
' - } - - var cluster_datastore_tab = { - title: tr("Datastores"), - icon: "fa-folder-open", - content : '
\ -
\ - '+generateDatastoreTableSelect("cluster_info_datastores")+'\ -
\ -
' - } - - //Sunstone.updateInfoPanelTab(info_panel_name,tab_name, new tab object); - Sunstone.updateInfoPanelTab("cluster_info_panel","cluster_info_tab",info_tab); - Sunstone.updateInfoPanelTab("cluster_info_panel","cluster_host_tab",cluster_host_tab); - Sunstone.updateInfoPanelTab("cluster_info_panel","cluster_vnet_tab",cluster_vnet_tab); - Sunstone.updateInfoPanelTab("cluster_info_panel","cluster_datastore_tab",cluster_datastore_tab); - - Sunstone.popUpInfoPanel("cluster_info_panel", "clusters-tab"); - - // Hosts datatable - - var host_ids = cluster_info.HOSTS.ID; - - if (typeof host_ids == 'string'){ - host_ids = [host_ids]; - } else if (host_ids == undefined){ - host_ids = []; - } - - var opts = { - read_only: true, - fixed_ids: host_ids - } - - setupHostTableSelect($("#cluster_info_panel"), "cluster_info_hosts", opts); - - refreshHostTableSelect($("#cluster_info_panel"), "cluster_info_hosts"); - - // Virtual networks datatable - - var vnet_ids = cluster_info.VNETS.ID; - - if (typeof vnet_ids == 'string'){ - vnet_ids = [vnet_ids]; - } else if (vnet_ids == undefined){ - vnet_ids = []; - } - - var opts = { - read_only: true, - fixed_ids: vnet_ids - } - - setupVNetTableSelect($("#cluster_info_panel"), "cluster_info_vnets", opts); - - refreshVNetTableSelect($("#cluster_info_panel"), "cluster_info_vnets"); - - // Datastores datatable - - var datastore_ids = cluster_info.DATASTORES.ID; - - if (typeof datastore_ids == 'string'){ - datastore_ids = [datastore_ids]; - } else if (datastore_ids == undefined){ - datastore_ids = []; - } - - var opts = { - read_only: true, - fixed_ids: datastore_ids - } - - setupDatastoreTableSelect($("#cluster_info_panel"), "cluster_info_datastores", opts); - - refreshDatastoreTableSelect($("#cluster_info_panel"), "cluster_info_datastores"); -} - -//This is executed after the sunstone.js ready() is run. -//Here we can basicly init the host datatable, preload it -//and add specific listeners -$(document).ready(function(){ - var tab_name = "clusters-tab" - - if (Config.isTabEnabled(tab_name)) { - //prepare clusters datatable - dataTable_clusters = $("#datatable_clusters",main_tabs_context).dataTable({ - "aoColumnDefs": [ - { "bSortable": false, "aTargets": ["check"] }, - { "sWidth": "35px", "aTargets": [0] }, - { "bVisible": true, "aTargets": Config.tabTableColumns(tab_name)}, - { "bVisible": false, "aTargets": ['_all']} - ], - "bSortClasses" : false, - "bDeferRender": true - }); - - $('#cluster_search').keyup(function(){ - dataTable_clusters.fnFilter( $(this).val() ); - }) - - dataTable_clusters.on('draw', function(){ - recountCheckboxes(dataTable_clusters); - }) - - Sunstone.runAction("Cluster.list"); - - setupCreateClusterDialog(); - - initCheckAllBoxes(dataTable_clusters); - tableCheckboxesListener(dataTable_clusters); - infoListener(dataTable_clusters, "Cluster.show"); - dataTable_clusters.fnSort( [ [1,config['user_config']['table_order']] ] ); - } -}); diff --git a/src/sunstone/public/js/plugins/config-tab.js b/src/sunstone/public/js/plugins/config-tab.js deleted file mode 100644 index 3bbe6c3586..0000000000 --- a/src/sunstone/public/js/plugins/config-tab.js +++ /dev/null @@ -1,607 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2002-2015, 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. */ -/* -------------------------------------------------------------------------- */ - -var user_cookie = cookie["one-user"]; - -setInterval(function(){ - if (whichUI() == "sunstone") { - var user_cookie = cookie["one-user"]; - readCookie(); - if ((cookie["one-user"] == null) || (cookie["one-user"] !== user_cookie)) { - window.location.href='/'; - } - } -},5000); - -Config = { - "isTabEnabled": function(tab_name){ - var enabled = config['view']['enabled_tabs'][tab_name]; - return enabled; - }, - - "isTabActionEnabled": function(tab_name, action_name, panel_name){ - var enabled = false; - var config_tab = config['view']['tabs'][tab_name]; - - if (config_tab != undefined){ - if (panel_name) { - enabled = config_tab['panel_tabs_actions'][panel_name][action_name]; - } else { - enabled = config_tab['actions'][action_name]; - } - } - - return enabled; - }, - - "isTabPanelEnabled": function(tab_name, panel_tab_name){ - if (config['view']['tabs'][tab_name]) { - var enabled = config['view']['tabs'][tab_name]['panel_tabs'][panel_tab_name]; - return enabled; - } else { - return false; - } - }, - - "isFeatureEnabled": function(feature_name){ - if (config['view']['features'] && config['view']['features'][feature_name]) { - return true; - } else { - return false; - } - }, - - "tabTableColumns": function(tab_name){ - var columns = config['view']['tabs'][tab_name]['table_columns']; - - if (columns) { - return columns; - } - else { - return []; - } - }, - - "isTemplateCreationTabEnabled": function(template_tab_name){ - if (config['view']['tabs']['templates-tab']){ - var enabled = config['view']['tabs']['templates-tab']['template_creation_tabs'][template_tab_name]; - return enabled; - } else { - return false; - } - }, - - "dashboardWidgets": function(per_row){ - var widgets = config['view']['tabs']['dashboard-tab'][per_row]; - - if (widgets) { - return widgets; - } - else { - return []; - } - }, - - "tableOrder": function(){ - return config['user_config']["table_order"]; - }, - - "provision": { - "dashboard": { - "isEnabled": function(widget) { - if (config['view']['tabs']['provision-tab']){ - var enabled = config['view']['tabs']['provision-tab']['dashboard'][widget]; - return enabled; - } else { - return false; - } - } - }, - "create_vm": { - "isEnabled": function(widget) { - if (config['view']['tabs']['provision-tab'] && config['view']['tabs']['provision-tab']["create_vm"]){ - return config['view']['tabs']['provision-tab']['create_vm'][widget]; - } else { - return false; - } - } - }, - "logo": (config['view']["provision_logo"] || "images/one_small_logo.png") - } -} - -var config_response = {}; -var config_tab_content = -'
\ -
\ -

'+tr("Configuration")+'

\ -
\ -
\ -
\ -

'+tr("Info")+'
\ -

'+tr("Conf")+'
\ -

'+tr("Quotas")+'
\ -

'+tr("Accounting")+'
'+ - ( Config.isFeatureEnabled("showback") ? - '

'+tr("Showback")+'
' : '')+ - '
\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ - \ - \ - \ - \ - \ - \ -
' + tr("User information") +'
\ -
\ -
' + - '\ - \ - \ - \ - \ - \ - \ -
' + tr("Public SSH Key") + '\ - \ -
\ - \ -
\ -
\ - \ -
\ -
\ -
\ - ×\ -
'; - -var datastore_image_table_tmpl='\ - \ - '+tr("All")+'\ - '+tr("ID")+'\ - '+tr("Owner")+'\ - '+tr("Group")+'\ - '+tr("Name")+'\ - '+tr("Datastore")+'\ - '+tr("Size")+'\ - '+tr("Type")+'\ - '+tr("Registration time")+'\ - '+tr("Persistent")+'\ - '+tr("Status")+'\ - '+tr("#VMS")+'\ - '+tr("Target")+'\ - \ - \ - \ - ' - -var dataTable_datastores; -var $create_datastore_dialog; - - -/* -------- Image datatable -------- */ - -//Setup actions -var datastore_image_actions = { - - "DatastoreImageInfo.list" : { - type: "list", - call: OpenNebula.Image.list, - callback: updateDatastoreImagesInfoView, - error: onError - } -} - -//callback to update the list of images for Create dialog -function updateDatastoreImagesInfoView (request,image_list){ - var image_list_array = []; - - $.each(image_list,function(){ - if (this.IMAGE.DATASTORE==datastore_name) - { - if(datastore_type=="IMAGE_DS"||datastore_type=="SYSTEM_DS") - image_list_array.push(imageElementArray(this)); - else - image_list_array.push(fileElementArray(this)); - } - }); - - updateView(image_list_array,dataTable_datastore_images_panel); -} - -//Setup actions -var datastore_actions = { - - "Datastore.create" : { - type: "create", - call : OpenNebula.Datastore.create, - callback : function(request, response) { - // Reset the create wizard - $create_datastore_dialog.foundation('reveal', 'close'); - $create_datastore_dialog.empty(); - setupCreateDatastoreDialog(); - - addDatastoreElement(request, response); - notifyCustom(tr("Datastore created"), " ID: " + response.DATASTORE.ID, false); - }, - error : onError - }, - - "Datastore.create_dialog" : { - type: "custom", - call: popUpCreateDatastoreDialog - }, - - "Datastore.list" : { - type: "list", - call: OpenNebula.Datastore.list, - callback: updateDatastoresView, - error: onError - }, - - "Datastore.show" : { - type: "single", - call: OpenNebula.Datastore.show, - callback: function(request, response) { - updateDatastoreElement(request, response); - if (Sunstone.rightInfoVisible($("#datastores-tab"))) { - updateDatastoreInfo(request, response); - } - }, - error: onError - }, - - "Datastore.refresh" : { - type: "custom", - call: function(){ - var tab = dataTable_datastores.parents(".tab"); - if (Sunstone.rightInfoVisible(tab)) { - Sunstone.runAction("Datastore.show", Sunstone.rightInfoResourceId(tab)) - } else { - waitingNodes(dataTable_datastores); - Sunstone.runAction("Datastore.list", {force: true}); - } - }, - error: onError - }, - - - "Datastore.fetch_permissions" : { - type: "single", - call: OpenNebula.Datastore.show, - callback: function(request,element_json){ - var ds = element_json.DATASTORE; - setPermissionsTable(ds,$(".datastore_permissions_table")); - }, - error: onError - }, - - "Datastore.update_template" : { - type: "single", - call: OpenNebula.Datastore.update, - callback: function(request) { - Sunstone.runAction('Datastore.show',request.request.data[0][0]); - }, - error: onError - }, - - "Datastore.update" : { - type: "single", - call: OpenNebula.Datastore.update, - callback: function() { - Sunstone.runAction('Datastore.show',request.request.data[0][0]); - }, - error: onError - }, - - "Datastore.delete" : { - type: "multiple", - call : OpenNebula.Datastore.del, - callback : deleteDatastoreElement, - elements: datastoreElements, - error : onError, - notify:true - }, - - "Datastore.chown" : { - type: "multiple", - call: OpenNebula.Datastore.chown, - callback: function (req) { - Sunstone.runAction("Datastore.show",req.request.data[0][0]); - }, - elements: datastoreElements, - error: onError - }, - - "Datastore.chgrp" : { - type: "multiple", - call: OpenNebula.Datastore.chgrp, - callback: function (req) { - Sunstone.runAction("Datastore.show",req.request.data[0][0]); - }, - elements: datastoreElements, - error: onError - }, - - "Datastore.chmod" : { - type: "single", - call: OpenNebula.Datastore.chmod, - callback: function (req) { - Sunstone.runAction("Datastore.show",req.request.data[0]); - }, - error: onError - }, - - "Datastore.addtocluster" : { - type: "multiple", - call: function(params, success){ - var cluster = params.data.extra_param; - var ds = params.data.id; - - if (cluster == -1){ - OpenNebula.Datastore.show({ - data : { - id: ds - }, - success: function (request, ds_info){ - var current_cluster = ds_info.DATASTORE.CLUSTER_ID; - - if(current_cluster != -1){ - OpenNebula.Cluster.deldatastore({ - data: { - id: current_cluster, - extra_param: ds - }, - success: function(){ - OpenNebula.Helper.clear_cache("DATASTORE"); - Sunstone.runAction('Datastore.show',ds); - }, - error: onError - }); - } else { - OpenNebula.Helper.clear_cache("DATASTORE"); - Sunstone.runAction('Datastore.show',ds); - } - }, - error: onError - }); - } else { - OpenNebula.Cluster.adddatastore({ - data: { - id: cluster, - extra_param: ds - }, - success: function(){ - OpenNebula.Helper.clear_cache("DATASTORE"); - Sunstone.runAction('Datastore.show',ds); - }, - error: onError - }); - } - }, - elements: datastoreElements - }, - - "Datastore.rename" : { - type: "single", - call: OpenNebula.Datastore.rename, - callback: function(request) { - Sunstone.runAction('Datastore.show',request.request.data[0][0]); - }, - error: onError, - notify: true - }, - - "Datastore.enable" : { - type: "multiple", - call: OpenNebula.Datastore.enable, - callback: function (req) { - Sunstone.runAction("Datastore.show",req.request.data[0]); - }, - elements: datastoreElements, - error: onError, - notify: true - }, - - "Datastore.disable" : { - type: "multiple", - call: OpenNebula.Datastore.disable, - callback: function (req) { - Sunstone.runAction("Datastore.show",req.request.data[0]); - }, - elements: datastoreElements, - error: onError, - notify: true - } -}; - -var datastore_buttons = { - "Datastore.refresh" : { - type: "action", - layout: "refresh", - alwaysActive: true - }, -// "Sunstone.toggle_top" : { -// type: "custom", -// layout: "top", -// alwaysActive: true -// }, - "Datastore.create_dialog" : { - type: "create_dialog", - layout: "create", - condition: mustBeAdmin - }, - "Datastore.addtocluster" : { - type: "confirm_with_select", - text: tr("Select cluster"), - select: "Cluster", - layout: "main", - tip: tr("Select the destination cluster:"), - condition: mustBeAdmin - }, - "Datastore.chown" : { - type: "confirm_with_select", - text: tr("Change owner"), - select: "User", - layout: "user_select", - tip: tr("Select the new owner")+":", - condition: mustBeAdmin - }, - "Datastore.chgrp" : { - type: "confirm_with_select", - text: tr("Change group"), - select: "Group", - layout: "user_select", - tip: tr("Select the new group")+":", - condition: mustBeAdmin - }, - "Datastore.delete" : { - type: "confirm", - text: tr("Delete"), - layout: "del", - condition: mustBeAdmin - }, - "Datastore.enable" : { - type: "action", - layout: "more_select", - text: tr("Enable") - }, - "Datastore.disable" : { - type: "action", - layout: "more_select", - text: tr("Disable") - } -} - -var datastore_info_panel = { - "datastore_info_tab" : { - title: tr("Information"), - content: "" - } -} - -var datastores_tab = { - title: tr("Datastores"), - resource: 'Datastore', - buttons: datastore_buttons, - tabClass: "subTab", - parentTab: "infra-tab", - search_input: '', - list_header: ' '+tr("Datastores"), - info_header: ' '+tr("Datastore"), - subheader: '  ', - table: '\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
'+tr("ID")+''+tr("Owner")+''+tr("Group")+''+tr("Name")+''+tr("Capacity")+''+tr("Cluster")+''+tr("Basepath")+''+tr("TM MAD")+''+tr("DS MAD")+''+tr("Type")+''+tr("Status")+'
' -} - -Sunstone.addActions(datastore_actions); -Sunstone.addActions(datastore_image_actions); -Sunstone.addMainTab('datastores-tab',datastores_tab); -Sunstone.addInfoPanel('datastore_info_panel',datastore_info_panel); - - -function generate_datastore_capacity_bar(ds, ds_type) { - var total = parseInt(ds.TOTAL_MB); - - var used = total - parseInt(ds.FREE_MB); - - if (total > 0) { - var ratio = Math.round((used / total) * 100); - info_str = humanize_size_from_mb(used) + ' / ' + humanize_size_from_mb(total) + ' (' + ratio + '%)'; - } else { - if(ds_type == 1) { - info_str = '- / -'; - } else { - info_str = humanize_size(used) + ' / -'; - } - } - - return quotaBarHtml(used, total, info_str); -} - -function datastoreElements() { - return getSelectedNodes(dataTable_datastores); -} - -function datastoreElementArray(element_json){ - var element = element_json.DATASTORE; - - var ds_type_str = "IMAGE_DS"; - - if (typeof element.TEMPLATE.TYPE != "undefined") - { - ds_type_str = element.TEMPLATE.TYPE; - } - - var pb_capacity = generate_datastore_capacity_bar(element, element.TYPE); - - return [ - '', - element.ID, - element.UNAME, - element.GNAME, - element.NAME, - pb_capacity, - element.CLUSTER.length ? element.CLUSTER : "-", - element.BASE_PATH, - element.TM_MAD, - element.DS_MAD, - ds_type_str.toLowerCase().split('_')[0], - OpenNebula.Helper.resource_state("datastore",element.STATE) - ]; -} - -function updateDatastoreElement(request, element_json){ - var id = element_json.DATASTORE.ID; - var element = datastoreElementArray(element_json); - updateSingleElement(element,dataTable_datastores,'#datastore_'+id) -} - -function deleteDatastoreElement(request){ - deleteElement(dataTable_datastores,'#datastore_'+request.request.data); -} - -function addDatastoreElement(request,element_json){ - var id = element_json.DATASTORE.ID; - var element = datastoreElementArray(element_json); - addElement(element,dataTable_datastores); -} - - -function updateDatastoresView(request, list){ - var list_array = []; - - $.each(list,function(){ - list_array.push( datastoreElementArray(this)); - }); - - updateView(list_array,dataTable_datastores); -} - - -function updateDatastoreInfo(request,ds){ - var info = ds.DATASTORE; - - datastore_name = info.NAME; - datastore_type = info.TYPE; - - $(".resource-info-header", $("#datastores-tab")).html(info.NAME); - - switch(info.TYPE) - { - case '0': - datastore_type = "SYSTEM_DS"; - break; - case '1': - datastore_type = "IMAGE_DS"; - break; - case '2': - datastore_type = "FILE_DS"; - break; - } - - var images_str = ""; - if (info.IMAGES.ID && - info.IMAGES.ID.constructor == Array){ - for (var i=0; i\ - \ - \ - \ - '+tr("ID")+'\ - '+info.ID+'\ - \ - '+ - insert_rename_tr( - 'datastores-tab', - "Datastore", - info.ID, - info.NAME)+ - ''+ - cluster_str + - '\ - \ - '+tr("State")+'\ - '+OpenNebula.Helper.resource_state("datastore",info.STATE)+'\ - \ - \ - \ - '+tr("Base path")+'\ - '+info.BASE_PATH+'\ - \ - \ - \ - '+tr("Capacity")+'\ - ' + generate_datastore_capacity_bar(info, info.TYPE) + '\ - \ - \ - ' + tr("Limit") + '\ - '+(is_system_ssh || (typeof info.TEMPLATE.LIMIT_MB == "undefined") ? '-' : humanize_size_from_mb(info.TEMPLATE.LIMIT_MB))+'\ - \ - \ - \ - \ -
' - + insert_permissions_table('datastores-tab', - "Datastore", - info.ID, - info.UNAME, - info.GNAME, - info.UID, - info.GID)+ - '
\ - \ -
\ -
' + - insert_extended_template_table(info.TEMPLATE, - "Datastore", - info.ID, - tr("Attributes")) + - '
\ -
'; - - - var info_tab = { - title : tr("Info"), - icon: "fa-info-circle", - content: info_tab_content - } - - var datastore_info_tab = { - title: tr("Images"), - icon: "fa-upload", - content : '
\ -
\ - ' + - datastore_image_table_tmpl + - '
\ -
\ -
' - } - - // Add tabs - Sunstone.updateInfoPanelTab("datastore_info_panel","datastore_info_tab",info_tab); - Sunstone.updateInfoPanelTab("datastore_info_panel","datastore_image_tab",datastore_info_tab); - Sunstone.popUpInfoPanel("datastore_info_panel", "datastores-tab"); - - // Define datatables - // Images datatable - - dataTable_datastore_images_panel = $("#datatable_datastore_images_info_panel").dataTable({ - "bAutoWidth":false, - "sDom" : '<"H">t<"F"p>', - "oColVis": { - "aiExclude": [ 0 ] - }, - "bSortClasses" : false, - "bDeferRender": true, - "aoColumnDefs": [ - { "sWidth": "35px", "aTargets": [1] }, - { "bVisible": false, "aTargets": [0,5,6,8,12]} - ] - }); - - infoListener(dataTable_datastore_images_panel,'Image.show','images-tab'); - - // initialize datatables values - Sunstone.runAction("DatastoreImageInfo.list"); - Sunstone.runAction("Datastore.fetch_permissions",info.ID); - -} - -function hide_all(context) -{ - // Hide all the options that depends on datastore type - // and reset the selects - - $('input#image_ds_type').attr('checked', 'true'); - $('input[name=ds_type]').removeAttr('disabled', 'disabled'); - - $('label[for="bridge_list"],input#bridge_list',context).parent().hide(); - $('label[for="ds_tmp_dir"],input#ds_tmp_dir',context).parent().hide(); - $('label[for="vg_name"],input#vg_name',context).hide(); - $('label[for="gluster_host"],input#gluster_host',context).parent().hide(); - $('label[for="gluster_volume"],input#gluster_volume',context).parent().hide(); - $('label[for="pool_name"],input#pool_name',context).parent().hide(); - $('label[for="ceph_host"],input#ceph_host',context).parent().hide(); - $('label[for="ceph_secret"],input#ceph_secret',context).parent().hide(); - $('label[for="ceph_user"],input#ceph_user',context).parent().hide(); - $('label[for="rbd_format"],input#rbd_format',context).parent().hide(); - $('label[for="staging_dir"],input#staging_dir',context).parent().hide(); - $('label[for="limit_transfer_bw"],input#limit_transfer_bw',context).parent().hide(); - $('label[for="no_decompress"],input#no_decompress',context).parent().hide(); - $('select#ds_mad').removeAttr('disabled'); - $('select#tm_mad').removeAttr('disabled'); - $('select#tm_mad').children('option').each(function() { - $(this).removeAttr('disabled'); - }); - $('select#disk_type').removeAttr('disabled'); - $('select#disk_type').children('option').each(function() { - $(this).removeAttr('disabled'); - }); - - $('input[name="ds_tab_custom_ds_mad"]', context).parent().hide(); - $('input[name="ds_tab_custom_tm_mad"]', context).parent().hide(); -} - -// Set up the create datastore dialog -function setupCreateDatastoreDialog(){ - - dialogs_context.append('
'); - //Insert HTML in place - $create_datastore_dialog = $('#create_datastore_dialog') - var dialog = $create_datastore_dialog; - dialog.html(create_datastore_tmpl); - - dialog.addClass("reveal-modal medium max-height").attr("data-reveal", ""); - - setupTips(dialog); - - // Show custom driver input only when custom is selected in selects - $('input[name="ds_tab_custom_ds_mad"],'+ - 'input[name="ds_tab_custom_tm_mad"]',dialog).parent().hide(); - - $('select#ds_mad',dialog).change(function(){ - if ($(this).val()=="custom") - $('input[name="ds_tab_custom_ds_mad"]').parent().show(); - else - $('input[name="ds_tab_custom_ds_mad"]').parent().hide(); - }); - - $('select#tm_mad',dialog).change(function(){ - if ($(this).val()=="custom") - $('input[name="ds_tab_custom_tm_mad"]').parent().show(); - else - $('input[name="ds_tab_custom_tm_mad"]').parent().hide(); - }); - - $('#presets').change(function(){ - hide_all(dialog); - var choice_str = $(this).val(); - switch(choice_str) - { - case 'fs': - select_filesystem(); - break; - case 'vmware_vmfs': - select_vmware_vmfs(); - break; - case 'block_lvm': - select_block_lvm(); - break; - case 'fs_lvm': - select_fs_lvm(); - break; - case 'ceph': - select_ceph(); - break; - case 'gluster': - select_gluster(); - break; - case 'dev': - select_devices(); - break; - case 'custom': - select_custom(); - break; - } - }); - - - $('#create_datastore_submit',dialog).click(function(){ - var context = $( "#create_datastore_form", dialog); - var name = $('#name',context).val(); - var cluster_id = $(".resource_list_select", $('#cluster_id',dialog)).val(); - var ds_type = $('input[name=ds_type]:checked',context).val(); - var ds_mad = $('#ds_mad',context).val(); - ds_mad = ds_mad == "custom" ? $('input[name="ds_tab_custom_ds_mad"]').val() : ds_mad; - var tm_mad = $('#tm_mad',context).val(); - tm_mad = tm_mad == "custom" ? $('input[name="ds_tab_custom_tm_mad"]').val() : tm_mad; - var type = $('#disk_type',context).val(); - - var safe_dirs = $('#safe_dirs',context).val(); - var base_path = $('#base_path',context).val(); - var restricted_dirs = $('#restricted_dirs',context).val(); - var limit_transfer_bw = $('#limit_transfer_bw',context).val(); - var datastore_capacity_check = $('#datastore_capacity_check',context).is(':checked'); - var no_decompress = $('#no_decompress',context).is(':checked'); - - var bridge_list = $('#bridge_list',context).val(); - var ds_tmp_dir = $('#ds_tmp_dir',context).val(); - var vg_name = $('#vg_name',context).val(); - var limit_mb = $('#limit_mb',context).val(); - var gluster_host = $('#gluster_host',context).val(); - var gluster_volume = $('#gluster_volume',context).val(); - var pool_name = $('#pool_name',context).val(); - var ceph_host = $('#ceph_host',context).val(); - var ceph_secret = $('#ceph_secret',context).val(); - var ceph_user = $('#ceph_user',context).val(); - var rbd_format = $('#rbd_format',context).val(); - var staging_dir = $('#staging_dir',context).val(); - - - if (!name){ - notifyError("Please provide a name"); - return false; - }; - - var ds_obj = { - "datastore" : { - "name" : name, - "tm_mad" : tm_mad, - "disk_type" : type, - "type" : ds_type - }, - "cluster_id" : cluster_id - }; - - // If we are adding a system datastore then - // we do not use ds_mad - if (ds_type != "SYSTEM_DS") - ds_obj.datastore.ds_mad = ds_mad; - - if (base_path) - ds_obj.datastore.base_path = base_path; - - if (safe_dirs) - ds_obj.datastore.safe_dirs = safe_dirs; - - if (restricted_dirs) - ds_obj.datastore.restricted_dirs = restricted_dirs; - - if (limit_transfer_bw) - ds_obj.datastore.limit_transfer_bw = limit_transfer_bw; - - if (no_decompress) - ds_obj.datastore.no_decompress = "YES"; - - if (datastore_capacity_check) - ds_obj.datastore.datastore_capacity_check = "YES"; - - if (bridge_list) - ds_obj.datastore.bridge_list = bridge_list; - - if (ds_tmp_dir) - ds_obj.datastore.ds_tmp_dir = ds_tmp_dir; - - if (vg_name) - ds_obj.datastore.vg_name = vg_name; - - if (limit_mb) - ds_obj.datastore.limit_mb = limit_mb; - - if (gluster_host) - ds_obj.datastore.gluster_host = gluster_host; - - if (gluster_volume) - ds_obj.datastore.gluster_volume = gluster_volume; - - if (pool_name) - ds_obj.datastore.pool_name = pool_name; - - if (ceph_host) - ds_obj.datastore.ceph_host = ceph_host; - - if (ceph_secret) - ds_obj.datastore.ceph_secret = ceph_secret; - - if (ceph_user) - ds_obj.datastore.ceph_user = ceph_user; - - if (rbd_format) - ds_obj.datastore.rbd_format = rbd_format; - - if (staging_dir) - ds_obj.datastore.staging_dir = staging_dir; - - Sunstone.runAction("Datastore.create",ds_obj); - return false; - }); - - $('#create_datastore_submit_manual',dialog).click(function(){ - var template = $('#template',dialog).val(); - var cluster_id = $(".resource_list_select", $('#datastore_cluster_raw',dialog)).val(); - - if (!cluster_id){ - notifyError(tr("Please select a cluster for this datastore")); - return false; - }; - - var ds_obj = { - "datastore" : { - "datastore_raw" : template - }, - "cluster_id" : cluster_id - }; - Sunstone.runAction("Datastore.create",ds_obj); - return false; - }); - - $('#wizard_ds_reset_button').click(function(){ - $create_datastore_dialog.html(""); - setupCreateDatastoreDialog(); - - popUpCreateDatastoreDialog(); - }); - - $('#advanced_ds_reset_button').click(function(){ - $create_datastore_dialog.html(""); - setupCreateDatastoreDialog(); - - popUpCreateDatastoreDialog(); - $("a[href='#datastore_manual']").click(); - }); - - // Hide disk_type - $('select#disk_type').parent().hide(); - - hide_all($create_datastore_dialog); - select_filesystem(); -} - -function select_filesystem(){ - $('select#ds_mad').val('fs'); - $('select#tm_mad').val('shared'); - $('select#ds_mad').attr('disabled', 'disabled'); - $('select#tm_mad').children('option').each(function() { - var value_str = $(this).val(); - $(this).attr('disabled', 'disabled'); - if (value_str == "qcow2" || - value_str == "shared" || - value_str == "ssh") - { - $(this).removeAttr('disabled'); - } - }); - $('select#disk_type').val('file'); - $('select#disk_type').attr('disabled', 'disabled'); - $('label[for="limit_transfer_bw"],input#limit_transfer_bw').parent().fadeIn(); - $('label[for="no_decompress"],input#no_decompress').parent().fadeIn(); - $('label[for="datastore_capacity_check"],input#datastore_capacity_check').parent().fadeIn(); - $('input#safe_dirs').removeAttr('disabled'); - $('select#disk_type').removeAttr('disabled'); - $('input#base_path').removeAttr('disabled'); - $('input#limit_mb').removeAttr('disabled'); - $('input#restricted_dirs').removeAttr('disabled'); - $('label[for="bridge_list"],input#bridge_list').parent().fadeIn(); - $('label[for="staging_dir"],input#staging_dir').parent().fadeIn(); -} - -function select_vmware_vmfs(){ - $('label[for="bridge_list"],input#bridge_list').parent().fadeIn(); - $('label[for="ds_tmp_dir"],input#ds_tmp_dir').parent().fadeIn(); - $('select#ds_mad').val('vmfs'); - $('select#ds_mad').attr('disabled', 'disabled'); - $('select#tm_mad').val('vmfs'); - $('select#tm_mad').attr('disabled', 'disabled'); - $('label[for="limit_transfer_bw"],input#limit_transfer_bw').parent().fadeIn(); - $('label[for="no_decompress"],input#no_decompress').parent().fadeIn(); - $('label[for="datastore_capacity_check"],input#datastore_capacity_check').parent().fadeIn(); - $('select#disk_type').val('file'); - $('select#disk_type').attr('disabled', 'disabled'); - $('input#safe_dirs').removeAttr('disabled'); - $('input#base_path').removeAttr('disabled'); - $('input#limit_mb').removeAttr('disabled'); - $('input#restricted_dirs').removeAttr('disabled'); -} - -function select_ceph(){ - $('input#image_ds_type').attr('checked', 'true'); - $('input[name=ds_type]').attr('disabled', 'disabled'); - $('select#ds_mad').val('ceph'); - $('select#ds_mad').attr('disabled', 'disabled'); - $('select#tm_mad').val('ceph'); - $('select#tm_mad').attr('disabled', 'disabled'); - $('label[for="bridge_list"],input#bridge_list').parent().fadeIn(); - $('label[for="pool_name"],input#pool_name').parent().fadeIn(); - $('label[for="ceph_host"],input#ceph_host').parent().fadeIn(); - $('label[for="ceph_secret"],input#ceph_secret').parent().fadeIn(); - $('label[for="ceph_user"],input#ceph_user').parent().fadeIn(); - $('label[for="rbd_format"],input#rbd_format').parent().fadeIn(); - $('label[for="staging_dir"],input#staging_dir').parent().fadeIn(); - $('label[for="limit_transfer_bw"],input#limit_transfer_bw').parent().fadeIn(); - $('label[for="no_decompress"],input#no_decompress').parent().fadeIn(); - $('label[for="datastore_capacity_check"],input#datastore_capacity_check').parent().fadeIn(); - $('select#disk_type').val('RBD'); - $('select#disk_type').attr('disabled', 'disabled'); - $('input#safe_dirs').removeAttr('disabled'); - $('input#base_path').removeAttr('disabled'); - $('input#limit_mb').removeAttr('disabled'); - $('input#restricted_dirs').removeAttr('disabled'); -} - -function select_block_lvm(){ - $('select#ds_mad').val('lvm'); - $('select#ds_mad').attr('disabled', 'disabled'); - $('select#tm_mad').val('lvm'); - $('select#tm_mad').attr('disabled', 'disabled'); - $('input#image_ds_type').attr('checked', 'true'); - $('input[name=ds_type]').attr('disabled', 'disabled'); - $('label[for="bridge_list"],input#bridge_list').parent().fadeIn(); - $('label[for="vg_name"],input#vg_name').fadeIn(); - $('label[for="limit_transfer_bw"],input#limit_transfer_bw').parent().fadeIn(); - $('label[for="no_decompress"],input#no_decompress').parent().fadeIn(); - $('label[for="datastore_capacity_check"],input#datastore_capacity_check').parent().fadeIn(); - $('select#disk_type').val('block'); - $('select#disk_type').attr('disabled', 'disabled'); - $('input#safe_dirs').removeAttr('disabled'); - $('input#base_path').removeAttr('disabled'); - $('input#limit_mb').removeAttr('disabled'); - $('input#restricted_dirs').removeAttr('disabled'); -} - -function select_fs_lvm(){ - $('select#ds_mad').val('fs'); - $('select#ds_mad').attr('disabled', 'disabled'); - $('select#tm_mad').val('fs_lvm'); - $('select#tm_mad').attr('disabled', 'disabled'); - $('input#image_ds_type').attr('checked', 'true'); - $('input[name=ds_type]').attr('disabled', 'disabled'); - $('label[for="limit_transfer_bw"],input#limit_transfer_bw').parent().fadeIn(); - $('label[for="no_decompress"],input#no_decompress').parent().fadeIn(); - $('label[for="datastore_capacity_check"],input#datastore_capacity_check').parent().fadeIn(); - $('select#disk_type').val('block'); - $('select#disk_type').attr('disabled', 'disabled'); - $('input#safe_dirs').removeAttr('disabled'); - $('input#base_path').removeAttr('disabled'); - $('input#limit_mb').removeAttr('disabled'); - $('input#restricted_dirs').removeAttr('disabled'); -} - -function select_gluster(){ - $('select#ds_mad').val('fs'); - $('select#ds_mad').attr('disabled', 'disabled'); - $('select#tm_mad').val('shared'); - $('select#tm_mad').children('option').each(function() { - var value_str = $(this).val(); - $(this).attr('disabled', 'disabled'); - if (value_str == "shared" || - value_str == "ssh") - { - $(this).removeAttr('disabled'); - } - }); - $('input#image_ds_type').attr('checked', 'true'); - $('input[name=ds_type]').attr('disabled', 'disabled'); - $('select#disk_type').val('gluster'); - $('select#disk_type').attr('disabled', 'disabled'); - $('label[for="gluster_host"],input#gluster_host').parent().fadeIn(); - $('label[for="gluster_volume"],input#gluster_volume').parent().fadeIn(); - $('label[for="limit_transfer_bw"],input#limit_transfer_bw').parent().fadeIn(); - $('label[for="no_decompress"],input#no_decompress').parent().fadeIn(); - $('label[for="datastore_capacity_check"],input#datastore_capacity_check').parent().fadeIn(); - $('input#safe_dirs').removeAttr('disabled'); - $('input#base_path').removeAttr('disabled'); - $('input#limit_mb').removeAttr('disabled'); - $('input#restricted_dirs').removeAttr('disabled'); -} - -function select_devices(){ - $('select#ds_mad').val('dev'); - $('select#ds_mad').attr('disabled', 'disabled'); - $('select#tm_mad').val('dev'); - $('select#tm_mad').attr('disabled', 'disabled'); - $('input#image_ds_type').attr('checked', 'true'); - $('input[name=ds_type]').attr('disabled', 'disabled'); - $('select#disk_type').val('block'); - $('select#disk_type').attr('disabled', 'disabled'); - $('label[for="limit_transfer_bw"],input#limit_transfer_bw').parent().hide(); - $('label[for="no_decompress"],input#no_decompress').parent().hide(); - $('label[for="datastore_capacity_check"],input#datastore_capacity_check').parent().hide(); - $('input#safe_dirs').attr('disabled', 'disabled'); - $('input#base_path').attr('disabled', 'disabled'); - $('input#limit_mb').attr('disabled', 'disabled'); - $('input#restricted_dirs').attr('disabled', 'disabled'); -} - -function select_custom(){ - hide_all($create_datastore_dialog); - $('select#ds_mad').val('fs'); - $('select#tm_mad').val('shared'); - $('input#safe_dirs').removeAttr('disabled'); - $('select#disk_type').removeAttr('disabled'); - $('input#base_path').removeAttr('disabled'); - $('input#limit_mb').removeAttr('disabled'); - $('input#restricted_dirs').removeAttr('disabled'); - $('label[for="limit_transfer_bw"],input#limit_transfer_bw').parent().fadeIn(); - $('label[for="no_decompress"],input#no_decompress').parent().fadeIn(); - $('label[for="datastore_capacity_check"],input#datastore_capacity_check').parent().fadeIn(); -} - -function popUpCreateDatastoreDialog(){ - var cluster_id = $("div#cluster_id .resource_list_select", $create_datastore_dialog).val(); - if (!cluster_id) cluster_id = "-1"; - - var cluster_id_raw = $("div#datastore_cluster_raw .resource_list_select", $create_datastore_dialog).val(); - if (!cluster_id_raw) cluster_id_raw = "-1"; - - - insertSelectOptions('div#cluster_id', $create_datastore_dialog, "Cluster", cluster_id, false); - insertSelectOptions('div#datastore_cluster_raw', $create_datastore_dialog, "Cluster", cluster_id_raw, false); - $create_datastore_dialog.foundation().foundation('reveal', 'open'); - $("input#name",$create_datastore_dialog).focus(); -} - - -$(document).ready(function(){ - var tab_name = 'datastores-tab'; - - if (Config.isTabEnabled(tab_name)) { - dataTable_datastores = $("#datatable_datastores",main_tabs_context).dataTable({ - "bAutoWidth": false, - "aoColumnDefs": [ - { "bSortable": false, "aTargets": ["check"] }, - { "sWidth": "35px", "aTargets": [0] }, - { "sWidth": "250px", "aTargets": [5] }, - { "bVisible": true, "aTargets": Config.tabTableColumns(tab_name)}, - { "bVisible": false, "aTargets": ['_all']} - ], - "bSortClasses" : false, - "bDeferRender": true, - }); - - $('#datastore_search').keyup(function(){ - dataTable_datastores.fnFilter( $(this).val() ); - }) - - dataTable_datastores.on('draw', function(){ - recountCheckboxes(dataTable_datastores); - }) - - Sunstone.runAction("Datastore.list"); - - setupCreateDatastoreDialog(); - - initCheckAllBoxes(dataTable_datastores); - tableCheckboxesListener(dataTable_datastores); - infoListener(dataTable_datastores,'Datastore.show'); - - // Reset filter in case the view was filtered because it was accessed - // from a single cluster. - $('div#menu li#li_datastores_tab').live('click',function(){ - dataTable_datastores.fnFilter('',5); - }); - - $('div#datastores_tab div.legend_div').hide(); - dataTable_datastores.fnSort( [ [1,config['user_config']['table_order']] ] ); - } -}) diff --git a/src/sunstone/public/js/plugins/files-tab.js b/src/sunstone/public/js/plugins/files-tab.js deleted file mode 100644 index 58a295ef9c..0000000000 --- a/src/sunstone/public/js/plugins/files-tab.js +++ /dev/null @@ -1,852 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2002-2015, 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. */ -/* -------------------------------------------------------------------------- */ - -var create_file_tmpl ='
\ -
\ -

'+tr("Create File")+'

'+ - '
'+ - '\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ - \ -
\ -
\ -
\ -
\ -
\ -
\ -
\ - '+tr("Image location")+':\ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ -
\ - \ -
\ -
\ -
\ -
\ -
\ -
\ - \ -
\ -
\ -
\ - \ - \ -
\ -
\ -
\ - ×\ -
\ -'; - -var dataTable_files; -var $create_file_dialog; -var size_files = 0; - -var file_actions = { - - "File.create" : { - type: "create", - call: OpenNebula.Image.create, - callback: function(request, response) { - // Reset the create wizard - $create_file_dialog.foundation('reveal', 'close'); - $create_file_dialog.empty(); - setupCreateFileDialog(); - - addFileElement(request, response); - notifyCustom(tr("File created"), " ID: " + response.IMAGE.ID, false); - }, - error: onError - }, - - "File.create_dialog" : { - type: "custom", - call: popUpCreateFileDialog - }, - - "File.list" : { - type: "list", - call: OpenNebula.Image.list, - callback: updateFilesView, - error: onError - }, - - "File.show" : { - type : "single", - call: OpenNebula.Image.show, - callback: function(request, response){ - var tab = dataTable_files.parents(".tab"); - - if (Sunstone.rightInfoVisible(tab)) { - // individual view - updateFileInfo(request, response); - } - - // datatable row - updateFileElement(request, response); - }, - error: onError - }, - - "File.refresh" : { - type: "custom", - call: function () { - var tab = dataTable_files.parents(".tab"); - if (Sunstone.rightInfoVisible(tab)) { - Sunstone.runAction("File.show", Sunstone.rightInfoResourceId(tab)) - } else { - waitingNodes(dataTable_files); - Sunstone.runAction("File.list", {force: true}); - } - } - }, - - "File.update_template" : { - type: "single", - call: OpenNebula.Image.update, - callback: function(request) { - notifyMessage("Template updated correctly"); - Sunstone.runAction('File.show',request.request.data[0][0]); - }, - error: onError - }, - - "File.enable" : { - type: "multiple", - call: OpenNebula.Image.enable, - callback: function (req) { - Sunstone.runAction("File.show",req.request.data[0]); - }, - elements: fileElements, - error: onError, - notify: true - }, - - "File.disable" : { - type: "multiple", - call: OpenNebula.Image.disable, - callback: function (req) { - Sunstone.runAction("File.show",req.request.data[0]); - }, - elements: fileElements, - error: onError, - notify: true - }, - - "File.delete" : { - type: "multiple", - call: OpenNebula.Image.del, - callback: deleteFileElement, - elements: fileElements, - error: onError, - notify: true - }, - - "File.chown" : { - type: "multiple", - call: OpenNebula.Image.chown, - callback: function (req) { - Sunstone.runAction("File.show",req.request.data[0][0]); - }, - elements: fileElements, - error: onError, - notify: true - }, - - "File.chgrp" : { - type: "multiple", - call: OpenNebula.Image.chgrp, - callback: function (req) { - Sunstone.runAction("File.show",req.request.data[0][0]); - }, - elements: fileElements, - error: onError, - notify: true - }, - - "File.chmod" : { - type: "single", - call: OpenNebula.Image.chmod, -// callback - error: onError, - notify: true - }, - - "File.chtype" : { - type: "single", - call: OpenNebula.Image.chtype, - callback: function (req) { - Sunstone.runAction("File.show",req.request.data[0][0]); - }, - elements: fileElements, - error: onError, - notify: true - }, - "File.help" : { - type: "custom", - call: function() { - hideDialog(); - $('div#files_tab div.legend_div').slideToggle(); - } - }, - "File.rename" : { - type: "single", - call: OpenNebula.Image.rename, - callback: function(request) { - notifyMessage(tr("File renamed correctly")); - Sunstone.runAction('File.show',request.request.data[0]); - }, - error: onError, - notify: true - }, -}; - - -var file_buttons = { - "File.refresh" : { - type: "action", - layout: "refresh", - alwaysActive: true - }, -// "Sunstone.toggle_top" : { -// type: "custom", -// layout: "top", -// alwaysActive: true -// }, - "File.create_dialog" : { - type: "create_dialog", - layout: "create" - }, - "File.chown" : { - type: "confirm_with_select", - text: tr("Change owner"), - layout: "user_select", - select: "User", - tip: tr("Select the new owner")+":", - condition: mustBeAdmin - }, - "File.chgrp" : { - type: "confirm_with_select", - text: tr("Change group"), - layout: "user_select", - select: "Group", - tip: tr("Select the new group")+":", - condition: mustBeAdmin - }, - "File.enable" : { - type: "action", - layout: "more_select", - text: tr("Enable") - }, - "File.disable" : { - type: "action", - layout: "more_select", - text: tr("Disable") - }, - "File.delete" : { - type: "confirm", - layout: "del", - text: tr("Delete") - } -} - -var file_info_panel = { - "file_info_tab" : { - title: tr("Information"), - content: "" - } -} - -var files_tab = { - title: tr("Files & Kernels"), - resource: 'File', - buttons: file_buttons, - tabClass: 'subTab', - parentTab: 'vresources-tab', - content: '
\ -
\ -
', - search_input: '', - list_header: ' '+tr("Files & Kernels"), - info_header: ' '+tr("File"), - subheader: ' '+tr("TOTAL")+' \ - '+tr("SIZE")+'', - table: '\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
'+tr("ID")+''+tr("Owner")+''+tr("Group")+''+tr("Name")+''+tr("Datastore")+''+tr("Size")+''+tr("Type")+''+tr("Registration time")+''+tr("Persistent")+''+tr("Status")+''+tr("#VMS")+''+tr("Target")+'
' -} - -Sunstone.addActions(file_actions); -Sunstone.addMainTab('files-tab',files_tab); -Sunstone.addInfoPanel('file_info_panel',file_info_panel); - - -function fileElements() { - return getSelectedNodes(dataTable_files); -} - -// Returns an array containing the values of the file_json and ready -// to be inserted in the dataTable -function fileElementArray(file_json){ - //Changing this? It may affect to the is_persistent() functions. - var file = file_json.IMAGE; - - // OS || CDROM || DATABLOCK - if (file.TYPE == "0" || file.TYPE == "1" || file.TYPE == "2") { - return false; - } - - - size_files = size_files + parseInt(file.SIZE); - - //add also persistent/non-persistent selects, type select. - return [ - '', - file.ID, - file.UNAME, - file.GNAME, - file.NAME, - file.DATASTORE, - file.SIZE, - OpenNebula.Helper.image_type(file.TYPE), - pretty_time(file.REGTIME), - parseInt(file.PERSISTENT) ? "yes" : "no", - OpenNebula.Helper.resource_state("image",file.STATE), - file.RUNNING_VMS, - file.TEMPLATE.TARGET ? file.TEMPLATE.TARGET : '--' - ]; -} - -// Callback to update an element in the dataTable -function updateFileElement(request, file_json){ - var id = file_json.IMAGE.ID; - var element = fileElementArray(file_json); - updateSingleElement(element,dataTable_files,'#file_'+id); -} - -// Callback to remove an element from the dataTable -function deleteFileElement(req){ - deleteElement(dataTable_files,'#file_'+req.request.data); -} - -// Callback to add an file element -function addFileElement(request, file_json){ - var element = fileElementArray(file_json); - addElement(element,dataTable_files); -} - -// Callback to refresh the list of files -function updateFilesView(request, files_list){ - var file_list_array = []; - - size_files = 0; - - $.each(files_list,function(){ - var file = fileElementArray(this); - if (file) - file_list_array.push(file); - }); - - updateView(file_list_array,dataTable_files); - - var size = humanize_size_from_mb(size_files) - - $(".total_files").text(file_list_array.length); - $(".size_files").text(size); -} - -// Callback to update the information panel tabs and pop it up -function updateFileInfo(request,file){ - var file_info = file.IMAGE; - - $(".resource-info-header", $("#files-tab")).html(file_info.NAME); - - var info_tab = { - title : tr("Info"), - icon: "fa-info-circle", - content: - '
\ -
\ - \ - \ - \ - \ - \ - \ - \ - \ - '+ - insert_rename_tr( - 'files-tab', - "File", - file_info.ID, - file_info.NAME)+ - '\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
'+tr("File")+' - '+file_info.NAME+'
'+tr("ID")+''+file_info.ID+'
'+tr("Datastore")+''+file_info.DATASTORE+'
'+tr("Type")+''+OpenNebula.Helper.image_type(file_info.TYPE)+'
\ - \ -
\ -
'+tr("Register time")+''+pretty_time(file_info.REGTIME)+'
'+tr("Filesystem type")+''+(typeof file_info.FSTYPE === "string" ? file_info.FSTYPE : "--")+'
'+tr("Size")+''+humanize_size_from_mb(file_info.SIZE)+'
'+tr("State")+''+OpenNebula.Helper.resource_state("file",file_info.STATE)+'
'+tr("Running VMS")+''+file_info.RUNNING_VMS+'
\ -
\ -
' + - insert_permissions_table('files-tab', - "File", - file_info.ID, - file_info.UNAME, - file_info.GNAME, - file_info.UID, - file_info.GID) + - '
\ -
\ -
\ -
'+ - insert_extended_template_table(file_info.TEMPLATE, - "File", - file_info.ID, - tr("Attributes")) + - '
\ -
' - } - - $("#div_edit_chg_type_files_link").die(); - $("#chg_type_select_files").die(); - $("#div_edit_persistency_files").die(); - $("#persistency_select_files").die(); - - - // Listener for edit link for type change - $("#div_edit_chg_type_files_link").live("click", function() { - $(".value_td_type_files").html( - ''); - - $('#chg_type_select_files').val(OpenNebula.Helper.image_type(file_info.TYPE)); - }); - - $("#chg_type_select_files").live("change", function() { - var new_value = $(this).val(); - Sunstone.runAction("File.chtype", file_info.ID, new_value); - }); - - - Sunstone.updateInfoPanelTab("file_info_panel","file_info_tab",info_tab); - Sunstone.popUpInfoPanel("file_info_panel", "files-tab"); - - setPermissionsTable(file_info,''); -} - -function enable_all_datastores() -{ - - $('select#disk_type').children('option').each(function() { - $(this).removeAttr('disabled'); - }); -} - -// Prepare the file creation dialog -function setupCreateFileDialog(){ - dialogs_context.append('
'); - $create_file_dialog = $('#create_file_dialog',dialogs_context); - - var dialog = $create_file_dialog; - dialog.html(create_file_tmpl); - - dialog.addClass("reveal-modal medium").attr("data-reveal", ""); - - $('#files_file-uploader',dialog).closest('.row').hide(); - - $("input[name='src_path']", dialog).change(function(){ - var context = $create_file_dialog; - var value = $(this).val(); - switch (value){ - case "path": - $('#files_file-uploader',context).closest('.row').hide(); - $('#file_path',context).closest('.row').show(); - break; - case "upload": - $('#file_path',context).closest('.row').hide(); - $('#files_file-uploader',context).closest('.row').show(); - break; - }; - }); - - - $('#path_file',dialog).click(); - - $('#upload-progress',dialog).css({ - border: "1px solid #AAAAAA", - position: "relative", -// bottom: "29px", - width: "258px", -// left: "133px", - height: "15px", - display: "inline-block" - }); - $('#upload-progress div',dialog).css("border","1px solid #AAAAAA"); - - var file_obj; - - - if (getInternetExplorerVersion() > -1) { - $("#file_uploader").attr("disabled", "disabled"); - } else { - var file_uploader = new Resumable({ - target: 'upload_chunk', - chunkSize: 10*1024*1024, - maxFiles: 1, - testChunks: false, - query: { - csrftoken: csrftoken - } - }); - - file_uploader.assignBrowse($('#files_file-uploader-input',dialog)[0]); - - var fileName = ''; - var file_input = false; - - file_uploader.on('fileAdded', function(file){ - fileName = file.fileName; - file_input = fileName; - - $('#files_file-uploader-input',dialog).hide() - $("#files_file-uploader-label", dialog).html(file.fileName); - }); - - file_uploader.on('uploadStart', function() { - $('#files_upload_progress_bars').append('
\ -
\ - '+tr("Uploading...")+'\ -
\ -
\ -
\ - \ -
\ -
'+fileName+'
\ -
\ -
'); - }); - - file_uploader.on('progress', function() { - $('span.meter', $('div[id="files-'+fileName+'-progressBar"]')).css('width', file_uploader.progress()*100.0+'%') - }); - - file_uploader.on('fileSuccess', function(file) { - $('div[id="files-'+fileName+'-info"]').text(tr('Registering in OpenNebula')); - $.ajax({ - url: 'upload', - type: "POST", - data: { - csrftoken: csrftoken, - img : JSON.stringify(file_obj), - file: fileName, - tempfile: file.uniqueIdentifier - }, - success: function(){ - notifyMessage("File uploaded correctly"); - $('div[id="files-'+fileName+'-progressBar"]').remove(); - Sunstone.runAction("File.refresh"); - }, - error: function(response){ - onError({}, OpenNebula.Error(response)); - $('div[id="files-'+fileName+'-progressBar"]').remove(); - } - }); - }); - } - - $('#create_file_form_easy',dialog).submit(function(){ - var upload = false; - - var ds_id = $('#file_datastore .resource_list_select',dialog).val(); - if (!ds_id){ - notifyError(tr("Please select a datastore for this file")); - return false; - }; - - var file_json = {}; - - var name = $('#file_name',dialog).val(); - file_json["NAME"] = name; - - var desc = $('#file_desc',dialog).val(); - if (desc.length){ - file_json["DESCRIPTION"] = desc; - } - - var type = $('#file_type',dialog).val(); - file_json["TYPE"]= type; - - - switch ($('#src_path_select input:checked',dialog).val()){ - case "path": - path = $('#file_path',dialog).val(); - if (path) file_json["PATH"] = path; - break; - case "upload": - upload=true; - break; - } - - file_obj = { "image" : file_json, - "ds_id" : ds_id}; - - //we this is an file upload we trigger FileUploader - //to start the upload - if (upload){ - $create_file_dialog.foundation('reveal', 'close'); - $create_file_dialog.empty(); - setupCreateFileDialog(); - - file_uploader.upload(); - } else { - Sunstone.runAction("File.create", file_obj); - }; - - return false; - }); - - $('#create_file_submit_manual',dialog).click(function(){ - var template=$('#template',dialog).val(); - var ds_id = $('#file_datastore_raw .resource_list_select',dialog).val(); - - if (!ds_id){ - notifyError(tr("Please select a datastore for this file")); - return false; - }; - - var file_obj = { - "image" : { - "image_raw" : template - }, - "ds_id" : ds_id - }; - Sunstone.runAction("File.create",file_obj); - return false; - }); - - setupTips(dialog); - - $('#wizard_file_reset_button', dialog).click(function(){ - $('#create_file_dialog').html(""); - setupCreateFileDialog(); - - popUpCreateFileDialog(); - }); - - $('#advanced_file_reset_button', dialog).click(function(){ - $('#create_file_dialog').html(""); - setupCreateFileDialog(); - - popUpCreateFileDialog(); - $("a[href='#file_manual']").click(); - }); -} - -function popUpCreateFileDialog(){ - $('#files_file-uploader input',$create_file_dialog).removeAttr("style"); - $('#files_file-uploader input',$create_file_dialog).attr('style','margin:0;width:256px!important'); - - var ds_id = $("div#file_datastore .resource_list_select", - $create_file_dialog).val(); - - var ds_id_raw = $("div#file_datastore_raw .resource_list_select", - $create_file_dialog).val(); - - // Filter out DS with type image (0) or system (1) - var filter_att = ["TYPE", "TYPE"]; - var filter_val = ["0", "1"]; - - insertSelectOptions('div#file_datastore', $create_file_dialog, "Datastore", - ds_id, false, null, filter_att, filter_val); - - insertSelectOptions('div#file_datastore_raw', $create_file_dialog, "Datastore", - ds_id_raw, false, null, filter_att, filter_val); - - $create_file_dialog.foundation().foundation('reveal', 'open'); - $("input#file_name",$create_file_dialog).focus(); -} - -function is_persistent_file(id){ - var data = getElementData(id,"#file",dataTable_files)[8]; - return $(data).is(':checked'); -}; - -//The DOM is ready at this point -$(document).ready(function(){ - var tab_name = 'files-tab'; - - if (Config.isTabEnabled(tab_name)) { - dataTable_files = $("#datatable_files",main_tabs_context).dataTable({ - "aoColumnDefs": [ - { "bSortable": false, "aTargets": ["check"] }, - { "sWidth": "35px", "aTargets": [0] }, - { "bVisible": true, "aTargets": Config.tabTableColumns(tab_name)}, - { "bVisible": false, "aTargets": ['_all']} - ], - "bSortClasses" : false, - "bDeferRender": true, - }); - - $('#file_search').keyup(function(){ - dataTable_files.fnFilter( $(this).val() ); - }) - - dataTable_files.on('draw', function(){ - recountCheckboxes(dataTable_files); - }) - - Sunstone.runAction("File.list"); - - setupCreateFileDialog(); - - initCheckAllBoxes(dataTable_files); - tableCheckboxesListener(dataTable_files); - infoListener(dataTable_files,'File.show'); - - $('div#files_tab div.legend_div').hide(); - dataTable_files.fnSort( [ [1,config['user_config']['table_order']] ] ); - } -}); diff --git a/src/sunstone/public/js/plugins/groups-tab.js b/src/sunstone/public/js/plugins/groups-tab.js deleted file mode 100644 index d7e0b61114..0000000000 --- a/src/sunstone/public/js/plugins/groups-tab.js +++ /dev/null @@ -1,1306 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2002-2015, 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. */ -/* -------------------------------------------------------------------------- */ - -var dataTable_groups; -var $create_group_dialog; -var $group_quotas_dialog; - -var group_acct_graphs = [ - { title : tr("CPU"), - monitor_resources : "CPU", - humanize_figures : false - }, - { title : tr("Memory"), - monitor_resources : "MEMORY", - humanize_figures : true - }, - { title : tr("Net TX"), - monitor_resources : "NETTX", - humanize_figures : true - }, - { title : tr("Net RX"), - monitor_resources : "NETRX", - humanize_figures : true - } -]; - -function create_group_tmpl(dialog_name){ - return '
\ -
\ -

'+tr("Create Group")+'

\ -

'+tr("Update Group")+'

\ -
\ -
\ -
\ -
\ -
\ -
\ - \ -
\ - \ -
\ -
\ -
\ -
\ -
\ -

' - +tr("Allow users in this group to use the following Sunstone views")+ - ' '+tr("Views available to the group users. If the default is unset, the one set in sunstone-views.yaml will be used")+'\ -

\ -
\ -
\ -
\ -
'+ - insert_views(dialog_name) - +'
\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ - \ -
\ -
' + - user_creation_div + // from users-tab.js - '
\ -
\ -
\ -
\ -
\ -
\ - \ -
\ -
\ -
\ -
\ -

' - +tr("Allow users in this group to create the following resources")+ - ' '+tr("This will create new ACL Rules to define which virtual resources this group's users will be able to create.")+'\ -

\ -
\ -
\ -
\ -
\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
'+tr("VMs")+''+tr("VNets")+''+tr("Security Groups")+''+tr("Images")+''+tr("Templates")+''+tr("Documents")+''+tr("Documents are a special tool used for general purposes, mainly by OneFlow. If you want to enable users of this group to use service composition via OneFlow, let it checked.")+'
\ -
\ -
\ -
\ -
\ -
\ - \ - ×\ - \ -
'; -} - -function group_quotas_tmpl(){ - return '
\ -
\ -

'+tr("Update Quota")+'

\ -
\ -
\ -
\ -
'+ - quotas_tmpl() + - '\ - ×\ -
\ -
'; -} - - -var group_actions = { - "Group.create" : { - type: "create", - call : OpenNebula.Group.create, - callback : function(request, response) { - // Reset the create wizard - $create_group_dialog.foundation('reveal', 'close'); - $create_group_dialog.empty(); - setupCreateGroupDialog(); - - OpenNebula.Helper.clear_cache("USER"); - - Sunstone.runAction("Group.list"); - notifyCustom(tr("Group created"), " ID: " + response.GROUP.ID, false); - }, - error : onError - }, - - "Group.create_dialog" : { - type: "custom", - call: popUpCreateGroupDialog - }, - - "Group.list" : { - type: "list", - call: OpenNebula.Group.list, - callback: updateGroupsView, - error: onError - }, - - "Group.show" : { - type: "single", - call: OpenNebula.Group.show, - callback: function(request, response) { - updateGroupElement(request, response); - if (Sunstone.rightInfoVisible($("#groups-tab"))) { - updateGroupInfo(request, response); - } - }, - error: onError - }, - - "Group.refresh" : { - type: "custom", - call: function() { - var tab = dataTable_groups.parents(".tab"); - if (Sunstone.rightInfoVisible(tab)) { - Sunstone.runAction("Group.show", Sunstone.rightInfoResourceId(tab)) - } else { - waitingNodes(dataTable_groups); - Sunstone.runAction("Group.list", {force: true}); - } - }, - error: onError - }, - - "Group.update_template" : { - type: "single", - call: OpenNebula.Group.update, - callback: function(request) { - Sunstone.runAction('Group.show',request.request.data[0][0]); - }, - error: onError - }, - - "Group.update_dialog" : { - type: "single", - call: initUpdateGroupDialog - }, - - "Group.show_to_update" : { - type: "single", - call: OpenNebula.Group.show, - callback: function(request, response) { - popUpUpdateGroupDialog( - response.GROUP, - $create_group_dialog); - }, - error: onError - }, - - "Group.delete" : { - type: "multiple", - call : OpenNebula.Group.del, - callback : deleteGroupElement, - error : onError, - elements: groupElements - }, - - "Group.fetch_quotas" : { - type: "single", - call: OpenNebula.Group.show, - callback: function (request,response) { - populateQuotasDialog( - response.GROUP, - default_group_quotas, - "#group_quotas_dialog", - $group_quotas_dialog); - }, - error: onError - }, - - "Group.quotas_dialog" : { - type: "custom", - call: popUpGroupQuotasDialog - }, - - "Group.set_quota" : { - type: "multiple", - call: OpenNebula.Group.set_quota, - elements: groupElements, - callback: function(request,response) { - Sunstone.runAction('Group.show',request.request.data[0]); - }, - error: onError - }, - - "Group.accounting" : { - type: "monitor", - call: OpenNebula.Group.accounting, - callback: function(req,response) { - var info = req.request.data[0].monitor; - //plot_graph(response,'#group_acct_tabTab','group_acct_', info); - }, - error: onError - }, - - "Group.add_admin" : { - type: "single", - call : OpenNebula.Group.add_admin, - callback : function (req) { - Sunstone.runAction('Group.show',req.request.data[0][0]); - }, - error : onError - }, - - "Group.del_admin" : { - type: "single", - call : OpenNebula.Group.del_admin, - callback : function (req) { - Sunstone.runAction('Group.show',req.request.data[0][0]); - }, - error : onError - } -} - -var group_buttons = { - "Group.refresh" : { - type: "action", - layout: "refresh", - alwaysActive: true - }, -// "Sunstone.toggle_top" : { -// type: "custom", -// layout: "top", -// alwaysActive: true -// }, - "Group.create_dialog" : { - type: "create_dialog", - layout: "create", - condition: mustBeAdmin - }, - "Group.update_dialog" : { - type : "action", - layout: "main", - text : tr("Update") - }, - "Group.quotas_dialog" : { - type : "action", - text : tr("Quotas"), - layout: "main", - condition: mustBeAdmin - }, - "Group.delete" : { - type: "confirm", - text: tr("Delete"), - layout: "del", - condition: mustBeAdmin - }, -}; - -var group_info_panel = { - -}; - -var groups_tab = { - title: tr("Groups"), - resource: 'Group', - buttons: group_buttons, - tabClass: 'subTab', - parentTab: 'system-tab', - search_input: '', - list_header: ' '+tr("Groups"), - info_header: ' '+tr("Group"), - subheader: '\ - '+tr("TOTAL")+'\ - ', - table: '\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
'+tr("ID")+''+tr("Name")+''+tr("Users")+''+tr("VMs")+''+tr("Memory")+''+tr("CPU")+'
' -}; - - -Sunstone.addActions(group_actions); -Sunstone.addMainTab('groups-tab',groups_tab); -Sunstone.addInfoPanel("group_info_panel",group_info_panel); - -function generateViewTable(views, dialog_name) { - var table_str = ''+ - ""+ - ""+ - ""+ - ""+ - ""; - - $.each(views, function(id, view){ - var default_user_checked = view.id == 'cloud' ? "checked" : ""; - var default_admin_checked = view.id == 'groupadmin' ? "checked" : ""; - - table_str += ""+ - ''+ - ''; - }); - - table_str += '
"+tr("Group Users")+""+tr("Group Admins")+"
" + - view.name + - ' ' + tr("View") + - (view.description ? - ''+view.description+'' - : "") + - "\ - \ - \ - \ -
'; - - return table_str; -} - -function insert_views(dialog_name){ - var filtered_views = { - cloud : [], - advanced : [], - vcenter : [], - other : [] - } - - var view_info; - $.each(config['all_views'], function(index, view_id) { - view_info = views_info[view_id]; - if (view_info) { - switch (view_info.type) { - case 'advanced': - filtered_views.advanced.push(view_info); - break; - case 'cloud': - filtered_views.cloud.push(view_info); - break; - case 'vcenter': - filtered_views.vcenter.push(view_info); - break; - default: - filtered_views.other.push({ - id: view_id, - name: view_id, - description: null, - type: "other" - }); - break; - } - } else { - filtered_views.other.push({ - id: view_id, - name: view_id, - description: null, - type: "other" - }); - } - }) - - var str = ""; - - str += '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '

'; - - $.each(filtered_views, function(view_type, views){ - if (views.length > 0) { - str += '
'+ - '
'+ - '

'+view_types[view_type].name+ - (view_types[view_type].description ? - '' + view_types[view_type].description + '' - : "")+ - '

'+ - generateViewTable(views, dialog_name) + - '
'+ - '
'+ - (view_types[view_type].preview ? - '' : - '') + - '
'+ - '

'; - } - }) - - - return str; -} - -function groupElements(){ - return getSelectedNodes(dataTable_groups); -} - -function groupElementArray(group_json){ - var group = group_json.GROUP; - - var users_str = "0"; - - if (group.USERS.ID){ - if ($.isArray(group.USERS.ID)){ - users_str = group.USERS.ID.length; - } else { - users_str = "1"; - } - } - - var vms = '-'; - var memory = '-'; - var cpu = '-'; - - initEmptyQuotas(group); - - if (!$.isEmptyObject(group.VM_QUOTA)){ - - vms = quotaBar( - group.VM_QUOTA.VM.VMS_USED, - group.VM_QUOTA.VM.VMS, - default_group_quotas.VM_QUOTA.VM.VMS); - - memory = quotaBarMB( - group.VM_QUOTA.VM.MEMORY_USED, - group.VM_QUOTA.VM.MEMORY, - default_group_quotas.VM_QUOTA.VM.MEMORY); - - cpu = quotaBarFloat( - group.VM_QUOTA.VM.CPU_USED, - group.VM_QUOTA.VM.CPU, - default_group_quotas.VM_QUOTA.VM.CPU); - } - - return [ - '', - group.ID, - group.NAME, - users_str, - vms, - memory, - cpu - ]; -} - -function updateGroupElement(request, group_json){ - var id = group_json.GROUP.ID; - var element = groupElementArray(group_json); - updateSingleElement(element,dataTable_groups,'#group_'+id); - //No need to update select as all items are in it always -} - -function deleteGroupElement(request){ - deleteElement(dataTable_groups,'#group_'+request.request.data); -} - -function addGroupElement(request,group_json){ - var id = group_json.GROUP.ID; - var element = groupElementArray(group_json); - addElement(element,dataTable_groups); -} - -//updates the list -function updateGroupsView(request, group_list, quotas_hash){ - group_list_json = group_list; - var group_list_array = []; - - $.each(group_list,function(){ - // Inject the VM group quota. This info is returned separately in the - // pool info call, but the groupElementArray expects it inside the GROUP, - // as it is returned by the individual info call - var q = quotas_hash[this.GROUP.ID]; - - if (q != undefined) { - this.GROUP.VM_QUOTA = q.QUOTAS.VM_QUOTA; - } - - group_list_array.push(groupElementArray(this)); - }); - updateView(group_list_array,dataTable_groups); - - // Dashboard info - $(".total_groups").text(group_list.length); -} - -function generateUserViewsTableFromInfo(admin_views, user_views, default_admin_view, default_user_view) { - var html = ""; - - html += ''; - - if (admin_views) { - html += ''+ - ''+ - ''; - - $.each(admin_views.split(','), function(index, view){ - html += '' + - ''+ - ''; - }) - } - - if (user_views) { - html += ''+ - ''+ - ''; - - $.each(user_views.split(','), function(index, view){ - html += '' + - ''+ - ''; - }) - } - - html += '
'+tr("Group Admins Views")+'
'+ - (views_info[view] ? views_info[view].name : view) + - (view == default_admin_view ? ' (' + tr("default") + ') ': '') + - (views_info[view] ? - '' + views_info[view].description + '' - : "") - '
'+tr("Group Users Views")+'
'+ - (views_info[view] ? views_info[view].name : view) + - (view == default_user_view ? ' (' + tr("default") + ') ': '') + - (views_info[view] ? - '' + views_info[view].description + '' - : "") - '
'; - - return html; -} - -function updateGroupInfo(request,group){ - var info = group.GROUP; - - $(".resource-info-header", $("#groups-tab")).html(info.NAME); - - - var admin_views = info.TEMPLATE.GROUP_ADMIN_VIEWS; - delete info.TEMPLATE.GROUP_ADMIN_VIEWS; - var user_views = info.TEMPLATE.SUNSTONE_VIEWS; - delete info.TEMPLATE.SUNSTONE_VIEWS; - var default_admin_view = info.TEMPLATE.GROUP_ADMIN_DEFAULT_VIEW; - delete info.TEMPLATE.GROUP_ADMIN_DEFAULT_VIEW; - var default_user_view = info.TEMPLATE.DEFAULT_VIEW; - delete info.TEMPLATE.DEFAULT_VIEW; - - var info_tab = { - title: tr("Info"), - icon: "fa-info-circle", - content: - '
\ -
\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
'+tr("Information")+'
'+tr("ID")+''+info.ID+'
'+tr("Name")+''+info.NAME+'
\ -
\ -
' + - generateUserViewsTableFromInfo(admin_views, user_views, default_admin_view, default_user_view)+ - '
\ -
\ -
\ -
'+ - insert_extended_template_table(info.TEMPLATE, - "Group", - info.ID, - tr("Attributes"), - {GROUP_ADMIN_VIEWS: admin_views, - SUNSTONE_VIEWS: user_views, - GROUP_ADMIN_DEFAULT_VIEW: default_admin_view, - DEFAULT_VIEW: default_user_view}) + - '
\ -
' - } - - var users_tab = { - title : tr("Users"), - icon: "fa-users", - content: group_users_tab_content(info) - }; - - var default_group_quotas = Quotas.default_quotas(info.DEFAULT_GROUP_QUOTAS); - - var quotas_html = initQuotasPanel(info, default_group_quotas, - "#group_info_panel", - Config.isTabActionEnabled("groups-tab", "Group.quotas_dialog")); - - var quotas_tab = { - title : tr("Quotas"), - icon: "fa-align-left", - content : quotas_html - }; - - var accounting_tab = { - title: tr("Accounting"), - icon: "fa-bar-chart-o", - content: '
' - }; - - - Sunstone.updateInfoPanelTab("group_info_panel","group_info_tab",info_tab); - Sunstone.updateInfoPanelTab("group_info_panel","group_users_tab",users_tab); - Sunstone.updateInfoPanelTab("group_info_panel","group_quotas_tab",quotas_tab); - Sunstone.updateInfoPanelTab("group_info_panel","group_accounting_tab",accounting_tab); - - if (Config.isFeatureEnabled("showback")) { - var showback_tab = { - title: tr("Showback"), - icon: "fa-money", - content: '
' - }; - - Sunstone.updateInfoPanelTab("group_info_panel","group_showback_tab",showback_tab); - } - - Sunstone.popUpInfoPanel("group_info_panel", 'groups-tab'); - - setup_group_users_tab_content(info); - - if (Config.isFeatureEnabled("showback")) { - showbackGraphs( - $("#group_showback","#group_info_panel"), - { fixed_user: "", fixed_group: info.ID }); - } - - $("#add_rp_button", $("#group_info_panel")).click(function(){ - initUpdateGroupDialog(); - - return false; - }); - - accountingGraphs( - $("#group_accounting","#group_info_panel"), - { fixed_group: info.ID, - init_group_by: "user" }); - - setupQuotasPanel(info, - "#group_info_panel", - Config.isTabActionEnabled("groups-tab", "Group.quotas_dialog"), - "Group"); -} - -function group_users_tab_content(group_info){ - - var html = ""; - - if (Config.isTabActionEnabled("groups-tab", "Group.edit_admins")) { - html += - '
\ -
\ - \ - \ - \ - \ - \ -
\ -
'; - } - - html += '
\ - '+generateUserTableSelect("group_users_list")+'\ -
'; - - return html; -} - -function setup_group_users_tab_content(group_info){ - - var users = []; - - if (group_info.USERS.ID != undefined){ - users = group_info.USERS.ID; - - if (!$.isArray(users)){ - users = [users]; - } - } - - var admins = []; - - if (group_info.ADMINS.ID != undefined){ - admins = group_info.ADMINS.ID; - - if (!$.isArray(admins)){ - admins = [admins]; - } - } - - var opts = { - read_only: true, - fixed_ids: users, - admin_ids: admins - } - - setupUserTableSelect($("#group_info_panel"), "group_users_list", opts); - - refreshUserTableSelect($("#group_info_panel"), "group_users_list"); - - if (Config.isTabActionEnabled("groups-tab", "Group.edit_admins")) { - $("#group_info_panel").off("click", "#edit_admins_button"); - $("#group_info_panel").on("click", "#edit_admins_button", function() { - $("#edit_admins_button", "#group_info_panel").hide(); - $("#cancel_admins_button", "#group_info_panel").show(); - $("#submit_admins_button", "#group_info_panel").show(); - - $("#group_info_panel div.group_users_info_table").html( - generateUserTableSelect("group_users_edit_list") ); - - - var opts = { - multiple_choice: true, - fixed_ids: users, - admin_ids: admins - } - - setupUserTableSelect($("#group_info_panel"), "group_users_edit_list", opts); - - selectUserTableSelect($("#group_info_panel"), "group_users_edit_list", { ids : admins }); - - return false; - }); - - $("#group_info_panel").off("click", "#cancel_admins_button"); - $("#group_info_panel").on("click", "#cancel_admins_button", function() { - Sunstone.runAction("Group.show", group_info.ID); - return false; - }); - - $("#group_info_panel").off("click", "#submit_admins_button"); - $("#group_info_panel").on("click", "#submit_admins_button", function() { - // Add/delete admins - - var selected_admins_list = retrieveUserTableSelect( - $("#group_info_panel"), "group_users_edit_list"); - - $.each(selected_admins_list, function(i,admin_id){ - if (admins.indexOf(admin_id) == -1){ - Sunstone.runAction("Group.add_admin", - group_info.ID, {admin_id : admin_id}); - } - }); - - $.each(admins, function(i,admin_id){ - if (selected_admins_list.indexOf(admin_id) == -1){ - Sunstone.runAction("Group.del_admin", - group_info.ID, {admin_id : admin_id}); - } - }); - - return false; - }); - } - - -} - -function disableAdminUser(dialog){ - $('#username',dialog).attr('disabled','disabled'); - $('#pass',dialog).attr('disabled','disabled'); - $('#driver',dialog).attr('disabled','disabled'); - $('#custom_auth',dialog).attr('disabled','disabled'); -}; - -function enableAdminUser(dialog){ - $('#username',dialog).removeAttr("disabled"); - $('#pass',dialog).removeAttr("disabled"); - $('#driver',dialog).removeAttr("disabled"); - $('#custom_auth',dialog).removeAttr("disabled"); -}; - - -function generateUserViewsSelect(dialog, value) { - var views = []; - var old_value = $("#user_view_default").val(); - - $(".user_view_input:checked", dialog).each(function(){ - views.push({ - value: this.value, - name: (views_info[this.value] ? views_info[this.value].name : this.value)}); - }); - - $(".user_view_default_container", dialog).html( - generateValueSelect({ - id: 'user_view_default', - label: tr("Default Users View"), - options: views, - custom: false - })) - - $("#user_view_default", dialog).val(value ? value : old_value).change(); -}; - -function generateAdminViewsSelect(dialog, value) { - var views = []; - var old_value = value || $("#admin_view_default").val(); - - $(".admin_view_input:checked", dialog).each(function(){ - views.push({ - value: this.value, - name: (views_info[this.value] ? views_info[this.value].name : this.value)}); - }); - - $(".admin_view_default_container", dialog).html( - generateValueSelect({ - id: 'admin_view_default', - label: tr("Default Admins View"), - options: views, - custom: false - })) - - if (old_value) { - $("#admin_view_default", dialog).val(old_value).change(); - } -}; - -//Prepares the dialog to create -function setupCreateGroupDialog(){ - dialogs_context.append('
'); - $create_group_dialog = $('#create_group_dialog',dialogs_context); - var dialog = $create_group_dialog; - - dialog.html(create_group_tmpl('create')); - dialog.addClass("reveal-modal large max-height").attr("data-reveal", ""); - $(document).foundation(); - - // Hide update buttons - $('#update_group_submit',$create_group_dialog).hide(); - $('#update_group_header',$create_group_dialog).hide(); - - setupTips($create_group_dialog); - - $('#create_group_reset_button').click(function(){ - $create_group_dialog.html(""); - setupCreateGroupDialog(); - - popUpCreateGroupDialog(); - }); - - setupCustomAuthDialog(dialog); - - $('input#name', dialog).change(function(){ - var val = $(this).val(); - var dialog = $create_group_dialog; - - $('#username',dialog).val(val + "-admin"); - }); - - $('input#admin_user', dialog).change(function(){ - var dialog = $create_group_dialog; - if ($(this).prop('checked')) { - enableAdminUser(dialog); - } else { - disableAdminUser(dialog); - } - }); - - disableAdminUser(dialog); - - $.each($('[id^="group_res"]', dialog), function(){ - $(this).prop("checked", true); - }); - - $("#group_res_net", dialog).prop("checked", false); - - generateAdminViewsSelect(dialog, "groupadmin"); - $(dialog).off("change", ".admin_view_input"); - $(dialog).on("change", ".admin_view_input", function(){ - generateAdminViewsSelect(dialog); - }) - - generateUserViewsSelect(dialog, "cloud") - $(dialog).off("change", ".user_view_input") - $(dialog).on("change", ".user_view_input", function(){ - generateUserViewsSelect(dialog) - }) - - $('#create_group_form',dialog).submit(function(){ - var name = $('#name',this).val(); - - var user_json = null; - - if ( $('#admin_user', this).prop('checked') ){ - user_json = buildUserJSON(this); // from users-tab.js - - if (!user_json) { - notifyError(tr("User name and password must be filled in")); - return false; - } - } - - var group_json = { - "group" : { - "name" : name - } - }; - - if (user_json){ - group_json["group"]["group_admin"] = user_json["user"]; - } - - var resources = ""; - var separator = ""; - - $.each($('[id^="group_res"]:checked', dialog), function(){ - resources += (separator + $(this).val()); - separator = "+"; - }); - - group_json['group']['resources'] = resources; - - if ( $('#shared_resources', this).prop('checked') ){ - group_json['group']['shared_resources'] = "VM+DOCUMENT"; - } - - group_json['group']['views'] = []; - - $.each($('[id^="group_view"]:checked', dialog), function(){ - group_json['group']['views'].push($(this).val()); - }); - - var default_view = $('#user_view_default', dialog).val(); - if (default_view != undefined){ - group_json['group']['default_view'] = default_view; - } - - group_json['group']['admin_views'] = []; - - $.each($('[id^="group_admin_view"]:checked', dialog), function(){ - group_json['group']['admin_views'].push($(this).val()); - }); - - var default_view = $('#admin_view_default', dialog).val(); - if (default_view != undefined){ - group_json['group']['default_admin_view'] = default_view; - } - - Sunstone.runAction("Group.create",group_json); - return false; - }); -} - -function popUpCreateGroupDialog(){ - $create_group_dialog.foundation().foundation('reveal', 'open'); - $("input#name",$create_group_dialog).focus(); -} - -//Prepares the dialog to update -function setupUpdateGroupDialog(){ - if (typeof($update_group_dialog) !== "undefined"){ - $update_group_dialog.html(""); - } - - dialogs_context.append('
'); - $update_group_dialog = $('#update_group_dialog',dialogs_context); - var dialog = $update_group_dialog; - - dialog.html(create_group_tmpl('update')); - dialog.addClass("reveal-modal large max-height").attr("data-reveal", ""); - $(document).foundation(); - - setupTips($update_group_dialog); - - // Hide create button - $('#default_vdc_warning',$update_group_dialog).hide(); - $('#create_group_submit',$update_group_dialog).hide(); - $('#create_group_header',$update_group_dialog).hide(); - $('#create_group_reset_button',$update_group_dialog).hide(); - - // Disable parts of the wizard - $("input#name", dialog).attr("disabled", "disabled"); - - $("a[href='#administrators']", dialog).parents("dd").hide(); - $("a[href='#resource_creation']", dialog).parents("dd").hide(); - - $(dialog).off("change", ".admin_view_input") - $(dialog).on("change", ".admin_view_input", function(){ - generateAdminViewsSelect(dialog); - }) - - $(dialog).off("change", ".user_view_input") - $(dialog).on("change", ".user_view_input", function(){ - generateUserViewsSelect(dialog) - }) - - $update_group_dialog.foundation(); -} - -function initUpdateGroupDialog(){ - var selected_nodes = getSelectedNodes(dataTable_groups); - - if ( selected_nodes.length != 1 ) - { - notifyMessage("Please select one (and just one) group to update."); - return false; - } - - // Get proper id - var group_id = ""+selected_nodes[0]; - - setupUpdateGroupDialog(); - - Sunstone.runAction("Group.show_to_update", group_id); -} - -function popUpUpdateGroupDialog(group, dialog) -{ - var dialog = $update_group_dialog; - - dialog.foundation('reveal', 'open'); - - $("input#name",$update_group_dialog).val(group.NAME); - - var views_str = ""; - - $('input[id^="group_view"]', dialog).removeAttr('checked'); - - if (group.TEMPLATE.SUNSTONE_VIEWS){ - views_str = group.TEMPLATE.SUNSTONE_VIEWS; - - var views = views_str.split(","); - $.each(views, function(){ - $('input[id^="group_view"][value="'+this.trim()+'"]', - dialog).attr('checked','checked').change(); - }); - } - - $('input[id^="group_default_view"]', dialog).removeAttr('checked'); - - if (group.TEMPLATE.DEFAULT_VIEW){ - $('#user_view_default', dialog).val(group.TEMPLATE.DEFAULT_VIEW.trim()).change(); - } else { - $('#user_view_default', dialog).val("").change(); - } - - $('input[id^="group_admin_view"]', dialog).removeAttr('checked'); - - if (group.TEMPLATE.GROUP_ADMIN_VIEWS){ - views_str = group.TEMPLATE.GROUP_ADMIN_VIEWS; - - var views = views_str.split(","); - $.each(views, function(){ - $('input[id^="group_admin_view"][value="'+this.trim()+'"]', - dialog).attr('checked','checked').change(); - }); - } - - $('input[id^="group_default_admin_view"]', dialog).removeAttr('checked'); - - if (group.TEMPLATE.GROUP_ADMIN_DEFAULT_VIEW){ - $('#admin_view_default', dialog).val(group.TEMPLATE.GROUP_ADMIN_DEFAULT_VIEW.trim()).change(); - } else { - $('#admin_view_default', dialog).val("").change(); - } - - $(dialog).off("click", 'button#update_group_submit'); - $(dialog).on("click", 'button#update_group_submit', function(){ - - // Update Views - //------------------------------------- - var template_json = group.TEMPLATE; - - delete template_json["SUNSTONE_VIEWS"]; - delete template_json["DEFAULT_VIEW"]; - delete template_json["GROUP_ADMIN_VIEWS"]; - delete template_json["GROUP_ADMIN_DEFAULT_VIEW"]; - - var views = []; - - $.each($('[id^="group_view"]:checked', dialog), function(){ - views.push($(this).val()); - }); - - if (views.length != 0){ - template_json["SUNSTONE_VIEWS"] = views.join(","); - } - - var default_view = $('#user_view_default', dialog).val(); - - if (default_view != undefined){ - template_json["DEFAULT_VIEW"] = default_view; - } - - var admin_views = []; - - $.each($('[id^="group_admin_view"]:checked', dialog), function(){ - admin_views.push($(this).val()); - }); - - if (admin_views.length != 0){ - template_json["GROUP_ADMIN_VIEWS"] = admin_views.join(","); - } - - var default_admin_view = $('#admin_view_default', dialog).val(); - - if (default_admin_view != undefined){ - template_json["GROUP_ADMIN_DEFAULT_VIEW"] = default_admin_view; - } - - var template_str = convert_template_to_string(template_json); - - Sunstone.runAction("Group.update_template",group.ID,template_str); - - // Close the dialog - //------------------------------------- - - dialog.foundation('reveal', 'close'); - - return false; - }); - -} - -// Add groups quotas dialog and calls common setup() in sunstone utils. -function setupGroupQuotasDialog(){ - dialogs_context.append('
'); - $group_quotas_dialog = $('#group_quotas_dialog',dialogs_context); - var dialog = $group_quotas_dialog; - dialog.html(group_quotas_tmpl()); - - setupQuotasDialog(dialog); -} - -function popUpGroupQuotasDialog(){ - var tab = dataTable_groups.parents(".tab"); - if (Sunstone.rightInfoVisible(tab)) { - $('a[href="#group_quotas_tab"]', tab).click(); - $('#edit_quotas_button', tab).click(); - } else { - popUpQuotasDialog( - $group_quotas_dialog, - 'Group', - groupElements(), - default_group_quotas, - "#group_quotas_dialog"); - } -} - -$(document).ready(function(){ - var tab_name = 'groups-tab'; - - if (Config.isTabEnabled(tab_name)) { - dataTable_groups = $("#datatable_groups",main_tabs_context).dataTable({ - "bSortClasses" : false, - "bAutoWidth": false, - "bDeferRender": true, - "aoColumnDefs": [ - { "bSortable": false, "aTargets": ["check",4,5,6] }, - { "sWidth": "35px", "aTargets": [0] }, - { "sWidth": "150px", "aTargets": [4,5,6] }, - { "bVisible": true, "aTargets": Config.tabTableColumns(tab_name)}, - { "bVisible": false, "aTargets": ['_all']} - ] - }); - - $('#group_search').keyup(function(){ - dataTable_groups.fnFilter( $(this).val() ); - }) - - dataTable_groups.on('draw', function(){ - recountCheckboxes(dataTable_groups); - }) - - Sunstone.runAction("Group.list"); - setupCreateGroupDialog(); - setupGroupQuotasDialog(); - - initCheckAllBoxes(dataTable_groups); - tableCheckboxesListener(dataTable_groups); - infoListener(dataTable_groups, 'Group.show'); - - $('div#groups_tab div.legend_div').hide(); - $('div#groups_tab_non_admin div.legend_div').hide(); - - dataTable_groups.fnSort( [ [1,config['user_config']['table_order']] ] ); - } -}) diff --git a/src/sunstone/public/js/plugins/hosts-tab.js b/src/sunstone/public/js/plugins/hosts-tab.js deleted file mode 100644 index 1e34bd34a5..0000000000 --- a/src/sunstone/public/js/plugins/hosts-tab.js +++ /dev/null @@ -1,2033 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2002-2015, 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. */ -/* -------------------------------------------------------------------------- */ - -/*Host tab plugin*/ -/* HOST_HISTORY_LENGTH is ignored by server */ -var HOST_HISTORY_LENGTH = 40; - -var create_host_tmpl = -'
\ -
\ -

'+tr("Create Host")+'

\ -
\ -
\ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ - \ -
\ -
\ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ -
\ -
\ - '+tr("Drivers")+'\ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ -
\ -
\ - \ -
\ -
\ - \ - \ -
\ -
\ -
\ -×'; - -var dataTable_hosts; -var $create_host_dialog; -var on_hosts = 0; -var off_hosts = 0; -var error_hosts = 0; - - -//Setup actions -var host_actions = { - - "Host.create" : { - type: "create", - call : OpenNebula.Host.create, - callback : function(request, response) { - // Reset the create wizard - addHostElement(request, response); - notifyCustom(tr("Host created"), " ID: " + response.HOST.ID, false); - - if (request.request.data[0].host.vm_mad != "vcenter") { - $create_host_dialog.foundation('reveal', 'close'); - } - }, - error : onError - }, - - "Host.create_dialog" : { - type: "custom", - call: popUpCreateHostDialog - }, - - "Host.list" : { - type: "list", - call: OpenNebula.Host.list, - callback: updateHostsView, - error: onError - }, - - "Host.show" : { - type: "single", - call: OpenNebula.Host.show, - callback: function(request, response) { - updateHostElement(request, response); - if (Sunstone.rightInfoVisible($("#hosts-tab"))) { - updateHostInfo(request, response); - $(".right-info-tabs > dd.active > a", "#hosts-tab").trigger("click"); - } - }, - error: onError - }, - - "Host.refresh" : { - type: "custom", - call: function(){ - var tab = dataTable_hosts.parents(".tab"); - if (Sunstone.rightInfoVisible(tab)) { - Sunstone.runAction("Host.show", Sunstone.rightInfoResourceId(tab)) - } else { - waitingNodes(dataTable_hosts); - Sunstone.runAction("Host.list", {force: true}); - } - }, - error: onError - }, - - "Host.enable" : { - type: "multiple", - call : OpenNebula.Host.enable, - callback : function (req) { - Sunstone.runAction("Host.show",req.request.data[0]); - }, - elements: hostElements, - error : onError - }, - - "Host.disable" : { - type: "multiple", - call : OpenNebula.Host.disable, - callback : function (req) { - Sunstone.runAction("Host.show",req.request.data[0]); - }, - elements: hostElements, - error : onError - }, - - "Host.delete" : { - type: "multiple", - call : OpenNebula.Host.del, - callback : deleteHostElement, - elements: hostElements, - error : onError - }, - - "Host.monitor" : { - type: "monitor", - call : OpenNebula.Host.monitor, - callback: function(req,response) { - var host_graphs = [ - { - monitor_resources : "HOST_SHARE/CPU_USAGE,HOST_SHARE/USED_CPU,HOST_SHARE/MAX_CPU", - labels : tr("Allocated")+","+tr("Real")+","+tr("Total"), - humanize_figures : false, - div_graph : $("#host_cpu_graph"), - div_legend : $("#host_cpu_legend") - }, - { - monitor_resources : "HOST_SHARE/MEM_USAGE,HOST_SHARE/USED_MEM,HOST_SHARE/MAX_MEM", - labels : tr("Allocated")+","+tr("Real")+","+tr("Total"), - humanize_figures : true, - div_graph : $("#host_mem_graph"), - div_legend : $("#host_mem_legend") - } - ]; - - for(var i=0; i', - list_header: ' '+tr("Hosts"), - info_header: ' '+tr("Host"), - subheader: ' '+tr("TOTAL")+' \ - '+tr("ON")+' \ - '+tr("OFF")+' \ - '+tr("ERROR")+'', - table: '\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
' + tr("ID") + '' + tr("Name") + '' + tr("Cluster") + '' + tr("RVMs") + '' + tr("Real CPU") + '' + tr("Allocated CPU") + '' + tr("Real MEM") + '' + tr("Allocated MEM") + '' + tr("Status") + '' + tr("IM MAD") + '' + tr("VM MAD") + '' + tr("Last monitored on") + '
' -}; - -Sunstone.addActions(host_actions); -Sunstone.addMainTab('hosts-tab',hosts_tab); -Sunstone.addInfoPanel("host_info_panel",host_info_panel); - -// return selected elements from hosts datatable -function hostElements(){ - return getSelectedNodes(dataTable_hosts); -} - -function generateCPUProgressBar(host, host_share_flag) { - var host_share = host_share_flag ? host : host.HOST_SHARE; - var max_cpu = parseInt(host_share.MAX_CPU); - - var info_str; - - var pb_allocated_cpu - if (host_share.CPU_USAGE) { - var allocated_cpu = parseInt(host_share.CPU_USAGE); - - if (max_cpu > 0) { - var ratio_allocated_cpu = Math.round((allocated_cpu / max_cpu) * 100); - info_str = allocated_cpu + ' / ' + max_cpu + ' (' + ratio_allocated_cpu + '%)'; - } else { - info_str = ""; - } - - pb_allocated_cpu = quotaBarHtml(allocated_cpu, max_cpu, info_str); - } - - var pb_real_cpu - if (host_share.USED_CPU) { - var real_cpu = parseInt(host_share.USED_CPU); - - if (max_cpu > 0) { - var ratio_real_cpu = Math.round((real_cpu / max_cpu) * 100); - info_str = real_cpu + ' / ' + max_cpu + ' (' + ratio_real_cpu + '%)'; - } else { - info_str = ""; - } - - pb_real_cpu = quotaBarHtml(real_cpu, max_cpu, info_str); - } - - return { - real: pb_real_cpu, - allocated: pb_allocated_cpu - } -} - -function generateMEMProgressBar(host, host_share_flag) { - var host_share = host_share_flag ? host : host.HOST_SHARE; - // Generate MEM progress bars - var max_mem = parseInt(host_share.MAX_MEM); - - var pb_allocated_mem; - if (host_share.MEM_USAGE) { - var allocated_mem = parseInt(host_share.MEM_USAGE); - - if (max_mem > 0) { - var ratio_allocated_mem = Math.round((allocated_mem / max_mem) * 100); - info_str = humanize_size(allocated_mem) + ' / ' + humanize_size(max_mem) + ' (' + ratio_allocated_mem + '%)'; - } else { - info_str = humanize_size(allocated_mem) + ' / -'; - } - - pb_allocated_mem = quotaBarHtml(allocated_mem, max_mem, info_str); - } - - var pb_real_mem; - if (host_share.USED_MEM) { - var real_mem = parseInt(host_share.USED_MEM); - - if (max_mem > 0) { - var ratio_real_mem = Math.round((real_mem / max_mem) * 100); - info_str = humanize_size(real_mem) + ' / ' + humanize_size(max_mem) + ' (' + ratio_real_mem + '%)'; - } else { - info_str = humanize_size(real_mem) + ' / -'; - } - - pb_real_mem = quotaBarHtml(real_mem, max_mem, info_str); - } - - return { - real: pb_real_mem, - allocated: pb_allocated_mem - } -} - -//Creates an array to be added to the dataTable from the JSON of a host. -function hostElementArray(host_json){ - var host = host_json.HOST; - - var cpu_bars = generateCPUProgressBar(host); - var mem_bars = generateMEMProgressBar(host); - - var state_simple = OpenNebula.Helper.resource_state("host_simple",host.STATE); - switch (state_simple) { - case tr("INIT"): - case tr("UPDATE"): - case tr("ON"): - on_hosts++; - break; - case tr("ERROR"): - case tr("RETRY"): - error_hosts++; - break; - case tr("OFF"): - off_hosts++; - break; - default: - break; - } - - return [ - '', - host.ID, - host.NAME, - host.CLUSTER.length ? host.CLUSTER : "-", - host.HOST_SHARE.RUNNING_VMS, //rvm - cpu_bars.real, - cpu_bars.allocated, - mem_bars.real, - mem_bars.allocated, - state_simple, - host.IM_MAD, - host.VM_MAD, - pretty_time(host.LAST_MON_TIME) - ]; -} - -//callback for an action affecting a host element -function updateHostElement(request, host_json){ - var id = host_json.HOST.ID; - var element = hostElementArray(host_json); - updateSingleElement(element,dataTable_hosts,'#host_'+id); -} - -//callback for actions deleting a host element -function deleteHostElement(req){ - deleteElement(dataTable_hosts,'#host_'+req.request.data); -} - -//call back for actions creating a host element -function addHostElement(request,host_json){ - var id = host_json.HOST.ID; - var element = hostElementArray(host_json); - addElement(element,dataTable_hosts); -} - -//callback to update the list of hosts. -function updateHostsView (request,host_list){ - var host_list_array = []; - - on_hosts = 0; - off_hosts = 0; - error_hosts = 0; - - var max_cpu = 0; - var allocated_cpu = 0; - var real_cpu = 0; - - var max_mem = 0; - var allocated_mem = 0; - var real_mem = 0; - - - $.each(host_list,function(){ - //Grab table data from the host_list - host_list_array.push(hostElementArray(this)); - - max_cpu += parseInt(this.HOST.HOST_SHARE.MAX_CPU); - allocated_cpu += parseInt(this.HOST.HOST_SHARE.CPU_USAGE); - real_cpu += parseInt(this.HOST.HOST_SHARE.USED_CPU); - - max_mem += parseInt(this.HOST.HOST_SHARE.MAX_MEM); - allocated_mem += parseInt(this.HOST.HOST_SHARE.MEM_USAGE); - real_mem += parseInt(this.HOST.HOST_SHARE.USED_MEM); - }); - - updateView(host_list_array,dataTable_hosts); - - var ratio_allocated_cpu = 0; - if (max_cpu > 0) { - ratio_allocated_cpu = Math.round((allocated_cpu / max_cpu) * 100); - info_str = allocated_cpu + ' / ' + max_cpu ; - } else { - info_str = "- / -"; - } - - //$("#dash_host_allocated_cpu").html(usageBarHtml(allocated_cpu, max_cpu, info_str, true)); - - $("#dashboard_host_allocated_cpu").html(quotaDashboard( - "dashboard_host_allocated_cpu", - tr("ALLOCATED CPU"), - "30px", - "14px", - {"percentage": ratio_allocated_cpu, "str": info_str }) - ); - - var ratio_real_cpu = 0; - if (max_cpu > 0) { - ratio_real_cpu = Math.round((real_cpu / max_cpu) * 100); - info_str = real_cpu + ' / ' + max_cpu; - } else { - info_str = "- / -"; - } - - //$("#dash_host_real_cpu").html(usageBarHtml(real_cpu, max_cpu, info_str, true)); - - $("#dashboard_host_real_cpu").html(quotaDashboard( - "dashboard_host_real_cpu", - tr("REAL CPU"), - "30px", - "14px", - {"percentage": ratio_real_cpu, "str": info_str }) - ); - - var ratio_allocated_mem = 0; - if (max_mem > 0) { - ratio_allocated_mem = Math.round((allocated_mem / max_mem) * 100); - info_str = humanize_size(allocated_mem) + ' / ' + humanize_size(max_mem); - } else { - info_str = humanize_size(allocated_mem) + ' / -'; - } - - //$("#dash_host_allocated_mem").html(usageBarHtml(allocated_mem, max_mem, info_str, true)); - - $("#dashboard_host_allocated_mem").html(quotaDashboard( - "dashboard_host_allocated_mem", - tr("ALLOCATED MEMORY"), - "30px", - "14px", - {"percentage": ratio_allocated_mem, "str": info_str }) - ); - - var ratio_real_mem = 0; - if (max_mem > 0) { - ratio_real_mem = Math.round((real_mem / max_mem) * 100); - info_str = humanize_size(real_mem) + ' / ' + humanize_size(max_mem); - } else { - info_str = humanize_size(real_mem) + ' / -'; - } - - //$("#dash_host_real_mem").html(usageBarHtml(real_mem, max_mem, info_str, true)); - - $("#dashboard_host_real_mem").html(quotaDashboard( - "dashboard_host_real_mem", - tr("REAL MEMORY"), - "30px", - "14px", - {"percentage": ratio_real_mem, "str": info_str }) - ); - - $(".total_hosts").text(host_list.length); - $(".on_hosts").text(on_hosts); - $(".off_hosts").text(off_hosts); - $(".error_hosts").text(error_hosts); -} - -function insert_datastores_capacity_table(host_share) { - var datastores = [] - if ($.isArray(host_share.DATASTORES.DS)) - datastores = host_share.DATASTORES.DS - else if (!$.isEmptyObject(host_share.DATASTORES.DS)) - datastores = [host_share.DATASTORES.DS] - - var str = ""; - - if (datastores.length) { - str += '\ - \ - \ - \ - \ - \ - \ - '; - - $.each(datastores, function(index, value){ - var pbar = generate_datastore_capacity_bar(value, 1); - - str += '\ - \ - \ - ' - }) - - str += '\ -
' + tr("Datastore ID") + '' + tr("Capacity") + '
' + value.ID + ''+ pbar +'
' - } - - return str; -} - - -//Updates the host info panel tab content and pops it up -function updateHostInfo(request,host){ - var host_info = host.HOST; - - $(".resource-info-header", $("#hosts-tab")).html(host_info.NAME); - - var cpu_bars = generateCPUProgressBar(host_info); - var mem_bars = generateMEMProgressBar(host_info); - - // Get rid of the unwanted (for show) HOST keys - var stripped_host_template = {}; - var unshown_values = {}; - - var hypervisor_name = host_info.TEMPLATE.HYPERVISOR ? host_info.TEMPLATE.HYPERVISOR.toLowerCase() : "-" ; - - can_import_wilds = false; - - if (host_info.TEMPLATE.VM) - { - $.each(host_info.TEMPLATE.VM, function(){ - if (this.IMPORT_TEMPLATE) - { - can_import_wilds = true; - } - }); - } - - - if (!can_import_wilds) - { - stripped_host_template = host_info.TEMPLATE; - } - else - { - for (key in host_info.TEMPLATE) - if(!key.match(/^HOST$/) && !key.match(/^VM$/) && !key.match(/^WILDS$/)) - stripped_host_template[key]=host_info.TEMPLATE[key]; - else - unshown_values[key]=host_info.TEMPLATE[key]; - } - - //Information tab - var info_tab = { - title : tr("Info"), - icon: "fa-info-circle", - content : - '
\ -
\ - \ - \ - \ - \ - \ - \ - \ - \ - '+ - insert_rename_tr( - 'hosts-tab', - "Host", - host_info.ID, - host_info.NAME)+ - '' + - insert_cluster_dropdown("Host",host_info.ID,host_info.CLUSTER,host_info.CLUSTER_ID,"#info_host_table") + - '\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
' + tr("Information") + '
' + tr("id") + ''+host_info.ID+'
' + tr("State") + ''+tr(OpenNebula.Helper.resource_state("host",host_info.STATE))+'
' + tr("IM MAD") + ''+host_info.IM_MAD+'
' + tr("VM MAD") + ''+host_info.VM_MAD+'
'+ tr("VN MAD") +''+host_info.VN_MAD+'
\ -
\ -
\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
' + tr("Capacity") + '
' + tr("Allocated Memory") + ''+mem_bars.allocated+'
' + tr("Allocated CPU") + ''+cpu_bars.allocated+'
' + tr("Real Memory") + ''+mem_bars.real+'
' + tr("Real CPU") + ''+cpu_bars.real+'
' + - insert_datastores_capacity_table(host_info.HOST_SHARE) + - '
\ -
\ -
\ -
' - + insert_extended_template_table(stripped_host_template, - "Host", - host_info.ID, - tr("Attributes"), - unshown_values) + - '
\ -
\ - ' - } - - - var monitor_tab = { - title: tr("Graphs"), - icon: "fa-bar-chart-o", - content: - '
\ -
\ -
\ -

'+tr("CPU")+'

\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -

'+tr("MEMORY")+'

\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -
' - } - - var vms_info_tab = { - title: tr("VMs"), - icon: "fa-cloud", - content : '
\ -
\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
'+tr("ID")+''+tr("Owner")+''+tr("Group")+''+tr("Name")+''+tr("Status")+''+tr("Used CPU")+''+tr("Used Memory")+''+tr("Host")+''+tr("IPs")+''+tr("Start Time")+''+tr("VNC")+'
\ -
\ -
' - } - - var esx_info_tab = { - title: tr("ESX"), - icon: "fa-hdd-o", - content : '
\ -
\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
' + tr("Hostname") + '' + tr("Status") + '' + tr("Real CPU") + '' + tr("Real Memory") + '
\ -
\ -
' - } - - var wilds_info_tab = { - title: tr("WILDS"), - icon: "fa-hdd-o", - content : '
\ -
\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
' + tr("VM name") + '' + tr("Remote ID") + '
\ -
\ -
' - } - - // Add event listener for importing WILDS - $('#import_wilds').die( "click" ); - $('#import_wilds').live('click', function () { - $.each($("#import_wild_checker:checked", "#datatable_host_wilds"), function(){ - var vm_json = { - "vm": { - "vm_raw": $(this).data("wild_template") - } - }; - - var import_host_id = $(this).data("host_id"); - var wild_row = $(this).closest('tr'); - - // Create the VM in OpenNebula - OpenNebula.VM.create({ - timeout: true, - data: vm_json, - success: function(request, response) { - OpenNebula.Helper.clear_cache("VM"); - - var extra_info = {}; - - extra_info['host_id'] = import_host_id; - extra_info['ds_id'] = -1; - extra_info['enforce'] = false; - - // Deploy the VM - Sunstone.runAction("VM.silent_deploy_action", - response.VM.ID, - extra_info); - - // Notify - notifyCustom(tr("VM imported"), " ID: " + response.VM.ID, false); - - // Delete row (shouldn't be there in next monitorization) - dataTable_wilds_hosts = $("#datatable_host_wilds").dataTable(); - dataTable_wilds_hosts.fnDeleteRow(wild_row); - - }, - error: function (request, error_json){ - notifyError(error_json.error.message || tr("Cannot contact server: is it running and reachable?")); - } - }); - }) - }); - - //Sunstone.updateInfoPanelTab(info_panel_name,tab_name, new tab object); - Sunstone.updateInfoPanelTab("host_info_panel","host_info_tab",info_tab); - Sunstone.updateInfoPanelTab("host_info_panel","host_monitoring_tab",monitor_tab); - Sunstone.updateInfoPanelTab("host_info_panel","host_vms_tab",vms_info_tab); - - hypervisor_name = host_info.TEMPLATE.HYPERVISOR ? host_info.TEMPLATE.HYPERVISOR.toLowerCase() : "-"; - - if (hypervisor_name == "vcenter") { - Sunstone.updateInfoPanelTab("host_info_panel","host_esx_tab",esx_info_tab); - } - else - { - Sunstone.removeInfoPanelTab("host_info_panel","host_esx_tab"); - } - - - if (can_import_wilds) { - Sunstone.updateInfoPanelTab("host_info_panel","host_wilds_tab",wilds_info_tab); - } - else - { - Sunstone.removeInfoPanelTab("host_info_panel","host_wilds_tab"); - } - - Sunstone.popUpInfoPanel("host_info_panel", "hosts-tab"); - - if (host_info.TEMPLATE.HYPERVISOR == "vcenter") { - // ESX datatable - var dataTable_esx_hosts = $("#datatable_host_esx",main_tabs_context).dataTable({ - "bSortClasses" : false, - "bDeferRender": true - }); - - var host_list_array = []; - - if (host_info.TEMPLATE.HOST) { - if (!(host_info.TEMPLATE.HOST instanceof Array)) { - host_info.TEMPLATE.HOST = [host_info.TEMPLATE.HOST]; - } - - if (host_info.TEMPLATE.HOST instanceof Array) { - $.each(host_info.TEMPLATE.HOST, function(){ - var cpu_bars = generateCPUProgressBar(this, true); - var mem_bars = generateMEMProgressBar(this, true); - - host_list_array.push([ - this.HOSTNAME, - this.STATE, - cpu_bars.real, - mem_bars.real - ]); - }); - } - - dataTable_esx_hosts.fnAddData(host_list_array); - delete host_info.TEMPLATE.HOST; - } - } - - if (can_import_wilds) { - // WILDS datatable - var dataTable_wilds_hosts = $("#datatable_host_wilds",main_tabs_context).dataTable({ - "bSortClasses" : false, - "bDeferRender": true - }); - - var wilds_list_array = []; - - if (host_info.TEMPLATE.VM) { - wilds = host_info.TEMPLATE.VM; - - $.each(wilds, function(){ - name = this.VM_NAME; - safe_name = name.replace(/ /g,"_").replace(/\./g,"_"); - deploy_id = this.DEPLOY_ID; - - wilds_list_array.push([ - '', - name, - deploy_id - ]); - - dataTable_wilds_hosts.fnAddData(wilds_list_array); - - $(".import_"+safe_name, dataTable_wilds_hosts).data("wild_template", atob(this.IMPORT_TEMPLATE)); - $(".import_"+safe_name, dataTable_wilds_hosts).data("host_id", host_info.ID); - - wilds_list_array = []; - }); - } - - delete host_info.TEMPLATE.WILDS; - delete host_info.TEMPLATE.VM; - } - - var dataTable_host_vMachines = $("#datatable_host_vms", $("#host_info_panel")).dataTable({ - "bSortClasses" : false, - "bDeferRender": true, - "aoColumnDefs": [ - { "bSortable": false, "aTargets": ["check",6,7,11] }, - { "sWidth": "35px", "aTargets": [0] }, - { "bVisible": false, "aTargets": [0]}, - { "bVisible": true, "aTargets": Config.tabTableColumns("vms-tab")}, - { "bVisible": false, "aTargets": ['_all']}, - ] - }); - - infoListener(dataTable_host_vMachines,'VM.show','vms-tab'); - - if (host_info.VMS) { - - var vm_ids = host_info.VMS.ID; - var vm_ids_map = {}; - - if (!(vm_ids instanceof Array)) { - vm_ids = [vm_ids]; - } - - $.each(vm_ids,function(){ - vm_ids_map[this] = true; - }); - - OpenNebula.VM.list({ - timeout: true, - success: function (request, vm_list){ - var vm_list_array = []; - - $.each(vm_list,function(){ - if (vm_ids_map[this.VM.ID]){ - //Grab table data from the vm_list - vm_list_array.push(vMachineElementArray(this)); - } - }); - - updateView(vm_list_array, dataTable_host_vMachines); - }, - error: onError - }); - } - - // TODO: re-use Host.pool_monitor data? - - //pop up panel while we retrieve the graphs - - $("[href='#host_monitoring_tab']").on("click", function(){ - Sunstone.runAction("Host.monitor",host_info.ID, - {monitor_resources : "HOST_SHARE/CPU_USAGE,HOST_SHARE/USED_CPU,HOST_SHARE/MAX_CPU,HOST_SHARE/MEM_USAGE,HOST_SHARE/USED_MEM,HOST_SHARE/MAX_MEM"}); - }); -} - -/* - Retrieve the list of templates from vCenter and fill the container with them - - opts = { - datacenter: "Datacenter Name", - cluster: "Cluster Name", - container: Jquery div to inject the html, - vcenter_user: vCenter Username, - vcenter_password: vCenter Password, - vcenter_host: vCenter Host - } - */ -function fillVCenterTemplates(opts) { - var path = '/vcenter/templates'; - opts.container.html(generateAdvancedSection({ - html_id: path, - title: tr("Templates"), - content: ''+ - ''+ - ''+ - '' - })) - - $('a', opts.container).trigger("click") - - $.ajax({ - url: path, - type: "GET", - data: {timeout: false}, - dataType: "json", - headers: { - "X_VCENTER_USER": opts.vcenter_user, - "X_VCENTER_PASSWORD": opts.vcenter_password, - "X_VCENTER_HOST": opts.vcenter_host - }, - success: function(response){ - $(".content", opts.container).html(""); - - $('
' + - '
' + - '

' + tr("Please select the vCenter Templates to be imported to OpenNebula.") + '

' + - '
' + - '
').appendTo($(".content", opts.container)) - - $.each(response, function(datacenter_name, templates){ - $('
' + - '
' + - '
' + - datacenter_name + ' ' + tr("DataCenter") + - '
' + - '
' + - '
').appendTo($(".content", opts.container)) - - if (templates.length == 0) { - $('
' + - '
' + - '' + - '
' + - '
').appendTo($(".content", opts.container)) - } else { - $.each(templates, function(id, template){ - var trow = $('
' + - '
' + - '
' + - '' + - '
'+ - '
'+ - '
' + - '
'+ - '
'+ - '
'+ - '
').appendTo($(".content", opts.container)) - - $(".template_name", trow).data("template_name", template.name) - $(".template_name", trow).data("one_template", template.one) - }); - }; - }); - }, - error: function(response){ - opts.container.html(""); - onError({}, OpenNebula.Error(response)); - } - }); - - return false; -} - -/* - Retrieve the list of networks from vCenter and fill the container with them - - opts = { - datacenter: "Datacenter Name", - cluster: "Cluster Name", - container: Jquery div to inject the html, - vcenter_user: vCenter Username, - vcenter_password: vCenter Password, - vcenter_host: vCenter Host - } - */ -function fillVCenterNetworks(opts) { - var path = '/vcenter/networks'; - opts.container.html(generateAdvancedSection({ - html_id: path, - title: tr("Networks"), - content: ''+ - ''+ - ''+ - '' - })) - - $('a', opts.container).trigger("click") - - $.ajax({ - url: path, - type: "GET", - data: {timeout: false}, - dataType: "json", - headers: { - "X_VCENTER_USER": opts.vcenter_user, - "X_VCENTER_PASSWORD": opts.vcenter_password, - "X_VCENTER_HOST": opts.vcenter_host - }, - success: function(response){ - $(".content", opts.container).html(""); - - $('
' + - '
' + - '

' + tr("Please select the vCenter Networks to be imported to OpenNebula.") + '

' + - '
' + - '
').appendTo($(".content", opts.container)) - - $.each(response, function(datacenter_name, networks){ - $('
' + - '
' + - '
' + - datacenter_name + ' ' + tr("DataCenter") + - '
' + - '
' + - '
').appendTo($(".content", opts.container)) - - if (networks.length == 0) { - $('
' + - '
' + - '' + - '
' + - '
').appendTo($(".content", opts.container)) - } else { - $.each(networks, function(id, network){ - var netname = network.name.replace(" ","_"); - var vlan_info = "" - - if (network.vlan) - { - var vlan_info = '
' + - '
'+ - ''+ - '
'+ - '
'; - } - - var trow = $('
' + - '
' + - '
' + - '
' + - '' + - '
'+ - '
'+ - '' + - '
'+ - '
'+ - '' + - '
'+ - '
' + - '
'+ - ''+ - '
'+ - '
'+ - vlan_info + - '
'+ - '
'+ - '
' + - '
'+ - '
'+ - '
'+ - '
').appendTo($(".content", opts.container)) - - - $('.type_select', trow).on("change",function(){ - var network_context = $(this).closest(".vcenter_network"); - var type = $(this).val(); - - var net_form_str = '' - - switch(type) { - case 'ETHER': - net_form_str = - '
'+ - ''+ - '
'; - break; - case 'IP4': - net_form_str = - '
'+ - ''+ - '
'+ - '
'+ - ''+ - '
'; - break; - case 'IP6': - net_form_str = - '
'+ - ''+ - '
'+ - '
'+ - ''+ - '
'+ - '
'+ - ''+ - '
'; - break; - } - - $('.net_options', network_context).html(net_form_str); - }); - - $(".network_name", trow).data("network_name", netname) - $(".network_name", trow).data("one_network", network.one) - }); - }; - }); - }, - error: function(response){ - opts.container.html(""); - onError({}, OpenNebula.Error(response)); - } - }); - - return false; -} - -//Prepares the host creation dialog -function setupCreateHostDialog(){ - if ($('#create_host_dialog').length == 0) { - dialogs_context.append('
'); - } - - $('div#create_host_dialog').html(create_host_tmpl); - $create_host_dialog = $('#create_host_dialog'); - - $create_host_dialog.addClass("reveal-modal medium").attr("data-reveal", ""); - $create_host_dialog.foundation() - - $("#wizard_host_reset_button", $create_host_dialog).on("click", function(){ - resetCreateHostDialog(); - }) - - $(".drivers", $create_host_dialog).hide(); - - $("#host_type_mad", $create_host_dialog).on("change", function(){ - $("#vmm_mad", $create_host_dialog).val(this.value).change(); - $("#im_mad", $create_host_dialog).val(this.value).change(); - - if (this.value == "custom") { - $(".vcenter_credentials", $create_host_dialog).hide(); - $("#vnm_mads", $create_host_dialog).show(); - $("#name_container", $create_host_dialog).show(); - $("#create_host_submit", $create_host_dialog).show(); - $(".drivers", $create_host_dialog).show(); - } else if (this.value == "vcenter") { - $("#vnm_mads", $create_host_dialog).hide(); - $("#name_container", $create_host_dialog).hide(); - $(".vcenter_credentials", $create_host_dialog).show(); - $("#create_host_submit", $create_host_dialog).hide(); - $(".drivers", $create_host_dialog).hide(); - } else { - $(".vcenter_credentials", $create_host_dialog).hide(); - $("#vnm_mads", $create_host_dialog).show(); - $("#name_container", $create_host_dialog).show(); - $("#create_host_submit", $create_host_dialog).show(); - $(".drivers", $create_host_dialog).hide(); - } - }) - - $("#get_vcenter_clusters", $create_host_dialog).on("click", function(){ - // TODO notify if credentials empty - var container = $(".vcenter_clusters", $create_host_dialog); - - container.html(generateAdvancedSection({ - html_id: "/vcenter", - title: tr("Clusters"), - content: ''+ - ''+ - ''+ - '' - })) - - $('a', container).trigger("click") - - $.ajax({ - url: 'vcenter', - type: "GET", - data: {timeout: false}, - dataType: "json", - headers: { - "X_VCENTER_USER": $("#vcenter_user", $create_host_dialog).val(), - "X_VCENTER_PASSWORD": $("#vcenter_password", $create_host_dialog).val(), - "X_VCENTER_HOST": $("#vcenter_host", $create_host_dialog).val() - }, - success: function(response){ - $("#vcenter_user", $create_host_dialog).attr("disabled", "disabled") - $("#vcenter_password", $create_host_dialog).attr("disabled", "disabled") - $("#vcenter_host", $create_host_dialog).attr("disabled", "disabled") - $("#get_vcenter_clusters", $create_host_dialog).hide(); - $(".import_vcenter_clusters_div", $create_host_dialog).show(); - - $(".content", container).html(""); - - $('
' + - '
' + - '

' + tr("Please select the vCenter Clusters to be imported to OpenNebula. Each vCenter Cluster will be included as a new OpenNebula Host") + '

' + - '
' + - '
').appendTo($(".content", container)) - - $.each(response, function(datacenter_name, clusters){ - $('
' + - '
' + - '
' + - datacenter_name + ' ' + tr("Datacenter") + - '
' + - '
' + - '
').appendTo($(".content", container)) - - if (clusters.length == 0) { - $('
' + - '
' + - '' + - '
' + - '
').appendTo($(".content", container)) - } else { - $.each(clusters, function(id, cluster_name){ - var row = $('
' + - '
' + - '
' + - '' + - '
'+ - '
'+ - '
' + - '
'+ - '
'+ - '
'+ - '
').appendTo($(".content", container)) - - $(".cluster_name", row).data("cluster_name", cluster_name) - $(".cluster_name", row).data("datacenter_name", datacenter_name) - }); - } - }); - - var templates_container = $(".vcenter_templates", $create_host_dialog); - var vms_container = $(".vcenter_vms", $create_host_dialog); - var networks_container = $(".vcenter_networks", $create_host_dialog); - - var vcenter_user = $("#vcenter_user", $create_host_dialog).val(); - var vcenter_password = $("#vcenter_password", $create_host_dialog).val(); - var vcenter_host = $("#vcenter_host", $create_host_dialog).val(); - - fillVCenterTemplates({ - container: templates_container, - vcenter_user: vcenter_user, - vcenter_password: vcenter_password, - vcenter_host: vcenter_host - }); - - fillVCenterNetworks({ - container: networks_container, - vcenter_user: vcenter_user, - vcenter_password: vcenter_password, - vcenter_host: vcenter_host - }); - }, - error: function(response){ - $(".vcenter_clusters", $create_host_dialog).html('') - onError({}, OpenNebula.Error(response)); - } - }); - - return false; - }) - - - $("#import_vcenter_clusters", $create_host_dialog).on("click", function(){ - $(this).hide(); - - var cluster_id = $('#host_cluster_id .resource_list_select', $create_host_dialog).val(); - if (!cluster_id) cluster_id = "-1"; - - $.each($(".cluster_name:checked", $create_host_dialog), function(){ - var cluster_context = $(this).closest(".vcenter_cluster"); - $(".vcenter_host_result:not(.success)", cluster_context).html(''+ - ''+ - ''+ - ''); - - var host_json = { - "host": { - "name": $(this).data("cluster_name"), - "vm_mad": "vcenter", - "vnm_mad": "dummy", - "im_mad": "vcenter", - "cluster_id": cluster_id - } - }; - - OpenNebula.Host.create({ - timeout: true, - data: host_json, - success: function(request, response) { - OpenNebula.Helper.clear_cache("HOST"); - - $(".vcenter_host_result", cluster_context).addClass("success").html( - ''+ - ''+ - ''+ - ''); - - $(".vcenter_host_response", cluster_context).html('

'+ - tr("Host created successfully")+' ID:'+response.HOST.ID+ - '

'); - - var template_raw = - "VCENTER_USER=\"" + $("#vcenter_user", $create_host_dialog).val() + "\"\n" + - "VCENTER_PASSWORD=\"" + $("#vcenter_password", $create_host_dialog).val() + "\"\n" + - "VCENTER_HOST=\"" + $("#vcenter_host", $create_host_dialog).val() + "\"\n"; - - Sunstone.runAction("Host.update_template", response.HOST.ID, template_raw); - addHostElement(request, response); - }, - error: function (request, error_json){ - $(".vcenter_host_result", $create_host_dialog).html(''+ - ''+ - ''+ - ''); - - $(".vcenter_host_response", $create_host_dialog).html('

'+ - (error_json.error.message || tr("Cannot contact server: is it running and reachable?"))+ - '

'); - } - }); - }) - - $.each($(".template_name:checked", $create_host_dialog), function(){ - var template_context = $(this).closest(".vcenter_template"); - - $(".vcenter_template_result:not(.success)", template_context).html( - ''+ - ''+ - ''+ - ''); - - var template_json = { - "vmtemplate": { - "template_raw": $(this).data("one_template") - } - }; - - OpenNebula.Template.create({ - timeout: true, - data: template_json, - success: function(request, response) { - OpenNebula.Helper.clear_cache("VMTEMPLATE"); - $(".vcenter_template_result", template_context).addClass("success").html( - ''+ - ''+ - ''+ - ''); - - $(".vcenter_template_response", template_context).html('

'+ - tr("Template created successfully")+' ID:'+response.VMTEMPLATE.ID+ - '

'); - }, - error: function (request, error_json){ - $(".vcenter_template_result", template_context).html(''+ - ''+ - ''+ - ''); - - $(".vcenter_template_response", template_context).html('

'+ - (error_json.error.message || tr("Cannot contact server: is it running and reachable?"))+ - '

'); - } - }); - }) - - $.each($(".vm_name:checked", $create_host_dialog), function(){ - var vm_context = $(this).closest(".vcenter_vm"); - - $(".vcenter_vm_result:not(.success)", vm_context).html( - ''+ - ''+ - ''+ - ''); - - var vm_json = { - "vm": { - "vm_raw": $(this).data("one_vm") - } - }; - - var host_id_to_deploy = $(this).data("vm_to_host"); - - OpenNebula.VM.create({ - timeout: true, - data: vm_json, - success: function(request, response) { - OpenNebula.Helper.clear_cache("VM"); - - var extra_info = {}; - - extra_info['host_id'] = host_id_to_deploy; - extra_info['ds_id'] = -1; - extra_info['enforce'] = false; - - Sunstone.runAction("VM.deploy_action", response.VM.ID, extra_info); - - $(".vcenter_vm_result", vm_context).addClass("success").html( - ''+ - ''+ - ''+ - ''); - - $(".vcenter_vm_response", vm_context).html('

'+ - tr("VM imported successfully")+' ID:'+response.VM.ID+ - '

'); - }, - error: function (request, error_json){ - $(".vcenter_vm_response", vm_context).html(''+ - ''+ - ''+ - ''); - - $(".vcenter_vm_response", vm_context).html('

'+ - (error_json.error.message || tr("Cannot contact server: is it running and reachable?"))+ - '

'); - } - }); - }) - - $.each($(".network_name:checked", $create_host_dialog), function(){ - var network_context = $(this).closest(".vcenter_network"); - - $(".vcenter_network_result:not(.success)", network_context).html( - ''+ - ''+ - ''+ - ''); - - var network_size = $(".netsize", network_context).val(); - var network_tmpl = $(this).data("one_network"); - var netname = $(this).data("network_name"); - var type = $('.type_select', network_context).val(); - - var ar_array = []; - ar_array.push("TYPE=" + type); - ar_array.push("SIZE=" + network_size); - - switch(type) { - case 'ETHER': - var mac = $('.eth_mac_net', network_context).val(); - - if (mac){ - ar_array.push("MAC=" + mac); - } - - break; - case 'IP4': - var mac = $('.four_mac_net', network_context).val(); - var ip = $('.four_ip_net', network_context).val(); - - if (mac){ - ar_array.push("MAC=" + mac); - } - if (ip) { - ar_array.push("IP=" + ip); - } - - break; - case 'IP6': - var mac = $('.six_mac_net', network_context).val(); - var gp = $('.six_global_net', network_context).val(); - var ula = $('.six_mac_net', network_context).val(); - - if (mac){ - ar_array.push("MAC=" + mac); - } - if (gp) { - ar_array.push("GLOBAL_PREFIX=" + gp); - } - if (ula){ - ar_array.push("ULA_PREFIX=" + ula); - } - - break; - } - - network_tmpl += "\nAR=[" - network_tmpl += ar_array.join(",\n") - network_tmpl += "]" - - if($(".vlaninfo", network_context)) - { - network_tmpl += "VLAN=\"YES\"\n"; - network_tmpl += "VLAN_ID="+$(".vlaninfo", network_context).val()+"\n"; - } - - var vnet_json = { - "vnet": { - "vnet_raw": network_tmpl - } - }; - - OpenNebula.Network.create({ - timeout: true, - data: vnet_json, - success: function(request, response) { - OpenNebula.Helper.clear_cache("VNET"); - $(".vcenter_network_result", network_context).addClass("success").html( - ''+ - ''+ - ''+ - ''); - - $(".vcenter_network_response", network_context).html('

'+ - tr("Virtual Network created successfully")+' ID:'+response.VNET.ID+ - '

'); - }, - error: function (request, error_json){ - $(".vcenter_network_result", network_context).html(''+ - ''+ - ''+ - ''); - - $(".vcenter_network_response", network_context).html('

'+ - (error_json.error.message || tr("Cannot contact server: is it running and reachable?"))+ - '

'); - } - }); - }); - - return false - }); - - // Show custom driver input only when custom is selected in selects - $('input[name="custom_vmm_mad"],'+ - 'input[name="custom_im_mad"],'+ - 'input[name="custom_vnm_mad"]',$create_host_dialog).parent().hide(); - - $('select#vmm_mad',$create_host_dialog).change(function(){ - if ($(this).val()=="custom") - $('input[name="custom_vmm_mad"]').parent().show(); - else - $('input[name="custom_vmm_mad"]').parent().hide(); - }); - - $('select#im_mad',$create_host_dialog).change(function(){ - if ($(this).val()=="custom") - $('input[name="custom_im_mad"]').parent().show(); - else - $('input[name="custom_im_mad"]').parent().hide(); - }); - - $('select#vnm_mad',$create_host_dialog).change(function(){ - if ($(this).val()=="custom") - $('input[name="custom_vnm_mad"]').parent().show(); - else - $('input[name="custom_vnm_mad"]').parent().hide(); - }); - - $('#create_host_form').on("keyup keypress", function(e) { - var code = e.keyCode || e.which; - if (code == 13) { - e.preventDefault(); - return false; - } - }); - - //Handle the form submission - $('#create_host_form',$create_host_dialog).submit(function(){ - var name = $('#name',this).val(); - if (!name){ - notifyError(tr("Host name missing!")); - return false; - } - - var cluster_id = $('#host_cluster_id .resource_list_select',this).val(); - if (!cluster_id) cluster_id = "-1"; - - var vmm_mad = $('select#vmm_mad',this).val(); - vmm_mad = vmm_mad == "custom" ? $('input[name="custom_vmm_mad"]').val() : vmm_mad; - var im_mad = $('select#im_mad',this).val(); - im_mad = im_mad == "custom" ? $('input[name="custom_im_mad"]').val() : im_mad; - var vnm_mad = $('select#vnm_mad',this).val(); - vnm_mad = vnm_mad == "custom" ? $('input[name="custom_vnm_mad"]').val() : vnm_mad; - - var host_json = { - "host": { - "name": name, - "vm_mad": vmm_mad, - "vnm_mad": vnm_mad, - "im_mad": im_mad, - "cluster_id": cluster_id - } - }; - - //Create the OpenNebula.Host. - //If it is successfull we refresh the list. - Sunstone.runAction("Host.create",host_json); - return false; - }); -} - -function resetCreateHostDialog(){ - $create_host_dialog.empty(); - setupCreateHostDialog(); - - $create_host_dialog = $('div#create_host_dialog'); - - var cluster_id = $('#host_cluster_id .resource_list_select', $create_host_dialog).val(); - if (!cluster_id) cluster_id = "-1"; - - insertSelectOptions('#host_cluster_id', $create_host_dialog, "Cluster", cluster_id, false); - $("input#name", $create_host_dialog).focus(); - return false; -} - -//Open creation dialogs -function popUpCreateHostDialog(){ - resetCreateHostDialog(); - $create_host_dialog.foundation('reveal', 'open'); - return false; -} - -// Call back when individual host history monitoring fails -function hostMonitorError(req,error_json){ - var message = error_json.error.message; - var info = req.request.data[0].monitor; - var labels = info.monitor_resources; - var id_suffix = labels.replace(/,/g,'_'); - var id = '#host_monitor_'+id_suffix; - $('#host_monitoring_tab '+id).html('
'+message+'
'); -} - -//This is executed after the sunstone.js ready() is run. -//Here we can basicly init the host datatable, preload it -//and add specific listeners -$(document).ready(function(){ - var tab_name = 'hosts-tab'; - - if (Config.isTabEnabled(tab_name)) { - //prepare host datatable - dataTable_hosts = $("#datatable_hosts",main_tabs_context).dataTable({ - "bSortClasses" : false, - "bDeferRender": true, - "aoColumnDefs": [ - { "bSortable": false, "aTargets": ["check",5,6,7,8] }, - { "sWidth": "35px", "aTargets": [0] }, //check, ID, RVMS, Status, - { "bVisible": true, "aTargets": Config.tabTableColumns(tab_name)}, - { "bVisible": false, "aTargets": ['_all']} - ] - }); - - $('#hosts_search').keyup(function(){ - dataTable_hosts.fnFilter( $(this).val() ); - }) - - dataTable_hosts.on('draw', function(){ - recountCheckboxes(dataTable_hosts); - }) - - Sunstone.runAction("Host.list"); - - setupCreateHostDialog(); - - initCheckAllBoxes(dataTable_hosts); - tableCheckboxesListener(dataTable_hosts); - infoListener(dataTable_hosts, "Host.show"); - - // This listener removes any filter on hosts table when its menu item is - // selected. The cluster plugins will filter hosts when the hosts - // in a cluster are shown. So we have to make sure no filter has been - // left in place when we want to see all hosts. - $('div#menu li#li_hosts_tab').live('click',function(){ - dataTable_hosts.fnFilter('',3); - }); - - // Hide help - $('div#hosts_tab div.legend_div',main_tabs_context).hide(); - - dataTable_hosts.fnSort( [ [1,config['user_config']['table_order']] ] ); - } -}); diff --git a/src/sunstone/public/js/plugins/images-tab.js b/src/sunstone/public/js/plugins/images-tab.js deleted file mode 100644 index 8fb4c88464..0000000000 --- a/src/sunstone/public/js/plugins/images-tab.js +++ /dev/null @@ -1,1311 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2002-2015, 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. */ -/* -------------------------------------------------------------------------- */ - -/*Images tab plugin*/ - -size_images = 0; - -var create_image_tmpl ='
\ -
\ -

'+tr("Create Image")+'

'+ - '
'+ - '\ -
\ -
\ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ - \ -
\ -
\ -
\ -
'+ - (Config.isTabActionEnabled('images-tab', "Image.persistent") ? - '\ - ' : '') + - '
\ -
\ -
\ -
\ - '+tr("Image location")+':\ -
\ -
\ - \ - \ - \ -
\ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ -

'+tr("Advanced options")+'

\ -
\ -
\ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ -
\ -
\ -
\ - ' + tr("Custom attributes") + '\ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ -
\ -
\ - \ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ -
\ - \ -
\ -
\ -
\ -
\ -
\ -
\ - \ -
\ -
\ -
\ - \ - \ -
\ -
\ -
\ - ×\ - \ -'; - -var dataTable_images; -var $create_image_dialog; - -var image_actions = { - - "Image.create" : { - type: "create", - call: OpenNebula.Image.create, - callback: function(request, response){ - addImageElement(request, response); - $create_image_dialog.foundation('reveal', 'close'); - $create_image_dialog.empty(); - setupCreateImageDialog(); - notifyCustom(tr("Image created"), " ID: " + response.IMAGE.ID, false) - }, - error: onError - }, - - "Image.create_dialog" : { - type: "custom", - call: popUpCreateImageDialog - }, - - "Image.list" : { - type: "list", - call: OpenNebula.Image.list, - callback: updateImagesView, - error: onError - }, - - "Image.show" : { - type : "single", - call: OpenNebula.Image.show, - callback: function(request, response){ - var tab = dataTable_images.parents(".tab"); - - if (Sunstone.rightInfoVisible(tab)) { - // individual view - updateImageInfo(request, response); - } - - // datatable row - updateImageElement(request, response); - }, - error: onError - }, - - "Image.refresh" : { - type: "custom", - call: function () { - var tab = dataTable_images.parents(".tab"); - if (Sunstone.rightInfoVisible(tab)) { - Sunstone.runAction("Image.show", Sunstone.rightInfoResourceId(tab)) - } else { - waitingNodes(dataTable_images); - Sunstone.runAction("Image.list", {force: true}); - } - } - }, - - "Image.update_template" : { - type: "single", - call: OpenNebula.Image.update, - callback: function(request) { - notifyMessage("Template updated correctly"); - Sunstone.runAction('Image.show',request.request.data[0][0]); - }, - error: onError - }, - - "Image.enable" : { - type: "multiple", - call: OpenNebula.Image.enable, - callback: function (req) { - Sunstone.runAction("Image.show",req.request.data[0]); - }, - elements: imageElements, - error: onError, - notify: true - }, - - "Image.disable" : { - type: "multiple", - call: OpenNebula.Image.disable, - callback: function (req) { - Sunstone.runAction("Image.show",req.request.data[0]); - }, - elements: imageElements, - error: onError, - notify: true - }, - - "Image.persistent" : { - type: "multiple", - call: OpenNebula.Image.persistent, - callback: function (req) { - Sunstone.runAction("Image.show",req.request.data[0]); - }, - elements: imageElements, - error: function (req,error_json) { - Sunstone.runAction("Image.show",req.request.data[0]); - onError(req,error_json); - }, - notify: true - }, - - "Image.nonpersistent" : { - type: "multiple", - call: OpenNebula.Image.nonpersistent, - callback: function (req) { - Sunstone.runAction("Image.show",req.request.data[0]); - }, - elements: imageElements, - error: onError, - notify: true - }, - - "Image.delete" : { - type: "multiple", - call: OpenNebula.Image.del, - callback: deleteImageElement, - elements: imageElements, - error: onError, - notify: true - }, - - "Image.chown" : { - type: "multiple", - call: OpenNebula.Image.chown, - callback: function (req) { - Sunstone.runAction("Image.show",req.request.data[0]); - }, - elements: imageElements, - error: onError, - notify: true - }, - - "Image.chgrp" : { - type: "multiple", - call: OpenNebula.Image.chgrp, - callback: function (req) { - Sunstone.runAction("Image.show",req.request.data[0]); - }, - elements: imageElements, - error: onError, - notify: true - }, - - "Image.chmod" : { - type: "single", - call: OpenNebula.Image.chmod, -// callback - error: onError, - notify: true - }, - - "Image.chtype" : { - type: "single", - call: OpenNebula.Image.chtype, - callback: function (req) { - Sunstone.runAction("Image.show",req.request.data[0][0]); - }, - elements: imageElements, - error: onError, - notify: true - }, - "Image.clone_dialog" : { - type: "custom", - call: popUpImageCloneDialog - }, - "Image.clone" : { - type: "single", - call: OpenNebula.Image.clone, - error: onError, - notify: true - }, - "Image.help" : { - type: "custom", - call: function() { - hideDialog(); - $('div#images_tab div.legend_div').slideToggle(); - } - }, - "Image.rename" : { - type: "single", - call: OpenNebula.Image.rename, - callback: function(request) { - notifyMessage(tr("Image renamed correctly")); - Sunstone.runAction('Image.show',request.request.data[0][0]); - }, - error: onError, - notify: true - }, -}; - - -var image_buttons = { - "Image.refresh" : { - type: "action", - layout: "refresh", - alwaysActive: true - }, -// "Sunstone.toggle_top" : { -// type: "custom", -// layout: "top", -// alwaysActive: true -// }, - "Image.create_dialog" : { - type: "create_dialog", - layout: "create" - }, - "Image.chown" : { - type: "confirm_with_select", - text: tr("Change owner"), - layout: "user_select", - select: "User", - tip: tr("Select the new owner")+":", - condition: mustBeAdmin - }, - "Image.chgrp" : { - type: "confirm_with_select", - text: tr("Change group"), - layout: "user_select", - select: "Group", - tip: tr("Select the new group")+":", - condition: mustBeAdmin - }, - "Image.enable" : { - type: "action", - layout: "more_select", - text: tr("Enable") - }, - "Image.disable" : { - type: "action", - layout: "more_select", - text: tr("Disable") - }, - "Image.persistent" : { - type: "action", - layout: "more_select", - text: tr("Make persistent") - }, - "Image.nonpersistent" : { - type: "action", - layout: "more_select", - text: tr("Make non persistent") - }, - "Image.clone_dialog" : { - type: "action", - layout: "main", - text: tr("Clone") - }, - "Image.delete" : { - type: "confirm", - layout: "del", - text: tr("Delete") - }, -} - -var image_info_panel = { - "image_info_tab" : { - title: tr("Information"), - content: "" - } -} - -var images_tab = { - title: tr("Images"), - resource: 'Image', - buttons: image_buttons, - tabClass: 'subTab', - parentTab: 'vresources-tab', - content: '
\ -
\ -
', - search_input: '', - list_header: ' '+tr("Images"), - info_header: ' '+tr("Image"), - subheader: ' '+tr("TOTAL")+' \ - '+tr("USED")+'', - table: '\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
'+tr("ID")+''+tr("Owner")+''+tr("Group")+''+tr("Name")+''+tr("Datastore")+''+tr("Size")+''+tr("Type")+''+tr("Registration time")+''+tr("Persistent")+''+tr("Status")+''+tr("#VMS")+''+tr("Target")+'
' -} - -Sunstone.addActions(image_actions); -Sunstone.addMainTab('images-tab',images_tab); -Sunstone.addInfoPanel('image_info_panel',image_info_panel); - - -function imageElements() { - return getSelectedNodes(dataTable_images); -} - -// Returns an array containing the values of the image_json and ready -// to be inserted in the dataTable -function imageElementArray(image_json){ - //Changing this? It may affect to the is_persistent() functions. - var image = image_json.IMAGE; - - // KERNEL || RAMDISK || CONTEXT - if (image.TYPE == "3" || image.TYPE == "4" || image.TYPE == "5") { - return false; - } - - size_images = size_images + parseInt(image.SIZE); - - //add also persistent/non-persistent selects, type select. - return [ - '', - image.ID, - image.UNAME, - image.GNAME, - image.NAME, - image.DATASTORE, - image.SIZE, - OpenNebula.Helper.image_type(image.TYPE), - pretty_time(image.REGTIME), - parseInt(image.PERSISTENT) ? "yes" : "no", - OpenNebula.Helper.resource_state("image",image.STATE), - image.RUNNING_VMS, - image.TEMPLATE.TARGET ? image.TEMPLATE.TARGET : '--' - ]; -} - -// Callback to update an element in the dataTable -function updateImageElement(request, image_json){ - var id = image_json.IMAGE.ID; - var element = imageElementArray(image_json); - updateSingleElement(element,dataTable_images,'#image_'+id); -} - -// Callback to remove an element from the dataTable -function deleteImageElement(req){ - deleteElement(dataTable_images,'#image_'+req.request.data); -} - -// Callback to add an image element -function addImageElement(request, image_json){ - var element = imageElementArray(image_json); - addElement(element,dataTable_images); -} - -// Callback to refresh the list of images -function updateImagesView(request, images_list){ - var image_list_array = []; - - size_images = 0; - - $.each(images_list,function(){ - var image = imageElementArray(this); - if (image) - image_list_array.push(image); - }); - - updateView(image_list_array,dataTable_images); - - var size = humanize_size_from_mb(size_images) - - $(".total_images").text(image_list_array.length); - $(".size_images").text(size); -} - -// Callback to update the information panel tabs and pop it up -function updateImageInfo(request,img){ - var img_info = img.IMAGE; - - $(".resource-info-header", $("#images-tab")).html(img_info.NAME); - - var info_tab = { - title : tr("Info"), - icon: "fa-info-circle", - content: - '
\ -
\ - \ - \ - \ - \ - \ - \ - \ - \ - '+ - insert_rename_tr( - 'images-tab', - "Image", - img_info.ID, - img_info.NAME)+ - '\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
'+tr("Information")+'
'+tr("ID")+''+img_info.ID+'
'+tr("Datastore")+''+img_info.DATASTORE+'
'+tr("Type")+''+OpenNebula.Helper.image_type(img_info.TYPE)+'
\ - \ -
\ -
'+tr("Register time")+''+pretty_time(img_info.REGTIME)+'
'+tr("Persistent")+''+(parseInt(img_info.PERSISTENT) ? tr("yes") : tr("no"))+'
' + - (Config.isTabActionEnabled('images-tab', "Image.persistent") ? - '' : '') + - '
\ -
'+tr("Filesystem type")+''+(typeof img_info.FSTYPE === "string" ? img_info.FSTYPE : "--")+'
'+tr("Size")+''+humanize_size_from_mb(img_info.SIZE)+'
'+tr("State")+''+OpenNebula.Helper.resource_state("image",img_info.STATE)+'
'+tr("Running VMS")+''+img_info.RUNNING_VMS+'
\ -
\ -
' + - insert_permissions_table('images-tab', - "Image", - img_info.ID, - img_info.UNAME, - img_info.GNAME, - img_info.UID, - img_info.GID) + - '
\ -
\ -
\ -
'+ - insert_extended_template_table(img_info.TEMPLATE, - "Image", - img_info.ID, - tr("Attributes")) + - '
\ -
' - } - - $("#div_edit_chg_type_link").die(); - $("#chg_type_select").die(); - $("#div_edit_persistency").die(); - $("#persistency_select").die(); - - // Listener for edit link for type change - $("#div_edit_chg_type_link").live("click", function() { - $(".value_td_type").html( - ''); - - $('#chg_type_select').val(OpenNebula.Helper.image_type(img_info.TYPE)); - }); - - $("#chg_type_select").live("change", function() { - var new_value = $(this).val(); - - Sunstone.runAction("Image.chtype", img_info.ID, new_value); - }); - - // Listener for edit link for persistency change - $("#div_edit_persistency").live("click", function() { - $(".value_td_persistency").html( - ''); - - $('#persistency_select').val(parseInt(img_info.PERSISTENT) ? "yes" : "no"); - }); - - $("#persistency_select").live("change", function() { - var new_value = $(this).val(); - - if (new_value=="yes") - Sunstone.runAction("Image.persistent",[img_info.ID]); - else - Sunstone.runAction("Image.nonpersistent",[img_info.ID]); - - }); - - - var vms_info_tab = { - title: tr("VMs"), - icon: "fa-cloud", - content : '
\ -
\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
'+tr("ID")+''+tr("Owner")+''+tr("Group")+''+tr("Name")+''+tr("Status")+''+tr("Used CPU")+''+tr("Used Memory")+''+tr("Host")+''+tr("IPs")+''+tr("Start Time")+''+tr("VNC")+'
\ -
\ -
' - } - - Sunstone.updateInfoPanelTab("image_info_panel","image_info_tab",info_tab); - Sunstone.updateInfoPanelTab("image_info_panel","image_vms_tab",vms_info_tab); - Sunstone.popUpInfoPanel("image_info_panel", "images-tab"); - - - dataTable_image_vMachines = $("#datatable_image_vms", $("#image_info_panel")).dataTable({ - "bSortClasses" : false, - "bDeferRender": true, - "aoColumnDefs": [ - { "bSortable": false, "aTargets": ["check",6,7,11] }, - { "sWidth": "35px", "aTargets": [0] }, - { "bVisible": false, "aTargets": [0]}, - { "bVisible": true, "aTargets": Config.tabTableColumns("vms-tab")}, - { "bVisible": false, "aTargets": ['_all']}, - ] - }); - - infoListener(dataTable_image_vMachines,'VM.show','vms-tab'); - - if (img_info.VMS) { - var vm_ids = img_info.VMS.ID; - var vm_ids_map = {}; - - if (!(vm_ids instanceof Array)) { - vm_ids = [vm_ids]; - } - - $.each(vm_ids,function(){ - vm_ids_map[this] = true; - }); - - OpenNebula.VM.list({ - timeout: true, - success: function (request, vm_list){ - var vm_list_array = []; - - $.each(vm_list,function(){ - if (vm_ids_map[this.VM.ID]){ - //Grab table data from the vm_list - vm_list_array.push(vMachineElementArray(this)); - } - }); - - updateView(vm_list_array, dataTable_image_vMachines); - }, - error: onError - }); - } - - setPermissionsTable(img_info,''); -} - -function enable_all_datastores() -{ - - $('select#disk_type').children('option').each(function() { - $(this).removeAttr('disabled'); - }); -} - -// Prepare the image creation dialog -function setupCreateImageDialog(dialog) { - if ($('#create_image_dialog').length == 0) { - dialogs_context.append('
'); - } - - $create_image_dialog = $('#create_image_dialog'); - - var dialog = $create_image_dialog; - dialog.html(create_image_tmpl); - - dialog.addClass("reveal-modal medium").attr("data-reveal", ""); - - initialize_create_image_dialog(dialog); -} - -function initialize_create_image_dialog(dialog) { - setupTips(dialog); - $('.advanced',dialog).hide(); - - $('#advanced_image_create',dialog).click(function(){ - $('.advanced',dialog).toggle(); - return false; - }); - - $('select#img_type',dialog).change(function(){ - var value = $(this).val(); - var context = dialog; - switch (value){ - case "DATABLOCK": - $('#datablock_img',context).removeAttr("disabled"); - break; - default: - $('#datablock_img',context).attr('disabled','disabled'); - $('#path_image',context).click(); - - } - }); - - $('#img_path,#img_fstype,#img_size,#file-uploader',dialog).closest('.row').hide(); - - $("input[name='src_path']", dialog).change(function(){ - var context = dialog; - var value = $(this).val(); - switch (value){ - case "path": - $('#img_fstype,#img_size,#file-uploader',context).closest('.row').hide(); - $('#img_path',context).closest('.row').show(); - break; - case "datablock": - $('#img_path,#file-uploader',context).closest('.row').hide(); - $('#img_fstype,#img_size',context).closest('.row').show(); - break; - case "upload": - $('#img_path,#img_fstype,#img_size',context).closest('.row').hide(); - $('#file-uploader',context).closest('.row').show(); - break; - }; - }); - - - $('#path_image',dialog).click(); - - $('#add_custom_var_image_button', dialog).click( - function(){ - var name = $('#custom_var_image_name',dialog).val(); - var value = $('#custom_var_image_value',dialog).val(); - if (!name.length || !value.length) { - notifyError(tr("Custom attribute name and value must be filled in")); - return false; - } - option= ''; - $('select#custom_var_image_box',dialog).append(option); - return false; - } - ); - - $('#remove_custom_var_image_button', dialog).click( - function(){ - $('select#custom_var_image_box :selected',dialog).remove(); - return false; - } - ); - - $('#upload-progress',dialog).css({ - border: "1px solid #AAAAAA", - position: "relative", - width: "258px", - height: "15px", - display: "inline-block" - }); - $('#upload-progress div',dialog).css("border","1px solid #AAAAAA"); - - var img_obj; - - if (getInternetExplorerVersion() > -1) { - $("#upload_image").attr("disabled", "disabled"); - } else { - var uploader = new Resumable({ - target: 'upload_chunk', - chunkSize: 10*1024*1024, - maxFiles: 1, - testChunks: false, - query: { - csrftoken: csrftoken - } - }); - - uploader.assignBrowse($('#file-uploader-input',dialog)); - - var fileName = ''; - var file_input = false; - - uploader.on('fileAdded', function(file){ - fileName = file.fileName; - file_input = fileName; - - $('#file-uploader-input',dialog).hide() - $("#file-uploader-label", dialog).html(file.fileName); - }); - - uploader.on('uploadStart', function() { - $('#upload_progress_bars').append('
\ -
\ - '+tr("Uploading...")+'\ -
\ -
\ -
\ - \ -
\ -
'+fileName+'
\ -
\ -
'); - }); - - uploader.on('progress', function() { - $('span.meter', $('div[id="'+fileName+'progressBar"]')).css('width', uploader.progress()*100.0+'%') - }); - - uploader.on('fileSuccess', function(file) { - $('div[id="'+fileName+'-info"]').text(tr('Registering in OpenNebula')); - $.ajax({ - url: 'upload', - type: "POST", - data: { - csrftoken: csrftoken, - img : JSON.stringify(img_obj), - file: fileName, - tempfile: file.uniqueIdentifier - }, - success: function(){ - notifyMessage("Image uploaded correctly"); - $('div[id="'+fileName+'progressBar"]').remove(); - Sunstone.runAction("Image.refresh"); - }, - error: function(response){ - onError({}, OpenNebula.Error(response)); - $('div[id="'+fileName+'progressBar"]').remove(); - } - }); - }); - } - - $('#create_image',dialog).submit(function(){ - $create_image_dialog = dialog; - - var exit = false; - var upload = false; - $('.img_man',this).each(function(){ - if (!$('input',this).val().length){ - notifyError(tr("There are mandatory parameters missing")); - exit = true; - return false; - } - }); - if (exit) { return false; } - - var ds_id = $('#img_datastore .resource_list_select',dialog).val(); - if (!ds_id){ - notifyError(tr("Please select a datastore for this image")); - return false; - }; - - var img_json = {}; - - var name = $('#img_name',dialog).val(); - img_json["NAME"] = name; - - var desc = $('#img_desc',dialog).val(); - if (desc.length){ - img_json["DESCRIPTION"] = desc; - } - - var type = $('#img_type',dialog).val(); - img_json["TYPE"]= type; - - img_json["PERSISTENT"] = $('#img_persistent:checked',dialog).length ? "YES" : "NO"; - - var dev_prefix = $('#img_dev_prefix',dialog).val(); - if (dev_prefix.length){ - img_json["DEV_PREFIX"] = dev_prefix; - } - - var driver = $('#img_driver',dialog).val(); - if (driver.length) - img_json["DRIVER"] = driver; - - var target = $('#img_target',dialog).val(); - if (target) - img_json["TARGET"] = target; - - switch ($('#src_path_select input:checked',dialog).val()){ - case "path": - path = $('#img_path',dialog).val(); - if (path) img_json["PATH"] = path; - break; - case "datablock": - size = $('#img_size',dialog).val(); - fstype = $('#img_fstype',dialog).val(); - if (size) img_json["SIZE"] = size; - if (fstype) img_json["FSTYPE"] = fstype; - break; - case "upload": - upload=true; - break; - } - - //Time to add custom attributes - $('#custom_var_image_box option',dialog).each(function(){ - var attr_name = $(this).attr('name'); - var attr_value = $(this).val(); - img_json[attr_name] = attr_value; - }); - - img_obj = { "image" : img_json, - "ds_id" : ds_id}; - - - //we this is an image upload we trigger FileUploader - //to start the upload - if (upload){ - dialog.foundation('reveal', 'close'); - dialog.empty(); - setupCreateImageDialog(); - - //uploader._onInputChange(file_input); - uploader.upload(); - } else { - Sunstone.runAction("Image.create", img_obj); - }; - - return false; - }); - - - $('#create_image_submit_manual',dialog).click(function(){ - var template=$('#template',dialog).val(); - var ds_id = $('#img_datastore_raw .resource_list_select',dialog).val(); - - if (!ds_id){ - notifyError(tr("Please select a datastore for this image")); - return false; - }; - - var img_obj = { - "image" : { - "image_raw" : template - }, - "ds_id" : ds_id - }; - Sunstone.runAction("Image.create",img_obj); - - return false; - }); - - $('#wizard_image_reset_button', dialog).click(function(){ - $('#create_image_dialog').html(""); - setupCreateImageDialog(); - - popUpCreateImageDialog(); - }); - - $('#advanced_image_reset_button', dialog).click(function(){ - $('#create_image_dialog').html(""); - setupCreateImageDialog(); - - popUpCreateImageDialog(); - $("a[href='#img_manual']").click(); - }); -} - -function initialize_datastore_info_create_image_dialog(dialog) { - var ds_id = $('#img_datastore .resource_list_select',dialog).val(); - var ds_id_raw = $('#img_datastore_raw .resource_list_select',dialog).val(); - - // Filter out DS with type system (1) or file (2) - var filter_att = ["TYPE", "TYPE"]; - var filter_val = ["1", "2"]; - - insertSelectOptions('div#img_datastore', dialog, "Datastore", - ds_id, false, null, filter_att, filter_val); - - insertSelectOptions('div#img_datastore_raw', dialog, "Datastore", - ds_id_raw, false, null, filter_att, filter_val); - - $('#file-uploader input',dialog).removeAttr("style"); - $('#file-uploader input',dialog).attr('style','margin:0;width:256px!important'); -} - -function popUpCreateImageDialog(){ - $create_image_dialog = $('#create_image_dialog'); - initialize_datastore_info_create_image_dialog($create_image_dialog); - $create_image_dialog.foundation().foundation('reveal', 'open'); - $("input#img_name",$create_image_dialog).focus(); -} - -function is_persistent_image(id){ - var data = getElementData(id,"#image",dataTable_images)[8]; - return $(data).is(':checked'); -}; - -function setupImageCloneDialog(){ - //Append to DOM - dialogs_context.append('
'); - var dialog = $('#image_clone_dialog',dialogs_context); - - //Put HTML in place - - var html = -'
\ -

'+tr("Clone Image")+'

\ -
\ -
\ -
\ -
\ - \ - \ - \ -
\ -
\ -
\ -
\ -
\ -
'+tr("Advanced options")+'
\ -
\ -
\ -
\ -
\ - '+tr("You can select a different target datastore")+'\ -
\ -
\ -
\ - '+generateDatastoreTableSelect("image_clone")+'\ -
\ -
\ -
\ -
\ - \ -
\ - ×\ -
\ -'; - - dialog.html(html); - dialog.addClass("reveal-modal large").attr("data-reveal", ""); - - // TODO: Show DS with the same ds mad only - setupDatastoreTableSelect(dialog, "image_clone", - { filter_fn: function(ds){ return ds.TYPE == 0; } } - ); - - $('#image_clone_advanced_toggle',dialog).click(function(){ - $('#image_clone_advanced',dialog).toggle(); - return false; - }); - - $('form',dialog).submit(function(){ - var name = $('input[name="image_clone_name"]', this).val(); - var sel_elems = imageElements(); - - if (!name || !sel_elems.length) - notifyError('A name or prefix is needed!'); - - var extra_info = {}; - - if( $("#selected_resource_id_image_clone", dialog).val().length > 0 ){ - extra_info['target_ds'] = - $("#selected_resource_id_image_clone", dialog).val(); - } - - if (sel_elems.length > 1){ - for (var i=0; i< sel_elems.length; i++){ - //If we are cloning several images we - //use the name as prefix - extra_info['name'] = name+getImageName(sel_elems[i]); - Sunstone.runAction('Image.clone', - sel_elems[i], - extra_info); - } - } else { - extra_info['name'] = name; - Sunstone.runAction('Image.clone',sel_elems[0],extra_info) - } - - dialog.foundation('reveal', 'close') - setTimeout(function(){ - Sunstone.runAction('Image.refresh'); - }, 1500); - return false; - }); -} - -function popUpImageCloneDialog(){ - var dialog = $('#image_clone_dialog'); - var sel_elems = imageElements(); - //show different text depending on how many elements are selected - if (sel_elems.length > 1){ - $('.clone_one',dialog).hide(); - $('.clone_several',dialog).show(); - $('input[name="image_clone_name"]',dialog).val('Copy of '); - } - else { - $('.clone_one',dialog).show(); - $('.clone_several',dialog).hide(); - $('input[name="image_clone_name"]',dialog).val('Copy of '+getImageName(sel_elems[0])); - }; - - $('#image_clone_advanced', dialog).hide(); - resetResourceTableSelect(dialog, "image_clone"); - - $(dialog).foundation().foundation('reveal', 'open'); - $("input[name='image_clone_name']",dialog).focus(); -} - -//The DOM is ready at this point -$(document).ready(function(){ - var tab_name = 'images-tab'; - - if (Config.isTabEnabled(tab_name)) { - dataTable_images = $("#datatable_images",main_tabs_context).dataTable({ - "bSortClasses" : false, - "bDeferRender": true, - "aoColumnDefs": [ - { "bSortable": false, "aTargets": ["check"] }, - { "sWidth": "35px", "aTargets": [0] }, - { "bVisible": true, "aTargets": Config.tabTableColumns(tab_name)}, - { "bVisible": false, "aTargets": ['_all']} - ] - }); - - $('#image_search').keyup(function(){ - dataTable_images.fnFilter( $(this).val() ); - }) - - dataTable_images.on('draw', function(){ - recountCheckboxes(dataTable_images); - }) - - Sunstone.runAction("Image.list"); - - setupCreateImageDialog(); - setupImageCloneDialog(); - - initCheckAllBoxes(dataTable_images); - tableCheckboxesListener(dataTable_images); - infoListener(dataTable_images,'Image.show'); - - $('div#images_tab div.legend_div').hide(); - - dataTable_images.fnSort( [ [1,config['user_config']['table_order']] ] ); - } -}); diff --git a/src/sunstone/public/js/plugins/infra-tab.js b/src/sunstone/public/js/plugins/infra-tab.js deleted file mode 100644 index fe5b15cb45..0000000000 --- a/src/sunstone/public/js/plugins/infra-tab.js +++ /dev/null @@ -1,24 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2002-2015, 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. */ -/* -------------------------------------------------------------------------- */ - -var infra_tab = { - title: ' '+tr("Infrastructure"), - no_content: true -} - -Sunstone.addMainTab('infra-tab',infra_tab); - -$(document).ready(function(){}); diff --git a/src/sunstone/public/js/plugins/marketplace-tab.js b/src/sunstone/public/js/plugins/marketplace-tab.js deleted file mode 100644 index 6891831767..0000000000 --- a/src/sunstone/public/js/plugins/marketplace-tab.js +++ /dev/null @@ -1,617 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2010-2015, C12G Labs S.L */ -/* */ -/* 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. */ -/* -------------------------------------------------------------------------- */ - -/* Marketpplace tab plugin */ -var dataTable_marketplace; -var $marketplace_import_dialog; - -var market_actions = { - "Marketplace.list" : { - type: "list", - call: OpenNebula.Marketplace.list, - callback: function(req,res){ - updateView(res.appliances,dataTable_marketplace); - } - }, - "Marketplace.refresh" : { - type: "custom", - call: function () { - var tab = dataTable_marketplace.parents(".tab"); - if (Sunstone.rightInfoVisible(tab)) { - Sunstone.runAction("Marketplace.show", Sunstone.rightInfoResourceId(tab)) - } else { - waitingNodes(dataTable_marketplace); - Sunstone.runAction("Marketplace.list"); - } - } - }, - "Marketplace.import" : { - //fetches images information and fills in the image creation - //dialog with it. - type: "multiple", - elements: marketplaceElements, - call: OpenNebula.Marketplace.show, - callback: function(request,appliance){ - if (appliance['status'] && appliance['status'] != 'ready') { - notifyError(tr("The appliance is not ready")); - return; - } - - if ($('#market_import_dialog',dialogs_context) != undefined) { - $('#market_import_dialog',dialogs_context).remove(); - } - - dialogs_context.append(marketplace_import_dialog); - $marketplace_import_dialog = $('#market_import_dialog',dialogs_context); - $marketplace_import_dialog.addClass("reveal-modal medium").attr("data-reveal", ""); - - //var tab_id = 1; - $('
'+ - '
'+ - '

'+ - tr("The following images will be created in OpenNebula.")+ ' '+ - tr("If you want to edit parameters of the image you can do it later in the images tab")+ ' '+ - '

'+ - '
'+ - '
').appendTo($("#market_import_dialog_content")); - - $('
'+ - '
'+ - '
'+ - ''+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
').appendTo($("#market_import_dialog_content")); - - // Filter out DS with type system (1) or file (2) - var filter_att = ["TYPE", "TYPE"]; - var filter_val = ["1", "2"]; - - insertSelectOptions('div#market_img_datastore', $marketplace_import_dialog, "Datastore", - null, false, null, filter_att, filter_val); - - $.each(appliance['files'], function(index, value){ - $('
'+ - '
'+ - '
'+ - ''+ - ''+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
').appendTo($("#market_import_dialog_content")); - }) - - if (appliance['opennebula_template'] && appliance['opennebula_template'] !== "CPU=1") { - $('
'+ - '
'+ - '
'+ - '

'+ - tr("The following template will be created in OpenNebula and the previous images will be referenced in the disks")+ ' '+ - tr("If you want to edit parameters of the template you can do it later in the templates tab")+ ' '+ - '

'+ - '
'+ - '
').appendTo($("#market_import_dialog_content")); - - $('
'+ - '
'+ - '
'+ - ''+ - ''+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
').appendTo($("#market_import_dialog_content")); - } - - $marketplace_import_dialog.foundation().foundation('reveal', 'open'); - - var images_information = []; - - $("#market_import_form").submit(function(){ - function try_to_create_template(){ - var images_created = $(".market_image_result.success", $marketplace_import_dialog).length; - if ((images_created == number_of_files) && !template_created) { - template_created = true; - - if (appliance['opennebula_template'] && appliance['opennebula_template'] !== "CPU=1") { - var vm_template - try { - vm_template = JSON.parse(appliance['opennebula_template']) - } catch (error) { - $(".market_template_result", template_context).html(''+ - ''+ - ''+ - ''); - - $(".market_template_response", template_context).html('

'+ - (error.message || tr("Cannot contact server: is it running and reachable?"))+ - '

'); - - $("input", template_context).removeAttr("disabled"); - $("button", $marketplace_import_dialog).removeAttr("disabled"); - template_created = false; - return; - } - - if ($.isEmptyObject(vm_template.DISK)) - vm_template.DISK = [] - else if (!$.isArray(vm_template.DISK)) - vm_template.DISK = [vm_template.DISK] - - vm_template.NAME = $("input", template_context).val(); - if (!vm_template.CPU) - vm_template.CPU = "1" - if (!vm_template.MEMORY) - vm_template.MEMORY = "1024" - - $.each(images_information, function(image_index, image_info){ - if (!vm_template.DISK[image_index]) { - vm_template.DISK[image_index] = {} - } - - vm_template.DISK[image_index].IMAGE = image_info.IMAGE.NAME; - vm_template.DISK[image_index].IMAGE_UNAME = image_info.IMAGE.UNAME; - }) - - vm_template.FROM_APP = appliance['_id']["$oid"]; - vm_template.FROM_APP_NAME = appliance['name']; - - OpenNebula.Template.create({ - timeout: true, - data: {vmtemplate: vm_template}, - success: function (request, response){ - $(".market_template_result", template_context).addClass("success").html(''+ - ''+ - ''+ - ''); - - $(".market_template_response", template_context).html('

'+ - tr("Template created successfully")+' ID:'+response.VMTEMPLATE.ID+ - '

'); - - $("button", $marketplace_import_dialog).hide(); - }, - error: function (request, error_json){ - $(".market_template_result", template_context).html(''+ - ''+ - ''+ - ''); - - $(".market_template_response", template_context).html('

'+ - (error_json.error.message || tr("Cannot contact server: is it running and reachable?"))+ - '

'); - - $("input", template_context).removeAttr("disabled"); - $("button", $marketplace_import_dialog).removeAttr("disabled"); - template_created = false; - } - }); - } else { - $("button", $marketplace_import_dialog).hide(); - } - }; - } - - var number_of_files = appliance['files'].length; - var template_created = false; - - $("input, button", $marketplace_import_dialog).attr("disabled", "disabled"); - $(".market_image_result:not(.success)", $marketplace_import_dialog).html(''+ - ''+ - ''+ - ''); - $(".market_template_result", $marketplace_import_dialog).html(''+ - ''+ - ''+ - ''); - - var template_context = $("#market_import_file_template", $marketplace_import_dialog); - - $.each(appliance['files'], function(index, value){ - var context = $("#market_import_file_"+index, $marketplace_import_dialog); - - if ($(".market_image_result:not(.success)", context).length > 0) { - img_obj = { - "image" : { - "NAME": $("input.name",context).val(), - "PATH": appliance['links']['download']['href']+'/'+index, - "TYPE": value['type'], - "MD5": value['md5'], - "SHA1": value['sha1'], - "TYPE": value['type'], - "DRIVER": value['driver'], - "DEV_PREFIX": value['dev_prefix'], - "FROM_APP": appliance['_id']["$oid"], - "FROM_APP_NAME": appliance['name'], - "FROM_APP_FILE": index - }, - "ds_id" : $("#market_img_datastore select", $marketplace_import_dialog).val() - }; - - OpenNebula.Image.create({ - timeout: true, - data: img_obj, - success: function (file_index, file_context){ - return function(request, response) { - $(".market_image_result", file_context).addClass("success").html(''+ - ''+ - ''+ - ''); - - $(".market_image_response", file_context).html('

'+ - tr("Image created successfully")+' ID:'+response.IMAGE.ID+ - '

'); - - images_information[file_index] = response; - - try_to_create_template(); - }; - }(index, context), - error: function (request, error_json){ - $(".market_template_result", template_context).html(''); - - $(".market_image_result", context).html(''+ - ''+ - ''+ - ''); - - $(".market_image_response", context).html('

'+ - (error_json.error.message || tr("Cannot contact server: is it running and reachable?"))+ - '

'); - - $("input", template_context).removeAttr("disabled"); - $("input", context).removeAttr("disabled"); - $("button", $marketplace_import_dialog).removeAttr("disabled"); - } - }); - } - }); - - try_to_create_template(); - - return false; - }) - }, - error: onError - }, - - "Marketplace.show" : { - type: "single", - call: OpenNebula.Marketplace.show, - callback: function(request, response) { -// updateMarketElement(request, response); - if (Sunstone.rightInfoVisible($("#marketplace-tab"))) { - updateMarketInfo(request, response); - } - }, - error: onError - } -} - -var market_buttons = { - "Marketplace.refresh" : { - type: "action", - layout: "refresh", - text: '', - alwaysActive: true - }, - "Marketplace.import" : { - type: "action", - layout: "main", - text: tr('Import') - } -}; - -var marketplace_import_dialog = -'
'+ - '
'+ - '
'+ - '

'+tr("Import Appliance")+'

'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - ''+ - '
'+ - '
'+ - '×'+ -'
'; - - -var marketplace_tab = { - title: ' ' + tr("Marketplace"), - buttons: market_buttons, - search_input: '', - list_header: ' '+tr("OpenNebula Marketplace"), - info_header: ' '+tr("Appliance"), - subheader: '  ', - content: '', - table: '\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
'+tr("ID")+''+tr("Name")+''+tr("Publisher")+''+tr("Hypervisor")+''+tr("Arch")+''+tr("Format")+''+tr("Tags")+'
' -}; - -Sunstone.addMainTab('marketplace-tab', marketplace_tab); -Sunstone.addActions(market_actions); - - -/* - * INFO PANEL - */ - -var marketplace_info_panel = { - "marketplace_info_tab" : { - title: tr("Appliance information"), - content:"" - } -}; - -Sunstone.addInfoPanel("marketplace_info_panel", marketplace_info_panel); - -function marketplaceElements(){ - return getSelectedNodes(dataTable_marketplace); -} - -function updateMarketInfo(request,app){ - var url = app.links.download.href; - url = url.replace(/\/download$/, ''); - - $(".resource-info-header", $("#marketplace-tab")).html(app.name); - - var files_table = '\ - \ - \ - \ - '; - - if (app['files']) { - $.each(app['files'], function(index, value){ - files_table += '\ - \ - \ - ' - }); - } else { - files_table += '\ - \ - ' - } - - files_table += '\ -
'+tr("Images")+'
'+value['name']+''+humanize_size(value['size'], true)+'
'+tr("No Images defined")+'
'; - - var info_tab = { - title : tr("Info"), - icon: "fa-info-circle", - content: '
\ -
\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - '+ - (app['status'] ? '\ - \ - \ - ' : '') + - (app['tags'] ? '\ - \ - \ - ' : '') + - (app['catalog'] ? '\ - \ - \ - ' : '') + - '\ - \ - \ - \ - \ - \ - \ - ' + - (app['files'] ? '\ - \ - \ - ' : '') + - '\ - \ - \ - \ - \ - \ - \ - ' + - '\ -
'+tr("Information")+'
' + tr("ID") + ''+app['_id']["$oid"]+'
' + tr("Name") + ''+app['name']+'
' + tr("URL") + ''+tr("link")+'
' + tr("Publisher") + ''+app['publisher']+'
' + tr("Downloads") + ''+app['downloads']+'
' + tr("Status") + ''+app['status']+'
' + tr("Tags") + ''+app['tags'].join(' ')+'
' + tr("Catalog") + ''+app['catalog']+'
' + tr("OS") + ''+app['os-id']+' '+app['os-release']+'
' + tr("Arch") + ''+app['os-arch']+'
' + tr("Size") + ''+humanize_size(app['files'][0]['size'],true)+'
' + tr("Hypervisor") + ''+app['hypervisor']+'
' + tr("Format") + ''+app['format']+'
\ -
\ -
'+ - (app['short_description'] ? '\ - \ - \ - \ - \ - \ - \ - \ - \ -
'+tr("Short Description")+'
'+app['short_description'].replace(/\n/g, "
")+'
' : '') + - '\ - \ - \ - \ - \ - \ - \ - \ - \ -
'+tr("Description")+'
'+app['description'].replace(/\n/g, "
")+'
'+ - files_table+ - (app['opennebula_template'] ? '\ - \ - \ - \ - \ - \ - \ - \ - \ -
'+tr("OpenNebula Template")+'
'+app['opennebula_template'].replace(/\n/g, "
")+'
' : '') + - '
\ -
' - }; - - Sunstone.updateInfoPanelTab("marketplace_info_panel", "marketplace_info_tab", info_tab); - Sunstone.popUpInfoPanel("marketplace_info_panel", "marketplace-tab"); -}; - - function infoListenerMarket(dataTable){ - $('tbody tr',dataTable).live("click",function(e){ - if ($(e.target).is('input') || - $(e.target).is('select') || - $(e.target).is('option')) return true; - - var aData = dataTable.fnGetData(this); - var id =aData["_id"]["$oid"]; - - if (!id) return true; - - if (e.ctrlKey || e.metaKey || $(e.target).is('input')) { - $('.check_item',this).trigger('click'); - } else { - var context = $(this).parents(".tab"); - popDialogLoading($("#marketplace-tab")); - Sunstone.runAction("Marketplace.show",id); - $(".resource-id", context).html(id); - $('.top_button, .list_button', context).attr('disabled', false); - } - - return false; - }); -} - -/* - * Document - */ - -$(document).ready(function(){ - var tab_name = 'marketplace-tab'; - - if (Config.isTabEnabled(tab_name)) { - dataTable_marketplace = $("#datatable_marketplace", main_tabs_context).dataTable({ - "bSortClasses" : false, - "bDeferRender": true, - "aoColumns": [ - { "bSortable": false, - "mData": function ( o, val, data ) { - //we render 1st column as a checkbox directly - return '' - }, - "sWidth" : "60px" - }, - { "mDataProp": "_id.$oid", "sWidth" : "200px" }, - { "mDataProp": "name" }, - { "mDataProp": "publisher" }, - { "mDataProp": "files.0.hypervisor", "sWidth" : "100px", "sDefaultContent" : "-" }, - { "mDataProp": "files.0.os-arch", "sWidth" : "100px", "sDefaultContent" : "-" }, - { "mDataProp": "files.0.format", "sWidth" : "100px", "sDefaultContent" : "-" }, - { "mDataProp": "tags"} - ], - "aoColumnDefs": [ - { "bVisible": true, "aTargets": Config.tabTableColumns(tab_name)}, - { "bVisible": false, "aTargets": ['_all']} - ] - }); - - - $('#marketplace_search').keyup(function(){ - dataTable_marketplace.fnFilter( $(this).val() ); - }) - - dataTable_marketplace.on('draw', function(){ - recountCheckboxes(dataTable_marketplace); - }) - - tableCheckboxesListener(dataTable_marketplace); - onlyOneCheckboxListener(dataTable_marketplace); - - infoListenerMarket(dataTable_marketplace); - - Sunstone.runAction('Marketplace.list'); - } -}); diff --git a/src/sunstone/public/js/plugins/oneflow-dashboard.js b/src/sunstone/public/js/plugins/oneflow-dashboard.js deleted file mode 100644 index a54537d860..0000000000 --- a/src/sunstone/public/js/plugins/oneflow-dashboard.js +++ /dev/null @@ -1,23 +0,0 @@ -// ------------------------------------------------------------------------ // -// Copyright 2010-2015, C12G Labs S.L. // -// // -// 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. // -//------------------------------------------------------------------------- // - -var oneflow_dashboard_tab = { - title: ' OneFlow', - no_content: true -} - - -Sunstone.addMainTab('oneflow-dashboard',oneflow_dashboard_tab); diff --git a/src/sunstone/public/js/plugins/oneflow-services.js b/src/sunstone/public/js/plugins/oneflow-services.js deleted file mode 100644 index bfcba78330..0000000000 --- a/src/sunstone/public/js/plugins/oneflow-services.js +++ /dev/null @@ -1,1499 +0,0 @@ -// ------------------------------------------------------------------------ // -// Copyright 2010-2015, C12G Labs S.L. // -// // -// 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. // -//------------------------------------------------------------------------- // -var selected_row_role_id; -var last_selected_row_role; -var last_selected_row_rolevm; -var checked_row_rolevm_ids = []; - -var generate_batch_action_params = function(){ - var action_obj = { - "period" : $("#batch_action_period").val(), - "number" : $("#batch_action_number").val()}; - - return action_obj; -} - -var role_actions = { - "Role.update_dialog" : { - type: "custom", - call: popUpScaleDialog - }, - - "Role.update" : { - type: "multiple", - call: OpenNebula.Role.update, - callback: roleCallback, - elements: roleElements, - error: onError, - notify: true - }, - - "Role.hold" : { - type: "multiple", - call: OpenNebula.Role.hold, - callback: roleCallback, - elements: roleElements, - error: onError, - notify: true - }, - - "Role.release" : { - type: "multiple", - call: OpenNebula.Role.release, - callback: roleCallback, - elements: roleElements, - error: onError, - notify: true - }, - - "Role.suspend" : { - type: "multiple", - call: OpenNebula.Role.suspend, - callback: roleCallback, - elements: roleElements, - error: onError, - notify: true - }, - - "Role.resume" : { - type: "multiple", - call: OpenNebula.Role.resume, - callback: roleCallback, - elements: roleElements, - error: onError, - notify: true - }, - - "Role.stop" : { - type: "multiple", - call: OpenNebula.Role.stop, - callback: roleCallback, - elements: roleElements, - error: onError, - notify: true - }, - - "Role.reboot_hard" : { - type: "multiple", - call: OpenNebula.Role.reboot_hard, - callback: roleCallback, - elements: roleElements, - error: onError, - notify: true - }, - - "Role.delete_recreate" : { - type: "multiple", - call: OpenNebula.Role.delete_recreate, - callback: roleCallback, - elements: roleElements, - error: onError, - notify: true - }, - - "Role.reboot" : { - type: "multiple", - call: OpenNebula.Role.reboot, - callback: roleCallback, - elements: roleElements, - error: onError, - notify: true - }, - - "Role.poweroff" : { - type: "multiple", - call: OpenNebula.Role.poweroff, - callback: roleCallback, - elements: roleElements, - error: onError, - notify: true - }, - - "Role.poweroff_hard" : { - type: "multiple", - call: OpenNebula.Role.poweroff_hard, - callback: roleCallback, - elements: roleElements, - error: onError, - notify: true - }, - - "Role.undeploy" : { - type: "multiple", - call: OpenNebula.Role.undeploy, - callback: roleCallback, - elements: roleElements, - error: onError, - notify: true - }, - - "Role.undeploy_hard" : { - type: "multiple", - call: OpenNebula.Role.undeploy_hard, - callback: roleCallback, - elements: roleElements, - error: onError, - notify: true - }, - - "Role.snapshot_create" : { - type: "single", - call: OpenNebula.Role.snapshot_create, - callback: roleCallback, - error:onError, - notify: true - }, - - "Role.shutdown" : { - type: "multiple", - call: OpenNebula.Role.shutdown, - callback: roleCallback, - elements: roleElements, - error: onError, - notify: true - }, - - "Role.shutdown_hard" : { - type: "multiple", - call: OpenNebula.Role.cancel, - callback: roleCallback, - elements: roleElements, - error: onError, - notify: true - }, - - "Role.delete" : { - type: "multiple", - call: OpenNebula.Role.del, - callback: roleCallback, - elements: roleElements, - error: onError, - notify: true - }, - - "Role.recover" : { - type: "multiple", - call: OpenNebula.Role.recover, - callback: roleCallback, - elements: roleElements, - error: onError, - notify: true - }, - - "RoleVM.deploy" : { - type: "multiple", - call: OpenNebula.VM.deploy, - callback: roleCallback, - elements: roleVMElements, - error: onError, - notify: true - }, - - "RoleVM.migrate" : { - type: "multiple", - call: OpenNebula.VM.migrate, - callback: roleCallback, - elements: roleVMElements, - error: onError, - notify: true - }, - - "RoleVM.migrate_live" : { - type: "multiple", - call: OpenNebula.VM.livemigrate, - callback: roleCallback, - elements: roleVMElements, - error: onError, - notify: true - }, - - "RoleVM.hold" : { - type: "multiple", - call: OpenNebula.VM.hold, - callback: roleCallback, - elements: roleVMElements, - error: onError, - notify: true - }, - - "RoleVM.release" : { - type: "multiple", - call: OpenNebula.VM.release, - callback: roleCallback, - elements: roleVMElements, - error: onError, - notify: true - }, - - "RoleVM.suspend" : { - type: "multiple", - call: OpenNebula.VM.suspend, - callback: roleCallback, - elements: roleVMElements, - error: onError, - notify: true - }, - - "RoleVM.resume" : { - type: "multiple", - call: OpenNebula.VM.resume, - callback: roleCallback, - elements: roleVMElements, - error: onError, - notify: true - }, - - "RoleVM.stop" : { - type: "multiple", - call: OpenNebula.VM.stop, - callback: roleCallback, - elements: roleVMElements, - error: onError, - notify: true - }, - - "RoleVM.reboot_hard" : { - type: "multiple", - call: OpenNebula.VM.reset, - callback: roleCallback, - elements: roleVMElements, - error: onError, - notify: true - }, - - "RoleVM.delete_recreate" : { - type: "multiple", - call: OpenNebula.VM.resubmit, - callback: roleCallback, - elements: roleVMElements, - error: onError, - notify: true - }, - - "RoleVM.reboot" : { - type: "multiple", - call: OpenNebula.VM.reboot, - callback: roleCallback, - elements: roleVMElements, - error: onError, - notify: true - }, - - "RoleVM.poweroff" : { - type: "multiple", - call: OpenNebula.VM.poweroff, - callback: roleCallback, - elements: roleVMElements, - error: onError, - notify: true - }, - - "RoleVM.poweroff_hard" : { - type: "multiple", - call: OpenNebula.VM.poweroff_hard, - callback: roleCallback, - elements: roleVMElements, - error: onError, - notify: true - }, - - "RoleVM.undeploy" : { - type: "multiple", - call: OpenNebula.VM.undeploy, - callback: roleCallback, - elements: roleVMElements, - error: onError, - notify: true - }, - - "RoleVM.undeploy_hard" : { - type: "multiple", - call: OpenNebula.VM.undeploy_hard, - callback: roleCallback, - elements: roleVMElements, - error: onError, - notify: true - }, - - "RoleVM.shutdown" : { - type: "multiple", - call: OpenNebula.VM.shutdown, - callback: roleCallback, - elements: roleVMElements, - error: onError, - notify: true - }, - - "RoleVM.shutdown_hard" : { - type: "multiple", - call: OpenNebula.VM.cancel, - callback: roleCallback, - elements: roleVMElements, - error: onError, - notify: true - }, - - "RoleVM.delete" : { - type: "multiple", - call: OpenNebula.VM.del, - callback: deleteVMachineElement, - elements: roleVMElements, - error: onError, - notify: true - }, - - "RoleVM.recover" : { - type: "multiple", - call: OpenNebula.VM.recover, - callback: roleCallback, - elements: roleVMElements, - error: onError, - notify: true - }, - - "RoleVM.resched" : { - type: "multiple", - call: OpenNebula.VM.resched, - callback: roleCallback, - elements: roleVMElements, - error: onError, - notify: true - }, - - "RoleVM.unresched" : { - type: "multiple", - call: OpenNebula.VM.unresched, - callback: roleCallback, - elements: roleVMElements, - error: onError, - notify: true - }, - - "RoleVM.chown" : { - type: "multiple", - call: OpenNebula.VM.chown, - callback: roleCallback, - elements: roleVMElements, - error: onError, - notify: true - }, - "RoleVM.chgrp" : { - type: "multiple", - call: OpenNebula.VM.chgrp, - callback: roleCallback, - elements: roleVMElements, - error: onError, - notify: true - } -}; - -Sunstone.addActions(role_actions); - -function roleElements() { - return getSelectedNodes(servicerolesDataTable, true); -}; - -function roleVMElements() { - return getSelectedNodes(serviceroleVMsDataTable, true); -}; - -function roleCallback() { - return Sunstone.runAction('Service.refresh'); -} - -var role_buttons = { - "Role.update_dialog" : { - type: "action", - text: tr("Scale"), - tip: tr("This will hold selected pending VMs from being deployed"), - layout: "create" - }, - "Role.hold" : { - type: "action", - text: tr("Hold"), - tip: tr("This will hold selected pending VMs from being deployed"), - layout: "vmsplanification_buttons" - }, - "Role.release" : { - type: "action", - text: tr("Release"), - layout: "vmsplanification_buttons", - tip: tr("This will release held machines") - }, - "Role.suspend" : { - type: "action", - text: tr("Suspend"), - layout: "vmspause_buttons", - tip: tr("This will suspend selected machines") - }, - "Role.resume" : { - type: "action", - text: '', - layout: "vmsplay_buttons", - tip: tr("This will resume selected VMs") - }, - "Role.stop" : { - type: "action", - text: tr("Stop"), - layout: "vmsstop_buttons", - tip: tr("This will stop selected VMs") - }, - "Role.reboot" : { - type: "action", - text: tr("Reboot"), - layout: "vmsrepeat_buttons", - tip: tr("This will send a reboot action to running VMs") - }, - "Role.reboot_hard" : { - type: "action", - text: tr("Reboot") + ' hard', - layout: "vmsrepeat_buttons", - tip: tr("This will perform a hard reboot on selected VMs") - }, - "Role.poweroff" : { - type: "action", - text: tr("Power Off"), - layout: "vmspause_buttons", - tip: tr("This will send a power off signal to running VMs. They can be resumed later.") - }, - "Role.poweroff_hard" : { - type: "action", - text: tr("Power Off") + ' hard', - layout: "vmspause_buttons", - tip: tr("This will send a forced power off signal to running VMs. They can be resumed later.") - }, - "Role.undeploy" : { - type: "action", - text: tr("Undeploy"), - layout: "vmsstop_buttons", - tip: tr("Shuts down the given VM. The VM is saved in the system Datastore.") - }, - "Role.undeploy_hard" : { - type: "action", - text: tr("Undeploy") + ' hard', - layout: "vmsstop_buttons", - tip: tr("Shuts down the given VM. The VM is saved in the system Datastore.") - }, - "Role.shutdown" : { - type: "action", - text: tr("Shutdown"), - layout: "vmsdelete_buttons", - tip: tr("This will initiate the shutdown process in the selected VMs") - }, - "Role.shutdown_hard" : { - type: "action", - text: tr("Shutdown") + ' hard', - layout: "vmsdelete_buttons", - tip: tr("This will initiate the shutdown-hard (forced) process in the selected VMs") - }, - "Role.delete" : { - type: "action", - text: tr("Delete"), - layout: "vmsdelete_buttons", - tip: tr("This will delete the selected VMs from the database") - }, - "Role.delete_recreate" : { - type: "action", - text: tr("Delete") + ' recreate', - layout: "vmsrepeat_buttons", - tip: tr("This will delete and recreate VMs to PENDING state") - } -} - - -var role_vm_buttons = { - "RoleVM.hold" : { - type: "action", - text: tr("Hold"), - tip: tr("This will hold selected pending VMs from being deployed"), - layout: "vmsplanification_buttons", - }, - "RoleVM.release" : { - type: "action", - text: tr("Release"), - layout: "vmsplanification_buttons", - tip: tr("This will release held machines") - }, - "RoleVM.suspend" : { - type: "action", - text: tr("Suspend"), - layout: "vmspause_buttons", - tip: tr("This will suspend selected machines") - }, - "RoleVM.resume" : { - type: "action", - text: '', - layout: "vmsplay_buttons", - tip: tr("This will resume selected VMs") - }, - "RoleVM.stop" : { - type: "action", - text: tr("Stop"), - layout: "vmsstop_buttons", - tip: tr("This will stop selected VMs") - }, - "RoleVM.reboot" : { - type: "action", - text: tr("Reboot"), - layout: "vmsrepeat_buttons", - tip: tr("This will send a reboot action to running VMs") - }, - "RoleVM.reboot_hard" : { - type: "action", - text: tr("Reboot") + ' hard', - layout: "vmsrepeat_buttons", - tip: tr("This will perform a hard reboot on selected VMs") - }, - "RoleVM.poweroff" : { - type: "action", - text: tr("Power Off"), - layout: "vmspause_buttons", - tip: tr("This will send a power off signal to running VMs. They can be resumed later.") - }, - "RoleVM.poweroff_hard" : { - type: "action", - text: tr("Power Off") + ' hard', - layout: "vmspause_buttons", - tip: tr("This will send a forced power off signal to running VMs. They can be resumed later.") - }, - "RoleVM.undeploy" : { - type: "action", - text: tr("Undeploy"), - layout: "vmsstop_buttons", - tip: tr("Shuts down the given VM. The VM is saved in the system Datastore.") - }, - "RoleVM.undeploy_hard" : { - type: "action", - text: tr("Undeploy") + ' hard', - layout: "vmsstop_buttons", - tip: tr("Shuts down the given VM. The VM is saved in the system Datastore.") - }, - "RoleVM.shutdown" : { - type: "action", - text: tr("Shutdown"), - layout: "vmsdelete_buttons", - tip: tr("This will initiate the shutdown process in the selected VMs") - }, - "RoleVM.shutdown_hard" : { - type: "action", - text: tr("Shutdown") + ' hard', - layout: "vmsdelete_buttons", - tip: tr("This will initiate the shutdown-hard (forced) process in the selected VMs") - }, - - "RoleVM.delete" : { - type: "action", - text: tr("Delete"), - layout: "vmsdelete_buttons", - tip: tr("This will delete the selected VMs from the database") - }, - "RoleVM.delete_recreate" : { - type: "action", - text: tr("Delete") + ' recreate', - layout: "vmsrepeat_buttons", - tip: tr("This will delete and recreate VMs to PENDING state") - }, - "RoleVM.resched" : { - type: "action", - text: tr("Reschedule"), - layout: "vmsplanification_buttons", - tip: tr("This will reschedule selected VMs") - }, - "RoleVM.unresched" : { - type: "action", - text: tr("Un-Reschedule"), - layout: "vmsplanification_buttons", - tip: tr("This will cancel the rescheduling for the selected VMs") - } -} - -var dataTable_services; - -var service_actions = { - "Service.list" : { - type: "list", - call: OpenNebula.Service.list, - callback: function(request, service_list) { - $(".flow_error_message").hide(); - updateServicesView(request, service_list); - }, - error: function(request, error_json) { - onError(request, error_json, $(".flow_error_message")); - } - }, - - "Service.show" : { - type : "single", - call: OpenNebula.Service.show, - callback: function(request, response){ - var tab = dataTable_services.parents(".tab"); - - if (Sunstone.rightInfoVisible(tab)) { - // individual view - updateServiceInfo(request, response); - } - - // datatable row - updateServiceElement(request, response); - }, - error: onError - }, - - "Service.refresh" : { - type: "custom", - call: function () { - var tab = dataTable_services.parents(".tab"); - if (Sunstone.rightInfoVisible(tab)) { - checked_row_rolevm_ids = new Array(); - - if (typeof(serviceroleVMsDataTable) !== 'undefined') { - selected_row_role_id = $($('td.markrowchecked',servicerolesDataTable.fnGetNodes())[1]).html(); - $.each($(serviceroleVMsDataTable.fnGetNodes()), function(){ - if($('td.markrowchecked',this).length!=0) - { - checked_row_rolevm_ids.push($($('td',$(this))[1]).html()); - } - }); - } - - Sunstone.runAction("Service.show", Sunstone.rightInfoResourceId(tab)) - } else { - waitingNodes(dataTable_services); - Sunstone.runAction("Service.list", {force: true}); - } - } - }, - - "Service.delete" : { - type: "multiple", - call: OpenNebula.Service.del, - callback: deleteServiceElement, - elements: serviceElements, - error: onError, - notify: true - }, - - "Service.chown" : { - type: "multiple", - call: OpenNebula.Service.chown, - callback: function (req) { - Sunstone.runAction("Service.show",req.request.data[0][0]); - }, - elements: serviceElements, - error: onError, - notify: true - }, - - "Service.chgrp" : { - type: "multiple", - call: OpenNebula.Service.chgrp, - callback: function (req) { - Sunstone.runAction("Service.show",req.request.data[0][0]); - }, - elements: serviceElements, - error: onError, - notify: true - }, - - "Service.chmod" : { - type: "single", - call: OpenNebula.Service.chmod, - error: onError, - notify: true - }, - - "Service.shutdown" : { - type: "multiple", - call: OpenNebula.Service.shutdown, - elements: serviceElements, - error: onError, - notify: true - }, - - "Service.recover" : { - type: "multiple", - call: OpenNebula.Service.recover, - elements: serviceElements, - error: onError, - notify: true - } -}; - - -var service_buttons = { - "Service.refresh" : { - type: "action", - layout: "refresh", - alwaysActive: true - }, -// "Sunstone.toggle_top" : { -// type: "custom", -// layout: "top", -// alwaysActive: true -// }, - "Service.chown" : { - type: "confirm_with_select", - text: tr("Change owner"), - select: "User", - tip: tr("Select the new owner")+":", - layout: "user_select" - }, - "Service.chgrp" : { - type: "confirm_with_select", - text: tr("Change group"), - select: "Group", - tip: tr("Select the new group")+":", - layout: "user_select" - }, - "Service.shutdown" : { - type: "action", - layout: "main", - text: tr("Shutdown") - }, - "Service.recover" : { - type: "action", - layout: "main", - text: tr("Recover") - }, - "Service.delete" : { - type: "confirm", - text: tr("Delete"), - layout: "del", - tip: tr("This will delete the selected services") - } -} - -var service_info_panel = { - "service_info_tab" : { - title: tr("Service information"), - content: "" - } -} - -var services_tab = { - title: "Services", - resource: 'Service', - buttons: service_buttons, - tabClass: 'subTab', - parentTab: 'oneflow-dashboard', - search_input: '', - list_header: ' '+tr("OneFlow - Services"), - info_header: ' '+tr("OneFlow - Service"), - subheader: '  ', - content: '', - table: '\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
'+tr("ID")+''+tr("Owner")+''+tr("Group")+''+tr("Name")+''+tr("State")+'
' -} - -Sunstone.addActions(service_actions); -Sunstone.addMainTab('oneflow-services',services_tab); -Sunstone.addInfoPanel('service_info_panel',service_info_panel); - - -function serviceElements() { - return getSelectedNodes(dataTable_services); -} - -// Returns an array containing the values of the service_json and ready -// to be inserted in the dataTable -function serviceElementArray(service_json){ - var service = service_json.DOCUMENT; - - return [ - '', - service.ID, - service.UNAME, - service.GNAME, - service.NAME, - OpenNebula.Service.state(service.TEMPLATE.BODY.state) - ]; -} - -// Callback to update an element in the dataTable -function updateServiceElement(request, service_json){ - var id = service_json.DOCUMENT.ID; - var element = serviceElementArray(service_json); - updateSingleElement(element,dataTable_services,'#service_'+id); -} - -// Callback to remove an element from the dataTable -function deleteServiceElement(req){ - deleteElement(dataTable_services,'#service_'+req.request.data); -} - -// Callback to add an service element -function addServiceElement(request, service_json){ - var element = serviceElementArray(service_json); - addElement(element,dataTable_services); -} - -// Callback to refresh the list -function updateServicesView(request, services_list){ - var service_list_array = []; - - $.each(services_list,function(){ - service_list_array.push(serviceElementArray(this)); - }); - - updateView(service_list_array,dataTable_services); -} - -// Callback to refresh the list of Virtual Machines -function updateServiceVMInfo(vmachine_list){ - var vmachine_list_array = []; - - $.each(vmachine_list,function(){ - vmachine_list_array.push( vMachineElementArray(this)); - }); - - updateView(vmachine_list_array, serviceroleVMsDataTable); -}; - -// Callback to update the information panel tabs and pop it up -function updateServiceInfo(request,elem){ - var elem_info = elem.DOCUMENT; - - $(".resource-info-header", $("#oneflow-services")).html(elem_info.NAME); - - var info_tab = { - title : tr("Info"), - icon: "fa-info-circle", - content: - '
\ -
\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
'+tr("Information")+'
'+tr("ID")+''+elem_info.ID+'
'+tr("Name")+''+elem_info.NAME+'
'+tr("Strategy")+''+elem_info.TEMPLATE.BODY.deployment+'
'+tr("Shutdown action")+''+(elem_info.TEMPLATE.BODY.shutdown_action || "")+'
'+tr("State")+''+ OpenNebula.Service.state(elem_info.TEMPLATE.BODY.state) +'
'+tr("Ready Status Gate")+''+(elem_info.TEMPLATE.BODY.ready_status_gate ? "yes" : "no")+'
' + - '
\ -
' + insert_permissions_table('oneflow-services', - "Service", - elem_info.ID, - elem_info.UNAME, - elem_info.GNAME, - elem_info.UID, - elem_info.GID) + - '
\ -
' - } - - Sunstone.updateInfoPanelTab("service_info_panel", "service_info_tab",info_tab); - - var roles_tab = { - title : "Roles", - icon: "fa-wrench", - content : '
\ -
\ -
\ -
\ -

'+tr("Roles")+'

\ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ -
\ -
\ -
\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
'+tr("Name")+''+tr("State")+''+tr("Cardinality")+''+tr("VM Template")+''+tr("Parents")+'
\ -
\ -
\ - '+tr("Select a role in the table for more information")+'\ -
\ -
\ -
' - }; - - Sunstone.updateInfoPanelTab("service_info_panel", "service_roles_tab",roles_tab); - - var logs = elem_info.TEMPLATE.BODY.log - var log_info = '' - if (logs) { - log_info += '
' - - for (var i = 0; i < logs.length; i++) { - var line = pretty_time(logs[i].timestamp)+' ['+logs[i].severity + '] ' + logs[i].message+ '
'; - if (logs[i].severity == 'E'){ - line = ''+line+''; - } - - log_info += line; - } - - log_info += '
' - } - - var logs_tab = { - title: "Log", - icon: "fa-file-text", - content: log_info - } - - - Sunstone.updateInfoPanelTab("service_info_panel", "service_log_tab",logs_tab); - - - // Popup panel - Sunstone.popUpInfoPanel("service_info_panel", "oneflow-services"); - setPermissionsTable(elem_info,''); - - var roles = elem_info.TEMPLATE.BODY.roles - if (roles && roles.length) { - servicerolesDataTable = $('#datatable_service_roles').dataTable({ - "bSortClasses": false, - "bDeferRender": true, - "bAutoWidth":false, - "aoColumnDefs": [ - { "bSortable": false, "aTargets": ["check"] } - ], - "sDom" : '<"H">t<"F"p>' - }); - - var context = $("#roles_extended_info", $("#service_info_panel")); - var role_elements = []; - $.each(roles, function(){ - role_elements.push([ - '', - this.name, - OpenNebula.Role.state(this.state), - this.cardinality, - this.vm_template, - this.parents ? this.parents.join(', ') : '-' - ]) - }); - - updateView(role_elements ,servicerolesDataTable); - - insertButtonsInTab("oneflow-services", "service_roles_tab", role_buttons, $('#role_actions')) - - setupScaleDialog(); - - $('tbody input.check_item',servicerolesDataTable).die(); - $('tbody tr',servicerolesDataTable).die(); - - initCheckAllBoxes(servicerolesDataTable, $('#role_actions')); - tableCheckboxesListener(servicerolesDataTable, $('#role_actions')); - - $('tbody tr',servicerolesDataTable).die() - $('tbody tr',servicerolesDataTable).live("click",function(e){ - if ($(e.target).is('input') || - $(e.target).is('select') || - $(e.target).is('option')) return true; - - if (e.ctrlKey || e.metaKey || $(e.target).is('input')) - { - $('.check_item',this).trigger('click'); - } - else - { - var aData = servicerolesDataTable.fnGetData(this); - var role_name = $(aData[0]).val(); - - var role_index = servicerolesDataTable.fnGetPosition(this); - - generate_role_div(role_index); - - $('tbody input.check_item',$(this).parents('table')).removeAttr('checked'); - $('.check_item',this).click(); - $('td',$(this).parents('table')).removeClass('markrowchecked'); - - if(last_selected_row_role) { - last_selected_row_role.children().each(function(){ - $(this).removeClass('markrowchecked'); - }); - } - - last_selected_row_role = $(this); - $(this).children().each(function(){ - $(this).addClass('markrowchecked'); - }); - } - }); - - var generate_role_div = function(role_index) { - var role = roles[role_index] - var info_str = "
\ -

"+tr("Role")+" - "+role.name+"

\ -
\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
"+tr("Information")+"
"+tr("Shutdown action")+""+(role.shutdown_action || "-")+""+tr("Cooldown")+""+(role.cooldown || "-")+""+tr("Min VMs")+""+(role.min_vms || "-")+""+tr("Max VMs")+""+(role.max_vms || "-")+"
\ -
\ -
"; - - info_str += '
\ - '+tr("Virtual Machines")+'\ -
\ -
\ -
\ -
\ -
\ -
\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
'+tr("ID")+''+tr("Owner")+''+tr("Group")+''+tr("Name")+''+tr("Status")+''+tr("Used CPU")+''+tr("Used Memory")+''+tr("Host")+''+tr("IPs")+''+tr("Start Time")+''+tr("VNC")+'
\ -
\ -
'; - - info_str += "

"; - - if (role.elasticity_policies && role.elasticity_policies.length > 0) { - info_str += '\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - '; - - $.each(role.elasticity_policies, function(){ - info_str += '\ - \ - \ - \ - \ - \ - \ - \ - ' - }); - - info_str += '\ -
'+tr("Elasticity policies")+'
'+tr("Type")+'\ - '+tr("Type of adjustment.")+'

\ - '+tr("CHANGE: Add/substract the given number of VMs.")+'
\ - '+tr("CARDINALITY: Set the cardinality to the given number.")+'
\ - '+tr("PERCENTAGE_CHANGE: Add/substract the given percentage to the current cardinality.")+'\ -
\ -
'+tr("Adjust")+'\ - '+tr("Positive or negative adjustment. Its meaning depends on 'type'")+'

\ - '+tr("CHANGE: -2, will substract 2 VMs from the role")+'
\ - '+tr("CARDINALITY: 8, will set carditanilty to 8")+'
\ - '+tr("PERCENTAGE_CHANGE: 20, will increment cardinality by 20%")+'\ -
\ -
'+tr("Min")+'\ - '+tr("Optional parameter for PERCENTAGE_CHANGE adjustment type. If present, the policy will change the cardinality by at least the number of VMs set in this attribute.")+'\ - \ - '+tr("Expression")+'\ - '+tr("Expression to trigger the elasticity")+'

\ - '+tr("Example: ATT < 20")+'
\ -
\ -
'+tr("# Periods")+'\ - '+tr("Number of periods that the expression must be true before the elasticity is triggered")+'\ - \ - '+tr("Period")+'\ - '+tr("Duration, in seconds, of each period in '# Periods'")+'\ - \ - '+tr("Cooldown")+'\ - '+tr("Cooldown period duration after a scale operation, in seconds")+'\ - \ -
'+this.type+''+this.adjust+''+(this.min_adjust_step || "-")+''+(this.expression_evaluated || this.expression)+''+( this.period_number ? ((this.true_evals || 0 )+'/'+(this.period_number)) : '-' )+''+(this.period || "-")+''+(this.cooldown || "-")+'
'; - } - - if (role.scheduled_policies && role.scheduled_policies.length > 0) { - info_str += '\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - '; - - $.each(role.scheduled_policies, function(){ - info_str += '\ - \ - \ - '; - - if (this['start_time']) { - info_str += ''; - info_str += ''; - } else if (this['recurrence']) { - info_str += ''; - info_str += ''; - } - }); - - info_str += '\ -
'+tr("Scheduled policies")+'
'+tr("Type")+'\ - '+tr("Type of adjustment.")+'

\ - '+tr("CHANGE: Add/substract the given number of VMs.")+'
\ - '+tr("CARDINALITY: Set the cardinality to the given number.")+'
\ - '+tr("PERCENTAGE_CHANGE: Add/substract the given percentage to the current cardinality.")+'\ -
\ -
'+tr("Adjust")+'\ - '+tr("Positive or negative adjustment. Its meaning depends on 'type'")+'

\ - '+tr("CHANGE: -2, will substract 2 VMs from the role")+'
\ - '+tr("CARDINALITY: 8, will set carditanilty to 8")+'
\ - '+tr("PERCENTAGE_CHANGE: 20, will increment cardinality by 20%")+'\ -
\ -
'+tr("Min")+'\ - '+tr("Optional parameter for PERCENTAGE_CHANGE adjustment type. If present, the policy will change the cardinality by at least the number of VMs set in this attribute.")+'\ - \ - '+tr("Time format")+'\ - '+tr("Recurrence: Time for recurring adjustements. Time is specified with the Unix cron syntax")+'

\ - '+tr("Start time: Exact time for the adjustement")+'\ -
\ -
'+tr("Time expression")+'\ - '+tr("Time expression depends on the the time formar selected")+'

\ - '+tr("Recurrence: Time for recurring adjustements. Time is specified with the Unix cron syntax")+'
\ - '+tr("Start time: Exact time for the adjustement")+'
\ -
\ -
'+this.type+''+this.adjust+''+(this.min_adjust_step || "")+'start_time'+this.start_time+'recurrence'+this.recurrence+'
'; - } - - info_str += '
\ -
' - - context.html(info_str); - setupTips(context, "tip-top"); - - var vms = []; - serviceroleVMsDataTable = $('#datatable_service_vms_'+role.name, context).dataTable({ - "bSortClasses": false, - "bDeferRender": true, - "aoColumnDefs": [ - { "bSortable": false, "aTargets": [0,1,8,9,11,13] }, - { "sWidth": "35px", "aTargets": [0,1,2] }, - { "bVisible": false, "aTargets": [8,9,12]} - ] - }); - - if (role.nodes) { - $.each(role.nodes, function(){ - var vm_info = this.vm_info; - - var info = []; - if (this.scale_up) { - info.push(""); - } else if (this.disposed) { - info.push(""); - } else { - info.push(""); - } - - if (elem_info.TEMPLATE.BODY.ready_status_gate) { - if (vm_info.VM.USER_TEMPLATE.READY == "YES") { - info.push(''); - - } else { - info.push(''); - } - } else { - info.push(""); - } - - if (vm_info) { - vms.push(info.concat(vMachineElementArray(vm_info))); - } else { - empty_arr = [ - '', - this.deploy_id, - '', '', '', '', '', '', '', '', '', '', "-" ]; - - vms.push(info.concat(empty_arr)); - } - }); - - updateView(vms, serviceroleVMsDataTable); - } - - - insertButtonsInTab("oneflow-services", "service_roles_tab", role_vm_buttons, $('div#role_vms_actions')) - - $('tbody input.check_item',serviceroleVMsDataTable).die(); - $('tbody tr',serviceroleVMsDataTable).die(); - - initCheckAllBoxes(serviceroleVMsDataTable, $('div#role_vms_actions')); - tableCheckboxesListener(serviceroleVMsDataTable, $('div#role_vms_actions')); - - $('tbody tr',serviceroleVMsDataTable).live("click",function(e){ - if ($(e.target).is('input') || - $(e.target).is('select') || - $(e.target).is('option')) return true; - - if (e.ctrlKey || e.metaKey || $(e.target).is('input')) - { - $('.check_item',this).trigger('click'); - } - else - { - var aData = serviceroleVMsDataTable.fnGetData(this); - if (!aData) return true; - - var id = $(aData[2]).val(); - if (!id) return true; - - showElement("vms-tab", "VM.show", id); -/* - $('tbody input.check_item',$(this).parents('table')).removeAttr('checked'); - $('.check_item',this).click(); - $('td',$(this).parents('table')).removeClass('markrowchecked'); - - if(last_selected_row_rolevm) { - last_selected_row_rolevm.children().each(function(){ - $(this).removeClass('markrowchecked'); - }); - } - - last_selected_row_rolevm = $(this); - $(this).children().each(function(){ - $(this).addClass('markrowchecked'); - }); -*/ - } - }); - - - //insertButtonsInTab("oneflow-services", "service_roles_tab", role_buttons) - //$('li#service_roles_tabTab').foundationButtons(); - //$('li#service_roles_tabTab').foundationButtons(); - } - - if(selected_row_role_id) { - $.each($(servicerolesDataTable.fnGetNodes()),function(){ - if($($('td',this)[1]).html()==selected_row_role_id) { - $('td',this)[2].click(); - } - }); - } - - if(checked_row_rolevm_ids.length!=0) { - $.each($(serviceroleVMsDataTable.fnGetNodes()),function(){ - var current_id = $($('td',this)[1]).html(); - if (current_id) { - if(jQuery.inArray(current_id, checked_row_rolevm_ids)!=-1) { - $('input.check_item',this).first().click(); - $('td',this).addClass('markrowchecked'); - } - } - }); - } - //setupActionButtons($('li#service_roles_tabTab')); - } - - setupTips($("#roles_form")); -} - -function setupScaleDialog(){ - dialogs_context.append('
'); - $scale_dialog = $('#scale_dialog', dialogs_context); - var dialog = $scale_dialog; - - dialog.html('
\ -

'+tr("Scale")+'

\ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ - \ -
\ -
\ -
\ - \ -
\ - ×\ -
') - - dialog.addClass("reveal-modal").attr("data-reveal", ""); - setupTips(dialog); - - $('#scale_form',dialog).submit(function(){ - var force = false; - if ($("#force", this).is(":checked")) { - force = true; - } - - var obj = { - "force": force, - "cardinality": $("#cardinality", this).val(), - } - - Sunstone.runAction('Role.update', roleElements(), obj); - - $scale_dialog.foundation('reveal', 'close') - return false; - }); -}; - - -function popUpScaleDialog(){ - $scale_dialog.foundation().foundation('reveal', 'open'); - return false; -} - -//The DOM is ready at this point -$(document).ready(function(){ - var tab_name = "oneflow-services"; - - if (Config.isTabEnabled(tab_name)) { - dataTable_services = $("#datatable_services",main_tabs_context).dataTable({ - "bSortClasses": false, - "bDeferRender": true, - "aoColumnDefs": [ - { "bSortable": false, "aTargets": ["check"] }, - { "sWidth": "35px", "aTargets": [0] }, - { "bVisible": true, "aTargets": Config.tabTableColumns(tab_name)}, - { "bVisible": false, "aTargets": ['_all']} - ] - }); - - $('#services_search').keyup(function(){ - dataTable_services.fnFilter( $(this).val() ); - }) - - dataTable_services.on('draw', function(){ - recountCheckboxes(dataTable_services); - }) - - Sunstone.runAction("Service.list"); - - initCheckAllBoxes(dataTable_services); - tableCheckboxesListener(dataTable_services); - infoListener(dataTable_services,'Service.show'); - dataTable_services.fnSort( [ [1,config['user_config']['table_order']] ] ); - } -}); diff --git a/src/sunstone/public/js/plugins/oneflow-templates.js b/src/sunstone/public/js/plugins/oneflow-templates.js deleted file mode 100644 index cf86117982..0000000000 --- a/src/sunstone/public/js/plugins/oneflow-templates.js +++ /dev/null @@ -1,1935 +0,0 @@ -// ------------------------------------------------------------------------ // -// Copyright 2010-2015, C12G Labs S.L. // -// // -// 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. // -//------------------------------------------------------------------------- // -var selected_row_template_role_id; -var last_selected_row_template_role; - -var create_service_template_wizard_html = '\ -
\ -
\ -
\ - '+ - '\ -
\ -
'+ - '
\ -
\ -
\ -
'+ - ''+ - '' + - '
' + - '
' + - '
'; - -function generate_advanced_role_accordion(role_id, context){ - context.html(generateAdvancedSection({ - title: tr("Advanced Role Parameters"), - html_id: 'advanced_role'+role_id, - content: '
\ -
\ - \ - \ -
\ -
\ -
\ -
\ -
\ -
'+ - ''+ - ''+ - '
'+ - '
'+ - '
'+ - '
'+ - ''+ - ''+ - '
'+ - '
'+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ -''; - - -var provision_info_vdc_user = -'
'+ - ''+ - ''+ - ''+ - ''+ - '
'+ - '
'+ - ''+ - ''+ -'
'+ -'
'+ - '
'+ - '
'+ - ''+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - ''+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - ''+ - '
'+ - '
'+ - ''+tr("CPU hours")+''+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - ''+tr("Memory GB hours")+''+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - empty_graph_placeholder + - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ -'
' - -var list_users_accordion_id = 0; - -function provision_list_users(opts_arg){ - list_users_accordion_id += 1; - return '
'+ - '
'+ - ''+ - ''+ - ' '+ - ' '+ - //tr("Show List") + - '' + - ''+ - '

'+ - tr("Users")+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - '

'+ - '
'+ - '
'+ - '
'+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - ''+ - ''+ - '
'+ - provision_info_vdc_user + - '
'+ - '
'+ - '
'; -} - - -var provision_manage_vdc = ''; - -var list_templates_accordion_id = 0; - -function provision_list_templates(opts_arg){ - opts = $.extend({ - title: tr("Saved Templates"), - refresh: true, - create: true, - active: true, - filter: true - },opts_arg) - - list_templates_accordion_id += 1; - return '
'+ - '
'+ - ''+ - ''+ - ' '+ - ' '+ - //tr("Show List") + - '' + - ''+ - '

'+ - opts.title + - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - '

'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - ''+ - ''+ - '
'+ - //provision_info_vdc_template + - '
'+ - '
'+ - '
'; -} - -var provision_info_vm = -'
'+ - ''+ - ''+ - ''+ - ''+ - '
'+ - '
'+ - ''+ - ''+ -'
'+ -'
'+ - '
'+ - '
'+ - ''+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
    '+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '

'+tr("CPU")+'

'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '

'+tr("MEMORY")+'

'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '

'+tr("NET RX")+'

'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '

'+tr("NET TX")+'

'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '

'+tr("NET DOWNLOAD SPEED")+'

'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '

'+tr("NET UPLOAD SPEED")+'

'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ -'
'; - -var list_vms_accordion_id = 0; - -function provision_list_vms(opts_arg){ - opts = $.extend({ - title: tr("Virtual Machines"), - refresh: true, - create: true, - filter: true - },opts_arg) - - list_vms_accordion_id += 1; - return '
'+ - '
'+ - ''+ - ''+ - ' '+ - ' '+ - //tr("Show List") + - '' + - '' + - '

'+ - opts.title + - ''+ - ''+ - ''+ - ' '+ - ''+ - ''+ - ''+ - '' + - ''+ - ' '+ - ''+ - ''+ - '' + - ''+ - ''+ - ' '+ - '' + - '

'+ - '
'+ - '
'+ - '
'+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - ''+ - ''+ - '
'+ - provision_info_vm + - '
'+ - '
'+ - '
'; -} - -var provision_info_flow = -'
'+ - ''+ - ''+ - ''+ - ''+ - '
'+ - '
'+ - ''+ - ''+ -'
'+ -'
'+ - '
'+ - '
'+ - ''+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
    '+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
    '+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ -'
'; - -var list_flows_accordion_id = 0; - -function provision_list_flows(opts_arg){ - opts = $.extend({ - title: tr("Services"), - active: true, - refresh: true, - create: true, - filter: true - },opts_arg) - - list_flows_accordion_id += 1; - return '
'+ - '
'+ - ''+ - ''+ - ' '+ - ' '+ - //tr("Show List") + - '' + - ''+ - '

'+ - opts.title + - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ' '+ - ''+ - ''+ - ''+ - ''+ - ''+ - ' '+ - ''+ - '

'+ - '
'+ - '
'+ - '
'+ - '
'+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - ''+ - ''+ - '
'+ - provision_info_flow + - '
'+ - '
'+ - '
'; -} - -var provision_content = provision_dashboard + - provision_user_info + - provision_create_vm + - ''; - -if (Config.isTabPanelEnabled("provision-tab", "templates")) { - provision_content += ''; -} - -if (Config.isTabPanelEnabled("provision-tab", "users")) { - provision_content += provision_manage_vdc; - provision_content += ''; - provision_content += provision_create_user; -} - -if (Config.isTabPanelEnabled("provision-tab", "flows")) { - provision_content += '' - provision_content += provision_create_flow; -} - -var provision_header = ''+ - ''+ - ''+ - '' - -var provision_tab = { - list_header: "", - content: provision_content -}; - -var povision_actions = { - "Provision.User.show" : { - type: "single", - call: OpenNebula.User.show, - callback: show_provision_user_info_callback, - error: onError - }, - - "Provision.User.passwd" : { - type: "single", - call: OpenNebula.User.passwd, - callback: function() { - show_provision_user_info(); - notifyMessage("Password updated successfully"); - }, - error: onError - }, - - "Provision.User.update_template" : { - type: "single", - call: OpenNebula.User.update, - callback: function() { - show_provision_user_info(); - notifyMessage("SSH key updated successfully"); - }, - error: onError - }, - - "Provision.User.create" : { - type: "create", - call: OpenNebula.User.create, - callback: function(request, response) { - if ( $("div#provision_create_user_manual_quota", - $("#provision_create_user")).hasClass("active") ){ - - quota_json = retrieve_provision_quota_widget($("#provision_create_user")); - - Sunstone.runAction("Provision.User.set_quota", - [response.USER.ID], quota_json); - } else { - clear_provision_create_user(); - } - }, - error: onError - }, - - "Provision.User.set_quota" : { - type: "multiple", - call: OpenNebula.User.set_quota, - callback: function(request) { - clear_provision_create_user(); - }, - error: onError - }, - - "Provision.Group.show" : { - type: "single", - call: OpenNebula.Group.show, - callback: show_provision_group_info_callback, - error: onError - }, - - "Provision.Flow.instantiate" : { - type: "single", - call: OpenNebula.ServiceTemplate.instantiate, - callback: function(){ - OpenNebula.Helper.clear_cache("SERVICE"); - show_provision_flow_list(0); - var context = $("#provision_create_flow"); - $("#flow_name", context).val(''); - //$(".provision_selected_networks").html(""); - $(".provision-pricing-table", context).removeClass("selected"); - //$('a[href="#provision_system_templates_selector"]', context).click(); - }, - error: onError - }, - - "Provision.instantiate" : { - type: "single", - call: OpenNebula.Template.instantiate, - callback: function(){ - OpenNebula.Helper.clear_cache("VM"); - show_provision_vm_list(0); - var context = $("#provision_create_vm"); - $("#vm_name", context).val(''); - $(".provision_selected_networks").html(""); - $(".provision-pricing-table", context).removeClass("selected"); - $(".alert-box-error", context).hide(); - $('a[href="#provision_system_templates_selector"]', context).click(); - }, - error: onError - } - -} - -Sunstone.addMainTab('provision-tab',provision_tab); -Sunstone.addActions(povision_actions); - -$(document).foundation(); - -function generate_custom_attrs(context, custom_attrs) { - context.off(); - var text_attrs = []; - - $.each(custom_attrs, function(key, value){ - var parts = value.split("|"); - // 0 mandatory; 1 type; 2 desc; - var attrs = { - "name": key, - "mandatory": parts[0], - "type": parts[1], - "description": parts[2], - } - - switch (parts[1]) { - case "text": - text_attrs.push(attrs) - break; - case "password": - text_attrs.push(attrs) - break; - } - }) - - if (text_attrs.length > 0) { - context.html( - '
'+ - '
'+ - '
'+ - '

'+ - ''+ - ' '+ - tr("Custom Attributes")+ - ''+ - '

'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'); - - - $.each(text_attrs, function(index, custom_attr){ - $(".provision_custom_attributes", context).append( - '
'+ - '
'+ - '
'+ - ''+ - '
'+ - '
'); - }) - } else { - context.html(""); - } -} - -function generate_cardinality_selector(context, role_template, template_json) { - context.off(); - var min_vms = (role_template.min_vms||1); - var max_vms = (role_template.max_vms||20); - - context.html( - '
'+ - '
'+ - '
'+ - '

'+ - ''+ - ' '+ - tr("Cardinality")+ - ''+ - '

'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - ''+role_template.cardinality+''+ - '
'+ - ''+tr("VMs")+''+ - '
'+ - '
'+ - '
'+ - ''+tr("Change cardinality")+''+ - '
'+ - '
'+ - ''+ - ''+ - ''+ - '
'+ - ''+min_vms+''+ - ''+max_vms+''+ - '
'+ - '
'+ - '
'+ - '
'+ - ''+tr("The cardinality for this role cannot be changed")+''+ - '
'+ - '
'+ - ''+ - '
'+ - '
'+ - '
'); - - var capacity = template_json.VMTEMPLATE.TEMPLATE; - var cost = 0; - if (capacity.CPU_COST || capacity.MEMORY_COST && Config.isFeatureEnabled("showback")) { - $(".provision_create_service_cost_div").show(); - - if (capacity.CPU && capacity.CPU_COST) { - cost += capacity.CPU * capacity.CPU_COST - $(".cost_value", context).data("CPU_COST", capacity.CPU_COST); - } - - if (capacity.MEMORY && capacity.MEMORY_COST) { - cost += capacity.MEMORY * capacity.MEMORY_COST - $(".cost_value", context).data("MEMORY_COST", capacity.MEMORY_COST); - } - - $(".provision_create_service_cost_div", context).data("cost", cost) - var cost_value = cost*parseInt(role_template.cardinality); - $(".cost_value", context).html(cost_value.toFixed(2)); - } else { - $(".provision_create_service_cost_div").hide(); - } - - if (max_vms > min_vms) { - $( ".cardinality_slider", context).attr('data-options', 'start: '+min_vms+'; end: '+max_vms+';') - context.foundation(); - $( ".cardinality_slider_div", context).show(); - $( ".cardinality_no_slider_div", context).hide(); - - $( ".cardinality_slider", context).foundation('slider', 'set_value', role_template.cardinality); - - $( ".cardinality_slider", context).on('change', function(){ - $(".cardinality_value",context).html($(this).attr('data-slider')) - var cost_value = $(".provision_create_service_cost_div", context).data("cost")*$(this).attr('data-slider'); - $(".cost_value", context).html(cost_value.toFixed(2)); - }); - } else { - $( ".cardinality_slider_div", context).hide(); - $( ".cardinality_no_slider_div", context).show(); - } -} - -var provision_instance_type_accordion_id = 0; - -function generate_provision_instance_type_accordion(context, capacity) { - context.off(); - var memory_value; - var memory_unit; - - if (capacity.MEMORY > 1000){ - memory_value = Math.floor(capacity.MEMORY/1024); - memory_unit = "GB"; - } else { - memory_value = (capacity.MEMORY ? capacity.MEMORY : '-'); - memory_unit = "MB"; - } - - context.html( - '
'+ - '
'+ - '
'+ - '

'+ - ''+ - ' '+ - tr("Capacity")+ - ''+ - '

'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - ''+(capacity.CPU ? capacity.CPU : '-')+''+ - '
'+ - ''+tr("CPU")+''+ - '
'+ - '
'+ - ''+memory_value+''+ - ' '+ - ''+memory_unit+''+ - '
'+ - ''+tr("MEMORY")+''+ - '
'+ - ''+ - '
'+ - '
'+ - '
'+ - (Config.provision.create_vm.isEnabled("capacity_select") && (capacity.SUNSTONE_CAPACITY_SELECT != "NO") ? - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - ''+ - tr("Change Capacity")+ - ''+ - '
'+ - '
'+ - '
'+ - '

'+ - ''+ - '

'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
' : '' ) + - '
'); - - var cost = 0; - if (capacity.CPU_COST || capacity.MEMORY_COST && Config.isFeatureEnabled("showback")) { - $(".provision_create_template_cost_div").show(); - - if (capacity.CPU && capacity.CPU_COST) { - cost += capacity.CPU * capacity.CPU_COST - $(".cost_value").data("CPU_COST", capacity.CPU_COST); - } - - if (capacity.MEMORY && capacity.MEMORY_COST) { - cost += capacity.MEMORY * capacity.MEMORY_COST - $(".cost_value").data("MEMORY_COST", capacity.MEMORY_COST); - } - - $(".cost_value").html(cost.toFixed(2)); - } else { - $(".provision_create_template_cost_div").hide(); - } - - if (Config.provision.create_vm.isEnabled("capacity_select") && (capacity.SUNSTONE_CAPACITY_SELECT != "NO")) { - provision_instance_type_accordion_id += 1; - - var provision_instance_types_datatable = $('.provision_instance_types_table', context).dataTable({ - "iDisplayLength": 6, - "sDom" : '<"H">t<"F"lp>', - "bSort" : false, - "aLengthMenu": [[6, 12, 36, 72], [6, 12, 36, 72]], - "aoColumnDefs": [ - { "bVisible": false, "aTargets": ["all"]} - ], - "aoColumns": [ - { "mDataProp": "name" } - ], - "fnPreDrawCallback": function (oSettings) { - // create a thumbs container if it doesn't exist. put it in the dataTables_scrollbody div - if (this.$('tr', {"filter": "applied"} ).length == 0) { - this.html('
'+ - ''+ - ''+ - ''+ - ''+ - '
'+ - '
'+ - ''+ - tr("There are no instance_types available. Please contact your cloud administrator")+ - ''+ - '
'); - } else { - $(".provision_instance_types_table", context).html( - '
    '+ - '
'); - } - - return true; - }, - "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) { - var data = aData; - - var li = $('
  • '+ - '
      '+ - '
    • '+ - data.name+ - '
    • '+ - '
    • '+ - ''+ - ' '+ - ''+ - 'x'+data.cpu+' - '+ - ((data.memory > 1000) ? - (Math.floor(data.memory/1024)+'GB') : - (data.memory+'MB'))+ - ''+ - ''+ - '
    • '+ - '
    • '+ - (data.description || '')+ - '
    • '+ - '
    '+ - '
  • ').appendTo($(".provision_instance_types_ul", context)); - - $(".provision-pricing-table", li).data("opennebula", data) - - return nRow; - } - }); - - - $('.provision-search-input', context).on('keyup',function(){ - provision_instance_types_datatable.fnFilter( $(this).val() ); - }) - - $('.provision-search-input', context).on('change',function(){ - provision_instance_types_datatable.fnFilter( $(this).val() ); - }) - - context.on("click", ".provision-pricing-table.only-one" , function(){ - $(".cpu_value", context).html($(this).attr("cpu")); - - var memory_value; - var memory_unit; - - if ($(this).attr("memory") > 1000){ - memory_value = Math.floor($(this).attr("memory")/1024); - memory_unit = "GB"; - } else { - memory_value = $(this).attr("memory"); - memory_unit = "MB"; - } - - $(".memory_value", context).html(memory_value); - $(".memory_unit", context).html(memory_unit); - - if (Config.isFeatureEnabled("showback")) { - var cost = 0; - - if ($(".cost_value").data("CPU_COST")) { - cost += $(this).attr("cpu") * $(".cost_value").data("CPU_COST") - } - - if ($(".cost_value").data("MEMORY_COST")) { - cost += $(this).attr("memory") * $(".cost_value").data("MEMORY_COST") - } - - $(".cost_value").html(cost.toFixed(2)); - } - - $('.accordion a', context).first().trigger("click"); - }) - - $(document).foundation(); - - update_provision_instance_types_datatable(provision_instance_types_datatable); - } -} - -var provision_nic_accordion_id = 0; -var provision_nic_accordion_dd_id = 0; - -function generate_provision_network_table(context, nic, vnet_attr){ - context.off(); - var nic_span; - - if (nic) { - nic_span = ''+ - '' + tr("INTERFACE") + "  " + - '' + (nic.NETWORK||nic.NETWORK_ID) + "" + - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''; - } else if (vnet_attr) { - nic_span = '' + vnet_attr.description + "
    "+ - ''+ - '' + tr("INTERFACE") + "  " + - '' + tr("Select a Network") + "" + - ''+ - ''+ - tr("Select a Network for this interface")+ - ''+ - ''+ - ''+ - ''; - } else { - nic_span = - ''+ - '' + tr("INTERFACE") + "  " + - '' + tr("Select a Network") + "" + - ''+ - ''+ - tr("Select a Network for this interface")+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''; - } - - var dd_context = $('
    '+ - ''+ - nic_span + - ''+ - '
    '+ - '
    '+ - '
    '+ - '

    '+ - ''+ - '

    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    ').appendTo(context); - - provision_nic_accordion_dd_id += 1; - - var provision_networks_datatable = $('.provision_networks_table', dd_context).dataTable({ - "iDisplayLength": 6, - "sDom" : '<"H">t<"F"lp>', - "aLengthMenu": [[6, 12, 36, 72], [6, 12, 36, 72]], - "aoColumnDefs": [ - { "bVisible": false, "aTargets": ["all"]} - ], - "aoColumns": [ - { "mDataProp": "VNET.ID" }, - { "mDataProp": "VNET.NAME" } - ], - "fnPreDrawCallback": function (oSettings) { - // create a thumbs container if it doesn't exist. put it in the dataTables_scrollbody div - if (this.$('tr', {"filter": "applied"} ).length == 0) { - this.html('
    '+ - ''+ - ''+ - ''+ - ''+ - '
    '+ - '
    '+ - ''+ - tr("There are no networks available. Please contact your cloud administrator")+ - ''+ - '
    '); - } else { - $(".provision_networks_table", dd_context).html( - '
      '+ - '
    '); - } - - return true; - }, - "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) { - var data = aData.VNET; - $(".provision_networks_ul", dd_context).append( - '
  • '+ - '
      '+ - '
    • '+ - data.NAME+ - '
    • '+ - '
    • '+ - ''+ - '
    • '+ - '
    • '+ - (data.TEMPLATE.DESCRIPTION || '...')+ - '
    • '+ - '
    '+ - '
  • '); - - return nRow; - } - }); - - - $('.provision-search-input', dd_context).on('keyup',function(){ - provision_networks_datatable.fnFilter( $(this).val() ); - }) - - $('.provision-search-input', dd_context).on('change',function(){ - provision_networks_datatable.fnFilter( $(this).val() ); - }) - - dd_context.on("click", ".provision-pricing-table.more-than-one" , function(){ - $(".selected_network", dd_context).html( - '' + tr("INTERFACE") + "  " + - '' + $(this).attr("opennebula_name") + ""); - - $(".selected_network", dd_context).attr("opennebula_id", $(this).attr("opennebula_id")) - $(".selected_network", dd_context).removeAttr("template_nic") - - $('a', dd_context).first().trigger("click"); - }) - - dd_context.on("click", ".provision_remove_nic" , function(){ - dd_context.remove(); - return false; - }); - - if (!nic && !vnet_attr) { - $('a', dd_context).trigger("click"); - } - - update_provision_networks_datatable(provision_networks_datatable); -} - -function generate_provision_network_accordion(context, hide_add_button){ - context.off(); - context.html( - '
    '+ - '
    '+ - '
    '+ - '

    '+ - ''+ - ' '+ - tr("Network")+ - ''+ - '

    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - ''+ - tr("Add another Network Interface")+ - ''+ - '
    '+ - '
    '+ - '
    ') - - provision_nic_accordion_id += 1; - - $(".provision_add_network_interface", context).on("click", function(){ - generate_provision_network_table($(".accordion", context)); - }) - - $(document).foundation(); -} - -function show_provision_dashboard() { - $(".section_content").hide(); - $("#provision_dashboard").fadeIn(); - - $("#provision_dashboard").html(""); - - if (Config.provision.dashboard.isEnabled("quotas")) { - $("#provision_dashboard").append(provision_quotas_dashboard); - - - OpenNebula.User.show({ - data : { - id: "-1" - }, - success: function(request,user_json){ - var user = user_json.USER; - - initEmptyQuotas(user); - - if (!$.isEmptyObject(user.VM_QUOTA)){ - var default_user_quotas = Quotas.default_quotas(user.DEFAULT_USER_QUOTAS); - - var vms = quotaBar( - user.VM_QUOTA.VM.VMS_USED, - user.VM_QUOTA.VM.VMS, - default_user_quotas.VM_QUOTA.VM.VMS, - true); - - $("#provision_dashboard_rvms_percentage").html(vms["percentage"]); - $("#provision_dashboard_rvms_str").html(vms["str"]); - $("#provision_dashboard_rvms_meter").css("width", vms["percentage"]+"%"); - - var memory = quotaBarMB( - user.VM_QUOTA.VM.MEMORY_USED, - user.VM_QUOTA.VM.MEMORY, - default_user_quotas.VM_QUOTA.VM.MEMORY, - true); - - $("#provision_dashboard_memory_percentage").html(memory["percentage"]); - $("#provision_dashboard_memory_str").html(memory["str"]); - $("#provision_dashboard_memory_meter").css("width", memory["percentage"]+"%"); - - var cpu = quotaBarFloat( - user.VM_QUOTA.VM.CPU_USED, - user.VM_QUOTA.VM.CPU, - default_user_quotas.VM_QUOTA.VM.CPU, - true); - - $("#provision_dashboard_cpu_percentage").html(cpu["percentage"]); - $("#provision_dashboard_cpu_str").html(cpu["str"]); - $("#provision_dashboard_cpu_meter").css("width", cpu["percentage"]+"%"); - } - } - }) - } - - if (Config.provision.dashboard.isEnabled("vdcquotas")) { - $("#provision_dashboard").append(provision_vdc_quotas_dashboard); - - - OpenNebula.Group.show({ - data : { - id: "-1" - }, - success: function(request,group_json){ - var group = group_json.GROUP; - - initEmptyQuotas(group); - - if (!$.isEmptyObject(group.VM_QUOTA)){ - var default_group_quotas = Quotas.default_quotas(group.DEFAULT_GROUP_QUOTAS); - - var vms = quotaBar( - group.VM_QUOTA.VM.VMS_USED, - group.VM_QUOTA.VM.VMS, - default_group_quotas.VM_QUOTA.VM.VMS, - true); - - $("#provision_dashboard_vdc_rvms_percentage").html(vms["percentage"]); - $("#provision_dashboard_vdc_rvms_str").html(vms["str"]); - $("#provision_dashboard_vdc_rvms_meter").css("width", vms["percentage"]+"%"); - - var memory = quotaBarMB( - group.VM_QUOTA.VM.MEMORY_USED, - group.VM_QUOTA.VM.MEMORY, - default_group_quotas.VM_QUOTA.VM.MEMORY, - true); - - $("#provision_dashboard_vdc_memory_percentage").html(memory["percentage"]); - $("#provision_dashboard_vdc_memory_str").html(memory["str"]); - $("#provision_dashboard_vdc_memory_meter").css("width", memory["percentage"]+"%"); - - var cpu = quotaBarFloat( - group.VM_QUOTA.VM.CPU_USED, - group.VM_QUOTA.VM.CPU, - default_group_quotas.VM_QUOTA.VM.CPU, - true); - - $("#provision_dashboard_vdc_cpu_percentage").html(cpu["percentage"]); - $("#provision_dashboard_vdc_cpu_str").html(cpu["str"]); - $("#provision_dashboard_vdc_cpu_meter").css("width", cpu["percentage"]+"%"); - } - } - }) - } - - if (Config.provision.dashboard.isEnabled("vms")) { - $("#provision_dashboard").append(provision_vms_dashboard); - - var start_time = Math.floor(new Date().getTime() / 1000); - // ms to s - - // 604800 = 7 days = 7*24*60*60 - start_time = start_time - 604800; - - // today - var end_time = -1; - - var options = { - "start_time": start_time, - "end_time": end_time, - "userfilter": config["user_id"] - } - - var no_table = true; - - OpenNebula.VM.accounting({ - success: function(req, response){ - fillAccounting($("#dashboard_vm_accounting"), req, response, no_table); - }, - error: onError, - data: options - }); - - OpenNebula.VM.list({ - timeout: true, - success: function (request, item_list){ - var total = 0; - var running = 0; - var off = 0; - var error = 0; - var deploying = 0; - - $.each(item_list, function(index, vm){ - if (vm.VM.UID == config["user_id"]) { - var state = get_provision_vm_state(vm.VM); - - total = total + 1; - - switch (state.color) { - case "deploying": - deploying = deploying + 1; - break; - case "error": - error = error + 1; - break; - case "running": - running = running + 1; - break; - case "powering_off": - off = off + 1; - break; - case "off": - off = off + 1; - break; - } - } - }) - - var context = $("#provision_vms_dashboard"); - $("#provision_dashboard_total", context).html(total); - $("#provision_dashboard_running", context).html(running); - $("#provision_dashboard_off", context).html(off); - $("#provision_dashboard_error", context).html(error); - $("#provision_dashboard_deploying", context).html(deploying); - }, - error: onError - }); - } - - if (Config.provision.dashboard.isEnabled("vdcvms")) { - $("#provision_dashboard").append(provision_vdc_vms_dashboard); - - var start_time = Math.floor(new Date().getTime() / 1000); - // ms to s - - // 604800 = 7 days = 7*24*60*60 - start_time = start_time - 604800; - - // today - var end_time = -1; - - var options = { - "start_time": start_time, - "end_time": end_time - } - - var no_table = true; - - OpenNebula.VM.accounting({ - success: function(req, response){ - fillAccounting($("#dashboard_vdc_vm_accounting"), req, response, no_table); - }, - error: onError, - data: options - }); - - - OpenNebula.VM.list({ - timeout: true, - success: function (request, item_list){ - var total = 0; - var running = 0; - var off = 0; - var error = 0; - var deploying = 0; - - $.each(item_list, function(index, vm){ - var state = get_provision_vm_state(vm.VM); - - total = total + 1; - - switch (state.color) { - case "deploying": - deploying = deploying + 1; - break; - case "error": - error = error + 1; - break; - case "running": - running = running + 1; - break; - case "powering_off": - off = off + 1; - break; - case "off": - off = off + 1; - break; - default: - break; - } - }) - - var context = $("#provision_vdc_vms_dashboard"); - $("#provision_dashboard_vdc_total", context).html(total); - $("#provision_dashboard_vdc_running", context).html(running); - $("#provision_dashboard_vdc_off", context).html(off); - $("#provision_dashboard_vdc_error", context).html(error); - $("#provision_dashboard_vdc_deploying", context).html(deploying); - }, - error: onError - }); - } - - if (Config.provision.dashboard.isEnabled("users")) { - $("#provision_dashboard").append(provision_users_dashboard); - - var start_time = Math.floor(new Date().getTime() / 1000); - // ms to s - - // 604800 = 7 days = 7*24*60*60 - start_time = start_time - 604800; - - // today - var end_time = -1; - - var options = { - "start_time": start_time, - "end_time": end_time, - "group": config["user_gid"] - } - - var no_table = true; - - OpenNebula.VM.accounting({ - success: function(req, response){ - fillAccounting($("#dashboard_vdc_user_accounting"), req, response, no_table); - }, - error: onError, - data: options - }); - - OpenNebula.User.list({ - timeout: true, - success: function (request, item_list){ - var total = item_list.length || 0; - - var context = $("#provision_users_dashboard"); - $("#provision_dashboard_users_total", context).html(total); - }, - error: onError - }); - } - -} - - -function show_provision_user_info() { - Sunstone.runAction("Provision.User.show", "-1"); - $(".section_content").hide(); - $("#provision_user_info").fadeIn(); - $("dd.active a", $("#provision_user_info")).trigger("click"); -} - - -function show_provision_user_info_callback(request, response) { - var info = response.USER; - - var default_user_quotas = Quotas.default_quotas(info.DEFAULT_USER_QUOTAS); - - var quotas_tab_html = initQuotasPanel(info, default_user_quotas, - "#provision_user_info_quotas_div", false); - - $("#provision_user_info_quotas_div").html(quotas_tab_html); - - setupQuotasPanel(info, - "#provision_user_info_quotas_div", - false, - "User"); - - var ssh_key = info.TEMPLATE.SSH_PUBLIC_KEY; - if (ssh_key && ssh_key.length) { - $("#provision_ssh_key").val(ssh_key); - $(".provision_add_ssh_key_button").hide(); - $(".provision_update_ssh_key_button").show(); - } else { - $(".provision_add_ssh_key_button").show(); - $(".provision_update_ssh_key_button").hide(); - } - - $('#provision_new_language option[value="'+config['user_config']["lang"]+'"]').attr('selected','selected'); - $('#provision_user_views_select option[value="'+config['user_config']["default_view"]+'"]').attr('selected','selected'); - - accountingGraphs( - $("#provision_user_info_acct_div"), - { fixed_user: info.ID, - fixed_group_by: "vm" }); - - - if (Config.isFeatureEnabled("showback")) { - showbackGraphs( - $("#provision_user_info_showback_div"), - { fixed_user: info.ID, fixed_group: ""}); - } -} - - -function show_provision_group_info_callback(request, response) { - var info = response.GROUP; - - var context = $("#provision_manage_vdc"); - - var default_group_quotas = Quotas.default_quotas(info.DEFAULT_GROUP_QUOTAS); - - var quotas_tab_html = initQuotasPanel(info, default_group_quotas, - "#provision_vdc_quotas_div", false); - - $("#provision_vdc_quotas_div").html(quotas_tab_html); - - setupQuotasPanel(info, - "#provision_vdc_quotas_div", - false, - "Group"); - - accountingGraphs( - $("#provision_info_vdc_group_acct", context), - { fixed_group: info.ID, - init_group_by: "user" }); - - if (Config.isFeatureEnabled("showback")) { - showbackGraphs( - $("#provision_info_vdc_group_showback", context), - { fixed_user: "", fixed_group: info.ID }); - } - - $("#acct_placeholder", context).hide(); -} - -function show_provision_create_vm() { - OpenNebula.Helper.clear_cache("VMTEMPLATE"); - update_provision_templates_datatable(provision_system_templates_datatable); - provision_system_templates_datatable.fnFilter("^-$", 2, true, false) - - update_provision_templates_datatable(provision_vdc_templates_datatable); - provision_vdc_templates_datatable.fnFilter("^(?!\-$)", 2, true, false); - provision_vdc_templates_datatable.fnFilter("^1$", 3, true, false); - - if (Config.isTabPanelEnabled("provision-tab", "templates")) { - update_provision_templates_datatable(provision_saved_templates_datatable); - provision_saved_templates_datatable.fnFilter("^(?!\-$)", 2, true, false); - provision_saved_templates_datatable.fnFilter("^0$", 3, true, false); - } - - $(".provision_accordion_template .selected_template").hide(); - $(".provision_accordion_template .select_template").show(); - - $("#provision_create_vm .provision_capacity_selector").html(""); - $("#provision_create_vm .provision_network_selector").html(""); - $("#provision_create_vm .provision_custom_attributes_selector").html("") - - $("#provision_create_vm dd:not(.active) a[href='#provision_dd_template']").trigger("click") - - $(".section_content").hide(); - $("#provision_create_vm").fadeIn(); -} - -function show_provision_create_flow() { - update_provision_flow_templates_datatable(provision_flow_templates_datatable); - - var context = $("#provision_create_flow"); - - $("#provision_customize_flow_template", context).hide(); - $("#provision_customize_flow_template", context).html(""); - - $(".provision_network_selector", context).html("") - $(".provision_custom_attributes_selector", context).html("") - - $(".provision_accordion_flow_template .selected_template", context).hide(); - $(".provision_accordion_flow_template .select_template", context).show(); - - $("dd:not(.active) a[href='#provision_dd_flow_template']", context).trigger("click") - - $(".alert-box-error", context).hide(); - - $(".section_content").hide(); - $("#provision_create_flow").fadeIn(); -} - -function show_provision_create_user() { - $(".section_content").hide(); - $("#provision_create_user").fadeIn(); - $(document).foundation(); -} - -function show_provision_vm_list(timeout, context) { - $(".section_content").hide(); - $(".provision_vms_list_section").fadeIn(); - - $("dd:not(.active) .provision_back", $(".provision_vms_list_section")).trigger("click"); - $(".provision_vms_list_refresh_button", $(".provision_vms_list_section")).trigger("click"); -} - -function show_provision_flow_list(timeout) { - $(".section_content").hide(); - $(".provision_flows_list_section").fadeIn(); - - $("dd:not(.active) .provision_back", $(".provision_flows_list_section")).trigger("click"); - $(".provision_flows_list_refresh_button", $(".provision_flows_list_section")).trigger("click"); -} - -function show_provision_user_list(timeout) { - $(".section_content").hide(); - $(".provision_users_list_section").fadeIn(); - - $("dd:not(.active) .provision_back", $(".provision_users_list_section")).trigger("click"); - $(".provision_users_list_refresh_button", $(".provision_users_list_section")).trigger("click"); -} - -function show_provision_vdc_info() { - $(".section_content").hide(); - $("#provision_manage_vdc").fadeIn(); - - Sunstone.runAction('Provision.Group.show', "-1"); -} - -function show_provision_template_list(timeout) { - $(".section_content").hide(); - $(".provision_templates_list_section").fadeIn(); - - //$("dd:not(.active) .provision_back", $(".provision_templates_list_section")).trigger("click"); - $(".provision_templates_list_refresh_button", $(".provision_templates_list_section")).trigger("click"); -} - -function update_provision_templates_datatable(datatable, timeout) { - datatable.html('
    '+ - ''+ - ''+ - ''+ - ''+ - '
    '+ - '
    '+ - ''+ - ''+ - '
    '); - - setTimeout( function(){ - OpenNebula.Template.list({ - timeout: true, - success: function (request, item_list){ - datatable.fnClearTable(true); - if (item_list.length == 0) { - datatable.html('
    '+ - ''+ - ''+ - ''+ - ''+ - '
    '+ - '
    '+ - ''+ - tr("There are no templates available")+ - ''+ - '
    '); - } else { - datatable.fnAddData(item_list); - } - }, - error: onError - }); - }, timeout); -} - -function update_provision_instance_types_datatable(datatable) { - datatable.fnClearTable(true); - if (!config['instance_types'] || config['instance_types'].length == 0) { - datatable.html('
    '+ - ''+ - ''+ - ''+ - ''+ - '
    '+ - '
    '+ - ''+ - tr("There are no instance types available")+ - ''+ - '
    '); - } else { - datatable.fnAddData(config['instance_types']); - } -} - -function update_provision_networks_datatable(datatable) { - datatable.html('
    '+ - ''+ - ''+ - ''+ - ''+ - '
    '+ - '
    '+ - ''+ - ''+ - '
    '); - - OpenNebula.Network.list({ - timeout: true, - success: function (request, item_list){ - datatable.fnClearTable(true); - if (item_list.length == 0) { - datatable.html('
    '+ - ''+ - ''+ - ''+ - ''+ - '
    '+ - '
    '+ - ''+ - tr("There are no networks available.")+ - ''+ - '
    '); - } else { - datatable.fnAddData(item_list); - } - }, - error: onError - }); -} - - -function update_provision_flow_templates_datatable(datatable, timeout) { - datatable.html('
    '+ - ''+ - ''+ - ''+ - ''+ - '
    '+ - '
    '+ - ''+ - ''+ - '
    '); - - setTimeout( function(){ - OpenNebula.ServiceTemplate.list({ - timeout: true, - success: function (request, item_list){ - datatable.fnClearTable(true); - if (item_list.length == 0) { - datatable.html('
    '+ - ''+ - ''+ - ''+ - ''+ - '
    '+ - '
    '+ - ''+ - tr("There are no templates available")+ - ''+ - '
    '); - } else { - datatable.fnAddData(item_list); - } - }, - error: onError - }); - }, timeout); -} - - -function update_provision_users_datatable(datatable, timeout) { - datatable.html('
    '+ - ''+ - ''+ - ''+ - ''+ - '
    '+ - '
    '+ - ''+ - ''+ - '
    '); - - setTimeout( function(){ - OpenNebula.User.list({ - timeout: true, - success: function (request, item_list, quotas_list){ - datatable.fnClearTable(true); - if (item_list.length == 0) { - datatable.html('
    '+ - ''+ - ''+ - ''+ - ''+ - '
    '+ - '
    '+ - ''+ - tr("The list of users is empty")+ - ''+ - '
    '); - } else { - provision_quotas_list = quotas_list; - datatable.fnAddData(item_list); - } - }, - error: onError - }) - }, timeout ); -} - -function fill_provision_vms_datatable(datatable, item_list){ - datatable.fnClearTable(true); - if (item_list.length == 0) { - datatable.html('
    '+ - ''+ - ''+ - ''+ - ''+ - '
    '+ - '
    '+ - ''+ - tr("There are no Virtual Machines")+ - ''+ - '
    '+ - '
    '+ - '
    '); - } else { - datatable.fnAddData(item_list); - } -} - -function update_provision_vms_datatable(datatable, timeout) { - datatable.html('
    '+ - ''+ - ''+ - ''+ - ''+ - '
    '+ - '
    '+ - ''+ - ''+ - '
    '); - - var data = datatable.data('opennebula'); - if (data) { - fill_provision_vms_datatable(datatable, data) - } else { - setTimeout( function(){ - OpenNebula.VM.list({ - timeout: true, - success: function (request, item_list){ - fill_provision_vms_datatable(datatable, item_list) - }, - error: onError - }) - }, timeout ); - } -} - -function update_provision_flows_datatable(datatable, timeout) { - datatable.html('
    '+ - ''+ - ''+ - ''+ - ''+ - '
    '+ - '
    '+ - ''+ - ''+ - '
    '); - - setTimeout( function(){ - OpenNebula.Service.list({ - timeout: true, - success: function (request, item_list){ - $(".flow_error_message").hide(); - datatable.fnClearTable(true); - if (item_list.length == 0) { - datatable.html('
    '+ - ''+ - ''+ - ''+ - ''+ - '
    '+ - '
    '+ - ''+ - tr("There are no Services")+ - ''+ - '
    '+ - '
    '+ - '
    '); - } else { - datatable.fnAddData(item_list); - } - }, - error: function(request, error_json) { - datatable.html('
    '+ - '
    '+ - '
    '+ - ''+ - '
    '+ - '
    '+ - ''+ - ''+ - '
    '); - - onError(request, error_json, $(".flow_error_message")); - } - }) - }, timeout ); -} - - -function get_provision_flow_start_time(data) { - if (data.log) { - return data.log[0].timestamp - } else { - return null; - } -} - -// @params -// data: and BODY object of the Document representing the Service -// Example: data.ID -// @returns and object containing the following properties -// color: css class for this state. -// color + '-color' font color class -// color + '-bg' background class -// str: user friendly state string -function get_provision_flow_state(data) { - var state = OpenNebula.Service.state(data.state); - var state_color; - var state_str; - - switch (state) { - case tr("PENDING"): - state_color = 'deploying'; - state_str = tr("PENDING"); - break; - case tr("DEPLOYING"): - state_color = 'deploying'; - state_str = tr("DEPLOYING"); - break; - case tr("UNDEPLOYING"): - state_color = 'powering_off'; - state_str = tr("UNDEPLOYING"); - break; - case tr("FAILED_UNDEPLOYING"): - state_color = 'error'; - state_str = tr("FAILED UNDEPLOYING"); - break; - case tr("FAILED_DEPLOYING"): - state_color = 'error'; - state_str = tr("FAILED DEPLOYING"); - break; - case tr("FAILED_SCALING"): - state_color = 'error'; - state_str = tr("FAILED SCALING"); - break; - case tr("WARNING"): - state_color = 'error'; - state_str = tr("WARNING"); - break; - case tr("RUNNING"): - state_color = 'running'; - state_str = tr("RUNNING"); - break; - case tr("SCALING"): - state_color = 'deploying'; - state_str = tr("SCALING"); - break; - case tr("COOLDOWN"): - state_color = 'error'; - state_str = tr("COOLDOWN"); - break; - case tr("DONE"): - state_color = 'off'; - state_str = tr("DONE"); - break; - default: - state_color = 'powering_off'; - state_str = tr("UNKNOWN"); - break; - } - - return { - color: state_color, - str: state_str - } -} - -// @params -// data: and VM object -// Example: data.ID -// @returns and object containing the following properties -// color: css class for this state. -// color + '-color' font color class -// color + '-bg' background class -// str: user friendly state string -function get_provision_vm_state(data) { - var state = OpenNebula.Helper.resource_state("vm",data.STATE); - var state_color; - var state_str; - - switch (state) { - case tr("INIT"): - case tr("PENDING"): - case tr("HOLD"): - state_color = 'deploying'; - state_str = tr("DEPLOYING") + " (1/3)"; - break; - case tr("FAILED"): - state_color = 'error'; - state_str = tr("ERROR"); - break; - case tr("ACTIVE"): - var lcm_state = OpenNebula.Helper.resource_state("short_vm_lcm",data.LCM_STATE); - - switch (lcm_state) { - case tr("LCM_INIT"): - state_color = 'deploying'; - state_str = tr("DEPLOYING") + " (1/3)"; - break; - case tr("PROLOG"): - state_color = 'deploying'; - state_str = tr("DEPLOYING") + " (2/3)"; - break; - case tr("BOOT"): - state_color = 'deploying'; - state_str = tr("DEPLOYING") + " (3/3)"; - break; - case tr("RUNNING"): - case tr("SNAPSHOT"): - case tr("MIGRATE"): - state_color = 'running'; - state_str = tr("RUNNING"); - break; - case tr("HOTPLUG"): - state_color = 'deploying'; - state_str = tr("SAVING IMAGE"); - break; - case tr("FAILURE"): - state_color = 'error'; - state_str = tr("ERROR"); - break; - case tr("SAVE"): - case tr("EPILOG"): - case tr("SHUTDOWN"): - case tr("CLEANUP"): - state_color = 'powering_off'; - state_str = tr("POWERING OFF"); - break; - case tr("UNKNOWN"): - state_color = 'powering_off'; - state_str = tr("UNKNOWN"); - break; - default: - state_color = 'powering_off'; - state_str = tr("UNKNOWN"); - break; - } - - break; - case tr("STOPPED"): - case tr("SUSPENDED"): - case tr("POWEROFF"): - state_color = 'off'; - state_str = tr("OFF"); - - break; - default: - state_color = 'powering_off'; - state_str = tr("UNKNOWN"); - break; - } - - return { - color: state_color, - str: state_str - } -} - -function get_provision_disk_image(data) { - var disks = [] - if ($.isArray(data.TEMPLATE.DISK)) - disks = data.TEMPLATE.DISK - else if (!$.isEmptyObject(data.TEMPLATE.DISK)) - disks = [data.TEMPLATE.DISK] - - if (disks.length > 0) { - return ' ' + disks[0].IMAGE; - } else { - return ' -'; - } -} - -function get_provision_ips(data) { - return ' ' + ip_str(data, " - "); -} - -// @params -// data: and IMAGE object -// Example: data.ID -// @returns and object containing the following properties -// color: css class for this state. -// color + '-color' font color class -// color + '-bg' background class -// str: user friendly state string -function get_provision_image_state(data) { - var state = OpenNebula.Helper.resource_state("image",data.STATE); - var state_color; - var state_str; - - switch (state) { - case tr("READY"): - case tr("USED"): - state_color = 'running'; - state_str = tr("READY"); - break; - case tr("DISABLED"): - case tr("USED_PERS"): - state_color = 'off'; - state_str = tr("OFF"); - break; - case tr("LOCKED"): - case tr("CLONE"): - case tr("INIT"): - state_color = 'deploying'; - state_str = tr("DEPLOYING") + " (1/3)"; - break; - case tr("ERROR"): - state_color = 'error'; - state_str = tr("ERROR"); - break; - case tr("DELETE"): - state_color = 'error'; - state_str = tr("DELETING"); - break; - default: - state_color = 'powering_off'; - state_str = tr("UNKNOWN"); - break; - } - - return { - color: state_color, - str: state_str - } -} - -function setup_info_vm(context) { - function update_provision_vm_info(vm_id, context) { - //var tempScrollTop = $(window).scrollTop(); - $(".provision_info_vm_name", context).text(""); - $(".provision_info_vm_loading", context).show(); - $(".provision_info_vm", context).css('visibility', 'hidden'); - - OpenNebula.VM.show({ - data : { - id: vm_id - }, - error: onError, - success: function(request, response){ - var data = response.VM - var state = get_provision_vm_state(data); - - switch (state.color) { - case "deploying": - $(".provision_reboot_confirm_button", context).hide(); - $(".provision_poweroff_confirm_button", context).hide(); - $(".provision_poweron_button", context).hide(); - $(".provision_delete_confirm_button", context).show(); - $(".provision_shutdownhard_confirm_button", context).hide(); - $(".provision_snapshot_button", context).hide(); - $(".provision_vnc_button", context).hide(); - $(".provision_snapshot_button_disabled", context).hide(); - $(".provision_vnc_button_disabled", context).hide(); - break; - case "running": - $(".provision_reboot_confirm_button", context).show(); - $(".provision_poweroff_confirm_button", context).show(); - $(".provision_poweron_button", context).hide(); - $(".provision_delete_confirm_button", context).hide(); - $(".provision_shutdownhard_confirm_button", context).show(); - $(".provision_snapshot_button", context).hide(); - $(".provision_vnc_button", context).show(); - $(".provision_snapshot_button_disabled", context).show(); - $(".provision_vnc_button_disabled", context).hide(); - break; - case "off": - $(".provision_reboot_confirm_button", context).hide(); - $(".provision_poweroff_confirm_button", context).hide(); - $(".provision_poweron_button", context).show(); - $(".provision_delete_confirm_button", context).show(); - $(".provision_shutdownhard_confirm_button", context).hide(); - $(".provision_snapshot_button", context).show(); - $(".provision_vnc_button", context).hide(); - $(".provision_snapshot_button_disabled", context).hide(); - $(".provision_vnc_button_disabled", context).show(); - break; - case "powering_off": - case "error": - $(".provision_reboot_confirm_button", context).hide(); - $(".provision_poweroff_confirm_button", context).hide(); - $(".provision_poweron_button", context).hide(); - $(".provision_delete_confirm_button", context).show(); - $(".provision_shutdownhard_confirm_button", context).hide(); - $(".provision_snapshot_button", context).hide(); - $(".provision_vnc_button", context).hide(); - $(".provision_snapshot_button_disabled", context).hide(); - $(".provision_vnc_button_disabled", context).hide(); - break; - default: - color = 'secondary'; - $(".provision_reboot_confirm_button", context).hide(); - $(".provision_poweroff_confirm_button", context).hide(); - $(".provision_poweron_button", context).hide(); - $(".provision_delete_confirm_button", context).show(); - $(".provision_shutdownhard_confirm_button", context).hide(); - $(".provision_snapshot_button", context).hide(); - $(".provision_vnc_button", context).hide(); - $(".provision_snapshot_button_disabled", context).hide(); - $(".provision_vnc_button_disabled", context).hide(); - break; - } - - if (!enableVnc(data) && !enableSPICE(data)) { - $(".provision_vnc_button", context).hide(); - $(".provision_vnc_button_disabled", context).hide(); - } - - $(".provision_info_vm", context).attr("vm_id", data.ID); - $(".provision_info_vm", context).data("vm", data); - - $(".provision_info_vm_name", context).text(data.NAME); - - $(".provision-pricing-table_vm_info", context).html( - '
  • '+ - ''+ - ' '+ - state.str+ - ''+ - '
  • '+ - '
  • '+ - '
    '+ - '
  • '+ - '
  • '+ - ''+ - ' '+ - 'x'+data.TEMPLATE.CPU+' - '+ - ((data.TEMPLATE.MEMORY > 1000) ? - (Math.floor(data.TEMPLATE.MEMORY/1024)+'GB') : - (data.TEMPLATE.MEMORY+'MB'))+ - ''+ - '
  • '+ - '
  • '+ - ''+ - get_provision_disk_image(data) + - ''+ - '
  • '+ - '
  • '+ - ''+ - get_provision_ips(data) + - ''+ - '
  • '+ - //'
  • '+ - // ''+ - // "ID: " + - // data.ID+ - // '' + - //'
  • '+ - '
  • '+ - '
    '+ - '
  • '+ - '
  • '+ - ''+ - ' '+ - _format_date(data.STIME)+ - ''+ - '
  • '+ - '
  • '+ - ''+ - ' '+ - data.UNAME+ - ''+ - '
  • '+ - '
  • '+ - ''+ - ' '+ - data.ID+ - ''+ - '
  • '+ - '
  • '+ - '
  • '); - - $(".provision_confirm_action:first", context).html(""); - - $(".provision_info_vm", context).css('visibility', 'visible'); - $(".provision_info_vm_loading", context).hide(); - - //$(window).scrollTop(tempScrollTop); - - OpenNebula.VM.monitor({ - data : { - timeout: true, - id: data.ID, - monitor: { - monitor_resources : "CPU,MEMORY,NET_TX,NET_RX" - } - }, - success: function(request, response){ - var vm_graphs = [ - { - monitor_resources : "CPU", - labels : "Real CPU", - humanize_figures : false, - div_graph : $(".vm_cpu_graph", context) - }, - { - monitor_resources : "MEMORY", - labels : "Real MEM", - humanize_figures : true, - div_graph : $(".vm_memory_graph", context) - }, - { - labels : "Network reception", - monitor_resources : "NET_RX", - humanize_figures : true, - convert_from_bytes : true, - div_graph : $(".vm_net_rx_graph", context) - }, - { - labels : "Network transmission", - monitor_resources : "NET_TX", - humanize_figures : true, - convert_from_bytes : true, - div_graph : $(".vm_net_tx_graph", context) - }, - { - labels : "Network reception speed", - monitor_resources : "NET_RX", - humanize_figures : true, - convert_from_bytes : true, - y_sufix : "B/s", - derivative : true, - div_graph : $(".vm_net_rx_speed_graph", context) - }, - { - labels : "Network transmission speed", - monitor_resources : "NET_TX", - humanize_figures : true, - convert_from_bytes : true, - y_sufix : "B/s", - derivative : true, - div_graph : $(".vm_net_tx_speed_graph", context) - } - ]; - - for(var i=0; i'+ - '
    '+ - '
    '+ - ''+ - tr("This Virtual Machine will be saved in a new Template. Only the main disk will be preserved!")+ - '
    '+ - tr("You can then create a new Virtual Machine using this Template")+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - ''+ - '
    '+ - '
    '+ - '
    '+ - ''+ - '×'+ - ''); - }); - - context.on("click", ".provision_snapshot_create_button", function(){ - var button = $(this); - button.attr("disabled", "disabled"); - var context = $(".provision_info_vm[vm_id]"); - - var vm_id = context.attr("vm_id"); - var template_name = $('.provision_snapshot_name', context).val(); - - OpenNebula.VM.save_as_template({ - data : { - id: vm_id, - extra_param: { - name : template_name - } - }, - success: function(request, response){ - OpenNebula.Helper.clear_cache("VMTEMPLATE"); - notifyMessage(tr("Image") + ' ' + request.request.data[0][1].name + ' ' + tr("saved successfully")) - update_provision_vm_info(vm_id, context); - button.removeAttr("disabled"); - }, - error: function(request, response){ - onError(request, response); - button.removeAttr("disabled"); - } - }) - - return false; - }); - } - - context.on("click", ".provision_delete_confirm_button", function(){ - $(".provision_confirm_action:first", context).html( - '
    '+ - '
    '+ - '
    '+ - ''+ - tr("Be careful, this action will inmediately destroy your Virtual Machine")+ - '
    '+ - tr("All the information will be lost!")+ - '
    '+ - '
    '+ - '
    '+ - ''+tr("Delete")+''+ - '
    '+ - '
    '+ - '×'+ - '
    '); - }); - - context.on("click", ".provision_shutdownhard_confirm_button", function(){ - $(".provision_confirm_action:first", context).html( - '
    '+ - '
    '+ - '
    '+ - ''+ - tr("Be careful, this action will inmediately destroy your Virtual Machine")+ - '
    '+ - tr("All the information will be lost!")+ - '
    '+ - '
    '+ - '
    '+ - ''+tr("Delete")+''+ - '
    '+ - '
    '+ - '×'+ - '
    '); - }); - - context.on("click", ".provision_poweroff_confirm_button", function(){ - $(".provision_confirm_action:first", context).html( - '
    '+ - '
    '+ - '
    '+ - ''+ - tr("This action will power off this Virtual Machine. The Virtual Machine will remain in the poweroff state, and can be powered on later")+ - '
    '+ - '
    '+ - tr("You can send the power off signal to the Virtual Machine (this is equivalent to execute the command from the console). If that doesn't effect your Virtual Machine, try to Power off the machine (this is equivalent to pressing the power off button in a physical computer).")+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - ''+tr("Power off")+''+ - ''+ - ''+ - '
    '+ - '
    '+ - '×'+ - '
    '); - }); - - context.on("click", ".provision_reboot_confirm_button", function(){ - $(".provision_confirm_action:first", context).html( - '
    '+ - '
    '+ - '
    '+ - ''+ - tr("This action will reboot this Virtual Machine.")+ - '
    '+ - '
    '+ - tr("You can send the reboot signal to the Virtual Machine (this is equivalent to execute the reboot command form the console). If that doesn't effect your Virtual Machine, try to Reboot the machine (this is equivalent to pressing the reset button a physical computer).")+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - ''+tr("Reboot")+''+ - ''+ - ''+ - '
    '+ - '
    '+ - '×'+ - '
    '); - }); - - context.on("click", ".provision_delete_button", function(){ - var button = $(this); - button.attr("disabled", "disabled"); - var vm_id = $(".provision_info_vm", context).attr("vm_id"); - - OpenNebula.VM.del({ - data : { - id: vm_id - }, - success: function(request, response){ - $(".provision_back", context).click(); - $(".provision_vms_list_refresh_button", context).click(); - button.removeAttr("disabled"); - }, - error: function(request, response){ - onError(request, response); - button.removeAttr("disabled"); - } - }) - - return false; - }); - - context.on("click", ".provision_shutdownhard_button", function(){ - var button = $(this); - button.attr("disabled", "disabled"); - var vm_id = $(".provision_info_vm", context).attr("vm_id"); - - OpenNebula.VM.cancel({ - data : { - id: vm_id - }, - success: function(request, response){ - $(".provision_back", context).click(); - $(".provision_vms_list_refresh_button", context).click(); - button.removeAttr("disabled"); - }, - error: function(request, response){ - onError(request, response); - button.removeAttr("disabled"); - } - }) - - return false; - }); - - context.on("click", ".provision_poweroff_button", function(){ - var button = $(this); - button.attr("disabled", "disabled"); - var vm_id = $(".provision_info_vm", context).attr("vm_id"); - var poweroff_action = $('input[name=provision_poweroff_radio]:checked').val() - - OpenNebula.VM[poweroff_action]({ - data : { - id: vm_id - }, - success: function(request, response){ - update_provision_vm_info(vm_id, context); - button.removeAttr("disabled"); - }, - error: function(request, response){ - onError(request, response); - button.removeAttr("disabled"); - } - }) - - return false; - }); - - context.on("click", ".provision_reboot_button", function(){ - var button = $(this); - button.attr("disabled", "disabled"); - - var vm_id = $(".provision_info_vm", context).attr("vm_id"); - var reboot_action = $('input[name=provision_reboot_radio]:checked').val() - - OpenNebula.VM[reboot_action]({ - data : { - id: vm_id - }, - success: function(request, response){ - update_provision_vm_info(vm_id, context); - button.removeAttr("disabled"); - }, - error: function(request, response){ - onError(request, response); - button.removeAttr("disabled"); - } - }) - - return false; - }); - - context.on("click", ".provision_poweron_button", function(){ - var button = $(this); - button.attr("disabled", "disabled"); - var vm_id = $(".provision_info_vm", context).attr("vm_id"); - - OpenNebula.VM.resume({ - data : { - id: vm_id - }, - success: function(request, response){ - update_provision_vm_info(vm_id, context); - button.removeAttr("disabled"); - }, - error: function(request, response){ - onError(request, response); - button.removeAttr("disabled"); - } - }) - - return false; - }); - - context.on("click", ".provision_vnc_button", function(){ - var button = $(this); - button.attr("disabled", "disabled"); - var vm_id = $(".provision_info_vm", context).attr("vm_id"); - var vm_data = $(".provision_info_vm", context).data("vm"); - - OpenNebula.VM.startvnc({ - data : { - id: vm_id - }, - success: function(request, response){ - if (enableVnc(vm_data)) { - var proxy_host = window.location.hostname; - var proxy_port = config['system_config']['vnc_proxy_port']; - var pw = response["password"]; - var token = response["token"]; - var vm_name = response["vm_name"]; - var path = '?token='+token; - - var url = "vnc?"; - url += "host=" + proxy_host; - url += "&port=" + proxy_port; - url += "&token=" + token; - url += "&password=" + pw; - url += "&encrypt=" + config['user_config']['vnc_wss']; - url += "&title=" + vm_name; - - window.open(url, '', '_blank'); - button.removeAttr("disabled"); - } else if (enableSPICE(vm_data)) { - var host, port, password, scheme = "ws://", uri, token, vm_name; - - if (config['user_config']['vnc_wss'] == "yes") { - scheme = "wss://"; - } - - host = window.location.hostname; - port = config['system_config']['vnc_proxy_port']; - password = response["password"]; - token = response["token"]; - vm_name = response["vm_name"]; - - uri = scheme + host + ":" + port + "?token=" + token; - - var url = "spice?"; - url += "host=" + host; - url += "&port=" + port; - url += "&token=" + token; - url += "&password=" + password; - url += "&encrypt=" + config['user_config']['vnc_wss']; - url += "&title=" + vm_name; - - window.open(url, '', '_blank'); - button.removeAttr("disabled"); - } else { - notifyError("The remote console is not enabled for this VM") - } - }, - error: function(request, response){ - onError(request, response); - button.removeAttr("disabled"); - } - }) - - return false; - }); - - context.on("click", ".provision_refresh_info", function(){ - var vm_id = $(".provision_info_vm", context).attr("vm_id"); - update_provision_vm_info(vm_id, context); - return false; - }); - - // - // Info VM - // - - $(".provision_list_vms", context).on("click", ".provision_info_vm_button", function(){ - $("a.provision_show_vm_accordion", context).trigger("click"); - // TODO loading - - var vm_id = $(this).parents(".provision-pricing-table").attr("opennebula_id") - update_provision_vm_info(vm_id, context); - return false; - }) -} - -function setup_provision_vms_list(context, opts) { - var provision_vms_datatable = $('.provision_vms_table', context).dataTable({ - "iDisplayLength": 6, - "sDom" : '<"H">t<"F"lp>', - "aLengthMenu": [[6, 12, 36, 72], [6, 12, 36, 72]], - "aaSorting" : [[0, "desc"]], - "aoColumnDefs": [ - { "bVisible": false, "aTargets": ["all"]} - ], - "aoColumns": [ - { "mDataProp": "VM.ID" }, - { "mDataProp": "VM.NAME" }, - { "mDataProp": "VM.UID" } - ], - "fnPreDrawCallback": function (oSettings) { - // create a thumbs container if it doesn't exist. put it in the dataTables_scrollbody div - if (this.$('tr', {"filter": "applied"} ).length == 0) { - this.html('
    '+ - ''+ - ''+ - ''+ - ''+ - '
    '+ - '
    '+ - ''+ - tr("There are no Virtual Machines")+ - ''+ - '
    '); - } else { - $(".provision_vms_table", context).html('
      '); - } - - return true; - }, - "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) { - var data = aData.VM; - var state = get_provision_vm_state(data); - - $(".provision_vms_ul", context).append('
    • '+ - '
        '+ - '
      • '+ - ''+ data.NAME + ''+ - '