mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-29 18:50:08 +03:00
Feature #4012: Add list of vcenter customization specs to sunstone
This commit is contained in:
parent
cafdbade92
commit
2f12f61965
@ -21,14 +21,15 @@ define(function(require) {
|
||||
var OpenNebulaHelper = require('./helper');
|
||||
|
||||
|
||||
var pcisCache;
|
||||
var pcisWaiting = false;
|
||||
var infrastructureCache;
|
||||
var infrastructureWaiting = false;
|
||||
var pcisCallbacks = [];
|
||||
var customizationsCallbacks = [];
|
||||
|
||||
var CACHE_EXPIRE = 300000; //ms
|
||||
|
||||
var _clearCache = function() {
|
||||
pcisCache = null;
|
||||
infrastructureCache = null;
|
||||
//console.log("Host.pciDevices. Cache cleaned");
|
||||
};
|
||||
|
||||
@ -124,13 +125,13 @@ define(function(require) {
|
||||
var callbackError = params.error;
|
||||
var request = OpenNebulaHelper.request(RESOURCE, "infrastructure");
|
||||
|
||||
if (pcisCache &&
|
||||
pcisCache["timestamp"] + CACHE_EXPIRE > new Date().getTime()) {
|
||||
if (infrastructureCache &&
|
||||
infrastructureCache["timestamp"] + CACHE_EXPIRE > new Date().getTime()) {
|
||||
|
||||
//console.log("Host.pciDevices. Cache used");
|
||||
|
||||
return callback ?
|
||||
callback(request, pcisCache["data"]) : null;
|
||||
callback(request, infrastructureCache["pcis"]) : null;
|
||||
}
|
||||
|
||||
pcisCallbacks.push({
|
||||
@ -140,67 +141,129 @@ define(function(require) {
|
||||
|
||||
//console.log("Host.pciDevices. Callback queued");
|
||||
|
||||
if (pcisWaiting) {
|
||||
return;
|
||||
_infrastructure();
|
||||
},
|
||||
"vcenterCustomizations": function(params){
|
||||
var callback = params.success;
|
||||
var callbackError = params.error;
|
||||
var request = OpenNebulaHelper.request(RESOURCE, "infrastructure");
|
||||
|
||||
if (infrastructureCache &&
|
||||
infrastructureCache["timestamp"] + CACHE_EXPIRE > new Date().getTime()) {
|
||||
|
||||
//console.log("Host.vcenterCustomizations. Cache used");
|
||||
|
||||
return callback ?
|
||||
callback(request, infrastructureCache["customizations"]) : null;
|
||||
}
|
||||
|
||||
pcisWaiting = true;
|
||||
|
||||
//console.log("Host.pciDevices. NO cache, calling ajax");
|
||||
|
||||
$.ajax({
|
||||
url: "infrastructure",
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
success: function(response) {
|
||||
var pcis = response.pci_devices;
|
||||
|
||||
if (pcis == undefined){
|
||||
pcis = [];
|
||||
}
|
||||
|
||||
if (!$.isArray(pcis)){ // If only 1 convert to array
|
||||
pcis = [pcis];
|
||||
}
|
||||
|
||||
pcisCache = {
|
||||
timestamp : new Date().getTime(),
|
||||
data : pcis
|
||||
};
|
||||
|
||||
pcisWaiting = false;
|
||||
|
||||
for (var i = 0; i < pcisCallbacks.length; i++) {
|
||||
var callback = pcisCallbacks[i].success;
|
||||
|
||||
if (callback) {
|
||||
//console.log("Host.pciDevices. Callback called");
|
||||
callback(request, pcis);
|
||||
}
|
||||
}
|
||||
|
||||
pcisCallbacks = [];
|
||||
|
||||
return;
|
||||
},
|
||||
error: function(response) {
|
||||
pcisWaiting = false;
|
||||
|
||||
for (var i = 0; i < pcisCallbacks.length; i++) {
|
||||
var callback = pcisCallbacks[i].error;
|
||||
|
||||
if (callback) {
|
||||
//console.log("Host.pciDevices. ERROR Callback called");
|
||||
callback(request, OpenNebulaError(response));
|
||||
}
|
||||
}
|
||||
|
||||
pcisCallbacks = [];
|
||||
|
||||
return;
|
||||
}
|
||||
customizationsCallbacks.push({
|
||||
success : callback,
|
||||
error : callbackError
|
||||
});
|
||||
|
||||
//console.log("Host.vcenterCustomizations. Callback queued");
|
||||
|
||||
_infrastructure();
|
||||
}
|
||||
};
|
||||
|
||||
function _infrastructure(){
|
||||
if (infrastructureWaiting) {
|
||||
return;
|
||||
}
|
||||
|
||||
var request = OpenNebulaHelper.request(RESOURCE, "infrastructure");
|
||||
|
||||
infrastructureWaiting = true;
|
||||
|
||||
//console.log("Host.infrastructure. NO cache, calling ajax");
|
||||
|
||||
$.ajax({
|
||||
url: "infrastructure",
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
success: function(response) {
|
||||
var pcis = response.pci_devices;
|
||||
|
||||
if (pcis == undefined){
|
||||
pcis = [];
|
||||
}
|
||||
|
||||
if (!$.isArray(pcis)){ // If only 1 convert to array
|
||||
pcis = [pcis];
|
||||
}
|
||||
|
||||
var customizations = response.vcenter_customizations;
|
||||
|
||||
if (customizations == undefined){
|
||||
customizations = [];
|
||||
}
|
||||
|
||||
if (!$.isArray(customizations)){ // If only 1 convert to array
|
||||
customizations = [customizations];
|
||||
}
|
||||
|
||||
infrastructureCache = {
|
||||
timestamp : new Date().getTime(),
|
||||
pcis : pcis,
|
||||
customizations : customizations
|
||||
};
|
||||
|
||||
infrastructureWaiting = false;
|
||||
|
||||
for (var i = 0; i < pcisCallbacks.length; i++) {
|
||||
var callback = pcisCallbacks[i].success;
|
||||
|
||||
if (callback) {
|
||||
//console.log("Host.pciDevices. Callback called");
|
||||
callback(request, pcis);
|
||||
}
|
||||
}
|
||||
|
||||
pcisCallbacks = [];
|
||||
|
||||
for (var i = 0; i < customizationsCallbacks.length; i++) {
|
||||
var callback = customizationsCallbacks[i].success;
|
||||
|
||||
if (callback) {
|
||||
//console.log("Host.vcenterCustomizations. Callback called");
|
||||
callback(request, customizations);
|
||||
}
|
||||
}
|
||||
|
||||
customizationsCallbacks = [];
|
||||
|
||||
return;
|
||||
},
|
||||
error: function(response) {
|
||||
infrastructureWaiting = false;
|
||||
|
||||
for (var i = 0; i < pcisCallbacks.length; i++) {
|
||||
var callback = pcisCallbacks[i].error;
|
||||
|
||||
if (callback) {
|
||||
//console.log("Host.pciDevices. ERROR Callback called");
|
||||
callback(request, OpenNebulaError(response));
|
||||
}
|
||||
}
|
||||
|
||||
pcisCallbacks = [];
|
||||
|
||||
for (var i = 0; i < customizationsCallbacks.length; i++) {
|
||||
var callback = customizationsCallbacks[i].error;
|
||||
|
||||
if (callback) {
|
||||
//console.log("Host.vcenterCustomizations. ERROR Callback called");
|
||||
callback(request, OpenNebulaError(response));
|
||||
}
|
||||
}
|
||||
|
||||
customizationsCallbacks = [];
|
||||
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return Host;
|
||||
|
@ -139,6 +139,20 @@ define(function(require) {
|
||||
$.extend(true, templateJSON, wizardTab.retrieve($('#' + wizardTab.wizardTabId, context)));
|
||||
});
|
||||
|
||||
// vCenter PUBLIC_CLOUD is not defined in the hybrid tab. Because it is
|
||||
// part of an array, and it is filled in different tabs, the $.extend deep
|
||||
// merge can't work. We define an auxiliary attribute for it.
|
||||
|
||||
if (templateJSON["VCENTER_PUBLIC_CLOUD"]) {
|
||||
if (templateJSON['PUBLIC_CLOUD'] == undefined) {
|
||||
templateJSON['PUBLIC_CLOUD'] = [];
|
||||
}
|
||||
|
||||
templateJSON['PUBLIC_CLOUD'].push(templateJSON["VCENTER_PUBLIC_CLOUD"]);
|
||||
|
||||
delete templateJSON["VCENTER_PUBLIC_CLOUD"];
|
||||
}
|
||||
|
||||
if (this.action == "create") {
|
||||
Sunstone.runAction("Template.create",
|
||||
{'vmtemplate': templateJSON});
|
||||
|
@ -26,6 +26,7 @@ define(function(require) {
|
||||
var TemplateUtils = require('utils/template-utils');
|
||||
var CustomTagsTable = require('utils/custom-tags-table');
|
||||
var FilesTable = require('tabs/files-tab/datatable')
|
||||
var OpenNebulaHost = require('opennebula/host');
|
||||
|
||||
/*
|
||||
TEMPLATES
|
||||
@ -88,6 +89,47 @@ define(function(require) {
|
||||
function _setup(context) {
|
||||
var that = this;
|
||||
|
||||
context.on("change", "select#vcenter_customizations", function(){
|
||||
var option = $("option:selected", this);
|
||||
|
||||
if (option.attr("custom") == "true"){
|
||||
$('input#vcenter_customizations_value', context).show();
|
||||
} else {
|
||||
$('input#vcenter_customizations_value', context).hide();
|
||||
}
|
||||
|
||||
$('input#vcenter_customizations_value', context).val( $(this).val() );
|
||||
});
|
||||
|
||||
$('input#vcenter_customizations_value', context).hide();
|
||||
|
||||
OpenNebulaHost.vcenterCustomizations({
|
||||
data : {},
|
||||
timeout: true,
|
||||
success: function (request, customizations){
|
||||
_fillCustomizations(context, customizations);
|
||||
},
|
||||
error: function(request, error_json){
|
||||
console.error("There was an error requesting the vCenter customizations: "+
|
||||
error_json.error.message);
|
||||
|
||||
_fillCustomizations(context, []);
|
||||
}
|
||||
});
|
||||
|
||||
context.on("change", "input#vcenter_customizations_value", function(){
|
||||
var opt =
|
||||
$('option'+
|
||||
'[value="'+$('input#vcenter_customizations_value', context).val()+'"]', context);
|
||||
|
||||
if (opt.size() == 0){
|
||||
opt = $('option[custom="true"]', context);
|
||||
$('input#vcenter_customizations_value', context).show();
|
||||
}
|
||||
|
||||
opt.attr('selected', 'selected');
|
||||
});
|
||||
|
||||
CustomTagsTable.setup(context);
|
||||
|
||||
var selectOptions = {
|
||||
@ -132,11 +174,35 @@ define(function(require) {
|
||||
});
|
||||
}
|
||||
|
||||
function _fillCustomizations(context, customizations) {
|
||||
var html = "<select>";
|
||||
|
||||
html += '<option value="">'+Locale.tr("Please select")+'</option>';
|
||||
|
||||
$.each(customizations, function(i,customization){
|
||||
html += '<option value="'+customization+'">'+customization+'</option>';
|
||||
});
|
||||
|
||||
html += '<option value="" custom="true">'+Locale.tr("Set manually")+'</option>';
|
||||
|
||||
html += '</select>';
|
||||
|
||||
$("#vcenter_customizations", context).html(html);
|
||||
}
|
||||
|
||||
function _retrieve(context) {
|
||||
var templateJSON = {};
|
||||
var contextJSON = WizardFields.retrieve(context);
|
||||
$.extend(contextJSON, CustomTagsTable.retrieve(context));
|
||||
|
||||
var customization = $('input#vcenter_customizations_value', context).val();
|
||||
|
||||
if (customization) {
|
||||
templateJSON["VCENTER_PUBLIC_CLOUD"] = {
|
||||
CUSTOMIZATION_SPEC : customization
|
||||
};
|
||||
}
|
||||
|
||||
if ($("#ssh_context", context).is(":checked")) {
|
||||
var public_key = $("#ssh_public_key", context).val();
|
||||
if (public_key) {
|
||||
@ -205,6 +271,21 @@ define(function(require) {
|
||||
delete templateJSON['USER_INPUTS'];
|
||||
}
|
||||
|
||||
var publicClouds = templateJSON["PUBLIC_CLOUD"];
|
||||
|
||||
if (publicClouds != undefined) {
|
||||
if (!$.isArray(publicClouds)){
|
||||
publicClouds = [publicClouds];
|
||||
}
|
||||
|
||||
$.each(publicClouds, function(){
|
||||
if(this["TYPE"] == "vcenter"){
|
||||
$('input#vcenter_customizations_value', context).val(this["CUSTOMIZATION_SPEC"]).change();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (contextJSON) {
|
||||
var file_ds_regexp = /\$FILE\[IMAGE_ID=([0-9]+)+/g;
|
||||
var net_regexp = /^NETWORK$/;;
|
||||
|
@ -27,6 +27,16 @@
|
||||
</dl>
|
||||
<div class="tabs-content vertical">
|
||||
<div class="wizard_internal_tab active content" id="netsshTab">
|
||||
<div class="row hypervisor only_vcenter" style="display: none;">
|
||||
<div class="columns medium-6">
|
||||
<label for="vcenter_customizations">{{tr "vCenter customizations"}}:</label>
|
||||
<select id="vcenter_customizations"/>
|
||||
</div>
|
||||
<div class="columns medium-6">
|
||||
<label> </label>
|
||||
<input id="vcenter_customizations_value" type="text">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="columns medium-6">
|
||||
<div class="row">
|
||||
|
@ -118,10 +118,10 @@ define(function(require) {
|
||||
var templateJSON = WizardFields.retrieve(context);
|
||||
|
||||
if (templateJSON["HYPERVISOR"] == 'vcenter') {
|
||||
templateJSON["PUBLIC_CLOUD"] = {
|
||||
templateJSON["VCENTER_PUBLIC_CLOUD"] = {
|
||||
'TYPE': 'vcenter',
|
||||
'VM_TEMPLATE': $("#vcenter_template_uuid", context).val()
|
||||
}
|
||||
};
|
||||
|
||||
templateJSON["KEEP_DISKS_ON_DONE"] = $("#KEEP_DISKS", context).is(':checked')?"YES":"NO"
|
||||
}
|
||||
@ -157,6 +157,23 @@ define(function(require) {
|
||||
delete templateJSON["KEEP_DISKS_ON_DONE"]
|
||||
}
|
||||
|
||||
if (templateJSON["HYPERVISOR"] == 'vcenter') {
|
||||
var publicClouds = templateJSON["PUBLIC_CLOUD"];
|
||||
|
||||
if (publicClouds != undefined) {
|
||||
if (!$.isArray(publicClouds)){
|
||||
publicClouds = [publicClouds];
|
||||
}
|
||||
|
||||
$.each(publicClouds, function(){
|
||||
if(this["TYPE"] == "vcenter"){
|
||||
$("#vcenter_template_uuid", context).val(this["VM_TEMPLATE"]);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (templateJSON["HYPERVISOR"]) {
|
||||
$("input[name='hypervisor'][value='"+templateJSON["HYPERVISOR"]+"']", context).trigger("click")
|
||||
delete templateJSON["HYPERVISOR"];
|
||||
|
@ -397,18 +397,6 @@ define(function(require) {
|
||||
var publicCloudJSON = [];
|
||||
var ec2JSON = [];
|
||||
|
||||
/* TODO Check if vCenter is defined
|
||||
if ($.isEmptyObject(vm_json["PUBLIC_CLOUD"])) {
|
||||
vm_json["PUBLIC_CLOUD"] = [];
|
||||
}*/
|
||||
|
||||
if ($("[wizard_field='HYPERVISOR']:checked").val() == 'vcenter') {
|
||||
publicCloudJSON.push({
|
||||
'TYPE': 'vcenter',
|
||||
'VM_TEMPLATE': $("#vcenter_template_uuid").val()
|
||||
});
|
||||
}
|
||||
|
||||
$('.provider', context).each(function() {
|
||||
var hash = WizardFields.retrieve(this);
|
||||
if (!$.isEmptyObject(hash)) {
|
||||
@ -536,15 +524,15 @@ define(function(require) {
|
||||
function _fillProviderTab(context, provider, providerType, clickButton) {
|
||||
var that = this;
|
||||
if (providerType == "vcenter") {
|
||||
$("#vcenter_template_uuid").val(provider["VM_TEMPLATE"])
|
||||
} else {
|
||||
if (clickButton) {
|
||||
$("#tf_btn_hybrid", context).trigger("click");
|
||||
}
|
||||
|
||||
var providerContext = $(".provider", context).last();
|
||||
$("input.hybridRadio[value='" + providerType + "']", providerContext).trigger("click");
|
||||
WizardFields.fill(providerContext, provider);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (clickButton) {
|
||||
$("#tf_btn_hybrid", context).trigger("click");
|
||||
}
|
||||
|
||||
var providerContext = $(".provider", context).last();
|
||||
$("input.hybridRadio[value='" + providerType + "']", providerContext).trigger("click");
|
||||
WizardFields.fill(providerContext, provider);
|
||||
}
|
||||
});
|
||||
|
@ -470,6 +470,8 @@ get '/infrastructure' do
|
||||
error 500, ""
|
||||
end
|
||||
|
||||
infrastructure = {}
|
||||
|
||||
set = Set.new
|
||||
|
||||
xml = XMLElement.new
|
||||
@ -483,9 +485,15 @@ get '/infrastructure' do
|
||||
})
|
||||
end
|
||||
|
||||
infrastructure = {
|
||||
:pci_devices => set.to_a
|
||||
}
|
||||
infrastructure[:pci_devices] = set.to_a
|
||||
|
||||
set = Set.new
|
||||
|
||||
xml.each('HOST/TEMPLATE/CUSTOMIZATION') do |customization|
|
||||
set.add(customization['NAME'])
|
||||
end
|
||||
|
||||
infrastructure[:vcenter_customizations] = set.to_a
|
||||
|
||||
[200, infrastructure.to_json]
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user