Commit 49f7d48d authored by Alain Takoudjou's avatar Alain Takoudjou

kvm: add parameter to set text content which will be available for VMs of cluster

text content is saved in a file called 'data' of the corresponding http server. the file can be downloaded into the vm with:
- https://10.0.2.101/FOLDER_HASH/data : if parameter 'cluster-data' is used (for kvm-cluster only, file is accessible from all vm)
- http://10.0.2.100/data : if parameter 'data-to-vm' is used.
parent 2754449a
...@@ -95,7 +95,7 @@ mode = 0644 ...@@ -95,7 +95,7 @@ mode = 0644
recipe = hexagonit.recipe.download recipe = hexagonit.recipe.download
url = ${:_profile_base_location_}/instance-kvm.cfg.jinja2 url = ${:_profile_base_location_}/instance-kvm.cfg.jinja2
mode = 644 mode = 644
md5sum = 3e3354844b2052609e3c49eca03b607e md5sum = fb2dcca424fa0bf4d6ec445965a8bc81
download-only = true download-only = true
on-update = true on-update = true
...@@ -103,7 +103,7 @@ on-update = true ...@@ -103,7 +103,7 @@ on-update = true
recipe = hexagonit.recipe.download recipe = hexagonit.recipe.download
url = ${:_profile_base_location_}/instance-kvm-cluster.cfg.jinja2.in url = ${:_profile_base_location_}/instance-kvm-cluster.cfg.jinja2.in
mode = 644 mode = 644
md5sum = 1f7dc7b7f2740cf416927b144e93ccb1 md5sum = 36d9ea062c13f88eadd6f635eed36b7e
download-only = true download-only = true
on-update = true on-update = true
...@@ -182,7 +182,7 @@ recipe = hexagonit.recipe.download ...@@ -182,7 +182,7 @@ recipe = hexagonit.recipe.download
url = ${:_profile_base_location_}/template/template-content.in url = ${:_profile_base_location_}/template/template-content.in
mode = 644 mode = 644
filename = template-content.in filename = template-content.in
md5sum = 47d492dafe5cb314bdc49bf013d21ead md5sum = 822737e483864bf255ad1259237bef2a
download-only = true download-only = true
on-update = true on-update = true
......
...@@ -122,11 +122,16 @@ ...@@ -122,11 +122,16 @@
}, },
"type": "object" "type": "object"
}, },
"authorized-key": { "authorized-keys": {
"title": "Public keys for virtual machines.", "title": "Public keys for virtual machines.",
"description": "Set the list of public keys to add in your virtual machine. The public key file will be available in the VM via url http://10.0.2.100/authorized_keys if you keep the NAT interface enabled", "description": "Set the list of public keys to add in your virtual machine. The public key file will be available in the VM via url http://10.0.2.100/authorized_keys if you keep the NAT interface enabled",
"type": "array" "type": "array"
}, },
"cluster-data": {
"title": "Text content to share with virtual machines.",
"description": "Text content which will be written in a file data of cluster http server. All VM will be able to download that file via the static URL of cluster HTTP server: https://10.0.2.101/FOLDER_HASH/data.",
"type": "string"
},
"kvm-partition-dict": { "kvm-partition-dict": {
"title": "kvm instances definition", "title": "kvm instances definition",
"description": "kvm instances definition", "description": "kvm instances definition",
...@@ -284,6 +289,11 @@ ...@@ -284,6 +289,11 @@
80, 80,
443 443
] ]
},
"data-to-vm": {
"title": "Text content to send to this virtual machine.",
"description": "Text content which will be written in a file 'data' of http server of this virtual machine instance. The file will be available via URL: http://10.0.2.100/data in the VM.",
"type": "string"
} }
}, },
"type": "object" "type": "object"
......
...@@ -34,8 +34,8 @@ config-frontend-software-type = {{ dumps(frontend_dict.get('software-type', 'fro ...@@ -34,8 +34,8 @@ config-frontend-software-type = {{ dumps(frontend_dict.get('software-type', 'fro
config-frontend-software-url = {{ dumps(frontend_dict.get('software-url', 'http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.92:/software/kvm/software.cfg')) }} config-frontend-software-url = {{ dumps(frontend_dict.get('software-url', 'http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.92:/software/kvm/software.cfg')) }}
config-frontend-instance-guid = {{ dumps(frontend_dict.get('instance-guid', '')) }} config-frontend-instance-guid = {{ dumps(frontend_dict.get('instance-guid', '')) }}
config-name = {{ instance_name }} config-name = {{ instance_name }}
{% if slapparameter_dict.get('authorized-key', []) -%} {% if slapparameter_dict.get('authorized-keys', []) -%}
config-authorized-key = {{ slapparameter_dict.get('authorized-key') | join('##') }} config-authorized-key = {{ dumps(slapparameter_dict.get('authorized-keys') | join('\n')) }}
{% endif -%} {% endif -%}
config-nbd-port = {{ dumps(kvm_parameter_dict.get('nbd-port', 1024)) }} config-nbd-port = {{ dumps(kvm_parameter_dict.get('nbd-port', 1024)) }}
config-nbd-host = {{ dumps(kvm_parameter_dict.get('nbd-host', '')) }} config-nbd-host = {{ dumps(kvm_parameter_dict.get('nbd-host', '')) }}
...@@ -61,6 +61,9 @@ config-external-disk-size = {{ dumps(kvm_parameter_dict.get('external-disk-size' ...@@ -61,6 +61,9 @@ config-external-disk-size = {{ dumps(kvm_parameter_dict.get('external-disk-size'
config-external-disk-format = {{ dumps(kvm_parameter_dict.get('external-disk-format', 'qcow2')) }} config-external-disk-format = {{ dumps(kvm_parameter_dict.get('external-disk-format', 'qcow2')) }}
config-enable-http-server = {{ dumps(kvm_parameter_dict.get('enable-http-server', True)) }} config-enable-http-server = {{ dumps(kvm_parameter_dict.get('enable-http-server', True)) }}
config-httpd-port = {{ dumps(kvm_parameter_dict.get('httpd-port', 8081)) }} config-httpd-port = {{ dumps(kvm_parameter_dict.get('httpd-port', 8081)) }}
{% if kvm_parameter_dict.get('data-to-vm', '') -%}
config-data-to-vm = {{ dumps(kvm_parameter_dict.get('data-to-vm', '')) }}
{% endif -%}
# Enable simple http server on ipv6 so all VMs will access it # Enable simple http server on ipv6 so all VMs will access it
config-document-host = ${http-server:host} config-document-host = ${http-server:host}
...@@ -161,6 +164,7 @@ wrapper = ${directory:services}/simple-http-server ...@@ -161,6 +164,7 @@ wrapper = ${directory:services}/simple-http-server
log-file = ${directory:log}/http.log log-file = ${directory:log}/http.log
cert-file = ${http-ssl:cert} cert-file = ${http-ssl:cert}
key-file = ${http-ssl:key} key-file = ${http-ssl:key}
{% do publish_dict.__setitem__('http-file-server', 'https://' ~ '[${http-server:host}]:' ~ '${http-server:port}/' ~ '${http-server:path}') -%}
[write-vm-hostname] [write-vm-hostname]
recipe = slapos.recipe.template:jinja2 recipe = slapos.recipe.template:jinja2
...@@ -171,6 +175,22 @@ context = ...@@ -171,6 +175,22 @@ context =
raw content_list {{ kvm_hostname_list | join('#') }} raw content_list {{ kvm_hostname_list | join('#') }}
raw sep # raw sep #
{% macro writefile(section_name, file_path, content, mode='') -%}
{% do part_list.append(section_name) -%}
{% set data_list = content.split('\n') -%}
[{{ section_name }}]
recipe = collective.recipe.template
input = inline:
{{ data_list | join('\n ') }}
output = {{ file_path }}
mode = {{ mode }}
{% endmacro -%}
# write cluster-data into file public/data
{% if slapparameter_dict.get('cluster-data', '') -%}
{{ writefile('cluster-data-content', '${http-server:root-dir}/data', slapparameter_dict.get('cluster-data', ''), '700') }}
{% endif -%}
[publish] [publish]
recipe = slapos.cookbook:publish recipe = slapos.cookbook:publish
{% for name, value in publish_dict.items() -%} {% for name, value in publish_dict.items() -%}
......
...@@ -135,9 +135,28 @@ ...@@ -135,9 +135,28 @@
"description": "List of rules for NAT of QEMU user mode network stack, as comma-separated list of ports. For each port specified, it will redirect port x of the VM (example: 80) to the port x + 10000 of the public IPv6 (example: 10080). Defaults to \"22 80 443\". Ignored if \"use-tap\" parameter is enabled.", "description": "List of rules for NAT of QEMU user mode network stack, as comma-separated list of ports. For each port specified, it will redirect port x of the VM (example: 80) to the port x + 10000 of the public IPv6 (example: 10080). Defaults to \"22 80 443\". Ignored if \"use-tap\" parameter is enabled.",
"type": "string" "type": "string"
}, },
"enable-http-server": {
"title": "Enable local http server",
"description": "Set if local http server which serve files to the vm should be deployed. If set to true, get file into the vm with URL: http://10.0.2.100/FILE.",
"type": "boolean",
"default": false
},
"httpd-port": {
"title": "Local http server port",
"description": "Port of the local http server used to share files.",
"type": "integer",
"default": 8081,
"minimum": 1,
"maximum": 65535
},
"authorized-key": { "authorized-key": {
"title": "Public keys to get from all virtual machines.", "title": "Public keys to get from all virtual machines.",
"description": "Set the public keys to add in your virtual machine. Keys are separated with '##'. The public key file will be available in the VM via url http://10.0.2.100/authorized_keys if you keep the NAT interface enabled", "description": "Set the public keys to add in your virtual machine. The public key file will be available in the VM via url http://10.0.2.100/authorized_keys if you keep the NAT interface enabled",
"type": "string"
},
"data-to-vm": {
"title": "Text content to send to this virtual machine.",
"description": "Text content which will be written in a file 'data' of http server of this virtual machine instance. The file will be available via URL: http://10.0.2.100/data in the VM.",
"type": "string" "type": "string"
}, },
"frontend-instance-guid": { "frontend-instance-guid": {
......
...@@ -23,6 +23,12 @@ parts = ...@@ -23,6 +23,12 @@ parts =
httpd httpd
httpd-promise httpd-promise
publish-host-config publish-host-config
{% if slapparameter_dict.get('data-to-vm', '') %}
vm-data-content
{% endif -%}
{% if slapparameter_dict.get('authorized-key', '') %}
get-authorized-key
{% endif -%}
extends = extends =
{{ template_httpd_cfg }} {{ template_httpd_cfg }}
...@@ -295,7 +301,7 @@ tap-ipv4 = ${slap-network-information:tap-ipv4} ...@@ -295,7 +301,7 @@ tap-ipv4 = ${slap-network-information:tap-ipv4}
{% set kvm_http = 'http://10.0.2.100' -%} {% set kvm_http = 'http://10.0.2.100' -%}
{% endif %} {% endif %}
{% if slapparameter_dict.get('authorized-key', '') -%} {% if slapparameter_dict.get('authorized-key', '') -%}
7_info = Get the publick key file in your VM with the command: wget {{ kvm_http }}/${get-authorized-key:filename} 7_info = Get the publick key file in your VM with the command: wget {{ kvm_http }}/authorized_keys
{% endif %} {% endif %}
{% endif %} {% endif %}
...@@ -332,15 +338,21 @@ command = ...@@ -332,15 +338,21 @@ command =
update-command = ${:command} update-command = ${:command}
{% endif -%} {% endif -%}
[get-authorized-key] {% macro writefile(section_name, file_path, content, mode='') -%}
recipe = slapos.recipe.template:jinja2 {% set data_list = content.split('\n') -%}
template = {{ template_content }} [{{ section_name }}]
filename = authorized_keys recipe = collective.recipe.template
rendered = ${directory:public}/${:filename} input = inline:
public-key = {{ slapparameter_dict.get('authorized-key', '') }} {{ data_list | join('\n ') }}
context = output = {{ file_path }}
key content_list :public-key mode = {{ mode }}
raw sep ## {% endmacro -%}
# write vm-data into file public/data
{{ writefile('vm-data-content', '${directory:public}/data', slapparameter_dict.get('data-to-vm', ''), '700') }}
# write public key for vms to public/authorized_keys
{{ writefile('get-authorized-key', '${directory:public}/authorized_keys', slapparameter_dict.get('authorized-key', ''), '700') }}
[publish-host-config] [publish-host-config]
recipe = plone.recipe.command recipe = plone.recipe.command
...@@ -419,3 +431,6 @@ enable-http-server = False ...@@ -419,3 +431,6 @@ enable-http-server = False
httpd-port = 8081 httpd-port = 8081
# for auto config, the public key file will be available in the VM via url http://10.0.2.100/authorized_key if use-nat = True # for auto config, the public key file will be available in the VM via url http://10.0.2.100/authorized_key if use-nat = True
authorized-key = authorized-key =
# send some content which will be accessible to the vm through static url: http://10.0.2.100/data
data-to-vm =
{% for content in content_list.split(sep) -%} {% if not sep -%}
{{ content_list }}
{% else -%}
{% for content in content_list.split(sep) -%}
{{ content }} {{ content }}
{% endfor -%} {% endfor -%}
\ No newline at end of file {% endif -%}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment