diff --git a/src/sunstone/models/OpenNebulaJSON/HostJSON.rb b/src/sunstone/models/OpenNebulaJSON/HostJSON.rb index 94d88a07ec..fdc0280b42 100644 --- a/src/sunstone/models/OpenNebulaJSON/HostJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/HostJSON.rb @@ -26,10 +26,19 @@ module OpenNebulaJSON return host_hash end - self.allocate(host_hash['name'], + id = self.allocate(host_hash['name'], host_hash['im_mad'], host_hash['vm_mad'], host_hash['cluster_id'].to_i) + delete_values = ['name', 'im_mad', 'vm_mad', 'cluster_id'] + + template_str = hash_to_str(host_hash, delete_values) + if !template_str.nil? + params=Hash.new + params['template_raw'] = template_str + params['append'] = true + self.update(params) + end end def delete diff --git a/src/sunstone/models/OpenNebulaJSON/JSONUtils.rb b/src/sunstone/models/OpenNebulaJSON/JSONUtils.rb index 1071168461..6f8db308a3 100644 --- a/src/sunstone/models/OpenNebulaJSON/JSONUtils.rb +++ b/src/sunstone/models/OpenNebulaJSON/JSONUtils.rb @@ -113,5 +113,31 @@ module OpenNebulaJSON str end + + def hash_to_str(template_hash, delete_values) + for del in delete_values + template_hash.delete(del) + end + + if !template_hash.empty? + template_str = "" + template_hash.collect do |key,value| + if value.kind_of?(Array) + template_str << key.to_s.upcase << " = \[" + for obj in value + if obj.kind_of?(Hash) + obj.collect do |key,value| + template_str << key.to_s.upcase << " = \""<< value.to_s << "\"\n" + end + end + end + template_str << "\]\n" + else + template_str << key.to_s.upcase << " = \""<< value.to_s << "\"\n" + end + end + end + return template_str + end end end diff --git a/src/sunstone/public/app/tabs/hosts-tab/form-panels/create.js b/src/sunstone/public/app/tabs/hosts-tab/form-panels/create.js index ec5cd68860..003d8a7d48 100644 --- a/src/sunstone/public/app/tabs/hosts-tab/form-panels/create.js +++ b/src/sunstone/public/app/tabs/hosts-tab/form-panels/create.js @@ -119,25 +119,47 @@ define(function(require) { $("#host_type_mad", context).on("change", function() { $("#vmm_mad", context).val(this.value).change(); $("#im_mad", context).val(this.value).change(); + $(".vcenter_credentials", context).hide(); + $(".ec2_extra", context).hide(); + $(".drivers", context).hide(); + $("#name_container", context).show(); if (this.value == "custom") { - $(".vcenter_credentials", context).hide(); - $("#name_container", context).show(); Sunstone.showFormPanelSubmit(TAB_ID); $(".drivers", context).show(); } else if (this.value == "vcenter") { $("#name_container", context).hide(); $(".vcenter_credentials", context).show(); Sunstone.hideFormPanelSubmit(TAB_ID); - $(".drivers", context).hide(); - } else { - $(".vcenter_credentials", context).hide(); - $("#name_container", context).show(); + } else if (this.value == "ec2") { + $(".ec2_extra", context).show(); + Sunstone.showFormPanelSubmit(TAB_ID); + } else { Sunstone.showFormPanelSubmit(TAB_ID); - $(".drivers", context).hide(); } }); + context.off("click", ".add_custom_tag"); + context.on("click", ".add_custom_tag", function(){ + $("tbody.capacity_ec2", context).append( + "\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + "); + }); + + context.on("click", "tbody.capacity_ec2 i.remove-capacity", function(){ + var tr = $(this).closest('tr'); + tr.remove(); + }); + $("#host_type_mad", context).change(); $("form.vcenter_credentials", context) @@ -222,6 +244,26 @@ define(function(require) { } }; + if(vmm_mad == "ec2"){ + var capacity = []; + var key = ""; + var value = ""; + var obj = {}; + var region_name = $('input[name="REGION_NAME"]').val(); + var ec2_access = $('input[name="EC2_ACCESS"]').val(); + var ec2_secret = $('input[name="EC2_SECRET"]').val(); + $('tr.row_capacity',context).each(function() { + key = $("input[name='key']", this).val(); + value = $("input[name='value']", this).val(); + obj[key] = value; + capacity.push(obj); + }); + + host_json["host"]["region_name"] = region_name; + host_json["host"]["ec2_secret"] = ec2_secret; + host_json["host"]["ec2_access"] = ec2_access; + host_json["host"]["capacity"] = capacity; + } //Create the OpenNebula.Host. //If it is successfull we refresh the list. Sunstone.runAction("Host.create", host_json); diff --git a/src/sunstone/public/app/tabs/hosts-tab/form-panels/create/wizard.hbs b/src/sunstone/public/app/tabs/hosts-tab/form-panels/create/wizard.hbs index d9b4d662d4..56c8e6a406 100644 --- a/src/sunstone/public/app/tabs/hosts-tab/form-panels/create/wizard.hbs +++ b/src/sunstone/public/app/tabs/hosts-tab/form-panels/create/wizard.hbs @@ -80,6 +80,57 @@ + +
+
+ {{tr "EC2"}} +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ +
+
+ + + + + + + + + + + + + + + +
{{tr "Key"}}{{tr "Value"}}
+ + + +
+
+
+
+
+
+
diff --git a/src/sunstone/public/app/tabs/hosts-tab/panels/info.js b/src/sunstone/public/app/tabs/hosts-tab/panels/info.js index 6b4b9ac135..b41b5494df 100644 --- a/src/sunstone/public/app/tabs/hosts-tab/panels/info.js +++ b/src/sunstone/public/app/tabs/hosts-tab/panels/info.js @@ -32,6 +32,8 @@ define(function(require) { var CanImportWilds = require('../utils/can-import-wilds'); var Sunstone = require('sunstone'); var TemplateUtils = require('utils/template-utils'); + var CapacityTable = require('utils/custom-tags-table'); + var EC2Tr = require('utils/panel/ec2-tr'); /* TEMPLATES @@ -68,7 +70,7 @@ define(function(require) { that.unshownTemplate = {}; that.strippedTemplateVcenter = {}; that.strippedTemplate = {}; - var unshownKeys = ['HOST', 'VM', 'WILDS', 'ZOMBIES', 'RESERVED_CPU', 'RESERVED_MEM']; + var unshownKeys = ['HOST', 'VM', 'WILDS', 'ZOMBIES', 'RESERVED_CPU', 'RESERVED_MEM', "EC2_ACCESS", "EC2_SECRET", "CAPACITY", "REGION_NAME"]; $.each(that.element.TEMPLATE, function(key, value) { if ($.inArray(key, unshownKeys) > -1) { that.unshownTemplate[key] = value; @@ -126,7 +128,9 @@ define(function(require) { 'maxReservedCPU': realCPU * 2, 'realCPU': realCPU, 'realMEM': Humanize.size(realMEM), - 'virtualMEMInput': Humanize.size(this.element.HOST_SHARE.MAX_MEM) + 'virtualMEMInput': Humanize.size(this.element.HOST_SHARE.MAX_MEM), + 'ec2_tr': EC2Tr.html(RESOURCE, this.element.TEMPLATE), + 'capacityTableHTML': CapacityTable.html() }); } @@ -166,7 +170,7 @@ define(function(require) { function _setup(context) { var that = this; - + $(".ec2",context).show(); RenameTr.setup(TAB_ID, RESOURCE, this.element.ID, context); ClusterTr.setup(RESOURCE, this.element.ID, this.element.CLUSTER_ID, context); @@ -207,8 +211,25 @@ define(function(require) { changeColorInputMEM(that.element.HOST_SHARE.TOTAL_MEM); document.getElementById('textInput_reserved_mem_hosts').value = Humanize.size(parseInt(document.getElementById('change_bar_mem_hosts').value)); }); + document.getElementById("textInput_reserved_mem_hosts").addEventListener("input", function(){ changeInputMEM(that.element.HOST_SHARE.TOTAL_MEM); }); + + CapacityTable.setup(context, true, RESOURCE, this.element.TEMPLATE, this.element.ID); + EC2Tr.setup(RESOURCE, this.element.ID, context); + CapacityTable.fill(context, this.element.TEMPLATE.CAPACITY); + $(".change_to_vector_attribute", context).hide(); + $(".custom_tag_value",context).focusout(function(){ + var key = $(".custom_tag_key",this.parentElement.parentElement).val(); + if(!that.element.TEMPLATE.CAPACITY){ + that.element.TEMPLATE.CAPACITY = {}; + } + that.element.TEMPLATE.CAPACITY[key] = this.value; + Sunstone.runAction(RESOURCE+".update_template",that.element.ID, TemplateUtils.templateToString(that.element.TEMPLATE)); + }); + if (this.element.TEMPLATE.IM_MAD != "ec2"){ + $(".ec2",context).hide(); + } } }); diff --git a/src/sunstone/public/app/tabs/hosts-tab/panels/info/html.hbs b/src/sunstone/public/app/tabs/hosts-tab/panels/info/html.hbs index d4bed044df..d5469881c0 100644 --- a/src/sunstone/public/app/tabs/hosts-tab/panels/info/html.hbs +++ b/src/sunstone/public/app/tabs/hosts-tab/panels/info/html.hbs @@ -113,3 +113,42 @@
{{{templateTableHTML}}}
+
+
+ + + + + + + + +
+
+
+
{{tr "EC2"}}
+ + + + + + + {{{ec2_tr}}} + +
{{tr "Attributes"}}
+
+
+
+
+
+ {{tr "Capacity"}} + {{{capacityTableHTML}}} +
+
+
+ + + + + + \ No newline at end of file diff --git a/src/sunstone/public/app/utils/custom-tags-table.js b/src/sunstone/public/app/utils/custom-tags-table.js index 790d1767ae..1118d633d4 100644 --- a/src/sunstone/public/app/utils/custom-tags-table.js +++ b/src/sunstone/public/app/utils/custom-tags-table.js @@ -23,15 +23,27 @@ define(function(require) { var VectorAttributeRowTemplateHTML = require('hbs!./custom-tags-table/vector-attribute-row'); var TemplateUtils = require('utils/template-utils'); var WizardFields = require('utils/wizard-fields'); + var Sunstone = require('sunstone'); function _html(){ return TemplateHTML(); } - function _setup(context){ + function _setup(context, hide_vector_button = false, resourceType = undefined, element = undefined, elementID = undefined){ context.off("click", ".add_custom_tag"); context.on("click", ".add_custom_tag", function(){ $("tbody.custom_tags", context).append(RowTemplateHTML()); + if(hide_vector_button){ + $(".change_to_vector_attribute", context).hide(); + $(".custom_tag_value",context).focusout(function(){ + var key = $(".custom_tag_key",this.parentElement.parentElement).val(); + if(!element.CAPACITY){ + element.CAPACITY = {}; + } + element.CAPACITY[key] = this.value; + Sunstone.runAction(resourceType+".update_template",elementID, TemplateUtils.templateToString(element)); + }); + } }); context.off("click", ".add_vector_attribute"); @@ -58,6 +70,13 @@ define(function(require) { context.on("click", "tbody.custom_tags i.remove-tab", function(){ var tr = $(this).closest('tr'); tr.remove(); + if(hide_vector_button){ + var key = $(".custom_tag_key",this.parentElement.parentElement.parentElement).val() + if(element.CAPACITY && element.CAPACITY[key]){ + delete element.CAPACITY[key]; + Sunstone.runAction(resourceType+".update_template",elementID, TemplateUtils.templateToString(element)); + } + } }); } diff --git a/src/sunstone/public/app/utils/panel/ec2-tr.js b/src/sunstone/public/app/utils/panel/ec2-tr.js new file mode 100644 index 0000000000..827a259a24 --- /dev/null +++ b/src/sunstone/public/app/utils/panel/ec2-tr.js @@ -0,0 +1,95 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2017, OpenNebula Project, OpenNebula Systems */ +/* */ +/* 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. */ +/* -------------------------------------------------------------------------- */ +define(function(require) { + /* + This module insert a row with the name of the resource. + The row can be edited and a rename action will be sent + */ + + var TemplateEC2Tr = require('hbs!./ec2-tr/html'); + var TemplateUtils = require('utils/template-utils'); + var Sunstone = require('sunstone'); + var Config = require('sunstone-config'); + + /* + Generate the tr HTML with the name of the resource and an edit icon + @param {String} tabName + @param {String} resourceType Resource type (i.e: Zone, Host, Image...) + @param {String} resourceName Name of the resource + @returns {String} HTML row + */ + var _html = function(resourceType, ec2_attributes) { + this.element = ec2_attributes; + this.valueRegion = ec2_attributes['REGION_NAME']? ec2_attributes['REGION_NAME']: ""; + this.valueSecret = ec2_attributes['EC2_SECRET']? ec2_attributes['EC2_SECRET']: ""; + this.valueAccess = ec2_attributes['EC2_ACCESS']? ec2_attributes['EC2_ACCESS']: ""; + var renameTrHTML = TemplateEC2Tr({ + 'region_name': ec2_attributes['REGION_NAME'], + 'ec2_secret': ec2_attributes['EC2_SECRET'], + 'ec2_access': ec2_attributes['EC2_ACCESS'] + }); + + return renameTrHTML; + }; + + + function _setup(resourceType, resourceId,context) { + var that = this; + context.off("click", "#div_edit_region_link"); + context.on("click", "#div_edit_region_link", function() { + var valueStr = $(".value_td_region", context).text(); + $(".value_td_region", context).html(''); + }); + + context.off("click", "#div_edit_access_link"); + context.on("click", "#div_edit_access_link", function() { + var valueStr = $(".value_td_access", context).text(); + $(".value_td_access", context).html(''); + }); + + context.off("click", "#div_edit_secret_link"); + context.on("click", "#div_edit_secret_link", function() { + var valueStr = $(".input_edit_value_secret", context).text(); + $(".value_td_secret", context).html(''); + }); + + context.off("change", ".input_edit_value_region"); + context.on("change", ".input_edit_value_region", function() { + var valueRegion = $(".input_edit_value_region").val(); + that.element["REGION_NAME"] = valueRegion; + Sunstone.runAction(resourceType+".update_template",resourceId, TemplateUtils.templateToString(that.element)); + }); + + context.off("change", ".input_edit_value_access"); + context.on("change", ".input_edit_value_access", function() { + var valueAccess = $(".input_edit_value_access").val(); + that.element["EC2_ACCESS"] = valueAccess; + Sunstone.runAction(resourceType+".update_template",resourceId, TemplateUtils.templateToString(that.element)); + }); + + context.off("change", ".input_edit_value_secret"); + context.on("change", ".input_edit_value_secret", function() { + var valueSecret = $(".input_edit_value_secret").val(); + that.element["EC2_SECRET"] = valueSecret; + Sunstone.runAction(resourceType+".update_template",resourceId, TemplateUtils.templateToString(that.element)); + }); + } + + return { + 'html': _html, + 'setup': _setup + } +}); diff --git a/src/sunstone/public/app/utils/panel/ec2-tr/html.hbs b/src/sunstone/public/app/utils/panel/ec2-tr/html.hbs new file mode 100644 index 0000000000..a33bff165e --- /dev/null +++ b/src/sunstone/public/app/utils/panel/ec2-tr/html.hbs @@ -0,0 +1,27 @@ + + {{tr "Region name"}} + {{region_name}} + +
+ +
+ + + + {{tr "EC2 Access"}} + {{ec2_access}} + +
+ +
+ + + + {{tr "EC2 Secret"}} + {{ec2_secret}} + +
+ +
+ + \ No newline at end of file