instance-kvm-cluster.cfg.jinja2.in 12 KB
Newer Older
1
{% set publish_dict = {} -%}
2 3
{% set part_list = [] -%}
{% set ipv6 = (ipv6 | list)[0] -%}
4
{% set frontend_dict = slapparameter_dict.get('frontend', {}) -%}
5
{% set slave_frontend_dict = slapparameter_dict.get('slave-frontend', {}) -%}
6
{% set slave_frontend_sr = slave_frontend_dict.get('software-url', 'http://git.erp5.org/gitweb/slapos.git/blob_plain/HEAD:/software/apache-frontend/software.cfg') -%}
7
{% set slave_frontend_stype = slave_frontend_dict.get('software-type', 'custom-personal') -%}
8 9
{% set slave_frontend_iguid = slave_frontend_dict.get('instance-guid', '') -%}
{% set kvm_instance_dict = {} -%}
10
{% set kvm_hostname_list = [] -%}
11
{% set monitor_url_list = [] -%}
12
{% set enable_monitoring = slapparameter_dict.get('enable-monitor', True) -%}
13 14 15 16 17 18 19 20 21 22 23 24 25 26

[request-common]
recipe = slapos.cookbook:request
software-url = ${slap-connection:software-release-url}
server-url = ${slap-connection:server-url}
key-file = ${slap-connection:key-file}
cert-file = ${slap-connection:cert-file}
computer-id = ${slap-connection:computer-id}
partition-id = ${slap-connection:partition-id}
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 -%}
27
{% set use_nat = kvm_parameter_dict.get('use-nat', 'True') -%}
28 29 30 31
[{{ section }}]
<= request-common
software-type = kvm
name = {{ instance_name }}
32
sla-computer_guid = {{ dumps(kvm_parameter_dict.get('computer-guid', '')) }}
33 34 35
{% if kvm_parameter_dict.get('state', '') == 'stopped' -%}
state = stopped
{% endif -%}
36

37
config-frontend-instance-name = {{ instance_name ~ ' VNC Frontend' }}
38
config-frontend-software-type = {{ dumps(frontend_dict.get('software-type', 'frontend')) }}
39
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')) }}
40
config-frontend-instance-guid = {{ dumps(frontend_dict.get('instance-guid', '')) }}
41
config-name = {{ instance_name }}
42 43
{% if slapparameter_dict.get('authorized-keys', []) -%}
config-authorized-key = {{ dumps(slapparameter_dict.get('authorized-keys') | join('\n')) }}
44
{% endif -%}
45 46 47 48 49 50 51 52
config-nbd-port = {{ dumps(kvm_parameter_dict.get('nbd-port', 1024)) }}
config-nbd-host = {{ dumps(kvm_parameter_dict.get('nbd-host', '')) }}
config-nbd2-port = {{ dumps(kvm_parameter_dict.get('nbd-port2', 1024)) }}
config-nbd2-host = {{ dumps(kvm_parameter_dict.get('nbd-host2', '')) }}
config-ram-size = {{ dumps(kvm_parameter_dict.get('ram-size', 1024)) }}
config-disk-size = {{ dumps(kvm_parameter_dict.get('disk-size', 10)) }}
config-disk-type = {{ dumps(kvm_parameter_dict.get('disk-type', 'virtio')) }}
config-cpu-count = {{ dumps(kvm_parameter_dict.get('cpu-count', 1)) }}
53 54
config-cpu-options = {{ dumps(kvm_parameter_dict.get('cpu-options', '')) }}
config-numa = {{ dumps(kvm_parameter_dict.get('numa', '')) }}
55 56 57 58 59
config-disk-cache = {{ dumps(kvm_parameter_dict.get('disk-cache', '')) }}
config-disk-aio = {{ dumps(kvm_parameter_dict.get('disk-aio', '')) }}
config-auto-ballooning = {{ dumps(kvm_parameter_dict.get('auto-ballooning', True)) }}
config-machine-options = {{ dumps(kvm_parameter_dict.get('machine-options', '')) }}
config-cpu-model = {{ dumps(kvm_parameter_dict.get('cpu-model', '')) }}
60

