diff --git a/src/sunstone/public/app/opennebula/host.js b/src/sunstone/public/app/opennebula/host.js index a455a30fad..93582c4ba0 100644 --- a/src/sunstone/public/app/opennebula/host.js +++ b/src/sunstone/public/app/opennebula/host.js @@ -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) { diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general.js index e58c21032a..765c6b70b5 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general.js @@ -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 = ""; + $("#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"]; + } + } + }); diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/html.hbs b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/html.hbs index 623acece5e..0ad1ab87ea 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/html.hbs +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/html.hbs @@ -26,6 +26,8 @@ + +
@@ -109,6 +111,38 @@
+
{{{capacityCreateHTML}}}
diff --git a/src/sunstone/sunstone-server.rb b/src/sunstone/sunstone-server.rb index bbc07edbcc..b0504226e3 100755 --- a/src/sunstone/sunstone-server.rb +++ b/src/sunstone/sunstone-server.rb @@ -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