diff --git a/slapos/recipe/kvm/template/kvm_run.in b/slapos/recipe/kvm/template/kvm_run.in index 81116c5fad6c315abd8ae19c42ae336ded62d4f9..88eb0f0f3452620fbf4f438ee1af63032d8e3011 100644 --- a/slapos/recipe/kvm/template/kvm_run.in +++ b/slapos/recipe/kvm/template/kvm_run.in @@ -24,10 +24,10 @@ default_disk_image = '%(default-disk-image)s' disk_path = '%(disk-path)s' virtual_hard_drive_url = '%(virtual-hard-drive-url)s'.strip() virtual_hard_drive_md5sum = '%(virtual-hard-drive-md5sum)s'.strip() -virtual_hard_drive_gzipped = '%(virtual-hard-drive-gzipped)s'.strip() +virtual_hard_drive_gzipped = '%(virtual-hard-drive-gzipped)s'.strip().lower() nat_rules = '%(nat-rules)s'.strip() -use_tap = '%(use-tap)s' -use_nat = '%(use-nat)s' +use_tap = '%(use-tap)s'.lower() +use_nat = '%(use-nat)s'.lower() tap_interface = '%(tap-interface)s' listen_ip = '%(ipv4)s' mac_address = '%(mac-address)s' @@ -119,7 +119,7 @@ if not os.path.exists(disk_path) and virtual_hard_drive_url != '': print('Downloading virtual hard drive...') try: downloaded_disk = disk_path - if virtual_hard_drive_gzipped == 'True': + if virtual_hard_drive_gzipped == 'true': downloaded_disk = '%%s.gz' %% disk_path urllib.urlretrieve(virtual_hard_drive_url, downloaded_disk) except: @@ -162,7 +162,7 @@ for storage in disk_storage_list: key, val = storage.split(' ') disk_storage_dict[key.strip()] = val.strip() -if not external_disk_format in ['qcow2', 'raw', 'vdi', 'vmdk', 'cloop']: +if not external_disk_format in ['qcow2', 'raw', 'vdi', 'vmdk', 'cloop', 'qed']: external_disk_format = 'qcow2' map_storage_list, external_disk_number = getMapStorageList(disk_storage_dict, @@ -197,7 +197,7 @@ tap_network_parameter = [] nat_network_parameter = [] numa_parameter = [] number = -1 -if use_nat == 'True': +if use_nat == 'true': number += 1 rules = 'user,id=lan%%s,' %% number + ','.join('hostfwd=tcp:%%s:%%s-:%%s' %% (listen_ip, int(port) + 10000, port) for port in nat_rules.split()) @@ -209,7 +209,7 @@ if use_nat == 'True': cluster_doc_host, cluster_doc_port) nat_network_parameter = ['-netdev', rules, '-device', 'e1000,netdev=lan%%s,mac=%%s' %% (number, mac_address)] -if use_tap == 'True': +if use_tap == 'true': number += 1 tap_network_parameter = ['-netdev', 'tap,id=lan%%s,ifname=%%s,script=no,downscript=no' %% (number, diff --git a/software/kvm/common.cfg b/software/kvm/common.cfg index 07d4619769e4d9dcbc69ada2f5e14dbfd727ac93..1426a85a9f9d1c6508c7525293efbd98d8c40249 100644 --- a/software/kvm/common.cfg +++ b/software/kvm/common.cfg @@ -95,7 +95,7 @@ mode = 0644 recipe = hexagonit.recipe.download url = ${:_profile_base_location_}/instance-kvm.cfg.jinja2 mode = 644 -md5sum = fb2dcca424fa0bf4d6ec445965a8bc81 +md5sum = 55eb9cb0d85dedbda0f03986cef261db download-only = true on-update = true @@ -103,7 +103,7 @@ on-update = true recipe = hexagonit.recipe.download url = ${:_profile_base_location_}/instance-kvm-cluster.cfg.jinja2.in mode = 644 -md5sum = 36d9ea062c13f88eadd6f635eed36b7e +md5sum = 1e4d8eade6d291480e5112ef9f31f031 download-only = true on-update = true diff --git a/software/kvm/instance-kvm-cluster-input-schema.json b/software/kvm/instance-kvm-cluster-input-schema.json index 93115bf20d5ae39104afa99d7a3ca520386ecfc6..25e2d8197fb9d15827ec2f86bd1b2eac5f4ed059 100644 --- a/software/kvm/instance-kvm-cluster-input-schema.json +++ b/software/kvm/instance-kvm-cluster-input-schema.json @@ -266,7 +266,7 @@ "description": "Type of QEMU disk drive, to create.", "type": "string", "default": "qcow2", - "enum": ["qcow2", "raw", "vdi", "vmdk", "cloop"] + "enum": ["qcow2", "raw", "vdi", "vmdk", "cloop", "qed"] }, "use-tap": { "title": "Use QEMU TAP network interface", diff --git a/software/kvm/instance-kvm-cluster.cfg.jinja2.in b/software/kvm/instance-kvm-cluster.cfg.jinja2.in index 0b1db1acfc3c4ad52cbd1f431bf2aeaa441732c1..b36e50d1d2718fe9a172ac5fdf05dfc775ad2060 100644 --- a/software/kvm/instance-kvm-cluster.cfg.jinja2.in +++ b/software/kvm/instance-kvm-cluster.cfg.jinja2.in @@ -22,7 +22,7 @@ config-use-ipv6 = {{ dumps(slapparameter_dict.get('use-ipv6', False)) }} # Request kvm instances {% for instance_name, kvm_parameter_dict in slapparameter_dict.get('kvm-partition-dict', {'kvm-default': {}}).items() -%} {% set section = 'request-' ~ instance_name -%} -{% set use_nat = kvm_parameter_dict.get('use-nat', True) -%} +{% set use_nat = kvm_parameter_dict.get('use-nat', 'True') -%} [{{ section }}] <= request-common software-type = kvm @@ -73,12 +73,12 @@ config-document-path = ${http-server:path} return = backend-url url -{% if use_nat -%} +{% if use_nat.lower() -%} {% for port in nat_rules_list -%} {{ ' ' }}nat-rule-url-{{ port }} {% endfor -%} {% endif -%} -{% if kvm_parameter_dict.get('use-tap', True) -%} +{% if kvm_parameter_dict.get('use-tap', 'True').lower() == 'true' -%} {{ ' ' }}tap-ipv4 {% do publish_dict.__setitem__('lan-' ~ instance_name, '${' ~ section ~ ':connection-tap-ipv4}') -%} @@ -86,7 +86,7 @@ return = {% endif -%} {% do publish_dict.__setitem__(instance_name ~ '-backend-url', '${' ~ section ~ ':connection-backend-url}') -%} {% do publish_dict.__setitem__(instance_name ~ '-url', '${' ~ section ~ ':connection-url}') -%} -{% do kvm_instance_dict.__setitem__(instance_name, (kvm_parameter_dict.get('use-nat', True), nat_rules_list)) -%} +{% do kvm_instance_dict.__setitem__(instance_name, (use_nat, nat_rules_list)) -%} {% endfor %} @@ -145,6 +145,7 @@ log = ${:var}/log scripts = ${:etc}/run services = ${:etc}/service document = ${:srv}/document +promises = ${:etc}/promise ssl = ${:etc}/ssl [http-ssl] @@ -164,8 +165,16 @@ wrapper = ${directory:services}/simple-http-server log-file = ${directory:log}/http.log cert-file = ${http-ssl:cert} key-file = ${http-ssl:key} -{% do publish_dict.__setitem__('http-file-server', 'https://' ~ '[${http-server:host}]:' ~ '${http-server:port}/' ~ '${http-server:path}') -%} +use-hash-url = true +[http-promise] +recipe = slapos.cookbook:check_port_listening +path = ${directory:promises}/http-server +hostname = ${http-server:host} +port = ${http-server:port} + +{% if len(kvm_hostname_list) -%} +{% do part_list.append('write-vm-hostname') -%} [write-vm-hostname] recipe = slapos.recipe.template:jinja2 template = {{ template_content }} @@ -174,6 +183,7 @@ rendered = ${http-server:root-dir}/${:filename} context = raw content_list {{ kvm_hostname_list | join('#') }} raw sep # +{% endif -%} {% macro writefile(section_name, file_path, content, mode='') -%} {% do part_list.append(section_name) -%} @@ -199,7 +209,7 @@ recipe = slapos.cookbook:publish [buildout] parts = http-server - write-vm-hostname + http-promise publish # Complete parts with sections {{ part_list | join('\n ') }} diff --git a/software/kvm/instance-kvm-input-schema.json b/software/kvm/instance-kvm-input-schema.json index 264f3cb9c28f11bd5c95304ad9680a88cc08942e..abc78e17ec5d930cd1f9ed8b4204882187b47cc1 100644 --- a/software/kvm/instance-kvm-input-schema.json +++ b/software/kvm/instance-kvm-input-schema.json @@ -115,7 +115,7 @@ "description": "Type of QEMU disk drive, to create.", "type": "string", "default": "qcow2", - "enum": ["qcow2", "raw", "vdi", "vmdk", "cloop"] + "enum": ["qcow2", "raw", "vdi", "vmdk", "cloop", "qed"] }, "use-tap": { diff --git a/software/kvm/instance-kvm.cfg.jinja2 b/software/kvm/instance-kvm.cfg.jinja2 index 870090900ea29ac2dd4d0ef59790742f39efe4b1..dd2e6ea3795c72434d28e9d8108aefb2fd5050c8 100644 --- a/software/kvm/instance-kvm.cfg.jinja2 +++ b/software/kvm/instance-kvm.cfg.jinja2 @@ -1,4 +1,6 @@ -{% set enable_http = slapparameter_dict.get('enable-http-server', 'False') -%} +{% set enable_http = slapparameter_dict.get('enable-http-server', 'False').lower() -%} +{% set use_tap = slapparameter_dict.get('use-tap', 'False').lower() -%} +{% set use_nat = slapparameter_dict.get('use-nat', 'True').lower() -%} ############################# # # Instanciate kvm @@ -19,7 +21,7 @@ parts = {% if slapparameter_dict.get('document-host', '') %} cluster-url-path {% endif -%} -{% if slapparameter_dict.get('enable-http-server', 'False') == 'True' %} +{% if enable_http == 'true' %} httpd httpd-promise publish-host-config @@ -30,8 +32,8 @@ parts = get-authorized-key {% endif -%} -extends = - {{ template_httpd_cfg }} +# extends = +# {{ template_httpd_cfg }} {% endif -%} eggs-directory = {{ eggs_directory }} @@ -133,7 +135,7 @@ external-disk-number = ${slap-parameter:external-disk-number} external-disk-size = ${slap-parameter:external-disk-size} external-disk-format = ${slap-parameter:external-disk-format} -{% if slapparameter_dict.get('enable-http-server', 'False') == 'True' or ( slapparameter_dict.get('use-tap', 'False') == 'True' and tap_network_dict.has_key('ipv4') ) -%} +{% if enable_http == 'tue' or ( use_tap == 'true' and tap_network_dict.has_key('ipv4') ) -%} httpd-port = ${slap-parameter:httpd-port} {% else -%} httpd-port = 0 @@ -270,6 +272,23 @@ dash_path = {{ dash_executable_location }} curl_path = {{ curl_executable_location }} +{% if enable_http == 'true' %} +[httpd] +recipe = slapos.cookbook:simplehttpserver +host = ${slap-network-information:local-ipv4} +port = ${slap-parameter:httpd-port} +base-path = ${directory:public} +wrapper = ${directory:services}/http-server +log-file = ${directory:log}/httpd.log +use-hash-url = false + +[httpd-promise] +recipe = slapos.cookbook:check_port_listening +path = ${directory:promises}/httpd +hostname = ${httpd:host} +port = ${httpd:port} +{% endif %} + [publish-connection-information] recipe = slapos.cookbook:publish ipv6 = ${slap-network-information:global-ipv6} @@ -278,7 +297,7 @@ url = ${request-slave-frontend:connection-url}/vnc_auto.html?host=${request-slav {% set disk_number = len(storage_dict) -%} maximum-extra-disk-amount = {{ disk_number }} {% set iface = 'eth0' -%} -{% if slapparameter_dict.get('use-nat', 'True') == 'True' -%} +{% if use_nat == 'true' -%} {% set iface = 'eth1' -%} # Publish NAT port mapping status # XXX: hardcoded value from [slap-parameter] @@ -291,13 +310,13 @@ nat-rule-url-{{port}} = [${slap-network-information:global-ipv6}]:{{external_por {% endif -%} {% endfor -%} {% endif -%} -{% if slapparameter_dict.get('use-tap', 'False') == 'True' -%} +{% if use_tap == 'true' -%} tap-ipv4 = ${slap-network-information:tap-ipv4} {% endif -%} {% set kvm_http = 'http://${slap-network-information:local-ipv4}:' ~ slapparameter_dict.get('httpd-port', 8081) -%} {% if enable_http == 'True' %} -{% if slapparameter_dict.get('use-nat', 'True') == 'True' -%} +{% if use_nat == 'true' -%} {% set kvm_http = 'http://10.0.2.100' -%} {% endif %} {% if slapparameter_dict.get('authorized-key', '') -%} @@ -305,13 +324,13 @@ tap-ipv4 = ${slap-network-information:tap-ipv4} {% endif %} {% endif %} -{% if slapparameter_dict.get('use-tap', 'False') == 'True' and tap_network_dict.has_key('ipv4') -%} +{% if use_tap == 'true' and tap_network_dict.has_key('ipv4') -%} 1_info = Use these configurations below to configure interface {{ iface }} in your VM. 2_info = ${network-config:ifconfig} 3_info = ${network-config:route-iface} 4_info = ${network-config:route-network} 5_info = ${network-config:route-default} -{% if enable_http == 'True' %} +{% if enable_http == 'true' %} 6_info = Or run in your VM the command: wget -O- {{ kvm_http }}/netconfig.sh | /bin/sh - {% endif %} @@ -357,7 +376,7 @@ mode = {{ mode }} [publish-host-config] recipe = plone.recipe.command name = {{ slapparameter_dict.get('name', 'localhost') }} -{% if slapparameter_dict.get('use-tap', 'False') == 'True' and tap_network_dict.has_key('ipv4') -%} +{% if use_tap == 'true' and tap_network_dict.has_key('ipv4') -%} local-ipv4 = ${slap-network-information:tap-ipv4} {% else -%} local-ipv4 = 127.0.0.1