61
{% set nat_rules_list = kvm_parameter_dict.get('nat-rules', []) -%}
62
config-nat-rules = {{ nat_rules_list | join(' ') }}
63 64
config-publish-nat-url = True
config-use-nat = {{ use_nat }}
65
config-use-tap = {{ dumps(kvm_parameter_dict.get('use-tap', True)) }}
66
config-nat-restrict-mode = {{ dumps(kvm_parameter_dict.get('nat-restrict-mode', False)) }}
67
config-enable-vhost = {{ dumps(kvm_parameter_dict.get('enable-vhost', False)) }}
68 69 70
config-virtual-hard-drive-url = {{ dumps(kvm_parameter_dict.get('virtual-hard-drive-url', '')) }}
config-virtual-hard-drive-md5sum = {{ dumps(kvm_parameter_dict.get('virtual-hard-drive-md5sum', '')) }}
config-virtual-hard-drive-gzipped = {{ dumps(kvm_parameter_dict.get('virtual-hard-drive-gzipped', False)) }}
71
config-hard-drive-url-check-certificate = {{ dumps(kvm_parameter_dict.get('hard-drive-url-check-certificate', True)) }}
72 73
config-external-disk-number = {{ dumps(kvm_parameter_dict.get('external-disk-number', 0)) }}
config-external-disk-size = {{ dumps(kvm_parameter_dict.get('external-disk-size', 20)) }}
74
config-external-disk-format = {{ dumps(kvm_parameter_dict.get('external-disk-format', 'qcow2')) }}
75 76
config-enable-http-server = {{ dumps(kvm_parameter_dict.get('enable-http-server', True)) }}
config-httpd-port = {{ dumps(kvm_parameter_dict.get('httpd-port', 8081)) }}
77 78 79
{% if kvm_parameter_dict.get('data-to-vm', '') -%}
config-data-to-vm = {{ dumps(kvm_parameter_dict.get('data-to-vm', '')) }}
{% endif -%}
80 81
config-disable-ansible-promise = {{ dumps(kvm_parameter_dict.get('disable-ansible-promise', False)) }}
config-enable-monitor = {{ enable_monitoring }}
82
config-monitor-cors-domains = {{ slapparameter_dict.get('monitor-cors-domains', 'monitor.app.officejs.com') }}
83
config-monitor-username = ${monitor-instance-parameter:username}
84
config-monitor-password = ${monitor-htpasswd:passwd}
85

86
# Enable simple http server on ipv6 so all VMs will access it
87 88 89
config-document-host = ${apache-conf:ip}
config-document-port = ${apache-conf:port}
config-document-path = ${hash-code:passwd}
90
config-keyboard-layout-language = {{ dumps(kvm_parameter_dict.get('keyboard-layout-language', 'fr')) }}
91
config-type = cluster
92

93 94 95 96 97
{% set bootstrap_script_url = slapparameter_dict.get('bootstrap-script-url', kvm_parameter_dict.get('bootstrap-script-url', '')) -%}
{% if bootstrap_script_url -%}
config-bootstrap-script-url = {{ bootstrap_script_url }}
{% endif -%}

98 99 100 101 102
{% set authorized_source_list = slapparameter_dict.get('fw-authorized-sources', []) -%}
{% set rejected_source_list = slapparameter_dict.get('fw-reject-sources', []) -%}
sla-fw_authorized_sources = {{ authorized_source_list | join(' ') }}
sla-fw_rejected_sources = {{ rejected_source_list | join(' ') }}
sla-fw_restricted_access = {{ dumps(slapparameter_dict.get('fw-restricted-access', 'off')) }}
103

104 105
return = 
  url
106
  backend-url
107
{% if str(use_nat).lower() == 'true' -%}
108 109 110 111
{%   for port in nat_rules_list -%}
{{ '  ' }}nat-rule-url-{{ port }}
{%   endfor -%}
{% endif -%}
112 113 114 115
{% if enable_monitoring -%}
{{ '  ' }}monitor-base-url
{%    do monitor_url_list.append('${' ~ section ~ ':connection-monitor-base-url}') -%}
{% endif -%}
116
{% if str(kvm_parameter_dict.get('use-tap', 'True')).lower() == 'true' -%}
117 118 119
{{ '  ' }}tap-ipv4

{% do publish_dict.__setitem__('lan-' ~ instance_name, '${' ~ section ~ ':connection-tap-ipv4}') -%}
120
{% do kvm_hostname_list.append(instance_name ~ ' ' ~ '${' ~ section ~ ':connection-tap-ipv4}') -%}
121
{% endif -%}
122 123
{% do publish_dict.__setitem__(instance_name ~ '-backend-url', '${' ~ section ~ ':connection-backend-url}') -%}
{% do publish_dict.__setitem__(instance_name ~ '-url', '${' ~ section ~ ':connection-url}') -%}
124
{% do kvm_instance_dict.__setitem__(instance_name, (use_nat, nat_rules_list)) -%}
125 126 127 128 129 130 131 132 133 134
{% endfor %}


