diff --git a/install.sh b/install.sh index f3604b6402..2e5ad24983 100755 --- a/install.sh +++ b/install.sh @@ -421,6 +421,7 @@ VAR_DIRS="$VAR_LOCATION/remotes \ $VAR_LOCATION/remotes/market/http \ $VAR_LOCATION/remotes/market/one \ $VAR_LOCATION/remotes/market/s3 \ + $VAR_LOCATION/remotes/market/common \ $VAR_LOCATION/remotes/market/linuxcontainers \ $VAR_LOCATION/remotes/market/turnkeylinux \ $VAR_LOCATION/remotes/market/dockerhub \ @@ -626,6 +627,7 @@ INSTALL_FILES=( MARKETPLACE_DRIVER_ETC_HTTP_SCRIPTS:$VAR_LOCATION/remotes/etc/market/http MARKETPLACE_DRIVER_ONE_SCRIPTS:$VAR_LOCATION/remotes/market/one MARKETPLACE_DRIVER_S3_SCRIPTS:$VAR_LOCATION/remotes/market/s3 + MARKETPLACE_DRIVER_COMMON_SCRIPTS:$VAR_LOCATION/remotes/market/common MARKETPLACE_DRIVER_LXC_SCRIPTS:$VAR_LOCATION/remotes/market/linuxcontainers MARKETPLACE_DRIVER_TK_SCRIPTS:$VAR_LOCATION/remotes/market/turnkeylinux MARKETPLACE_DRIVER_DH_SCRIPTS:$VAR_LOCATION/remotes/market/dockerhub @@ -1891,6 +1893,8 @@ MARKETPLACE_DRIVER_S3_SCRIPTS="src/market_mad/remotes/s3/import \ src/market_mad/remotes/s3/monitor \ src/market_mad/remotes/s3/S3.rb" +MARKETPLACE_DRIVER_COMMON_SCRIPTS="src/market_mad/remotes/common/lxd.rb" + MARKETPLACE_DRIVER_LXC_SCRIPTS="src/market_mad/remotes/linuxcontainers/import \ src/market_mad/remotes/linuxcontainers/delete \ src/market_mad/remotes/linuxcontainers/monitor" diff --git a/src/market_mad/remotes/common/lxd.rb b/src/market_mad/remotes/common/lxd.rb new file mode 100644 index 0000000000..da6314a990 --- /dev/null +++ b/src/market_mad/remotes/common/lxd.rb @@ -0,0 +1,52 @@ +#!/usr/bin/ruby + +# -------------------------------------------------------------------------- # +# Copyright 2002-2019, OpenNebula Project, OpenNebula Systems # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +# -------------------------------------------------------------------------- # + +# Utilities for LXD based marketplaces +module LXDMarket + + class << self + + # TODO: Make configurable + def template + unindent(<<-EOS) + HYPERVISOR = \"lxd\" + SCHED_REQUIREMENTS = \"HYPERVISOR=\\\"lxd\\\"\" + CPU = \"1\" + MEMORY = \"768\" + LXD_SECURITY_PRIVILEGED = \"true\" + GRAPHICS = [ + LISTEN =\"0.0.0.0\", + TYPE =\"vnc\" + ] + CONTEXT = [ + NETWORK =\"YES\", + SSH_PUBLIC_KEY =\"$USER[SSH_PUBLIC_KEY]\", + SET_HOSTNAME =\"$NAME\" + ]" + EOS + end + + def unindent(str) + m = str.match(/^(\s*)/) + spaces = m[1].size + str.gsub!(/^ {#{spaces}}/, '') + end + + end + +end diff --git a/src/market_mad/remotes/linuxcontainers/monitor b/src/market_mad/remotes/linuxcontainers/monitor index 1e305c0a5a..4cf73ee7a9 100755 --- a/src/market_mad/remotes/linuxcontainers/monitor +++ b/src/market_mad/remotes/linuxcontainers/monitor @@ -24,6 +24,8 @@ require 'rexml/document' require 'time' require 'digest/md5' +require_relative '../common/lxd' + #------------------------------------------------------------------------------- # #------------------------------------------------------------------------------- @@ -42,22 +44,6 @@ class LinuxContainersMarket :skip_untested => 'yes' } - # TODO: Make configurable - TEMPLATE = " -HYPERVISOR = \"lxd\" -CPU = \"1\" -MEMORY = \"768\" -LXD_SECURITY_PRIVILEGED = \"yes\" -GRAPHICS = [ - LISTEN =\"0.0.0.0\", - TYPE =\"vnc\" -] -CONTEXT = [ - NETWORK =\"YES\", - SSH_PUBLIC_KEY =\"$USER[SSH_PUBLIC_KEY]\", - SET_HOSTNAME =\"$NAME\" -]" - #--------------------------------------------------------------------------- # Configuration varibales # :url of linuxcontainers market place @@ -172,7 +158,8 @@ CONTEXT = [ tmpl64 = '' print_var(tmpl64, 'DRIVER', 'raw') - data = { 'APPTEMPLATE64' => tmpl64, 'VMTEMPLATE64' => TEMPLATE } + data = { 'APPTEMPLATE64' => tmpl64, + 'VMTEMPLATE64' => LXDMarket.template } data.each do |key, val| print_var(tmpl, key, Base64.strict_encode64(val)) end diff --git a/src/market_mad/remotes/turnkeylinux/monitor b/src/market_mad/remotes/turnkeylinux/monitor index ad03525dc8..c35c35b159 100755 --- a/src/market_mad/remotes/turnkeylinux/monitor +++ b/src/market_mad/remotes/turnkeylinux/monitor @@ -41,11 +41,7 @@ require 'rexml/document' require 'nokogiri' require 'digest/md5' -def unindent(str) - m = str.match(/^(\s*)/) - spaces = m[1].size - str.gsub!(/^ {#{spaces}}/, '') -end +require_relative '../common/lxd' #------------------------------------------------------------------------------- # This class is used to query the TurnkeyLinux repository @@ -64,22 +60,6 @@ class TurnkeyLinux :agent => 'OpenNebula' } - TEMPLATE = unindent(<<-EOS) - HYPERVISOR = \"lxd\" - CPU = \"1\" - MEMORY = \"768\" - LXD_SECURITY_PRIVILEGED = \"true\" - GRAPHICS = [ - LISTEN =\"0.0.0.0\", - TYPE =\"vnc\" - ] - CONTEXT = [ - NETWORK =\"YES\", - SSH_PUBLIC_KEY =\"$USER[SSH_PUBLIC_KEY]\", - SET_HOSTNAME =\"$NAME\" - ]" - EOS - #--------------------------------------------------------------------------- # Configuration varibales # :url of linuxcontainers market place @@ -186,7 +166,8 @@ class TurnkeyLinux tmpl64 = '' print_var(tmpl64, 'DRIVER', 'raw') - data = { 'APPTEMPLATE64' => tmpl64, 'VMTEMPLATE64' => TEMPLATE } + data = { 'APPTEMPLATE64' => tmpl64, + 'VMTEMPLATE64' => LXDMarket.template } data.each do |key, val| print_var(tmpl, key, Base64.strict_encode64(val)) end