1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

F #2826: Add LXD radio button

Three attribute for LXD

    - LXD_SECURITY_NESTING
    - LXD_SECURITY_PRIVILEGED
    - LXD_PROFILE
This commit is contained in:
Tino Vazquez 2019-02-08 12:10:20 +01:00
parent 7c0a1ffadb
commit d6c94b534c
No known key found for this signature in database
GPG Key ID: 2FE9C32E94AEABBE
4 changed files with 159 additions and 5 deletions

View File

@ -26,6 +26,7 @@ define(function(require) {
var pcisCallbacks = [];
var customizationsCallbacks = [];
var kvmInfoCallbacks = [];
var lxdProfilesInfoCallbacks = [];
var CACHE_EXPIRE = 300000; //ms
@ -183,6 +184,25 @@ define(function(require) {
_infrastructure();
},
"lxdProfilesInfo": 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()) {
return callback ?
callback(request, infrastructureCache["lxd_profiles"]) : null;
}
lxdProfilesInfoCallbacks.push({
success : callback,
error : callbackError
});
_infrastructure();
},
"kvmInfo": function(params){
var callback = params.success;
var callbackError = params.error;
@ -240,6 +260,16 @@ define(function(require) {
customizations = [customizations];
}
var lxd_profiles = response.lxd_profiles;
if (lxd_profiles == undefined){
lxd_profiles = [];
}
if (!$.isArray(lxd_profiles)){ // If only 1 convert to array
lxd_profiles = [lxd_profiles];
}
var kvm_info = response.kvm_info;
if (kvm_info == undefined){
@ -254,7 +284,8 @@ define(function(require) {
timestamp : new Date().getTime(),
pcis : pcis,
customizations : customizations,
kvm_info : kvm_info
kvm_info : kvm_info,
lxd_profiles : lxd_profiles
};
infrastructureWaiting = false;
@ -291,6 +322,17 @@ define(function(require) {
kvmInfoCallbacks = [];
for (var i = 0; i < lxdProfilesInfoCallbacks.length; i++) {
var callback = lxdProfilesInfoCallbacks[i].success;
if (callback) {
callback(request, lxd_profiles);
}
}
lxdProfilesInfoCallbacks = [];
return;
},
error: function(response) {

View File

@ -29,6 +29,7 @@ define(function(require) {
var OpenNebula = require('opennebula');
var UsersTable = require("tabs/users-tab/datatable");
var GroupTable = require("tabs/groups-tab/datatable");
var OpenNebulaHost = require("opennebula/host");
/*
TEMPLATES
@ -198,6 +199,7 @@ define(function(require) {
$("#vcenter_ccr_ref", context).attr("required", "");
$("#MEMORY", context).attr("pattern", "^([048]|\\d*[13579][26]|\\d*[24680][048])$");
$('.only_kvm').hide();
$('.only_lxd').hide();
$('.only_vcenter').show();
} else {
$("#vcenter_template_ref", context).removeAttr("required");
@ -206,8 +208,20 @@ define(function(require) {
$("#MEMORY", context).removeAttr("pattern");
$('.only_kvm').show();
$('.only_vcenter').hide();
if (this.value != "lxd")
{
$('.only_lxd').hide();
}
}
// There is another listener in context.js setup
// Needs proper LXD view, this is just a workaround
// All KVM settings are available in LXD plus
// Privileged, Profile and Security Nesting
if (this.value == "lxd"){
$('.only_lxd').show();
}
});
CapacityCreate.setup($("div.capacityCreate", context));
@ -229,6 +243,33 @@ define(function(require) {
$('.only_kvm').hide();
$('.only_vcenter').show();
}
fillLXDProfiles(context)
}
function fillLXDProfiles(context){
OpenNebulaHost.lxdProfilesInfo({
data : {},
timeout: true,
success: function (request, lxdProfilesInfo){
if ($("#lxd_profile", context).html() === undefined){
lxdprofiles = lxdProfilesInfo;
var html = "<select id=\"lxd_profile\">";
html += "<option value=\"\">" + " " + "</option>";
$.each(lxdprofiles, function(i, lxdprofile){
html += "<option value='" + lxdprofile + "'>" + lxdprofile + "</option>";
});
html += "</select>";
$("#lxd_profile_label", context).append(html);
}
},
error: function(request, error_json){
console.error("There was an error requesting lxd info: " +
error_json.error.message);
}
});
}
function _retrieve(context) {
@ -243,6 +284,12 @@ define(function(require) {
}
}
if (templateJSON["HYPERVISOR"] == 'lxd') {
templateJSON["LXD_SECURITY_PRIVILEGED"] = WizardFields.retrieveInput($("#lxd_security_privileged", context));
templateJSON["LXD_PROFILE"] = WizardFields.retrieveInput($("#lxd_profile", context));
templateJSON["LXD_SECURITY_NESTING"] = WizardFields.retrieveInput($("#lxd_security_nesting", context));
}
var sunstone_template = {};
if ($('#sunstone_network_select:checked', context).length > 0) {
@ -351,6 +398,11 @@ define(function(require) {
}
}
// LXD specific attributes
if (templateJSON["HYPERVISOR"] == 'lxd') {
fillLXD(context, templateJSON)
}
if (templateJSON["HYPERVISOR"]) {
$("input[name='hypervisor'][value='"+templateJSON["HYPERVISOR"]+"']", context).trigger("click")
delete templateJSON["HYPERVISOR"];
@ -412,4 +464,22 @@ define(function(require) {
WizardFields.fill(context, templateJSON);
}
function fillLXD(context, templateJSON) {
if (templateJSON["LXD_SECURITY_PRIVILEGED"]){
WizardFields.fillInput($("#lxd_security_privileged", context), templateJSON["LXD_SECURITY_PRIVILEGED"]);
delete templateJSON["LXD_SECURITY_PRIVILEGED"];
}
if (templateJSON["LXD_PROFILE"]){
WizardFields.fillInput($("#lxd_profile", context), templateJSON["LXD_PROFILE"]);
delete templateJSON["LXD_PROFILE"];
}
if (templateJSON["LXD_SECURITY_NESTING"]){
WizardFields.fillInput($("#lxd_security_nesting", context), templateJSON["LXD_SECURITY_NESTING"]);
delete templateJSON["LXD_SECURITY_NESTING"];
}
}
});

View File

@ -26,6 +26,8 @@
<label for="kvmRadio">{{tr "KVM"}}</label>
<input type="radio" wizard_field="HYPERVISOR" name="hypervisor" value="vcenter" id="vcenterRadio">
<label for="vcenterRadio">{{tr "vCenter"}}</label>
<input type="radio" wizard_field="HYPERVISOR" name="hypervisor" value="lxd" id="lxdRadio">
<label for="lxdRadio">{{tr "LXD"}}</label>
</div>
</div>
<div class="row">
@ -109,6 +111,38 @@
</div>
</div>
</fieldset>
<fieldset class="hypervisor only_lxd" style="display: none;">
<legend>{{tr "LXD"}}</legend>
<div class="row hypervisor only_lxd" style="display: none;">
<div class="medium-6 columns">
<label for="lxd_security_privileged">
{{tr "Security Privileged"}}
</label>
<select id="lxd_security_privileged">
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
</div>
</div>
<div class="row hypervisor only_lxd" style="display: none;">
<div class="medium-6 columns">
<label for="lxd_security_nesting">
{{tr "Security Nesting"}}
</label>
<select id="lxd_security_nesting">
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
</div>
</div>
<div class="row hypervisor only_lxd" style="display: none;">
<div class="medium-6 columns">
<label id="lxd_profile_label">
{{tr "Profile"}}
</label>
</div>
</div>
</fieldset>
<div class="row">
<div class="capacityCreate large-12 columns">{{{capacityCreateHTML}}}</div>
</div>

View File

@ -44,10 +44,10 @@ LOGOS_CONFIGURATION_FILE = ETC_LOCATION + "/sunstone-logos.yaml"
SUNSTONE_ROOT_DIR = File.dirname(__FILE__)
$: << RUBY_LIB_LOCATION
$: << RUBY_LIB_LOCATION+'/cloud'
$: << SUNSTONE_ROOT_DIR
$: << SUNSTONE_ROOT_DIR+'/models'
$LOAD_PATH << RUBY_LIB_LOCATION
$LOAD_PATH << RUBY_LIB_LOCATION + '/cloud'
$LOAD_PATH << SUNSTONE_ROOT_DIR
$LOAD_PATH << SUNSTONE_ROOT_DIR + '/models'
DISPLAY_NAME_XPATH = 'TEMPLATE/SUNSTONE/DISPLAY_NAME'
TABLE_ORDER_XPATH = 'TEMPLATE/SUNSTONE/TABLE_ORDER'
@ -663,6 +663,14 @@ get '/infrastructure' do
infrastructure[:kvm_info] = { :set_cpu_models => set_cpu_models.to_a, :set_kvm_machines => set_kvm_machines.to_a }
set_lxd_profiles = Set.new
xml.each('HOST/TEMPLATE/LXD_PROFILES') do |lxd_profiles|
set_lxd_profiles += lxd_profiles.text.split(" ")
end
infrastructure[:lxd_profiles] = set_lxd_profiles.to_a
[200, infrastructure.to_json]
end