1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-16 22:50:10 +03:00

F OpenNebula/one#3667: Make LXD imported App Template more customizable (#1621)

* Make VM Template configurable (source code)
* Improve parameters description
* Show error message when fail
* Better labels for market wizard

(cherry picked from commit 637c1b5090afd0775f26dbb2c5bd6ec6e65079fe)
This commit is contained in:
Daniel Clavijo Coca 2021-12-01 03:27:29 -06:00 committed by Ruben S. Montero
parent 6625e09592
commit 587d4b71ad
No known key found for this signature in database
GPG Key ID: A0CEA6FA880A1D87
3 changed files with 60 additions and 23 deletions

View File

@ -22,12 +22,14 @@ module LXDMarket
class << self
# TODO: Make configurable
def template
def template(options = {})
unindent(<<-EOS)
SCHED_REQUIREMENTS = \"HYPERVISOR=\\\"lx*\\\"\"
CPU = \"1\"
MEMORY = \"768\"
LXD_SECURITY_PRIVILEGED = \"true\"
CPU = \"#{options[:cpu]}\"
VCPU = \"#{options[:vcpu]}\"
MEMORY = \"#{options[:memory]}\"
LXD_SECURITY_PRIVILEGED = \"#{options[:privileged]}\"
LXC_UNPRIVILEGED = \"#{!options[:privileged]}\"
GRAPHICS = [
LISTEN =\"0.0.0.0\",
TYPE =\"vnc\"

View File

@ -33,6 +33,15 @@ class LinuxContainersMarket
#---------------------------------------------------------------------------
# Default Configuration parameters for the Driver
# :url of linuxcontainers market place
# :sizemb default size for container images
# :fs filesystem for the image file
# :format for the image file, qcow2, raw
# :agent for HTTP client
# :memory Guest RAM
# :cpu Guest cpu share with host
# :vcpu Guest cores
# :privileged container idmap
#---------------------------------------------------------------------------
DEFAULTS = {
:url => 'https://images.linuxcontainers.org',
@ -41,17 +50,13 @@ class LinuxContainersMarket
:format => 'raw',
:agent => 'OpenNebula',
:tested_apps => %w[alpine alt centos debian ubuntu fedora devuan],
:skip_untested => 'yes'
:skip_untested => 'yes',
:memory => '768',
:cpu => 1,
:vcpu => 2,
:privileged => true
}
#---------------------------------------------------------------------------
# Configuration varibales
# :url of linuxcontainers market place
# :sizemb default size for container images
# :fs filesystem for the image file
# :format for the image file, qcow2, raw
# :agent for HTTP client
#---------------------------------------------------------------------------
def initialize(options = {})
@options = DEFAULTS
@options.merge!(options)
@ -159,7 +164,7 @@ class LinuxContainersMarket
print_var(tmpl64, 'DRIVER', 'raw')
data = { 'APPTEMPLATE64' => tmpl64,
'VMTEMPLATE64' => LXDMarket.template }
'VMTEMPLATE64' => LXDMarket.template(@options) }
data.each do |key, val|
print_var(tmpl, key, Base64.strict_encode64(val))
end
@ -253,13 +258,23 @@ begin
pre = 'MARKETPLACE/TEMPLATE'
data = { :url => "#{pre}/ENDPOINT", :sizemb => "#{pre}/IMAGE_SIZE_MB",
:fs => "#{pre}/FILESYSTEM", :format => "#{pre}/FORMAT",
:skip_untested => "#{pre}/SKIP_UNTESTED" }
data = {
:url => "#{pre}/ENDPOINT",
:sizemb => "#{pre}/IMAGE_SIZE_MB",
:fs => "#{pre}/FILESYSTEM",
:format => "#{pre}/FORMAT",
:skip_untested => "#{pre}/SKIP_UNTESTED",
:memory => "#{pre}/MEMORY",
:cpu => "#{pre}/CPU",
:vcpu => "#{pre}/VCPU",
:privileged => "#{pre}/PRIVILEGED"
}
data.each {|key, value| set_option(options, doc, key, value) }
puts LinuxContainersMarket.new(options).fetch_appliances
str = LinuxContainersMarket.new(options).fetch_appliances
puts str
rescue StandardError
nil
STDERR.puts str
exit(-1)
end

View File

@ -140,6 +140,26 @@ define(function(require) {
label: Locale.tr("Show only auto-contextualized apps"),
driver: 'linuxcontainers'
},
{
name: 'MEMORY',
label: Locale.tr("Memory"),
driver: 'linuxcontainers'
},
{
name: 'CPU',
label: Locale.tr("CPU"),
driver: 'linuxcontainers'
},
{
name: 'VCPU',
label: Locale.tr("VCPU"),
driver: 'linuxcontainers'
},
{
name: 'PRIVILEGED',
label: Locale.tr("Container security mode"),
driver: 'linuxcontainers'
},
{
name: 'BASE_URL',
id: 'DOCKER_REGISTRY_BASE_URL',
@ -261,18 +281,18 @@ define(function(require) {
var marketObj = {};
$.extend(marketObj, WizardFields.retrieve(dialog));
var checkboxAttr = MARKET_MAD_ATTRS.filter(function(e) {
return e.checkbox;
}).map(function(e){
return e.name;
});
$.each(marketObj, function(key, value){
if (checkboxAttr.includes(key)) marketObj[key] = (value === "on") ? "true" : "false";
});
if (this.action == "create") {
marketObj = {
"marketplace" : marketObj