diff --git a/sunstone/public/images/appenv_icon.png b/sunstone/public/images/appenv_icon.png new file mode 100644 index 0000000000..f7038a09a8 Binary files /dev/null and b/sunstone/public/images/appenv_icon.png differ diff --git a/sunstone/public/images/appflow_icon.png b/sunstone/public/images/appflow_icon.png new file mode 100644 index 0000000000..2ba4c30ad8 Binary files /dev/null and b/sunstone/public/images/appflow_icon.png differ diff --git a/sunstone/public/images/appmarket_icon.png b/sunstone/public/images/appmarket_icon.png new file mode 100644 index 0000000000..ff5360f962 Binary files /dev/null and b/sunstone/public/images/appmarket_icon.png differ diff --git a/sunstone/public/images/apptools_icon.png b/sunstone/public/images/apptools_icon.png new file mode 100644 index 0000000000..2e0c03eddd Binary files /dev/null and b/sunstone/public/images/apptools_icon.png differ diff --git a/sunstone/public/js/user-plugins/apptools.appenv.js b/sunstone/public/js/user-plugins/apptools.appenv.js new file mode 100644 index 0000000000..06959b95c0 --- /dev/null +++ b/sunstone/public/js/user-plugins/apptools.appenv.js @@ -0,0 +1,1018 @@ +//--------------------------------------------------------------------------// +// Copyright 2010-2012, C12G Labs S.L. // +// // +// Licensed under the C12G Commercial Open-source License (the // +// "License"); you may not use this file except in compliance // +// with the License. You may obtain a copy of the License as part // +// of the software distribution. // +// // +// Unless 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 AppEnv = { + "resource" : 'APPENV', + "create": function(params){ + OpenNebula.Action.create(params,AppEnv.resource); + }, + "del": function(params){ + OpenNebula.Action.del(params,AppEnv.resource); + }, + "list" : function(params){ + OpenNebula.Action.list(params, AppEnv.resource) + }, + "show" : function(params){ + OpenNebula.Action.show(params, AppEnv.resource) + }, + "chown" : function(params){ + OpenNebula.Action.chown(params,AppEnv.resource); + }, + "chgrp" : function(params){ + OpenNebula.Action.chgrp(params,AppEnv.resource); + }, + "chmod" : function(params){ + var action_obj = params.data.extra_param; + OpenNebula.Action.simple_action(params, + AppEnv.resource, + "chmod", + action_obj); + }, + "update" : function(params){ + OpenNebula.Action.simple_action(params, + AppEnv.resource, + "update", + params.data.extra_param); + }, + "instantiate" : function(params){ + OpenNebula.Action.simple_action(params, + AppEnv.resource, + "instantiate", + params.data.extra_param); + } +} + +var appenv_tab_content = '\ +

'+tr("AppEnv - Environments")+'

\ +
\ +
\ +
\ +\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ +
'+tr("All")+''+tr("ID")+''+tr("Owner")+''+tr("Group")+''+tr("Name")+''+tr("Description")+'
\ +\ +
'; + +var create_appenv_tmpl = '\ +
\ +
\ + ' + tr("Environment") + '\ +
\ + \ +
\ +
\ + \ +
\ +
\ + \ + \ +
\ +
\ + \ +
\ +
\ +\ +
\ +
\ + \ +
\ + \ +
\ +
\ +
\ +
\ +
\ +
\ +
\ +
\ +
'; + +var update_appenv_tmpl = + '
\ +

'+tr("Please, choose and modify the environment you want to update")+':

