instance-kvm.cfg.jinja2 14.3 KB
Newer Older
1
{% set enable_http = slapparameter_dict.get('enable-http-server', 'False') -%}
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#############################
#
# Instanciate kvm
#
#############################
[buildout]
parts =
  certificate-authority
  publish-connection-information
  kvm-vnc-promise
  kvm-disk-image-corruption-promise
  websockify-sighandler
  novnc-promise
#  kvm-monitor
  cron
#  cron-entry-monitor
  frontend-promise
19 20 21
{% if slapparameter_dict.get('document-host', '') %}
  cluster-url-path
{% endif -%}
22 23 24
{% if slapparameter_dict.get('enable-http-server', 'False') == 'True' %}
  httpd
  httpd-promise
25
  publish-host-config
26 27 28 29 30 31
{% if slapparameter_dict.get('data-to-vm', '') %}
  vm-data-content
{% endif -%}
{% if slapparameter_dict.get('authorized-key', '') %}
  get-authorized-key
{%   endif -%}
32
  
33 34 35
extends = 
  {{ template_httpd_cfg }}
{% endif -%}
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

eggs-directory = {{ eggs_directory }}
develop-eggs-directory = {{ develop_eggs_directory }}
offline = true

[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
promises = ${:etc}/promise
novnc-conf = ${:etc}/novnc
run = ${:var}/run
ca-dir = ${:srv}/ssl
54
public = ${:srv}/public/
55 56 57 58 59 60 61 62
cron-entries = ${:etc}/cron.d
crontabs = ${:etc}/crontabs
cronstamps = ${:etc}/cronstamps

[create-mac]
recipe = slapos.cookbook:generate.mac
storage-path = ${directory:srv}/mac

63 64 65 66
[create-tap-mac]
recipe = slapos.cookbook:generate.mac
storage-path = ${directory:srv}/tap_mac

67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
[gen-passwd]
recipe = slapos.cookbook:generate.password
storage-path = ${directory:srv}/passwd
bytes = 8


[kvm-instance]
# XXX-Cedric: change "KVM" recipe to simple "create wrappers". No need for this
# Specific code. It needs Jinja.
recipe = slapos.cookbook:kvm

vnc-passwd = ${gen-passwd:passwd}

ipv4 = ${slap-network-information:local-ipv4}
ipv6 = ${slap-network-information:global-ipv6}
vnc-ip = ${:ipv4}

vnc-port = 5901

# XXX-Cedric: should be named "default-cdrom-iso"
default-disk-image = {{ debian_amd64_netinst_location }}
nbd-host = ${slap-parameter:nbd-host}
nbd-port = ${slap-parameter:nbd-port}
nbd2-host = ${slap-parameter:nbd2-host}
nbd2-port = ${slap-parameter:nbd2-port}

tap-interface = ${slap-network-information:network-interface}

disk-path = ${directory:srv}/virtual.qcow2
disk-size = ${slap-parameter:disk-size}
disk-type = ${slap-parameter:disk-type}

socket-path = ${directory:var}/qmp_socket
pid-file-path = ${directory:run}/pid_file

smp-count = ${slap-parameter:cpu-count}
103
smp-options = ${slap-parameter:cpu-options}
104
ram-size = ${slap-parameter:ram-size}
105
numa = ${slap-parameter:numa}
106
mac-address = ${create-mac:mac-address}
107
tap-mac-address = ${create-tap-mac:mac-address}
108 109 110 111 112 113

# XXX-Cedric: should be named runner-wrapper-path and controller-wrapper-path
runner-path = ${directory:services}/kvm
controller-path = ${directory:scripts}/kvm_controller

use-tap = ${slap-parameter:use-tap}
114
use-nat = ${slap-parameter:use-nat}
115 116 117 118 119
nat-rules = ${slap-parameter:nat-rules}
6tunnel-wrapper-path = ${directory:services}/6tunnel

virtual-hard-drive-url = ${slap-parameter:virtual-hard-drive-url}
virtual-hard-drive-md5sum = ${slap-parameter:virtual-hard-drive-md5sum}
120
virtual-hard-drive-gzipped = ${slap-parameter:virtual-hard-drive-gzipped}
121 122 123 124 125 126

shell-path = {{ dash_executable_location }}
qemu-path =  {{ qemu_executable_location }}
qemu-img-path = {{ qemu_img_executable_location }}
6tunnel-path = {{ sixtunnel_executable_location }}

127
etc-directory = ${directory:etc}
128 129 130 131 132 133
disk-storage-list = 
{% for key, path in storage_dict.items() -%}
{{ '  ' ~ key ~ ' ' ~ path }}
{% endfor -%}
external-disk-number = ${slap-parameter:external-disk-number}
external-disk-size = ${slap-parameter:external-disk-size}
134
external-disk-format = ${slap-parameter:external-disk-format}
135

136
{% if slapparameter_dict.get('enable-http-server', 'False') == 'True' or ( slapparameter_dict.get('use-tap', 'False') == 'True' and tap_network_dict.has_key('ipv4') ) -%}
137 138 139 140
httpd-port = ${slap-parameter:httpd-port}
{% else -%}
httpd-port = 0
{% endif -%}
141 142 143 144 145 146 147 148 149

# Main instance document server info
{% if slapparameter_dict.get('document-host', '') and slapparameter_dict.get('document-port', '') -%}
cluster-doc-host = ${tunnel-cluster-url:ipv4}
cluster-doc-port = ${tunnel-cluster-url:ipv4-port}
{% else -%}
cluster-doc-host = 
cluster-doc-port = 0
{% endif -%}
150
netcat-binary = {{ netcat_bin }}
151

152 153 154 155 156 157 158 159 160 161
[kvm-vnc-promise]
recipe = slapos.cookbook:check_port_listening
path = ${directory:promises}/vnc_promise
hostname = ${kvm-instance:vnc-ip}
port = ${kvm-instance:vnc-port}

[kvm-disk-image-corruption-promise]
# Check that disk image is not corrupted
recipe = collective.recipe.template
input = inline:#!/bin/sh
162 163 164
  # Return code 0 is "OK"
  # Return code 3 is "found leaks, but image is OK"
  # http://git.qemu.org/?p=qemu.git;a=blob;f=qemu-img.c;h=4e9a7f5741c9cb863d978225829e68fefcae3947;hb=HEAD#l702
165
  ${kvm-instance:qemu-img-path} check ${kvm-instance:disk-path}
166 167 168 169 170 171
  RETURN_CODE=$?
  if [ $RETURN_CODE -eq 0 ] || [ $RETURN_CODE -eq 3 ]; then
    exit 0
  else
    exit 1
  fi
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
output = ${directory:promises}/kvm-disk-image-corruption
mode = 700


[novnc-instance]
recipe = slapos.cookbook:novnc
path = ${ca-novnc:executable}
ip = ${slap-network-information:global-ipv6}
port = 6080
vnc-ip = ${kvm-instance:vnc-ip}
vnc-port = ${kvm-instance:vnc-port}
novnc-location = {{ novnc_location }}
websockify-path = {{ websockify_executable_location }}
ssl-key-path = ${ca-novnc:key-file}
ssl-cert-path = ${ca-novnc:cert-file}

[websockify-sighandler]
recipe = slapos.cookbook:signalwrapper
wrapper-path = ${directory:services}/websockify
wrapped-path = ${novnc-instance:path}

[certificate-authority]
recipe = slapos.cookbook:certificate_authority
openssl-binary = {{ openssl_executable_location }}
ca-dir = ${directory:ca-dir}
requests-directory = ${cadirectory:requests}
wrapper = ${directory:services}/certificate_authority
ca-private = ${cadirectory:private}
ca-certs = ${cadirectory:certs}
ca-newcerts = ${cadirectory:newcerts}
ca-crl = ${cadirectory:crl}

[cadirectory]
recipe = slapos.cookbook:mkdirectory
requests = ${directory:ca-dir}/requests/
private = ${directory:ca-dir}/private/
certs = ${directory:ca-dir}/certs/
newcerts = ${directory:ca-dir}/newcerts/
crl = ${directory:ca-dir}/crl/

[ca-novnc]
<= certificate-authority
recipe = slapos.cookbook:certificate_authority.request
key-file = ${directory:novnc-conf}/novnc.key
cert-file = ${directory:novnc-conf}/novnc.crt
executable = ${directory:bin}/novnc
wrapper = ${directory:bin}/websockify

[novnc-promise]
recipe = slapos.cookbook:check_port_listening
path = ${directory:promises}/novnc_promise
hostname = ${novnc-instance:ip}
port = ${novnc-instance:port}


#----------------
#--
#-- Deploy cron.

[cron]
recipe = slapos.cookbook:cron
dcrond-binary = {{ dcron_executable_location }}
cron-entries = ${directory:cron-entries}
crontabs = ${directory:crontabs}
cronstamps = ${directory:cronstamps}
catcher = ${cron-simplelogger:wrapper}
binary = ${directory:services}/crond

[cron-simplelogger]
recipe = slapos.cookbook:simplelogger
wrapper = ${directory:bin}/cron_simplelogger
log = ${directory:log}/crond.log

#----------------
#--
#-- Deploy frontend.

[request-slave-frontend]
recipe = slapos.cookbook:requestoptional
software-url = ${slap-parameter:frontend-software-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}
257
name = ${slap-parameter:frontend-instance-name}
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
software-type = ${slap-parameter:frontend-software-type}
slave = true
config-host = ${novnc-instance:ip}
config-port = ${novnc-instance:port}
return = url resource port domainname
sla-instance_guid = ${slap-parameter:frontend-instance-guid}

[frontend-promise]
recipe = slapos.cookbook:check_url_available
path = ${directory:promises}/frontend_promise
url = ${publish-connection-information:url}
dash_path = {{ dash_executable_location }}
curl_path = {{ curl_executable_location }}


[publish-connection-information]
recipe = slapos.cookbook:publish
Alain Takoudjou's avatar
Alain Takoudjou committed
275
ipv6 = ${slap-network-information:global-ipv6}
276 277
backend-url = https://[${novnc-instance:ip}]:${novnc-instance:port}/vnc_auto.html?host=[${novnc-instance:ip}]&port=${novnc-instance:port}&encrypt=1&password=${kvm-instance:vnc-passwd}
url = ${request-slave-frontend:connection-url}/vnc_auto.html?host=${request-slave-frontend:connection-domainname}&port=${request-slave-frontend:connection-port}&encrypt=1&path=${request-slave-frontend:connection-resource}&password=${kvm-instance:vnc-passwd}
278 279
{% set disk_number = len(storage_dict) -%}
maximum-extra-disk-amount = {{ disk_number }}
280
{% set iface = 'eth0' -%}
281
{% if slapparameter_dict.get('use-nat', 'True') == 'True' -%}
282
{%   set iface = 'eth1' -%}
283 284
# Publish NAT port mapping status
# XXX: hardcoded value from [slap-parameter]
285 286 287 288 289 290 291 292 293
{%   set nat_rule_list = slapparameter_dict.get('nat-rules', '22 80 443') %}
{%   for port in nat_rule_list.split(' ') -%}
{%     set external_port = 10000 + port|int() -%}
nat-rule-port-{{port}} = ${slap-network-information:global-ipv6} : {{external_port}}
{%     if slapparameter_dict.get('publish-nat-url', False) -%}
nat-rule-url-{{port}} = [${slap-network-information:global-ipv6}]:{{external_port}}
{%     endif -%}
{%   endfor -%}
{% endif -%}
294 295 296
{% if slapparameter_dict.get('use-tap', 'False') == 'True' -%}
tap-ipv4 = ${slap-network-information:tap-ipv4}
{% endif -%}
297 298 299 300 301 302 303

{% 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' -%}
{%     set kvm_http = 'http://10.0.2.100' -%}
{%   endif %}
{%   if slapparameter_dict.get('authorized-key', '') -%}
304
7_info = Get the publick key file in your VM with the command: wget {{ kvm_http }}/authorized_keys
305 306 307
{%   endif %}
{% endif %}

308 309
{% if slapparameter_dict.get('use-tap', 'False') == 'True' and tap_network_dict.has_key('ipv4') -%}
1_info = Use these configurations below to configure interface {{ iface }} in your VM.
310 311 312 313
2_info = ${network-config:ifconfig}
3_info = ${network-config:route-iface}
4_info = ${network-config:route-network}
5_info = ${network-config:route-default}
314 315 316
{% if enable_http == 'True' %}
6_info = Or run in your VM the command: wget -O- {{ kvm_http }}/netconfig.sh | /bin/sh -
{% endif %}
317 318 319 320 321 322 323

[network-config]
recipe = plone.recipe.command
path = ${directory:public}/netconfig.sh
ifconfig = ifconfig {{ iface }} ${slap-network-information:tap-ipv4} netmask ${slap-network-information:tap-netmask}
route-iface = route add ${slap-network-information:tap-gateway} dev {{ iface }}
route-network = route add -net ${slap-network-information:tap-network} netmask ${slap-network-information:tap-netmask} gw ${slap-network-information:tap-gateway}
324
{%   if iface == 'eth0' -%}
325
route-default = route add default gw ${slap-network-information:tap-gateway}
326
{%   elif global_ipv4_prefix -%}
327
route-default = ip route add {{ global_ipv4_prefix }} via ${slap-network-information:tap-gateway} dev {{ iface }} src ${slap-network-information:tap-ipv4}
328 329
{% else -%}
route-default =
330
{%   endif -%}
331 332 333 334 335 336 337
command = 
  echo "#!/bin/sh" > ${:path}
  echo "" >> ${:path}
  echo "${:ifconfig}" >> ${:path}
  echo "${:route-iface}" >> ${:path}
  echo "${:route-network}" >> ${:path}
  echo "${:route-default}" >> ${:path}
338
update-command = ${:command}
339
{% endif -%}
340

341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
{% macro writefile(section_name, file_path, content, mode='') -%}
{% 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 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') }}
356

357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
[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') -%}
local-ipv4 = ${slap-network-information:tap-ipv4}
{% else -%}
local-ipv4 = 127.0.0.1
{% endif -%}
path-host = ${directory:public}/hostname
path-ip = ${directory:public}/ipv4
command = 
  rm -f ${:path-host}
  rm -f ${:path-ip}
  echo "${:name}" > ${:path-host}
  echo "${:local-ipv4}" > ${:path-ip}
update-command = ${:command}

374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
# To access documents of main instance (in case of kvm-cluster) through http
[cluster-url-path]
recipe = slapos.recipe.template:jinja2
template = {{ template_content }}
filename = cluster.hash
rendered = ${directory:public}/${:filename}
hash-url = https://10.0.2.101:443/{{ slapparameter_dict.get('document-path', '') }}
context =
    key content_list :hash-url
    raw sep #

# This 6to4 tunnel help to access document url in ipv4
[tunnel-cluster-url]
recipe = slapos.cookbook:ipv4toipv6
ipv6 = {{ slapparameter_dict.get('document-host', '') }}
ipv4 = ${slap-network-information:local-ipv4}
ipv6-port = {{ slapparameter_dict.get('document-port', '') }}
ipv4-port = 16936
shell-path = {{ dash_executable_location }}
6tunnel-path = {{ sixtunnel_executable_location }}
runner-path = ${directory:services}/6tunnel-cluster

396 397 398 399 400
[slap-parameter]
# Default values if not specified
frontend-software-type = frontend
frontend-software-url = http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.92:/software/kvm/software.cfg
frontend-instance-guid =
401
frontend-instance-name = VNC Frontend
402 403 404 405 406 407 408 409 410 411
nbd-port = 1024
nbd-host =
nbd2-port = 1024
nbd2-host =

ram-size = 1024
disk-size = 10
disk-type = virtio

cpu-count = 1
412 413 414 415
# cpu-option is a string: [cores=cores][,threads=threads][,sockets=sockets][,maxcpus=maxcpus]
cpu-options = 
# list of numa options separate by space: node,nodeid=1,cpus=9-15 node,nodeid=2,cpus=1,3,7
numa = 
416 417

nat-rules = 22 80 443
418
use-nat = True
419 420 421 422
use-tap = False

virtual-hard-drive-url =
virtual-hard-drive-md5sum =
423
virtual-hard-drive-gzipped = False
424 425 426

external-disk-number = 0
external-disk-size = 20
427
external-disk-format = qcow2
428

429
# Help to get some configuration files into the vm from http
430 431
enable-http-server = False
httpd-port = 8081
432 433
# 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 = 
434 435 436

# send some content which will be accessible to the vm through static url: http://10.0.2.100/data
data-to-vm =