'
+ }
+
+ 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 = '\
+';
+
+ 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 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") + '
\
+
\
+\
+
Installing 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") + '
\
+
\
+
App flow desc
\
+
bla
\
+
blabla
\
+
\
+
\
+
\
+
\
+
\
+
\
+
\
+
' + tr("AppMarket - Image repository") + '
\
+
\
+
App 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