\ +
\ + \ + \ +
\ + \ + \ +
\ + \ +
\ +
\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ +
'+tr("Permissions")+':'+tr("Use")+''+tr("Manage")+''+tr("Admin")+'
'+tr("Owner")+'
'+tr("Group")+'
'+tr("Other")+'
\ +
\ + \ +
\ + \ +
\ +
\ +
\ + \ +
\ +
\ +
'; + +var dataTable_appenvs; +var $create_appenv_dialog; + +var appenv_actions = { + + "AppEnv.create" : { + type: "create", + call: AppEnv.create, + callback: addAppEnvElement, + error: onError, + notify:true + }, + + "AppEnv.create_dialog" : { + type: "custom", + call: popUpCreateAppEnvDialog + }, + + "AppEnv.list" : { + type: "list", + call: AppEnv.list, + callback: updateAppEnvsView, + error: onError + }, + + "AppEnv.show" : { + type : "single", + call: AppEnv.show, + callback: updateAppEnvElement, + error: onError + }, + + "AppEnv.showinfo" : { + type: "single", + call: AppEnv.show, + callback: updateAppEnvInfo, + error: onError + }, + + "AppEnv.refresh" : { + type: "custom", + call: function () { + waitingNodes(dataTable_appenvs); + Sunstone.runAction("AppEnv.list"); + } + }, + + "AppEnv.autorefresh" : { + type: "custom", + call: function() { + AppEnv.list({timeout: true, success: updateAppEnvsView, error: onError}); + } + }, + + "AppEnv.fetch_update_info" : { + type: "single", + call: AppEnv.show, + callback: function (request,response) { + var body = JSON.parse(response.APPENV.TEMPLATE.BODY); + var templates = body.templates; + var dialog = $('#appenv_template_update_dialog'); + // Select current templates + if (templates) + for (var i = 0; i < templates.length; i++){ + var option = $('select[name="templates"] option[value="'+templates[i]+'"]', dialog); + option.text(option.text().replace(/☐/g,'☒')); + option.attr('clicked','clicked'); + }; + // Fill in node box with formatted json + var json = JSON.stringify(body.node, null, ' '); + $('#appenv_template_update_textarea', dialog).val(json); + + //Fill in permissions table + setPermissionsTable(response.APPENV,dialog); + }, + error: onError + }, + + "AppEnv.update_dialog" : { + type: "custom", + call: popUpAppEnvTemplateUpdateDialog + }, + + "AppEnv.update" : { + type: "single", + call: AppEnv.update, + callback: function() { + notifyMessage(tr("Environment updated correctly")); + }, + error: onError + }, + + "AppEnv.instantiate" : { + type: "single", + call: AppEnv.instantiate, + callback: function() { + notifyMessage(tr("Instantiated")); + }, + error: onError + }, + + "AppEnv.delete" : { + type: "multiple", + call: AppEnv.del, + callback: deleteAppEnvElement, + elements: appEnvElements, + error: onError, + notify: true + }, + + "AppEnv.chown" : { + type: "multiple", + call: AppEnv.chown, + callback: function (req) { + Sunstone.runAction("AppEnv.show",req.request.data[0][0]); + }, + elements: appEnvElements, + error: onError, + notify: true + }, + + "AppEnv.chgrp" : { + type: "multiple", + call: AppEnv.chgrp, + callback: function (req) { + Sunstone.runAction("AppEnv.show",req.request.data[0][0]); + }, + elements: appEnvElements, + error: onError, + notify: true + }, + + "AppEnv.chmod" : { + type: "single", + call: AppEnv.chmod, +// callback + error: onError, + notify: true + }, +/* + "AppEnv.clone_dialog" : { + type: "custom", + call: popUpAppEnvCloneDialog + }, + "AppEnv.clone" : { + type: "single", + call: AppEnv.clone, + error: onError, + notify: true + }, +*/ + "AppEnv.help" : { + type: "custom", + call: function() { + hideDialog(); + $('div#appenvs_tab div.legend_div').slideToggle(); + } + } +}; + + +var appenv_buttons = { + "AppEnv.refresh" : { + type: "action", + text: '', + alwaysActive: true + }, + "AppEnv.create_dialog" : { + type: "create_dialog", + text: tr('+ New') + }, + "AppEnv.update_dialog" : { + type: "action", + text: tr("Update properties"), + alwaysActive: true + }, + "AppEnv.chown" : { + type: "confirm_with_select", + text: tr("Change owner"), + select: users_sel, + tip: tr("Select the new owner")+":", + condition: mustBeAdmin + }, + "AppEnv.chgrp" : { + type: "confirm_with_select", + text: tr("Change group"), + select: groups_sel, + tip: tr("Select the new group")+":", + condition: mustBeAdmin + }, +/* + "AppEnv.clone_dialog" : { + type: "action", + text: tr("Clone") + }, +*/ + "AppEnv.delete" : { + type: "confirm", + text: tr("Delete") + }, + "AppEnv.help" : { + type: "action", + text: '?', + alwaysActive: true + } +} + +var appenv_info_panel = { + "appenv_info_tab" : { + title: tr("Environment information"), + content: "" + }, + + "appenv_node_tab" : { + title: tr("Node"), + content: "" + } + +} + +var appenvs_tab = { + title: "AppEnv", + content: appenv_tab_content, + buttons: appenv_buttons, + tabClass: 'subTab', + parentTab: 'apptools_tab' +} + +Sunstone.addActions(appenv_actions); +Sunstone.addMainTab('appenvs_tab',appenvs_tab); +Sunstone.addInfoPanel('appenv_info_panel',appenv_info_panel); + + +function appEnvElements() { + return getSelectedNodes(dataTable_appenvs); +} + +// Returns an array containing the values of the appenv_json and ready +// to be inserted in the dataTable +function appEnvElementArray(appenv_json){ + //Changing this? It may affect to the is_persistent() functions. + var appenv = appenv_json.APPENV; + var body = JSON.parse(appenv.TEMPLATE.BODY); + var description = body.description; + + return [ + '', + appenv.ID, + appenv.UNAME, + appenv.GNAME, + appenv.NAME, + description ? description : tr("None") + ]; +} + +// Callback to update an element in the dataTable +function updateAppEnvElement(request, appenv_json){ + var id = appenv_json.APPENV.ID; + var element = appEnvElementArray(appenv_json); + updateSingleElement(element,dataTable_appenvs,'#appenv_'+id); +} + +// Callback to remove an element from the dataTable +function deleteAppEnvElement(req){ + deleteElement(dataTable_appenvs,'#appenv_'+req.request.data); +} + +// Callback to add an appenv element +function addAppEnvElement(request, appenv_json){ + var element = appEnvElementArray(appenv_json); + addElement(element,dataTable_appenvs); +} + +// Callback to refresh the list +function updateAppEnvsView(request, appenvs_list){ + var appenv_list_array = []; + + $.each(appenvs_list,function(){ + appenv_list_array.push(appEnvElementArray(this)); + }); + + updateView(appenv_list_array,dataTable_appenvs); + //updateVResDashboard("images",images_list); +} + +// Callback to update the information panel tabs and pop it up +function updateAppEnvInfo(request,elem){ + var elem_info = elem.APPENV; + elem_info.TEMPLATE.BODY = JSON.parse(elem_info.TEMPLATE.BODY); + + // Form trs for variables + var vars = ''; + var defaults = elem_info.TEMPLATE.BODY.defaults; + if (!$.isEmptyObject(defaults)){ + for (key in defaults){ + vars += '\ + '+ key +'\ + \ + \ + '; + }; + } + + // Form options of compatible templates + var compat_templates = ''; + var templates = elem_info.TEMPLATE.BODY.templates; + if (templates) + for (var i = 0; i < templates.length; i++) + compat_templates += ''; + + + + + var info_tab = { + title: tr("Environment information"), + content: + '\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ +'+ (templates ? + '' : "") ++ (elem_info.TEMPLATE.BODY.cookbooks ? + '' : "")+ +' \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ +'+ (!$.isEmptyObject(defaults) ? + '' + + prettyPrintJSON(defaults, 28) : "") + '
'+tr("Environment")+' "'+elem_info.NAME+'" '+ + tr("information")+'
'+tr("ID")+''+elem_info.ID+'
'+tr("Name")+''+elem_info.NAME+'
'+tr("Description")+''+(elem_info.TEMPLATE.BODY.description ? elem_info.TEMPLATE.BODY.description : "None" )+'
'+tr("Owner")+''+elem_info.UNAME+'
'+tr("Group")+''+elem_info.GNAME+'
'+tr("Compatible templates")+''+ templates.join(',')+'
'+tr("Cookbooks")+''+elem_info.TEMPLATE.BODY.cookbooks+'
'+tr("Permissions")+'
     '+tr("Owner")+''+ownerPermStr(elem_info)+'
     '+tr("Group")+''+groupPermStr(elem_info)+'
     '+tr("Other")+''+otherPermStr(elem_info)+'
