#############################
#
# Instanciate kvm
#
#############################
[buildout]
parts =
  certificate-authority
  kvm-instance
  websockify-sighandler
  kvm-promise
  novnc-promise
  request-openstack-frontend
  nova-install
#  openstack-frontend-promise
  frontend-promise
  publish-kvm-connection-information

eggs-directory = ${buildout:eggs-directory}
develop-eggs-directory = ${buildout: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
scripts = $${:etc}/run
services = $${:etc}/service
promises = $${:etc}/promise
novnc-conf = $${:etc}/novnc
run = $${:var}/run
ca-dir = $${:srv}/ssl
nova = $${:bin}/nova
log = $${:var}/log

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

[gen-passwd]
recipe = slapos.cookbook:generate.password
storage-path = $${directory:srv}/passwd
bytes = 8

[master-passwd]
recipe = slapos.cookbook:generate.password
storage-path = $${directory:srv}/openstack.passwd
bytes = 8

[kvm-instance]
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.iso:location}/${debian-amd64-netinst.iso:filename}
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}/kvm_run.pid

smp-count = $${slap-parameter:cpu-count}
ram-size = $${slap-parameter:ram-size}
mac-address = $${create-mac:mac-address}

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

ssh-port = 22222
use-tap = False
nat-rules = 22:$${:ssh-port} 80:$${tunnel-http:port} 443:$${tunnel-http:port-https} 5000:5000 6080:$${tunnel-http:port-vnc} 6082:6082 3333:3333 9292:9292 9696:9696 3306:3306 35357:35357
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}

shell-path = ${dash:location}/bin/dash
qemu-path = ${kvm:location}/bin/qemu-system-x86_64
qemu-img-path = ${kvm:location}/bin/qemu-img
6tunnel-path = ${6tunnel:location}/bin/6tunnel

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

[tunnel-ipv6-base]
recipe = slapos.cookbook:ipv6toipv4
ipv6 = $${slap-network-information:global-ipv6}
ipv4 = $${slap-network-information:local-ipv4}
shell-path = ${dash:location}/bin/dash
6tunnel-path = ${6tunnel:location}/bin/6tunnel

[install-script]
recipe = slapos.recipe.template
url = ${openstack-grizzly:location}/${openstack-grizzly:filename}
output = $${directory:nova}/stack_controller_grizzly.sh
mode = 0700

#nova-url = https://github.com/openstack-dev/devstack.git
image-url = $${slap-parameter:glance-image-url}
image-name = $${slap-parameter:glance-image-name}
slap-ipv4 = $${slap-network-information:local-ipv4}
nova-passwd = $${master-passwd:passwd}
nova-user = $${slap-parameter:system-user}
vnc-url = $${request-openstack-vnc-frontend:connection-url}
project = $${slap-parameter:project}
user-name = $${slap-parameter:user-name}

[nova-conf-run]
recipe = slapos.recipe.template
url = ${compute-script-run:location}/${compute-script-run:filename}
output = $${directory:nova}/nova_configure.py
mode = 0700

host-ip = $${tunnel-ipv6-ssh:ipv6}
ssh-port = $${tunnel-ipv6-ssh:ipv6-port}
system-user = $${slap-parameter:system-user}
system-passwd = $${slap-parameter:system-passwd}
nova-configure = $${install-script:output}
keystone-endpoints-script = ${openstack-keystone-endpoints-script:location}/${openstack-keystone-endpoints-script:filename}
keystone-script = ${openstack-keystone-script:location}/${openstack-keystone-script:filename}
floating-ip-generate = ${network-floating-ip-generate:location}/${network-floating-ip-generate:filename}
nova-result = $${directory:log}
python_path = ${buildout:executable}
eggs-dir = ${buildout:eggs-directory}
instance = manage

[nova-install]
recipe = slapos.cookbook:wrapper
command-line = $${nova-conf-run:output}
wrapper-path = $${directory:scripts}/openstack-install

######################################################################
### PREDEFINED PORT AND HOST FOR SSH ACCESS TO OPENSTACK COMPUTER ####
[tunnel-ipv6-ssh]
ipv6-port = $${kvm-instance:ssh-port}
ipv4-port = $${kvm-instance:ssh-port}
ipv6 = $${slap-network-information:global-ipv6}
ipv4 = $${slap-network-information:local-ipv4}