#request custom kvm frontend
{% for frontend_name, frontend_parameter_dict in slave_frontend_dict.get('slave-frontend-dict', {}).items() -%}
{%   set name = frontend_name -%}
{%   set url = frontend_parameter_dict.get('url', '') -%}
{%   set error = '' -%}
{%   if frontend_parameter_dict.get('kvm-partition-name', '') != '' -%}
{%     set kvm_name = frontend_parameter_dict['kvm-partition-name'] -%}
135
{%     set service_port = str(frontend_parameter_dict['service-port']) -%}
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
{%     if kvm_name in kvm_instance_dict.keys()  and not kvm_instance_dict[kvm_name][0] -%}
{%       set error = "You should set parameter use-nat to 'true' for '" ~ kvm_name ~ "', or provide url to use for frontend." -%}
{%     elif kvm_name in kvm_instance_dict.keys() and service_port in kvm_instance_dict[kvm_name][1] -%}
{%       set url = '${request-' ~ kvm_name ~ ':connection-nat-rule-url-' ~ service_port ~ '}' -%}
{%       set url = frontend_parameter_dict.get('url-scheme', 'http') ~ '://' ~ url -%}
{%     else -%}
{%       set error = kvm_name ~ " and/or port " ~ service_port ~ " doesn't match any KVM name and/or related nat-rules in your request parameters." -%}
{%     endif -%}
{%   endif -%}
{%   set section = 'request-' ~ name ~ '-slave-frontend' -%}
[{{ section }}]
<= request-common
recipe = slapos.cookbook:request
software-url = {{ slave_frontend_sr }}
name = Frontend {{ name }}
software-type = {{ slave_frontend_stype }}
slave = true
config-url = {{ url }}
154
config-custom_domain = {{ dumps(frontend_parameter_dict.get('domain', '')) }}
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
config-enable_cache = {{ dumps(frontend_parameter_dict.get('enable-cache', False)) }}
config-https-only = {{ dumps(frontend_parameter_dict.get('https-only', False)) }}
{%  if frontend_parameter_dict.get('type', '') -%}
config-type = {{ dumps(frontend_parameter_dict['type']) }}
{%    if frontend_parameter_dict.get('path', '') -%}
config-path = {{ dumps(frontend_parameter_dict['path']) }}
{%    endif -%}
{%  endif -%}
return = 
  site_url
sla-instance_guid = {{ slave_frontend_iguid }}
{%   do publish_dict.__setitem__(name ~ '-url', '${' ~ section ~ ':connection-site_url}') -%}
{%   if error != '' -%}
{%     do publish_dict.__setitem__('1_error', error) -%}
{%   endif -%}
170 171
{% endfor %}

172
# Enable simple http server on ipv6 so all VMs will access it
173 174 175 176 177
[hash-code]
recipe = slapos.cookbook:generate.password
storage-path = ${directory:etc}/code
bytes = 24

178 179 180 181 182 183 184 185 186
[directory]
recipe = slapos.cookbook:mkdirectory
etc = ${buildout:directory}/etc
bin = ${buildout:directory}/bin
srv = ${buildout:directory}/srv
var = ${buildout:directory}/var
log = ${:var}/log
scripts = ${:etc}/run
services = ${:etc}/service
187
webroot = ${:srv}/document
188
promises = ${:etc}/promise
189 190
ssl = ${:etc}/ssl

191 192 193 194 195 196 197 198
[directory-doc]
recipe = slapos.cookbook:mkdirectory
document = ${directory:webroot}/${hash-code:passwd}

[apache-conf]
denied-root-access = true
root = ${directory:webroot}/
index = ${directory:webroot}/${hash-code:passwd}
199
port = 9002
200 201 202

{% if len(kvm_hostname_list) -%}
{%   do part_list.append('write-vm-hostname') -%}
203 204 205 206
[write-vm-hostname]
recipe = slapos.recipe.template:jinja2
template = {{ template_content }}
filename = hosts
207
rendered = ${directory:webroot}/${hash-code:passwd}/${:filename}
208 209 210
context =
    raw content_list {{ kvm_hostname_list | join('#') }}
    raw sep #
211
{% endif -%}
212

213 214 215 216 217 218 219 220 221 222 223 224 225
{% 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', '') -%}
226
{{ writefile('cluster-data-content', '${directory:webroot}/${hash-code:passwd}/data', slapparameter_dict.get('cluster-data', ''), '700') }}
227 228
{% endif -%}

229 230
[monitor-instance-parameter]
monitor-httpd-port = 8060
231
cors-domains = {{ slapparameter_dict.get('monitor-cors-domains', 'monitor.app.officejs.com') }}
232
username = admin
233 234 235 236 237 238 239 240 241 242
password = ${monitor-htpasswd:passwd}

[monitor-conf-parameters]
monitor-url-list +=
{% for url in monitor_url_list -%}
{{ '  ' ~ url }}
{% endfor %}
private-path-list += 
  ${directory:webroot}/

243
[publish-connection-information]
244 245 246 247
recipe = slapos.cookbook:publish
{% for name, value in publish_dict.items() -%}
{{   name }} = {{ value }}
{% endfor %}
248 249 250
{% if enable_monitoring -%}
{%   set monitor_interface_url = slapparameter_dict.get('monitor-interface-url', 'https://monitor.app.officejs.com') -%}
{% do part_list.append('monitor-base') -%}
251
monitor-setup-url = {{ monitor_interface_url }}/#page=settings_configurator&url=${monitor-publish-parameters:monitor-url}&username=${monitor-publish-parameters:monitor-user}&password=${monitor-publish-parameters:monitor-password}
252
{% endif -%}
253

254
[buildout]
255 256
extends = 
  {{ template_httpd_cfg }}
257 258 259
{% if enable_monitoring -%}
{{ '  ' ~ template_monitor }}
{% endif -%}
260

261
parts = 
262
  httpd
263
  httpd-graceful
264
  httpd-promise
265
  publish-connection-information
266
  directory-doc
267

268 269 270
# Complete parts with sections
  {{ part_list | join('\n  ') }}
 
271 272
eggs-directory = {{ eggs_directory }}
develop-eggs-directory = {{ develop_eggs_directory }}
273
offline = true