'+tr("Default variables")+'
\ +\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ +'+ vars +'\ + \ + \ + \ +
'+tr("Instantiate this environment")+'
'+tr("Template")+':
'+tr("Variables")+':
' + } + + var node_tab = { + title: tr("Node"), + content: '\ + '+ + (elem_info.TEMPLATE.BODY.node ? prettyPrintJSON(elem_info.TEMPLATE.BODY.node) : "" )+ + '
'+tr("Node")+'
' + } + + Sunstone.updateInfoPanelTab("appenv_info_panel","appenv_info_tab",info_tab); + Sunstone.updateInfoPanelTab("appenv_info_panel","appenv_node_tab",node_tab); + + Sunstone.popUpInfoPanel("appenv_info_panel"); + +} + +// Prepare the creation dialog +function setupCreateAppEnvDialog(){ + dialogs_context.append('
'); + $create_appenv_dialog = $('#create_appenv_dialog',dialogs_context); + + var dialog = $create_appenv_dialog; + dialog.html(create_appenv_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: 520, + height: height + }); + + $('button',dialog).button(); + + $('select[name="templates"]', dialog).change(function(){ + $(this).val(""); + return false; + }); + + $('#add_custom_var_appenv_button', dialog).click( + function(){ + var name = $('#custom_var_appenv_name',dialog).val(); + var value = $('#custom_var_appenv_value',dialog).val(); + if (!name.length || !value.length) { + notifyError("Variable name and value must be filled in"); + return false; + } + option= ''; + $('select#custom_var_appenv_box',dialog).append(option); + return false; + } + ); + + $('#remove_custom_var_appenv_button', dialog).click( + function(){ + $('select#custom_var_appenv_box :selected',dialog).remove(); + return false; + } + ); + + + $('#create_appenv_form',dialog).submit(function(){ + var name = $('input[name="name"]', this).val(); + var description = $('input[name="description"]', this).val(); + var cookbooks = $('input[name="cookbooks"]', this).val(); + var node = $('textarea[name="node"]', this).val(); + + if (!name){ + notifyError(tr("Name is mandatory!")); + return false; + } + + var appenv_obj = { + name: name, + } + + if (description) appenv_obj.description = description; + if (cookbooks) appenv_obj.cookbooks = cookbooks; + if (node) appenv_obj.node = node; + + var templates = $('select[name="templates"] option[clicked="clicked"]', + this); + + if (templates.length){ + var tmpls = [] + templates.each(function(){ + tmpls.push($(this).val()) + }); + appenv_obj.templates = tmpls + }; + + //UNUSED AT THIS POINT +/* + var variables_array = []; + var variables; + $('#custom_var_appenv_box option', this).each(function(){ + var attr_name = $(this).attr('name'); + var attr_value = $(this).val(); + variables_array.push(attr_name +'='+ attr_value); + }); + variables = variables_array.join(','); + + if (variables) appenv_obj.variables = variables; +*/ + + Sunstone.runAction("AppEnv.create", { 'APPENV': appenv_obj }); + dialog.dialog('close'); + return false; + }); +} + +function popUpCreateAppEnvDialog(){ + var dialog = $create_appenv_dialog; + var tpl_select = makeSelectOptions(dataTable_templates, 1, 4, [], [], true); + $('select[name="templates"]', dialog).html(tpl_select); + $('select[name="templates"] option', dialog).each(function(){ + $(this).text('☐ '+$(this).text()); + }); + + //Somehow this needs to go here. Live() doesn't respond in setup function + $('select[name="templates"] option', dialog).click(function(){ + var clicked = $(this).attr('clicked'); + if (clicked){//unbold, unmark + $(this).text($(this).text().replace(/☒/g,'☐')); + $(this).removeAttr('clicked'); + } + else {//bold,mark + $(this).text($(this).text().replace(/☐/g,'☒')); + $(this).attr('clicked','clicked'); + } + return false; + }); + + dialog.dialog('open'); +} + + + +function setupAppEnvTemplateUpdateDialog(){ + + //Append to DOM + dialogs_context.append('
'); + var dialog = $('#appenv_template_update_dialog',dialogs_context); + + //Put HTML in place + dialog.html(update_appenv_tmpl); + + var height = Math.floor($(window).height()*0.8); //set height to a percentage of the window + //Convert into jQuery + dialog.dialog({ + autoOpen:false, + width:700, + modal:true, + height:height, + resizable:false + }); + + $('button',dialog).button(); + + $('#appenv_template_update_select',dialog).change(function(){ + var id = $(this).val(); + $('.permissions_table input',dialog).removeAttr('checked') + $('.permissions_table',dialog).removeAttr('update'); + if (id && id.length){ + var dialog = $('#appenv_template_update_dialog'); + $('#appenv_template_update_textarea',dialog).val(tr("Loading")+ + "..."); + Sunstone.runAction("AppEnv.fetch_update_info", id); + } else { + $('#appenv_template_update_textarea',dialog).val(""); + }; + }); + + $('.permissions_table input',dialog).change(function(){ + $(this).parents('table').attr('update','update'); + }); + + $('select[name="templates"]', dialog).change(function(){ + $(this).val(""); + return false; + }); + + + $('form',dialog).submit(function(){ + var dialog = $(this); + var new_node = $('#appenv_template_update_textarea',dialog).val(); + var cookbooks = $('input[name="cookbooks"]',dialog).val(); + var id = $('#appenv_template_update_select',dialog).val(); + if (!id || !id.length) { + $(this).parents('#appenv_template_update_dialog').dialog('close'); + return false; + }; + + var permissions = $('.permissions_table',dialog); + if (permissions.attr('update')){ + var perms = { + octet : buildOctet(permissions) + }; + Sunstone.runAction("AppEnv.chmod",id,perms); + }; + + var appenv_obj = { + cookbooks: cookbooks, + templates: templates + }; + + if (new_node) appenv_obj.node = new_node; + + var templates = $('select[name="templates"] option[clicked="clicked"]', + this); + var tmpls = [] + templates.each(function(){ + tmpls.push($(this).val()) + }); + appenv_obj.templates = tmpls + + Sunstone.runAction("AppEnv.update", id, {'APPENV' : appenv_obj}); + $(this).parents('#appenv_template_update_dialog').dialog('close'); + return false; + }); +}; + + +function popUpAppEnvTemplateUpdateDialog(){ + var select = makeSelectOptions(dataTable_appenvs, + 1,//id_col + 4,//name_col + [], + [] + ); + var sel_elems = appEnvElements(); + + + var dialog = $('#appenv_template_update_dialog'); + $('#appenv_template_update_select',dialog).html(select); + $('#appenv_template_update_textarea',dialog).val(""); + $('#appenv_template_update_persistent',dialog).removeAttr('checked'); + $('.permissions_table input',dialog).removeAttr('checked'); + $('.permissions_table',dialog).removeAttr('update'); + + + if (sel_elems.length >= 1){ //several items in the list are selected + //grep them + var new_select= sel_elems.length > 1? '' : ""; + $('option','').each(function(){ + var val = $(this).val(); + if ($.inArray(val,sel_elems) >= 0){ + new_select+=''; + }; + }); + $('#appenv_template_update_select',dialog).html(new_select); + if (sel_elems.length == 1) { + $('#appenv_template_update_select option',dialog).attr('selected','selected'); + $('#appenv_template_update_select',dialog).trigger("change"); + }; + }; + + var tpl_select = makeSelectOptions(dataTable_templates, 1, 4, [], [], true); + $('select[name="templates"]', dialog).html(tpl_select); + $('select[name="templates"] option', dialog).each(function(){ + $(this).text('☐ '+$(this).text()); + }); + + $('select[name="templates"] option', dialog).click(function(){ + var clicked = $(this).attr('clicked'); + if (clicked){//unbold, unmark + $(this).text($(this).text().replace(/☒/g,'☐')); + $(this).removeAttr('clicked'); + } + else {//bold,mark + $(this).text($(this).text().replace(/☐/g,'☒')); + $(this).attr('clicked','clicked'); + } + return false; + }); + + dialog.dialog('open'); + return false; +}; + +function setupAppEnvInstantiate(){ + $('button#appenv_instantiate_button').live('click', function(){ + var vars = []; + var context = $(this).parents('table#appenv_instantiate_table'); + + var id = $('input[type="hidden"]', context).val(); + var template_id = $('select', context).val(); + + $('input[type="text"]', context).each(function(){ + var key = $(this).attr('name'); + var val = $(this).val(); + + if (val) + vars.push(key +'='+ val) + }); + + var obj = { vars: vars, + template_id: template_id + }; + + if (vars.length) + Sunstone.runAction("AppEnv.instantiate", id, obj); + return false; + }); + +} + + +// Set the autorefresh interval for the datatable +function setAppEnvAutorefresh() { + setInterval(function(){ + var checked = $('input.check_item:checked',dataTable_appenvs); + var filter = $("#datatable_appenvs_filter input", + dataTable_appenvs.parents("#datatable_appenvs_wrapper")).attr('value'); + if (!checked.length && !filter.length){ + Sunstone.runAction("AppEnv.autorefresh"); + } + },INTERVAL+someTime()); +}; + +/* +function setupAppEnvCloneDialog(){ + //Append to DOM + dialogs_context.append('
'); + var dialog = $('#appenv_clone_dialog',dialogs_context); + + //Put HTML in place + + var html = '
\ +
'+tr("Choose a new name for the environment")+':
\ +
'+tr("Several environments are selected, please choose prefix to name the new copies")+':
\ +
\ +\ +\ +\ +
\ + \ +
\ +'; + + dialog.html(html); + + //Convert into jQuery + dialog.dialog({ + autoOpen:false, + width:375, + modal:true, + resizable:false + }); + + $('button',dialog).button(); + + $('form',dialog).submit(function(){ + var name = $('input', this).val(); + var sel_elems = appEnvElements(); + if (!name || !sel_elems.length) + notifyError('A name or prefix is needed!'); + if (sel_elems.length > 1){ + for (var i=0; i< sel_elems.length; i++) + //If we are cloning several items we + //use the name as prefix + Sunstone.runAction('AppEnv.clone', + sel_elems[i], + name + getName(sel_elems[i], + dataTable_appenvs, + 4)); + } else { + Sunstone.runAction('AppEnv.clone',sel_elems[0],name) + }; + dialog.dialog('close'); + setTimeout(function(){ + Sunstone.runAction('AppEnv.refresh'); + }, 1500); + return false; + }); +} + +function popUpAppEnvCloneDialog(){ + var dialog = $('#appenv_clone_dialog'); + var sel_elems = appEnvElements(); + //show different text depending on how many elements are selected + if (sel_elems.length > 1){ + $('.clone_one',dialog).hide(); + $('.clone_several',dialog).show(); + $('input',dialog).val('Copy of '); + } + else { + $('.clone_one',dialog).show(); + $('.clone_several',dialog).hide(); + $('input',dialog).val('Copy of '+getName(sel_elems[0], + dataTable_appenvs, 4)); + }; + + $(dialog).dialog('open'); +} + +*/ + +//The DOM is ready at this point +$(document).ready(function(){ + + dataTable_appenvs = $("#datatable_appenvs",main_tabs_context).dataTable({ + "bJQueryUI": true, + "bSortClasses": false, + "bAutoWidth":false, + "sDom" : '<"H"lfrC>t<"F"ip>', + "oColVis": { + "aiExclude": [ 0 ] + }, + "sPaginationType": "full_numbers", + "aoColumnDefs": [ + { "bSortable": false, "aTargets": ["check"] }, + { "sWidth": "60px", "aTargets": [0] }, + { "sWidth": "100px", "aTargets": [2,3] }, + { "sWidth": "200px", "aTargets": [4] }, + { "sWidth": "35px", "aTargets": [1] } + ], + "oLanguage": (datatable_lang != "") ? + { + sUrl: "locale/"+lang+"/"+datatable_lang + } : "" + }); + + dataTable_appenvs.fnClearTable(); + addElement([ + spinner, + '','','','',''],dataTable_appenvs); + Sunstone.runAction("AppEnv.list"); + + setupCreateAppEnvDialog(); + setupAppEnvTemplateUpdateDialog(); + setupAppEnvInstantiate(); + setupTips($create_appenv_dialog); +// setupImageCloneDialog(); + setAppEnvAutorefresh(); + + initCheckAllBoxes(dataTable_appenvs); + tableCheckboxesListener(dataTable_appenvs); + infoListener(dataTable_appenvs,'AppEnv.showinfo'); + + $('div#appenvs_tab div.legend_div').hide(); +}); diff --git a/sunstone/public/js/user-plugins/apptools.js b/sunstone/public/js/user-plugins/apptools.js new file mode 100644 index 0000000000..d4d0ef77dd --- /dev/null +++ b/sunstone/public/js/user-plugins/apptools.js @@ -0,0 +1,95 @@ +//--------------------------------------------------------------------------// +// Copyright 2010-2012, C12G Labs S.L. // +// // +// Licensed under the C12G Commercial Open-source License (the // +// "License"); you may not use this file except in compliance // +// with the License. You may obtain a copy of the License as part // +// of the software distribution. // +// // +// Unless 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 apptools_dashboard_tmpl = '\ +\ +\ +\ +\ +
\ +\ + \ + \ + \ +
\ +
\ +

