Blame view

software/kvm/instance-kvm-cluster.cfg.jinja2.in 6.72 KB
Alain Takoudjou committed
1 2
{% set publish_dict = {} -%}
{% set frontend_dict = slapparameter_dict.get('frontend', {}) -%}
Alain Takoudjou committed
3 4 5 6 7
{% set slave_frontend_dict = slapparameter_dict.get('slave-frontend', {}) -%}
{% 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') -%}
{% set slave_frontend_stype = slave_frontend_dict.get('software-type', 'default') -%}
{% set slave_frontend_iguid = slave_frontend_dict.get('instance-guid', '') -%}
{% set kvm_instance_dict = {} -%}
Alain Takoudjou committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21

[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 -%}
Alain Takoudjou committed
22
{% set use_nat = kvm_parameter_dict.get('use-nat', True) -%}
Alain Takoudjou committed
23 24 25 26
[{{ section }}]
<= request-common
software-type = kvm
name = {{ instance_name }}
Alain Takoudjou committed
27
sla-computer_guid = {{ dumps(kvm_parameter_dict.get('computer-guid', '')) }}
Alain Takoudjou committed
28

Alain Takoudjou committed
29
config-frontend-instance-name = {{ instance_name ~ ' VNC Frontend' }}
Alain Takoudjou committed
30 31 32 33 34 35 36 37 38 39 40
config-frontend-software-type = {{ dumps(frontend_dict.get('software-type', 'frontend')) }}
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-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)) }}
Alain Takoudjou committed
41 42
config-cpu-options = {{ dumps(kvm_parameter_dict.get('cpu-options', '')) }}
config-numa = {{ dumps(kvm_parameter_dict.get('numa', '')) }}
Alain Takoudjou committed
43 44 45

{% set nat_rules_list = kvm_parameter_dict.get('nat-rules', [22, 80, 443]) -%}
config-nat-rules = {{ nat_rules_list | join(' ') }}
Alain Takoudjou committed
46 47
config-publish-nat-url = True
config-use-nat = {{ use_nat }}
Alain Takoudjou committed
48
config-use-tap = {{ dumps(kvm_parameter_dict.get('use-tap', True)) }}
Alain Takoudjou committed
49 50 51
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)) }}
Alain Takoudjou committed
52 53
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)) }}
Alain Takoudjou committed
54
config-external-disk-format = {{ dumps(kvm_parameter_dict.get('external-disk-format', 'qcow2')) }}
Alain Takoudjou committed
55 56 57
config-enable-http-server = {{ dumps(kvm_parameter_dict.get('enable-http-server', True)) }}
config-httpd-port = {{ dumps(kvm_parameter_dict.get('httpd-port', 8081)) }}

Alain Takoudjou committed
58 59 60
return = 
  backend-url
  url
Alain Takoudjou committed
61 62 63 64 65
{% if use_nat -%}
{%   for port in nat_rules_list -%}
{{ '  ' }}nat-rule-url-{{ port }}
{%   endfor -%}
{% endif -%}
Alain Takoudjou committed
66 67 68 69 70
{% if kvm_parameter_dict.get('use-tap', True) -%}
{{ '  ' }}tap-ipv4

{% do publish_dict.__setitem__('lan-' ~ instance_name, '${' ~ section ~ ':connection-tap-ipv4}') -%}
{% endif -%}
Alain Takoudjou committed
71 72
{% do publish_dict.__setitem__(instance_name ~ '-backend-url', '${' ~ section ~ ':connection-backend-url}') -%}
{% do publish_dict.__setitem__(instance_name ~ '-url', '${' ~ section ~ ':connection-url}') -%}
Alain Takoudjou committed
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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
{% do kvm_instance_dict.__setitem__(instance_name, (kvm_parameter_dict.get('use-nat', True), nat_rules_list)) -%}
{% 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'] -%}
{%     set service_port = frontend_parameter_dict['service-port'] -%}
{%     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 }}
config-domain = {{ dumps(frontend_parameter_dict.get('domain', '')) }}
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 -%}
Alain Takoudjou committed
119 120 121 122 123 124 125
{% endfor %}

[publish]
recipe = slapos.cookbook:publish
{% for name, value in publish_dict.items() -%}
{{   name }} = {{ value }}
{% endfor %}
Alain Takoudjou committed
126
{% set disk_number = len(storage_dict) -%}
Alain Takoudjou committed
127
{% if disk_number > 0 -%}
Alain Takoudjou committed
128
1_info = It is possible to mount up to {{ disk_number }} external disk to your virtual machine. See parameter 'external-disk-number'
Alain Takoudjou committed
129
{% endif %}
Alain Takoudjou committed
130 131 132 133 134 135
[buildout]
parts = publish

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