##########################################################
### PREDEFINED PORT AND HOST FOR NOVA HORIZON SERVICE ####
[tunnel-http]
host = $${slap-network-information:global-ipv6}
port = 8080
port-https = 4443
port-vnc = 6080

##########################################################

[novnc-instance]
recipe = slapos.cookbook:novnc
path = $${ca-novnc:executable}
ip = $${slap-network-information:global-ipv6}
port = 6090
vnc-ip = $${kvm-instance:vnc-ip}
vnc-port = $${kvm-instance:vnc-port}
novnc-location = ${noVNC:location}
websockify-path = ${buildout:directory}/bin/websockify
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:location}/bin/openssl
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}


[kvm-monitor]
recipe = slapos.cookbook:generic.slapmonitor
db-path = $${directory:srv}/slapmonitor_database


[request-slave-frontend]
recipe = slapos.cookbook:requestoptional
software-url = $${slap-parameter:kvm-frontend-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}
name = VNC Frontend
software-type = $${slap-parameter:frontend-software-type}
slave = true
config = host port
config-host = $${novnc-instance:ip}
config-port = $${novnc-instance:port}
return = url resource port domainname
sla = instance_guid
sla-instance_guid = $${slap-parameter:frontend-instance-guid}

[request-openstack-vnc-frontend]
recipe = slapos.cookbook:requestoptional
software-url = $${slap-parameter:kvm-frontend-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}
name = OpenStack VNC Frontend
software-type = $${slap-parameter:frontend-software-type}
slave = true
config = host port
config-host = $${slap-network-information:global-ipv6}
config-port = $${tunnel-http:port-vnc}
return = url resource port domainname
sla = instance_guid
sla-instance_guid = $${slap-parameter:frontend-instance-guid}

[request-openstack-frontend]
<= slap-connection
recipe = slapos.cookbook:requestoptional
name = Frontend OpenStack
# XXX We have hardcoded SR URL here.
software-url = $${slap-parameter:frontend-software-url}
slave = true
config = url custom_domain
config-url = http://[$${tunnel-http:host}]:$${tunnel-http:port}/
return = site_url
config-custom_domain = $${slap-parameter:domain}

[publish-kvm-connection-information]
recipe = slapos.cookbook:publish
vnc-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}
vnc-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}
ssh = ssh stack@$${tunnel-ipv6-ssh:ipv6} -p $${tunnel-ipv6-ssh:ipv6-port}
ssh-defaul-passwd = openstack
openstack-services-passwd = $${master-passwd:passwd}
openstack-url = $${request-openstack-frontend:connection-site_url}
openstack-vnc = $${request-openstack-vnc-frontend:connection-url}/vnc_auto.html
openstack-services-host = $${slap-network-information:global-ipv6}

[frontend-promise]
recipe = slapos.cookbook:check_url_available
path = $${directory:promises}/frontend_promise
url = $${publish-kvm-connection-information:vnc-url}
dash_path = ${dash:location}/bin/dash
curl_path = ${curl:location}/bin/curl
openstack-url = $${publish-kvm-connection-information:openstack-url}
openstack-vnc = $${publish-kvm-connection-information:openstack-vnc}/vnc_auto.html

[openstack-frontend-promise]
recipe = slapos.cookbook:check_url_available
path = $${directory:promises}/openstack_frontend
url = $${request-openstack-frontend:connection-site_url}
dash_path = ${dash:location}/bin/dash
curl_path = ${curl:location}/bin/curl
match = OpenStack


[slap-parameter]
# Default values if not specified
frontend-software-type = frontend
kvm-frontend-url = http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.92:/software/kvm/software.cfg
frontend-software-url = http://git.erp5.org/gitweb/slapos.git/blob_plain/HEAD:/software/apache-frontend/software.cfg
frontend-instance-guid =

ram-size = 2048
disk-size = 20
disk-type = virtio
virtual-hard-drive-url =
virtual-hard-drive-md5sum =

cpu-count = 4
nbd-port = 1024
nbd-host = 2001:470:1f14:169:dd6b:3f84:9205:c750
nbd2-port = 1024
nbd2-host =
  
system-user = stack
system-passwd = openstack
project = slapos
user-name = slapos
glance-image-url = http://download.cirros-cloud.net/0.3.1/cirros-0.3.1-x86_64-disk.img
glance-image-name = cirros-0.3.1-x86_64

domain =
virtual-hard-drive-url =
virtual-hard-drive-md5sum =

#Using devstack to auto install openstack. We just specify here the commit to use
#devstack-revision =