' + tr("AppTools") + '

\ +
\ +\ +

apptools logoAppTools is a group of tools for users and administrators of OpenNebula clouds to simplify and optimize application management. These tools enable the building, distribution and execution of multi-tier applications.

\ +\ +
    \ +
  • AppEnv performs the automatic installation and configuration of the software stack that constitute an application environment
  • \ +
  • AppFlow enables the automatic execution of multi-tiered applications composed of interconnected applications
  • \ +
  • AppPlace builds a centralized catalog of virtual appliances to easily share and distribute applications across OpenNebula instances
  • \ +
\ +\ +

AppTools fills the gap between the application and the virtual infrastructure layer. While OpenNebula manages the execution of the virtual infrastructure, being fully application agnostic, AppTools manages the application being executed within the virtual infrastructure. AppTools leverages the OpenNebula contextualization framework and external APIs.

\ +\ +
\ +
\ +
\ +
\ +\ + \ + \ + \ + \ + \ + \ + \ + \ + \ +
\ +
\ +

' + tr("AppEnv - A tool to manage environments") + '

\ +
\ +\ +

appenv logoInstalling services can sometimes be tedious. Getting the VM ins good shape, installing the packages needed, deploying the application and configuring it. On case of disaster or scaling the service you will need to perform again these tasks. To automate all this burden we now have Configuration Management software like Chef, Puppet or CFEngine.

