mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-19 19:32:56 +09:00
F #1884 : Sunstone Template importation
================================================ F #1884: Generic feedback for vCenter resources F #1884: New vCenter importer for templates [Sinatra] F #1884: New interface for vCenter templates importation F #1884: Improved vCenter Template importation F #1884: Added libs for jGrowl feedback F #1884: Added post path for vCenter templates importation F #1884: Solved bug with master selector in vCenter resources importation F #1884: Network importation makeover and improved
This commit is contained in:
1 parent
c0fed7da9a
commit
68aadedffa
10 files changed
+282
-615
No files matched your search
@@ -24,6 +24,9 @@ define(function(require) {
|
||||
var Sunstone = require('sunstone');
|
||||
var Locale = require('utils/locale');
|
||||
var VCenterTemplates = require('utils/vcenter/templates');
|
||||
var HostsTable = require('tabs/hosts-tab/datatable');
|
||||
var UniqueId = require('utils/unique-id');
|
||||
var Notifier = require('utils/notifier');
|
||||
|
||||
/*
|
||||
TEMPLATES
|
||||
@@ -55,6 +58,16 @@ define(function(require) {
|
||||
|
||||
this.vCenterTemplates = new VCenterTemplates();
|
||||
|
||||
var options = {
|
||||
'select': true,
|
||||
'selectOptions': {
|
||||
'multiple_choice': false,
|
||||
"filter_fn": function(host) { return host.VM_MAD === "vcenter" && host.IM_MAD === "vcenter"; }
|
||||
}
|
||||
};
|
||||
this.hostsTable = new HostsTable('HostsTable' + UniqueId.id(), options);
|
||||
|
||||
|
||||
BaseFormPanel.call(this);
|
||||
}
|
||||
|
||||
@@ -75,38 +88,36 @@ define(function(require) {
|
||||
function _htmlWizard() {
|
||||
return TemplateHTML({
|
||||
'formPanelId': this.formPanelId,
|
||||
'vCenterHostsHTML': this.hostsTable.dataTableHTML,
|
||||
'vCenterTemplatesHTML': this.vCenterTemplates.html()
|
||||
});
|
||||
}
|
||||
|
||||
function _setup(context) {
|
||||
var that = this;
|
||||
this.hostsTable.initialize();
|
||||
this.hostsTable.refreshResourceTableSelect();
|
||||
|
||||
$("form.vcenter_credentials", context)
|
||||
.off('forminvalid.zf.abide').off('formvalid.zf.abide').off("submit");
|
||||
|
||||
Foundation.reInit($("form.vcenter_credentials", context));
|
||||
|
||||
$("form.vcenter_credentials", context)
|
||||
.on('forminvalid.zf.abide', function(ev, frm) {
|
||||
})
|
||||
.on('formvalid.zf.abide', function(ev, frm) {
|
||||
Sunstone.enableFormPanelSubmit(TAB_ID);
|
||||
|
||||
var vcenter_user = $("#vcenter_user", context).val();
|
||||
var vcenter_password = $("#vcenter_password", context).val();
|
||||
var vcenter_host = $("#vcenter_host", context).val();
|
||||
|
||||
$(context).off("click", "#get-vcenter-templates");
|
||||
$(context).on("click", "#get-vcenter-templates", function(){
|
||||
var selectedHost = that.hostsTable.retrieveResourceTableSelect();
|
||||
if (selectedHost !== ""){
|
||||
that.vCenterTemplates.insert({
|
||||
container: context,
|
||||
vcenter_user: vcenter_user,
|
||||
vcenter_password: vcenter_password,
|
||||
vcenter_host: vcenter_host
|
||||
selectedHost: selectedHost
|
||||
});
|
||||
})
|
||||
.on("submit", function(ev) {
|
||||
ev.preventDefault();
|
||||
});
|
||||
$("#import_vcenter_templates", this.parentElement).prop("disabled", false);
|
||||
}
|
||||
else {
|
||||
Notifier.notifyMessage("You need select a vCenter host first");
|
||||
}
|
||||
});
|
||||
|
||||
$(context).off("click", "#import_vcenter_templates");
|
||||
$(context).on("click", "#import_vcenter_templates", function(){
|
||||
that.vCenterTemplates.import(context);
|
||||
return false;
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -122,5 +133,6 @@ define(function(require) {
|
||||
}
|
||||
|
||||
function _onShow(context) {
|
||||
$("#templates-tab .submit_button").hide();
|
||||
}
|
||||
});
|
||||
@@ -15,30 +15,14 @@
|
||||
{{! -------------------------------------------------------------------------- }}
|
||||
|
||||
<div id="import_templates_form_wrapper">
|
||||
<form data-abide novalidate id="{{formPanelId}}Wizard" class="custom creation">
|
||||
</form>
|
||||
<form data-abide novalidate class="vcenter_credentials" action="">
|
||||
<div class="row">
|
||||
<div class="large-3 medium-6 columns">
|
||||
<label for="vcenter_host">{{tr "Hostname"}}</label>
|
||||
<input type="text" name="vcenter_host" id="vcenter_host" required />
|
||||
</div>
|
||||
<div class="large-3 medium-6 columns">
|
||||
<label for="vcenter_user">{{tr "User"}}</label>
|
||||
<input type="text" name="vcenter_user" id="vcenter_user" required />
|
||||
</div>
|
||||
<div class="large-3 medium-6 columns">
|
||||
<label for="vcenter_password">{{tr "Password"}}</label>
|
||||
<input type="password" name="vcenter_password" id="vcenter_password" required />
|
||||
</div>
|
||||
<div class="large-3 medium-6 columns">
|
||||
<label> </label>
|
||||
<button type="submit" class="button radius">
|
||||
{{tr "Get VM Templates"}}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div class="row collapse">
|
||||
{{{vCenterHostsHTML}}}
|
||||
</div>
|
||||
<div style="float:left">
|
||||
<button class="button radius" id="get-vcenter-templates"> {{tr "Get Templates"}} </button>
|
||||
<button class="button right success" id="import_vcenter_templates" disabled>{{tr "Import"}}</button>
|
||||
</div>
|
||||
<br><br><br>
|
||||
<div class="row collapse">
|
||||
{{{vCenterTemplatesHTML}}}
|
||||
</div>
|
||||
|
||||
@@ -31,6 +31,7 @@ define(function(require) {
|
||||
var FieldsetTableHTML = require("hbs!./common/fieldset-table");
|
||||
|
||||
var path = "/vcenter/datastores";
|
||||
var resource = "Datastore";
|
||||
|
||||
function VCenterDatastores() {
|
||||
return this;
|
||||
@@ -97,8 +98,10 @@ define(function(require) {
|
||||
var newdiv = $(content).appendTo($(".vcenter_datacenter_list", context));
|
||||
var tbody = $("#" + tableId + " tbody", context);
|
||||
|
||||
var ds_num = 0;
|
||||
$.each(response, function(datastore_name, element){
|
||||
if (element.cluster.length !== 0){
|
||||
ds_num++;
|
||||
var opts = { name: element.simple_name, vcenter_ref: element.ref, datacenter: element.datacenter, cluster: element.cluster, free_mb: element.free_mb, total_mb: element.total_mb };
|
||||
var trow = $(RowTemplate(opts)).appendTo(tbody);
|
||||
$(".check_item", trow).data("import_data", element);
|
||||
@@ -124,6 +127,8 @@ define(function(require) {
|
||||
|
||||
elementsTable.initialize();
|
||||
|
||||
$("a.vcenter-table-select-all", context).text(Locale.tr("Select all %1$s Datastores", ds_num));
|
||||
|
||||
VCenterCommon.setupTable({
|
||||
context : newdiv,
|
||||
allSelected : Locale.tr("All %1$s Datastores selected."),
|
||||
@@ -145,7 +150,6 @@ define(function(require) {
|
||||
}
|
||||
|
||||
function _import(context) {
|
||||
var that = this;
|
||||
var vcenter_refs = [];
|
||||
|
||||
var table = $("table.vcenter_import_table", context);
|
||||
@@ -167,24 +171,14 @@ define(function(require) {
|
||||
data: { datastores: vcenter_refs, timeout: false },
|
||||
dataType: "json",
|
||||
success: function(response){
|
||||
var success = response.success;
|
||||
if (success.length !== 0){
|
||||
$.each(success, function(key, value){
|
||||
var ds1 = Navigation.link(value.id[0], "datastores-tab", value.id[0]);
|
||||
var ds2 = Navigation.link(value.id[1], "datastores-tab", value.id[1]);
|
||||
Notifier.notifyMessage("Datastore " + value.name + " imported as " + ds1 + " " + ds2 + " successfully");
|
||||
});
|
||||
}
|
||||
var error = response.error;
|
||||
if (error.length !== 0){
|
||||
$.each(error, function(key, value){
|
||||
Notifier.notifyError("Datastore with ref " + value + " could not be imported");
|
||||
});
|
||||
}
|
||||
VCenterCommon.jGrowlSuccess({success : response.success, resource : resource, link_tab : "datastores-tab"});
|
||||
VCenterCommon.jGrowlFailure({error : response.error, resource : resource});
|
||||
|
||||
$("#get-vcenter-ds").click();
|
||||
},
|
||||
error: function (request, error_json) {
|
||||
Notifier.notifyError(request.responseJSON.error.message);
|
||||
$("#get-vcenter-ds").click();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ define(function(require) {
|
||||
|
||||
elementsTable.initialize();
|
||||
|
||||
$("a.vcenter-table-select-all").text(Locale.tr("Select all %1$s Images", response.length));
|
||||
$("a.vcenter-table-select-all", context).text(Locale.tr("Select all %1$s Images", response.length));
|
||||
|
||||
VCenterCommon.setupTable({
|
||||
context : newdiv,
|
||||
|
||||
@@ -93,7 +93,8 @@ define(function(require) {
|
||||
toggleAdvanced : true,
|
||||
columns : [
|
||||
'<input type="checkbox" class="check_all"/>',
|
||||
Locale.tr("Network")
|
||||
Locale.tr("Network"),
|
||||
""
|
||||
]
|
||||
});
|
||||
|
||||
@@ -126,7 +127,7 @@ define(function(require) {
|
||||
|
||||
elementsTable.initialize();
|
||||
|
||||
$("a.vcenter-table-select-all").text(Locale.tr("Select all %1$s Networks", elements.length));
|
||||
$("a.vcenter-table-select-all", context).text(Locale.tr("Select all %1$s Networks", elements.length));
|
||||
|
||||
VCenterCommon.setupTable({
|
||||
context : newdiv,
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
{{! -------------------------------------------------------------------------- }}
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
<input type="checkbox" class="check_item"/>
|
||||
<td style="vertical-align: top">
|
||||
<input type="checkbox" class="check_item" style="margin-top: 5px"/>
|
||||
</td>
|
||||
<td>
|
||||
<div class="accordion_advanced vcenter_row">
|
||||
@@ -27,50 +27,49 @@
|
||||
</a>
|
||||
{{data.name}}
|
||||
- <i>{{data.type}}</i>
|
||||
- Cluster: <i>{{data.cluster}}</i>
|
||||
- Location: <i>{{data.cluster_location}}</i>
|
||||
- OpenNebula Cluster ID: <i>{{data.one_cluster_id}}</i>
|
||||
{{#if data.vlan}} - <i>VLAN: <span class="vlaninfo">{{data.vlan}}</span></i>{{/if}}
|
||||
{{#if data.cluster}} - {{tr "Cluster"}}: <i>{{data.cluster}}</i>{{/if}}
|
||||
{{#if data.cluster_location}} - {{tr "Location"}}: <i>{{data.cluster_location}}</i>{{/if}}
|
||||
{{#if data.one_cluster_id}} - {{tr "OpenNebula Cluster ID"}}: <i>{{data.one_cluster_id}}</i>{{/if}}
|
||||
{{#if data.vlan}} - {{tr "VLAN"}}: <i><span class="vlaninfo">{{data.vlan}}</span></i>{{/if}}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div id="{{data.uuid}}Advanced" class="content row" hidden>
|
||||
<div class="large-2 medium-3 small-6 columns">
|
||||
<label>
|
||||
{{tr "Size"}}
|
||||
<input type="text" class="netsize" value="255"/>
|
||||
</label>
|
||||
</div>
|
||||
<div class="large-2 medium-3 small-6 columns">
|
||||
<label>
|
||||
{{tr "Type"}}
|
||||
<select class="type_select">
|
||||
<option value="ETHER">eth</option>
|
||||
<option value="IP4">ipv4</option>
|
||||
<option value="IP6">ipv6</option>
|
||||
<option value="IP6_STATIC">ipv6 static</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<div class="large-6 medium-12 small-12 columns end">
|
||||
<div class="row net_options">
|
||||
<div class="large-4 medium-3 small-12 columns end">
|
||||
<div class="row">
|
||||
<div id="{{data.uuid}}Advanced" class="content row" hidden>
|
||||
<div class="vcenter_rp_input row" style="margin-left: 59px">
|
||||
<div class="large-2 medium-3 small-6 columns">
|
||||
<label>
|
||||
{{tr "MAC"}}
|
||||
<input type="text" class="eth_mac_net" placeholder="{{tr "Optional"}}"/>
|
||||
{{tr "Size"}}
|
||||
<input type="text" class="netsize" value="255"/>
|
||||
</label>
|
||||
</div>
|
||||
<div class="large-2 medium-3 small-6 columns">
|
||||
<label>
|
||||
{{tr "Type"}}
|
||||
<select class="type_select">
|
||||
<option value="ETHER">eth</option>
|
||||
<option value="IP4">ipv4</option>
|
||||
<option value="IP6">ipv6</option>
|
||||
<option value="IP6_STATIC">ipv6 static</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<div class="large-6 medium-12 small-12 columns end">
|
||||
<div class="row net_options">
|
||||
<div class="large-4 medium-3 small-12 columns end">
|
||||
<label>
|
||||
{{tr "MAC"}}
|
||||
<input type="text" class="eth_mac_net" placeholder="{{tr "Optional"}}"/>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row vcenter_import_result_row" style="display:none">
|
||||
<div class="large-11 large-centered columns">
|
||||
<span class="vcenter_import_result">
|
||||
</span>
|
||||
<span class="vcenter_import_response">
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<span class="vcenter_import_result"></span>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -16,32 +16,35 @@
|
||||
|
||||
define(function(require) {
|
||||
// Dependencies
|
||||
var Locale = require('utils/locale');
|
||||
var OpenNebulaTemplate = require('opennebula/template');
|
||||
var OpenNebulaNetwork = require('opennebula/network');
|
||||
var OpenNebulaImage = require('opennebula/image');
|
||||
var OpenNebulaError = require('opennebula/error');
|
||||
var DomDataTable = require('utils/dom-datatable');
|
||||
var UserInputs = require('utils/user-inputs');
|
||||
var Notifier = require('utils/notifier');
|
||||
var UniqueId = require('utils/unique-id');
|
||||
var VCenterCommon = require('./vcenter-common');
|
||||
var Sunstone = require('sunstone');
|
||||
var Tips = require('utils/tips');
|
||||
var Locale = require("utils/locale");
|
||||
var OpenNebulaTemplate = require("opennebula/template");
|
||||
var OpenNebulaNetwork = require("opennebula/network");
|
||||
var OpenNebulaImage = require("opennebula/image");
|
||||
var OpenNebulaError = require("opennebula/error");
|
||||
var DomDataTable = require("utils/dom-datatable");
|
||||
var UserInputs = require("utils/user-inputs");
|
||||
var Notifier = require("utils/notifier");
|
||||
var UniqueId = require("utils/unique-id");
|
||||
var VCenterCommon = require("./vcenter-common");
|
||||
var Sunstone = require("sunstone");
|
||||
var Tips = require("utils/tips");
|
||||
|
||||
var TemplateHTML = require('hbs!./common/html');
|
||||
var RowTemplate = require('hbs!./templates/row');
|
||||
var EmptyFieldsetHTML = require('hbs!./common/empty-fieldset');
|
||||
var FieldsetTableHTML = require('hbs!./common/fieldset-table');
|
||||
var TemplateHTML = require("hbs!./common/html");
|
||||
var RowTemplate = require("hbs!./templates/row");
|
||||
var EmptyFieldsetHTML = require("hbs!./common/empty-fieldset");
|
||||
var FieldsetTableHTML = require("hbs!./common/fieldset-table");
|
||||
|
||||
var path = "/vcenter/templates";
|
||||
var resource = "Template";
|
||||
|
||||
function VCenterTemplates() {
|
||||
return this;
|
||||
}
|
||||
|
||||
VCenterTemplates.prototype = {
|
||||
'html': VCenterCommon.html,
|
||||
'insert': _fillVCenterTemplates,
|
||||
'import': _import
|
||||
"html": VCenterCommon.html,
|
||||
"insert": _fillVCenterTemplates,
|
||||
"import": _import
|
||||
};
|
||||
VCenterTemplates.prototype.constructor = VCenterTemplates;
|
||||
|
||||
@@ -49,18 +52,14 @@ define(function(require) {
|
||||
|
||||
/*
|
||||
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
|
||||
selectedHost: Host selected for vCenter credentials
|
||||
}
|
||||
*/
|
||||
function _fillVCenterTemplates(opts) {
|
||||
this.opts = opts;
|
||||
var path = '/vcenter/templates';
|
||||
|
||||
var context = $(".vcenter_import", opts.container);
|
||||
context.html(TemplateHTML());
|
||||
@@ -69,94 +68,46 @@ define(function(require) {
|
||||
$.ajax({
|
||||
url: path,
|
||||
type: "GET",
|
||||
data: {timeout: false},
|
||||
data: { host: opts.selectedHost, 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){
|
||||
$(".vcenter_datacenter_list", context).html("");
|
||||
|
||||
$.each(response, function(datacenter_name, elements){
|
||||
var content;
|
||||
if (elements.length == 0) {
|
||||
content = EmptyFieldsetHTML({
|
||||
title : datacenter_name + ' ' + Locale.tr("DataCenter"),
|
||||
message : Locale.tr("No new templates found in this DataCenter")
|
||||
});
|
||||
if (response.length === 0){
|
||||
content = EmptyFieldsetHTML({
|
||||
title : Locale.tr("vCenter Templates"),
|
||||
message : Locale.tr("No new templates found")
|
||||
});
|
||||
$(".vcenter_datacenter_list", context).append(content);
|
||||
|
||||
$(".vcenter_datacenter_list", context).append(content);
|
||||
} else {
|
||||
var tableId = "vcenter_import_table_" + UniqueId.id();
|
||||
} else {
|
||||
var tableId = "vcenter_import_table_" + UniqueId.id();
|
||||
content = FieldsetTableHTML({
|
||||
tableId : tableId,
|
||||
title : datacenter_name + ' ' + Locale.tr("DataCenter"),
|
||||
clearImported : Locale.tr("Clear Imported Templates"),
|
||||
title : Locale.tr("vCenter Templates"),
|
||||
toggleAdvanced : true,
|
||||
columns : [
|
||||
'<input type="checkbox" class="check_all"/>',
|
||||
Locale.tr("Template")
|
||||
"<input type=\"checkbox\" class=\"check_all\"/>",
|
||||
Locale.tr("Template"),
|
||||
""
|
||||
]
|
||||
});
|
||||
|
||||
var newdiv = $(content).appendTo($(".vcenter_datacenter_list", context));
|
||||
var tbody = $('#' + tableId + ' tbody', context);
|
||||
var tbody = $("#" + tableId + " tbody", context);
|
||||
|
||||
$.each(elements, function(id, element) {
|
||||
$.each(response, function(template_name, element){
|
||||
var opts = {};
|
||||
|
||||
opts.data = element;
|
||||
opts.id = UniqueId.id();
|
||||
|
||||
if (element.rp && element.rp !== '') {
|
||||
if (element.rp && element.rp !== "") {
|
||||
opts.resourcePool = UserInputs.unmarshall(element.rp);
|
||||
opts.resourcePool.params = opts.resourcePool.params.split(",");
|
||||
/* $.each(opts.resourcePool.params, function(){
|
||||
$("#available_rps_" + opts.id + " [value ='" + this + "']").mousedown(function(e) {
|
||||
e.preventDefault();
|
||||
$(this).prop('selected', !$(this).prop('selected'));
|
||||
return false;
|
||||
});
|
||||
});*/
|
||||
}
|
||||
|
||||
var trow = $(RowTemplate(opts)).appendTo(tbody);
|
||||
Tips.setup(trow);
|
||||
|
||||
$("#modify_rp_" + opts.id).change(function(){
|
||||
var val = $("#modify_rp_" + opts.id).val();
|
||||
if (val == "default"){
|
||||
$("#div_rp_" + opts.id).hide();
|
||||
} else if (val == "fixed"){
|
||||
$("#div_rp_" + opts.id).show();
|
||||
$("#available_rps_" + opts.id).attr("multiple", false);
|
||||
} else {
|
||||
$("#div_rp_" + opts.id).show();
|
||||
$("#available_rps_" + opts.id).attr("multiple", true);
|
||||
}
|
||||
});
|
||||
|
||||
$("#linked_clone_"+opts.id).on("change", function(){
|
||||
if ($("#linked_clone_"+opts.id).is(":checked")){
|
||||
$("#create_"+opts.id).show();
|
||||
} else {
|
||||
$("#create_"+opts.id).hide();
|
||||
$("#create_copy_"+opts.id).prop("checked", false);
|
||||
$("#name_"+opts.id).hide();
|
||||
}
|
||||
});
|
||||
|
||||
$("#create_copy_"+opts.id).on("change", function(){
|
||||
if ($("#create_copy_"+opts.id).is(":checked")){
|
||||
$("#name_"+opts.id).show();
|
||||
} else {
|
||||
$("#name_"+opts.id).hide();
|
||||
}
|
||||
});
|
||||
|
||||
$('.check_item', trow).data("import_data", element);
|
||||
setupAdvanced(opts, trow);
|
||||
$(".check_item", trow).data("import_data", element);
|
||||
});
|
||||
|
||||
var elementsTable = new DomDataTable(
|
||||
@@ -170,7 +121,7 @@ define(function(require) {
|
||||
"bDeferRender": false,
|
||||
"ordering": false,
|
||||
"aoColumnDefs": [
|
||||
{"sWidth": "35px", "aTargets": [0]},
|
||||
{ "sWidth": "35px", "aTargets": [0] },
|
||||
],
|
||||
},
|
||||
"customTrListener": function(tableObj, tr){ return false; }
|
||||
@@ -178,7 +129,7 @@ define(function(require) {
|
||||
|
||||
elementsTable.initialize();
|
||||
|
||||
$("a.vcenter-table-select-all").text(Locale.tr("Select all %1$s Templates", elements.length));
|
||||
$("a.vcenter-table-select-all", context).text(Locale.tr("Select all %1$s Templates", Object.keys(response).length));
|
||||
|
||||
VCenterCommon.setupTable({
|
||||
context : newdiv,
|
||||
@@ -186,13 +137,12 @@ define(function(require) {
|
||||
selected: Locale.tr("%1$s Templates selected.")
|
||||
});
|
||||
|
||||
context.off('click', '.clear_imported');
|
||||
context.on('click', '.clear_imported', function() {
|
||||
_fillVCenterTemplates(opts);
|
||||
context.off("click", ".clear_imported");
|
||||
context.on("click", ".clear_imported", function() {
|
||||
_fillVCenterDatastores(opts);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
error: function(response){
|
||||
context.hide();
|
||||
@@ -201,399 +151,108 @@ define(function(require) {
|
||||
});
|
||||
}
|
||||
|
||||
function rollback_nics_and_disk(error_message, template_id, rollback_items, row_context) {
|
||||
var rollback_index = 0;
|
||||
|
||||
function nextRollback() {
|
||||
|
||||
if (rollback_items.length == rollback_index) {
|
||||
var path = '/vcenter/template_rollback/' + template_id;
|
||||
$.ajax({
|
||||
url: path,
|
||||
type: "POST",
|
||||
data: {timeout: false},
|
||||
dataType: "json",
|
||||
success: function(response){
|
||||
VCenterCommon.importFailure({
|
||||
context : row_context,
|
||||
message : Locale.tr("Could not import the template due to " + error_message + ". A rollback has been applied.")
|
||||
});
|
||||
},
|
||||
error: function(response){
|
||||
VCenterCommon.importFailure({
|
||||
context : row_context,
|
||||
message : OpenNebulaError(response).error.message
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (rollback_items[rollback_index].type === "NETWORK") {
|
||||
var path = '/vcenter/network_rollback/' + rollback_items[rollback_index].id;
|
||||
$.ajax({
|
||||
url: path,
|
||||
type: "POST",
|
||||
data: {timeout: false},
|
||||
dataType: "json",
|
||||
success: function(response){
|
||||
++rollback_index;
|
||||
nextRollback();
|
||||
},
|
||||
error: function(response){
|
||||
VCenterCommon.importFailure({
|
||||
context : row_context,
|
||||
message : OpenNebulaError(response).error.message
|
||||
});
|
||||
Notifier.onError({}, OpenNebulaError(response));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (rollback_items[rollback_index].type === "IMAGE") {
|
||||
var path = '/vcenter/image_rollback/' + rollback_items[rollback_index].id;
|
||||
$.ajax({
|
||||
url: path,
|
||||
type: "POST",
|
||||
data: {timeout: false},
|
||||
dataType: "json",
|
||||
success: function(response){
|
||||
++rollback_index;
|
||||
nextRollback();
|
||||
},
|
||||
error: function(response){
|
||||
VCenterCommon.importFailure({
|
||||
context : row_context,
|
||||
message : OpenNebulaError(response).error.message
|
||||
});
|
||||
Notifier.onError({}, OpenNebulaError(response));
|
||||
}
|
||||
});
|
||||
}
|
||||
function setupAdvanced(opts, context){
|
||||
$(".modify_rp", context).change(function(){
|
||||
switch ($(this).val()){
|
||||
case "default":
|
||||
$("#div_rp_" + opts.id).hide();
|
||||
break;
|
||||
case "fixed":
|
||||
$("#div_rp_" + opts.id).show();
|
||||
$(".available_rps", context).attr("multiple", false);
|
||||
break;
|
||||
case "list":
|
||||
$("#div_rp_" + opts.id).show();
|
||||
$(".available_rps", context).attr("multiple", true);
|
||||
}
|
||||
}
|
||||
|
||||
nextRollback();
|
||||
}
|
||||
|
||||
function import_images_and_nets(disks_and_nets, row_context, template_id) {
|
||||
var index = 0;
|
||||
var template = "";
|
||||
var rollback = [];
|
||||
var duplicated_nics = {};
|
||||
|
||||
function getNext() {
|
||||
|
||||
// Update the template
|
||||
if (disks_and_nets.length == index) {
|
||||
var template_json = {
|
||||
"extra_param": template
|
||||
};
|
||||
|
||||
Sunstone.runAction('Template.append_template', template_id, template);
|
||||
|
||||
VCenterCommon.importSuccess({
|
||||
context : row_context,
|
||||
message : Locale.tr("Template created successfully. ID: %1$s", template_id)
|
||||
});
|
||||
});
|
||||
|
||||
$(".linked_clone", context).change(function(){
|
||||
if ($(this).is(":checked")){
|
||||
$(".div_create", context).show();
|
||||
} else {
|
||||
|
||||
if (disks_and_nets[index].type === "NEW_DISK") {
|
||||
|
||||
var image_json = {
|
||||
"image": {
|
||||
"image_raw": disks_and_nets[index].image_tmpl
|
||||
},
|
||||
"ds_id" : disks_and_nets[index].ds_id
|
||||
};
|
||||
|
||||
OpenNebulaImage.create({
|
||||
timeout: true,
|
||||
data: image_json,
|
||||
success: function(request, response) {
|
||||
var image_id = response.IMAGE.ID;
|
||||
var image_uname = response.IMAGE.UNAME;
|
||||
++index;
|
||||
template += "DISK=[\n";
|
||||
template += "IMAGE_ID=\"" + image_id + "\",\n";
|
||||
template += "OPENNEBULA_MANAGED=\"NO\"\n";
|
||||
template += "]\n";
|
||||
|
||||
var rollback_info = { type: "IMAGE", id: image_id};
|
||||
rollback.push(rollback_info);
|
||||
getNext();
|
||||
},
|
||||
error: function (request, error_json) {
|
||||
var error_message_str = error_json.error.message;
|
||||
|
||||
// Rollback
|
||||
VCenterCommon.importFailure({
|
||||
context : row_context,
|
||||
message : (error_json.error.message || Locale.tr("Cannot contact server: is it running and reachable?"))
|
||||
});
|
||||
|
||||
rollback_nics_and_disk(error_json.error.message, template_id, rollback, row_context);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (disks_and_nets[index].type === "EXISTING_DISK") {
|
||||
template += disks_and_nets[index].image_tmpl;
|
||||
++index;
|
||||
getNext();
|
||||
}
|
||||
|
||||
if (disks_and_nets[index].type === "NEW_NIC") {
|
||||
|
||||
var vnet_json = {
|
||||
"vnet": {
|
||||
"vnet_raw": disks_and_nets[index].network_tmpl
|
||||
}
|
||||
};
|
||||
|
||||
var one_cluster_id = disks_and_nets[index].one_cluster_id;
|
||||
|
||||
OpenNebulaNetwork.create({
|
||||
timeout: true,
|
||||
data: vnet_json,
|
||||
success: function(request, response) {
|
||||
var network_id = response.VNET.ID;
|
||||
if (one_cluster_id != -1) {
|
||||
Sunstone.runAction("Cluster.addvnet",one_cluster_id,response.VNET.ID);
|
||||
//Remove bnet from default datastore
|
||||
Sunstone.runAction("Cluster.delvnet",0,response.VNET.ID);
|
||||
}
|
||||
duplicated_nics[disks_and_nets[index].network_name]=network_id;
|
||||
|
||||
++index;
|
||||
template += "NIC=[\n";
|
||||
template += "NETWORK_ID=\"" + network_id + "\",\n";
|
||||
template += "OPENNEBULA_MANAGED=\"NO\"\n";
|
||||
template += "]\n";
|
||||
|
||||
var rollback_info = { type: "NETWORK", id: network_id};
|
||||
rollback.push(rollback_info);
|
||||
getNext();
|
||||
},
|
||||
error: function (request, error_json) {
|
||||
// Rollback
|
||||
VCenterCommon.importFailure({
|
||||
context : row_context,
|
||||
message : (error_json.error.message || Locale.tr("Cannot contact server: is it running and reachable?"))
|
||||
});
|
||||
|
||||
rollback_nics_and_disk(error_json.error.message, template_id, rollback, row_context);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (disks_and_nets[index] != undefined && disks_and_nets[index].type == "EXISTING_NIC") {
|
||||
template += disks_and_nets[index].network_tmpl;
|
||||
++index;
|
||||
getNext();
|
||||
}
|
||||
|
||||
if (disks_and_nets[index] != undefined && disks_and_nets[index].type == "DUPLICATED_NIC") {
|
||||
var network_id = duplicated_nics[disks_and_nets[index].network_name];
|
||||
|
||||
template += "NIC=[\n";
|
||||
template += "NETWORK_ID=\"" + network_id + "\",\n";
|
||||
template += "OPENNEBULA_MANAGED=\"NO\"\n";
|
||||
template += "]\n";
|
||||
++index;
|
||||
getNext();
|
||||
}
|
||||
$(".div_create", context).hide();
|
||||
$(".create_copy", context).prop("checked", false);
|
||||
$("#name_" + opts.id, context).hide();
|
||||
}
|
||||
}
|
||||
getNext();
|
||||
});
|
||||
|
||||
$(".create_copy", context).change(function(){
|
||||
var name_input = $("#name_" + opts.id, context);
|
||||
if ($(this).is(":checked")){
|
||||
name_input.show();
|
||||
} else {
|
||||
name_input.hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function _import(context) {
|
||||
that = this;
|
||||
$.each($(".vcenter_import_table", context), function() {
|
||||
$.each($(this).DataTable().$(".check_item:checked"), function() {
|
||||
var vcenter_ref = $(this).data("import_data").vcenter_ref;
|
||||
var linked = false;
|
||||
var copy = false;
|
||||
var template_name = "";
|
||||
var row_context = $(this).closest("tr");
|
||||
var vcenter_refs = [];
|
||||
var opts = {};
|
||||
|
||||
VCenterCommon.importLoading({context : row_context});
|
||||
var table = $("table.vcenter_import_table", context);
|
||||
$.each(table.DataTable().$(".check_item:checked"), function(){
|
||||
var row_context = $(this).closest("tr");
|
||||
VCenterCommon.importLoading({context : row_context});
|
||||
|
||||
var attrs = [];
|
||||
var userInputs = [];
|
||||
var ref = $(this).data("import_data").ref;
|
||||
vcenter_refs.push(ref);
|
||||
|
||||
// Retrieve Resource Pool Attribute
|
||||
var rpInput = $(".vcenter_rp_input", row_context);
|
||||
if (rpInput.length > 0) {
|
||||
var rpModify = $('.modify_rp', rpInput).val();
|
||||
var rpParams = "";
|
||||
var linkedClone = $('.linked_clone', rpInput).prop("checked");
|
||||
var createCopy = $('.create_copy', rpInput).prop("checked");
|
||||
var templateName = $('.template_name', rpInput).val();
|
||||
opts[ref] = {};
|
||||
|
||||
if (linkedClone) {
|
||||
linked = true;
|
||||
opts[ref].type = $(".modify_rp", row_context).val();
|
||||
|
||||
if (createCopy && templateName != "") {
|
||||
copy = true;
|
||||
template_name = templateName;
|
||||
} else {
|
||||
copy = false;
|
||||
template_name = "";
|
||||
}
|
||||
}
|
||||
|
||||
$.each($('.available_rps option:selected', rpInput), function(){
|
||||
rpParams += $(this).val() + ",";
|
||||
});
|
||||
var rpParams = rpParams.slice(0,-1);
|
||||
|
||||
if (rpModify === 'fixed' && rpParams!== '') {
|
||||
attrs.push('VCENTER_RESOURCE_POOL="' + rpParams + '"');
|
||||
} else if (rpModify === 'list' && rpParams !== '') {
|
||||
var rpUserInputs = UserInputs.marshall({
|
||||
type: 'list',
|
||||
description: Locale.tr("Which resource pool you want this VM to run in?"),
|
||||
initial: "",
|
||||
params: rpParams
|
||||
});
|
||||
|
||||
userInputs.push('VCENTER_RESOURCE_POOL="' + rpUserInputs + '"');
|
||||
}
|
||||
}
|
||||
|
||||
// Append new attrs and user inputs if necessary
|
||||
var template = $(this).data("import_data").one;
|
||||
|
||||
if (attrs.length > 0) {
|
||||
template += "\n" + attrs.join("\n");
|
||||
}
|
||||
|
||||
if (userInputs.length > 0) {
|
||||
template += "\nUSER_INPUTS=[\n" + userInputs.join(",\n") + "]";
|
||||
}
|
||||
|
||||
if (linked) {
|
||||
template += "\nVCENTER_LINKED_CLONES=\"YES\"";
|
||||
}
|
||||
|
||||
if($(this).data("import_data").import_disks_and_nics){
|
||||
var template_json = {
|
||||
"vmtemplate": { "template_raw": template }
|
||||
};
|
||||
OpenNebulaTemplate.create({
|
||||
timeout: false,
|
||||
data: template_json,
|
||||
success: function(request, response) {
|
||||
VCenterCommon.importLoading({
|
||||
context : row_context,
|
||||
message : Locale.tr("Importing images and vnets associated to template disks and nics...")
|
||||
});
|
||||
var template_id = response.VMTEMPLATE.ID;
|
||||
var path = '/vcenter/template/' + vcenter_ref + '/' + template_id;
|
||||
|
||||
$.ajax({
|
||||
url: path,
|
||||
type: "GET",
|
||||
data: {
|
||||
timeout: false,
|
||||
use_linked_clones: linked,
|
||||
create_copy: copy,
|
||||
template_name: template_name
|
||||
},
|
||||
headers: {
|
||||
"X-VCENTER-USER": that.opts.vcenter_user,
|
||||
"X-VCENTER-PASSWORD": that.opts.vcenter_password,
|
||||
"X-VCENTER-HOST": that.opts.vcenter_host
|
||||
},
|
||||
dataType: "json",
|
||||
success: function(response){
|
||||
var disks_and_nets = response.disks.concat(response.nics);
|
||||
|
||||
var template_json = {
|
||||
"vmtemplate": { "template_raw": response.one }
|
||||
};
|
||||
|
||||
if(response.create_copy){
|
||||
OpenNebulaTemplate.del({
|
||||
timeout: true,
|
||||
data : {
|
||||
id : template_id
|
||||
},
|
||||
success: function(){
|
||||
OpenNebulaTemplate.create({
|
||||
timeout: false,
|
||||
data: template_json,
|
||||
success: function(request, response){
|
||||
import_images_and_nets(disks_and_nets, row_context, response.VMTEMPLATE.ID);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
import_images_and_nets(disks_and_nets, row_context, template_id);
|
||||
}
|
||||
},
|
||||
error: function(response){
|
||||
VCenterCommon.importFailure({
|
||||
context : row_context,
|
||||
message : OpenNebulaError(response).error.message
|
||||
});
|
||||
Notifier.onError({}, OpenNebulaError(response));
|
||||
|
||||
// Remove template - Rollback
|
||||
var path = '/vcenter/template_rollback/' + template_id;
|
||||
$.ajax({
|
||||
url: path,
|
||||
type: "POST",
|
||||
data: {timeout: false},
|
||||
dataType: "json",
|
||||
success: function(response){
|
||||
// Do nothing
|
||||
},
|
||||
error: function(response){
|
||||
VCenterCommon.importFailure({
|
||||
context : row_context,
|
||||
message : Locale.tr("Could not delete the template " + template_id + " due to " + OpenNebulaError(response).error.message + ". Please remote it manually before importing this template again.")
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
error: function (request, error_json) {
|
||||
VCenterCommon.importFailure({
|
||||
context : row_context,
|
||||
message : (error_json.error.message || Locale.tr("Cannot contact server: is it running and reachable?"))
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
var template_json = {
|
||||
"vmtemplate": {
|
||||
"template_raw": template
|
||||
}
|
||||
};
|
||||
|
||||
OpenNebulaTemplate.create({
|
||||
timeout: true,
|
||||
data: template_json,
|
||||
success: function(request, response) {
|
||||
VCenterCommon.importSuccess({
|
||||
context : row_context,
|
||||
message : Locale.tr("Template created successfully. ID: %1$s", response.VMTEMPLATE.ID)
|
||||
});
|
||||
},
|
||||
error: function (request, error_json) {
|
||||
VCenterCommon.importFailure({
|
||||
context : row_context,
|
||||
message : (error_json.error.message || Locale.tr("Cannot contact server: is it running and reachable?"))
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
var rpInput = $(".vcenter_rp_input", row_context);
|
||||
var rpParams = [];
|
||||
$.each($(".available_rps option:selected", rpInput), function(){
|
||||
rpParams.push($(this).val());
|
||||
});
|
||||
opts[ref].resourcepool = rpParams;
|
||||
|
||||
if ($(".linked_clone", row_context).is(":checked")){
|
||||
opts[ref].linked_clone = 1;
|
||||
} else {
|
||||
opts[ref].linked_clone = 0;
|
||||
}
|
||||
|
||||
if ($(".create_copy", row_context).is(":checked")){
|
||||
opts[ref].copy = 1;
|
||||
} else {
|
||||
opts[ref].copy = 0;
|
||||
}
|
||||
|
||||
opts[ref].name = $(".template_name", row_context).val();
|
||||
|
||||
opts[ref].folder = $(".folder", row_context).val();
|
||||
});
|
||||
|
||||
vcenter_refs = vcenter_refs.join(",");
|
||||
|
||||
if (vcenter_refs.length === 0){
|
||||
Notifier.notifyMessage("You must select at least one template");
|
||||
return false;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: path,
|
||||
type: "POST",
|
||||
data: {
|
||||
timeout: false,
|
||||
templates: vcenter_refs,
|
||||
opts: opts
|
||||
},
|
||||
dataType: "json",
|
||||
success: function(response){
|
||||
VCenterCommon.jGrowlSuccess({success : response.success, resource : resource, link_tab : "templates-tab"});
|
||||
VCenterCommon.jGrowlFailure({error : response.error, resource : resource});
|
||||
|
||||
$("#get-vcenter-templates").click();
|
||||
},
|
||||
error: function(request, error_json){
|
||||
Notifier.notifyError(request.responseJSON.error.message);
|
||||
$("#get-vcenter-templates").click();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -59,25 +59,35 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="row vcenter_rp_input">
|
||||
<div class="large-11 large-centered columns" style="margin-top: 20px">
|
||||
<div class="large-12 large-centered columns" style="margin-top: 20px;margin-left: 11px">
|
||||
<div class="medium-4 columns" id="folder_{{id}}">
|
||||
<label>
|
||||
{{tr "Folder"}}
|
||||
<input type="text" class="folder" id="folder_{{id}}"/>
|
||||
</label>
|
||||
</div>
|
||||
<div class="medium-4 columns left" id="name_{{id}}" hidden>
|
||||
<label>
|
||||
{{tr "Template name"}}
|
||||
<input type="text" class="template_name" id="template_name_{{id}}"/>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row vcenter_rp_input">
|
||||
<div class="large-12 large-centered columns" style="margin-top: 20px;margin-left: 11px">
|
||||
<div class="medium-2 columns">
|
||||
<label>
|
||||
{{tr "Linked clone"}}
|
||||
<input type="checkbox" class="linked_clone" id="linked_clone_{{id}}"/>
|
||||
</label>
|
||||
</div>
|
||||
<div class="medium-2 columns" id="create_{{id}}" hidden>
|
||||
<div class="medium-2 columns left div_create" id="create_{{id}}" hidden>
|
||||
<label>
|
||||
{{tr "Create copy"}}
|
||||
<input type="checkbox" class="create_copy" id="create_copy_{{id}}"/>
|
||||
</label>
|
||||
</div>
|
||||
<div class="medium-5 columns left" id="name_{{id}}" hidden>
|
||||
<label>
|
||||
{{tr "Template name"}}
|
||||
<input class="template_name" id="template_name_{{id}}"/>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
@@ -85,14 +95,8 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row vcenter_import_result_row" style="display:none">
|
||||
<div class="large-11 large-centered columns">
|
||||
<span class="vcenter_import_result">
|
||||
</span>
|
||||
<span class="vcenter_import_response">
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<span class="vcenter_import_result"></span>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
define(function(require) {
|
||||
var sprintf = require("sprintf").sprintf
|
||||
var Notifier = require("utils/notifier");
|
||||
var Navigation = require('utils/navigation');
|
||||
|
||||
function _html() {
|
||||
return '<div class="vcenter_import"></div>';
|
||||
@@ -127,11 +129,29 @@ define(function(require) {
|
||||
opts.message);
|
||||
}
|
||||
|
||||
function _jGrowlSuccess(opts){
|
||||
var success = opts.success;
|
||||
$.each(success, function(key, value){
|
||||
var rs1 = Navigation.link(value.id[0], opts.link_tab, value.id[0]);
|
||||
var rs2 = Navigation.link(value.id[1], opts.link_tab, value.id[1]);
|
||||
Notifier.notifyMessage(opts.resource + " " + value.name + " imported as " + rs1 + " " + rs2 + " successfully");
|
||||
});
|
||||
}
|
||||
|
||||
function _jGrowlFailure(opts){
|
||||
var error = opts.error;
|
||||
$.each(error, function(key, value){
|
||||
Notifier.notifyError(opts.resource + " with ref " + value + " could not be imported");
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
'html': _html,
|
||||
'setupTable': _setupTable,
|
||||
'importLoading': _importLoading,
|
||||
'importSuccess': _importSuccess,
|
||||
'importFailure': _importFailure
|
||||
'importFailure': _importFailure,
|
||||
'jGrowlSuccess': _jGrowlSuccess,
|
||||
'jGrowlFailure': _jGrowlFailure
|
||||
};
|
||||
});
|
||||
@@ -137,27 +137,21 @@ end
|
||||
|
||||
get '/vcenter/templates' do
|
||||
begin
|
||||
dc_folder = VCenterDriver::DatacenterFolder.new(vcenter_client)
|
||||
new_vcenter_importer("templates")
|
||||
|
||||
tpool = VCenterDriver::VIHelper.one_pool(OpenNebula::TemplatePool, false)
|
||||
[200, $importer.get_list.to_json]
|
||||
rescue Exception => e
|
||||
logger.error("[vCenter] " + e.message)
|
||||
error = Error.new(e.message)
|
||||
error 403, error.to_json
|
||||
end
|
||||
end
|
||||
|
||||
if tpool.respond_to?(:message)
|
||||
msg = "Could not get OpenNebula TemplatePool: #{tpool.message}"
|
||||
logger.error("[vCenter] " + msg)
|
||||
error = Error.new(msg)
|
||||
error 404, error.to_json
|
||||
end
|
||||
post '/vcenter/templates' do
|
||||
begin
|
||||
$importer.process_import(params["templates"], params["opts"])
|
||||
|
||||
templates = dc_folder.get_unimported_templates(vcenter_client, tpool)
|
||||
|
||||
if templates.nil?
|
||||
msg = "No datacenter found"
|
||||
logger.error("[vCenter] " + msg)
|
||||
error = Error.new(msg)
|
||||
error 404, error.to_json
|
||||
end
|
||||
|
||||
[200, templates.to_json]
|
||||
[200, $importer.output.to_json]
|
||||
rescue Exception => e
|
||||
logger.error("[vCenter] " + e.message)
|
||||
error = Error.new(e.message)
|
||||
|
||||
Reference in new issue
Block a user