diff --git a/src/sunstone/etc/sunstone-views/admin.yaml b/src/sunstone/etc/sunstone-views/admin.yaml
index 5f23bab64c..6733ab3d48 100644
--- a/src/sunstone/etc/sunstone-views/admin.yaml
+++ b/src/sunstone/etc/sunstone-views/admin.yaml
@@ -213,6 +213,7 @@ tabs:
actions:
Template.refresh: true
Template.create_dialog: true
+ Template.import_dialog: false
Template.update_dialog: true
Template.instantiate_vms: true
Template.chown: true
diff --git a/src/sunstone/etc/sunstone-views/admin_vcenter.yaml b/src/sunstone/etc/sunstone-views/admin_vcenter.yaml
index e952afae73..feb4b9e130 100644
--- a/src/sunstone/etc/sunstone-views/admin_vcenter.yaml
+++ b/src/sunstone/etc/sunstone-views/admin_vcenter.yaml
@@ -213,6 +213,7 @@ tabs:
actions:
Template.refresh: true
Template.create_dialog: true
+ Template.import_dialog: true
Template.update_dialog: true
Template.instantiate_vms: true
Template.chown: true
diff --git a/src/sunstone/etc/sunstone-views/user.yaml b/src/sunstone/etc/sunstone-views/user.yaml
index 696af99a2b..cebd529e92 100644
--- a/src/sunstone/etc/sunstone-views/user.yaml
+++ b/src/sunstone/etc/sunstone-views/user.yaml
@@ -214,6 +214,7 @@ tabs:
actions:
Template.refresh: true
Template.create_dialog: true
+ Template.import_dialog: false
Template.update_dialog: true
Template.instantiate_vms: true
Template.chown: false
diff --git a/src/sunstone/public/js/plugins/templates-tab.js b/src/sunstone/public/js/plugins/templates-tab.js
index eb4e14388f..9ebc835427 100644
--- a/src/sunstone/public/js/plugins/templates-tab.js
+++ b/src/sunstone/public/js/plugins/templates-tab.js
@@ -1387,6 +1387,13 @@ var template_actions = {
}
},
+ "Template.import_dialog" : {
+ type: "create",
+ call: function(){
+ popUpTemplateImportDialog();
+ }
+ },
+
"Template.update_dialog" : {
type: "custom",
call: function(){
@@ -1611,6 +1618,15 @@ var template_buttons = {
type: "create_dialog",
layout: "create"
},
+
+ "Template.import_dialog" : {
+ type: "create_dialog",
+ layout: "create",
+ text: tr("Import"),
+ icon: '',
+ alwaysActive: true
+ },
+
"Template.update_dialog" : {
type: "action",
layout: "main",
@@ -4995,6 +5011,227 @@ function popUpTemplateCloneDialog(){
$("input[name='name']",dialog).focus();
}
+function popUpTemplateImportDialog(){
+ setupTemplateImportDialog();
+ var dialog = $('#template_import_dialog');
+ $(dialog).foundation().foundation('reveal', 'open');
+}
+
+// Template import dialog
+function setupTemplateImportDialog(){
+ //Append to DOM
+ dialogs_context.append('
');
+ var dialog = $('#template_import_dialog',dialogs_context);
+
+ //Put HTML in place
+
+ var html = '\
+ \
+
\
+ \
+
\
+
×\
+
\
+ ';
+
+
+ dialog.html(html);
+ dialog.addClass("reveal-modal medium").attr("data-reveal", "");
+
+ $("#get_vcenter_templates", dialog).on("click", function(){
+ var templates_container = $(".vcenter_templates", dialog);
+
+ var vcenter_user = $("#vcenter_user", dialog).val();
+ var vcenter_password = $("#vcenter_password", dialog).val();
+ var vcenter_host = $("#vcenter_host", dialog).val();
+
+ fillVCenterTemplates({
+ container: templates_container,
+ vcenter_user: vcenter_user,
+ vcenter_password: vcenter_password,
+ vcenter_host: vcenter_host
+ });
+
+
+ return false;
+ })
+
+ $("#import_vcenter_templates", dialog).on("click", function(){
+ $(this).hide();
+
+ $.each($(".template_name:checked", 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+
+ '
');
+ Sunstone.runAction('Template.refresh');
+ },
+ 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?"))+
+ '
');
+ Sunstone.runAction('Template.refresh');
+ }
+ });
+ })
+ });
+}
+
+
+/*
+ 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;
+}
+
+
// Instantiate dialog
// Sets up the instiantiate template dialog and all the processing associated to it
function setupInstantiateTemplateDialog(){
diff --git a/src/sunstone/public/js/plugins/vnets-tab.js b/src/sunstone/public/js/plugins/vnets-tab.js
index 0fbe7fb5c7..36f5a61d57 100644
--- a/src/sunstone/public/js/plugins/vnets-tab.js
+++ b/src/sunstone/public/js/plugins/vnets-tab.js
@@ -256,6 +256,13 @@ var vnet_actions = {
}
},
+ "Network.import_dialog" : {
+ type: "create",
+ call: function(){
+ popUpNetworkImportDialog();
+ }
+ },
+
"Network.list" : {
type: "list",
call: OpenNebula.Network.list,
@@ -556,6 +563,13 @@ var vnet_buttons = {
type: "create_dialog",
layout: "create"
},
+ "Network.import_dialog" : {
+ type: "create_dialog",
+ layout: "create",
+ text: tr("Import"),
+ icon: '',
+ alwaysActive: true
+ },
"Network.update_dialog" : {
type: "action",
layout: "main",
@@ -2336,6 +2350,374 @@ function setupARTableSelect(section, context_id, vnet_id_fn){
return setupResourceTableSelect(section, context_id, options);
}
+function popUpNetworkImportDialog(){
+ setupNetworkImportDialog();
+ var dialog = $('#network_import_dialog');
+ $(dialog).foundation().foundation('reveal', 'open');
+}
+
+// Netowrk import dialog
+function setupNetworkImportDialog(){
+ //Append to DOM
+ dialogs_context.append('');
+ var dialog = $('#network_import_dialog',dialogs_context);
+
+ //Put HTML in place
+
+ var html = '\
+ \
+
\
+ \
+
\
+
×\
+
\
+ ';
+
+
+ dialog.html(html);
+ dialog.addClass("reveal-modal medium").attr("data-reveal", "");
+
+ $("#get_vcenter_networks", dialog).on("click", function(){
+ var networks_container = $(".vcenter_networks", dialog);
+
+ var vcenter_user = $("#vcenter_user", dialog).val();
+ var vcenter_password = $("#vcenter_password", dialog).val();
+ var vcenter_host = $("#vcenter_host", dialog).val();
+
+
+ fillVCenterNetworks({
+ container: networks_container,
+ vcenter_user: vcenter_user,
+ vcenter_password: vcenter_password,
+ vcenter_host: vcenter_host
+ });
+
+ return false;
+ })
+
+ $("#import_vcenter_networks", dialog).on("click", function(){
+ $(this).hide();
+
+ $.each($(".network_name:checked", 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+
+ '
');
+ Sunstone.runAction("Network.refresh");
+ },
+ 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?"))+
+ '
');
+ Sunstone.runAction("Network.refresh");
+ }
+ });
+ });
+ });
+}
+
+
+/*
+ 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;
+}
+
//The DOM is ready and the ready() from sunstone.js
//has been executed at this point.
$(document).ready(function(){
diff --git a/src/sunstone/public/js/sunstone.js b/src/sunstone/public/js/sunstone.js
index a2bcdf240a..0fc1069f1d 100644
--- a/src/sunstone/public/js/sunstone.js
+++ b/src/sunstone/public/js/sunstone.js
@@ -868,7 +868,8 @@ function insertButtonsInTab(tab_name, panel_name, panel_buttons, custom_context)
switch (button.layout) {
case "create":
button_context = $("#"+custom_id+"create_buttons", buttons_row);
- text = button.text ? ' ' + button.text : '';
+ icon = button.icon ? button.icon : '';
+ text = button.text ? icon + ' ' + button.text : icon;
str_class.push("success", "button", "small", "radius");
button_code = '';
break;