\ +\ +

With this software we can script the installation and configuration of applications and services. You can also describe the services and their configuration that will be installed on a node so we can automate its installation. We will also be sure that each installation will be equal to other using the same configuration.

\ +\ +

The tool oneenv will make use of Chef-solo. It lets you register chef configurations and instantiate them using predefined templates and images.

\ +\ +
\ +
\ +
\ +
\ +

' + tr("AppFlow - Service deployment") + '

\ +
\ +

appflow logoApp flow desc

\ +

bla

\ +

blabla

\ +
\ +
\ +
\ +
\ +

' + tr("AppMarket - Image repository") + '

\ +
\ +

appflow logoApp flow desc

\ +

bla

\ +

blabla

\ +
\ +
\ +
\ +
'; + +var apptools_tab = { + title: 'AppTools', + content: apptools_dashboard_tmpl, +} + + +Sunstone.addMainTab('apptools_tab',apptools_tab); \ No newline at end of file diff --git a/sunstone/routes/appenv.rb b/sunstone/routes/appenv.rb new file mode 100644 index 0000000000..56dbff3b73 --- /dev/null +++ b/sunstone/routes/appenv.rb @@ -0,0 +1,149 @@ +# -------------------------------------------------------------------------- # +# Copyright 2010-2012, C12G Labs S.L. # +# # +# Licensed under the C12G Commercial Open-source License (the # +# "License"); you may not use this file except in compliance # +# with the License. You may obtain a copy of the License as part # +# of the software distribution. # +# # +# Unless 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. # +#--------------------------------------------------------------------------- # + +require 'apptools/env/onechef.rb' + +# Name for the resource. +#Used to generate correct ... tags +RESOURCE = 'APPENV' + +helpers do + def client + settings.cloud_auth.client(session[:user]) + end + + def appenv_to_json(resource) + { "#{RESOURCE}" => resource.to_hash['DOCUMENT']}.to_json + end + + def appenv_pool + pool = OpenNebula::ChefDocPool.new(client()) + rc = pool.info + return [500, rc.to_json] if OpenNebula.is_error?(rc) + + # Pool comes in ... + # Need to set the resource type correctly to $RESOURCE + appenv_pool = { "#{RESOURCE}_POOL" => {}} + pool.each do | elem | + hash = elem.to_hash['DOCUMENT'] + appenv_pool["#{RESOURCE}_POOL"]["#{RESOURCE}"] ||= [] + appenv_pool["#{RESOURCE}_POOL"]["#{RESOURCE}"] << hash + end + [200, appenv_pool.to_json] + end + + def appenv_create(template) + node = OpenNebula::ChefConf.new + node.name = template['name'] + node.description = template['description'] if template['description'] + node.cookbooks = template['cookbooks'] if template['cookbacks'] + node.templates = template['templates'] if template['templates'] + #variables currently unused + node.variables = template['variables'] if template['variables'] + node.node = template['node'] if template['node'] + + client = settings.cloud_auth.client(session[:user]) + doc = node.save(client)[0] + + if OpenNebula.is_error?(doc) + return [500, doc.to_json] + end + + doc.info + [201, appenv_to_json(doc)] + end + + def appenv_retrieve(id) + resource = OpenNebula::ChefDoc.new_with_id(id, client()) + rc = resource.info + + return [404, rc.to_json] if OpenNebula.is_error?(rc) + [200, appenv_to_json(resource)] + end + + def appenv_update(resource, template) + node = resource.node + node.node = template['node'] if template['node'] + node.templates = template['templates'] + node.cookbooks = template['cookbooks'] + resource.update(node.to_json) + end + + def appenv_action(id, action_hash) + resource = OpenNebula::ChefDoc.new_with_id(id,client()) + rc = resource.info + if OpenNebula.is_error?(rc) + return [404, rc.to_json] + end + + params = action_hash['params'] + rc = case action_hash['perform'] + when "chown" then resource.chown(params['owner_id'].to_i, + params['group_id'].to_i) + + when "chmod" then resource.chmod_octet(params['octet']) + + when "update" then appenv_update(resource, params[RESOURCE]) + + when "instantiate" then resource.instantiate(params['template_id'], + params['vars']) + else + error_msg = "#{action_hash['perform']} action not " << + " available for this resource" + return [500, OpenNebula::Error.new(error_msg).to_json] + end + + + return [500, rc.to_json] if OpenNebula.is_error?(rc) + [204, appenv_to_json(resource)] + end + + def appenv_delete(id) + resource = OpenNebula::ChefDoc.new_with_id(id, client()) + rc = resource.delete + + return [500, rc.to_json] if OpenNebula.is_error?(rc) + 204 + end +end + +################################################################ +# PLUGIN ROUTES +################################################################ +get '/appenv' do + appenv_pool() +end + +post '/appenv' do + template = parse_json(request.body.read, RESOURCE) + appenv_create(template) +end + +get '/appenv/:id' do + appenv_retrieve(params[:id].to_i) +end + +post '/appenv/:id/action' do + action_hash = parse_json(request.body.read, 'action') + if OpenNebula.is_error?(action_hash) + return [500, action_hash.to_json] + end + + appenv_action(params[:id].to_i, action_hash) +end + +delete '/appenv/:id' do + appenv_delete(params[:id].to_i) +end