Commit e2387787 authored by Kristopher Ruzic's avatar Kristopher Ruzic

adds support for packer image creation, sets cpu type in kvm to host

parent bf6545aa
[buildout] [buildout]
parts = extends =
slap-configuration ../../stack/slapos.cfg
../../component/dash/buildout.cfg
parts +=
dash
dash-output
slapos-cookbook
packer packer
instance-profile
[slap-configuration]
recipe = slapos.cookbook:slapconfiguration
computer = $${slap_connection:computer_id}
partition = $${slap_connection:partition_id}
url = $${slap_connection:server_url}
key = $${slap_connection:key_file}
cert = $${slap_connection:cert_file}
[packer] [packer]
...@@ -37,12 +38,17 @@ script = ...@@ -37,12 +38,17 @@ script =
extract_dir = self.extract(self.download(url, md5sum)) extract_dir = self.extract(self.download(url, md5sum))
shutil.move(extract_dir, location) shutil.move(extract_dir, location)
[template-wrapper]
[packer-json-template] recipe = slapos.recipe.template
recipe = hexagonit.recipe.download url = ${:_profile_base_location_}/templates/wrapper.in
url = ${instance-parameter:configuration.packer_json} output = ${buildout:directory}/template-wrapper.cfg
destination = ${buildout:parts-directory} mode = 0644
filename = packer-template.json
#md5sum = 47d492dafe5cb314bdc49bf013d21ead [instance-profile]
download-only = true recipe = slapos.recipe.template
on-update = true url = ${:_profile_base_location_}/instance.cfg.in
\ No newline at end of file output = ${buildout:directory}/instance.cfg
#md5sum = 968bea0fc81dc604a874c53648b7d13f
mode = 0644
{
"variables": {
"user": "nexedi",
"password": "test",
"disk_size": ${disk-size},
"domain": ""
},
"builders":
[
{
"name": "blah",
"type": "qemu",
"format": "qcow2",
"accelerator": "kvm",
"disk_size": "{{ user `disk_size`}}",
"iso_url": "http://cdimage.debian.org/debian-cd/8.1.0/amd64/iso-cd/debian-8.1.0-amd64-netinst.iso",
"iso_checksum": "0b31bccccb048d20b551f70830bb7ad0",
"iso_checksum_type": "md5",
"http_directory": "http",
"ssh_username": "{{user `user`}}",
"ssh_password": "{{user `password`}}",
"shutdown_command": "echo '{{user `password`}}'|sudo -S shutdown -h now",
"boot_wait": "2s",
"boot_command": [
"<esc><wait><wait>",
"install auto ",
"preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg ",
"debian-installer=en_US locale=en_US keymap=us ",
"netcfg/get_hostname={{ .Name }} ",
"netcfg/get_domain={{ user `domain`}} ",
"fb=false debconf/frontend=noninteractive ",
"passwd/user-fullname={{user `user`}} ",
"passwd/user-password={{user `password`}} ",
"passwd/user-password-again={{user `password`}} ",
"passwd/username={{user `user`}} ",
"<enter>"
]
}
]
}
\ No newline at end of file
[buildout]
eggs-directory = ${buildout:eggs-directory}
develop-eggs-directory = ${buildout:develop-eggs-directory}
extends =
../../software/kvm/instance-kvm.cfg.jinja2
parts +=
packer-json-template
packer-build-template
kvm-instance
[directory]
recipe = slapos.cookbook:mkdirectory
etc = $${buildout:directory}/etc/
etc-run = $${:etc}/run
[jinja2-template-base]
recipe = slapos.recipe.template:jinja2
rendered = $${buildout:directory}/$${:filename}
extra-context =
context =
import json_module json
key eggs_directory buildout:eggs-directory
key develop_eggs_directory buildout:develop-eggs-directory
$${:extra-context}
[instance-parameter]
recipe = slapos.cookbook:slapconfiguration.serialised
computer = $${slap_connection:computer_id}
partition = $${slap_connection:partition_id}
url = $${slap_connection:server_url}
key = $${slap_connection:key_file}
cert = $${slap_connection:cert_file}
configuration.packer_json = ${:_profile_base_location_}/debian77.json.cfg
[packer-json-template]
recipe = slapos.recipe.template
url = $${instance-parameter:configuration.packer_json}
output = ${buildout:parts-directory}/packer-template.json
context =
key disk_size slap-parameter:disk-size
#destination = ${buildout:parts-directory}
#md5sum = 47d492dafe5cb314bdc49bf013d21ead
[packer-build-template]
< = jinja2-template-base
template = ${template-wrapper:output}
rendered = $${directory:etc-run}/packer-build
mode = 0700
extra-context =
key env packer-configuration:packer-environment
key content packer-configuration:packer-build-command
[packer-configuration]
packer-environment = ${buildout:parts-directory}/qemu/bin/
packer-build-command =
${buildout:parts-directory}/packer/packer build -debug -color=false $${packer-json-template:output} > testing.log
[kvm-instance]
disk-path = ${directory:srv}/virtual.qcow2
\ No newline at end of file
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
# BEWARE: This file is operated by slapgrid # BEWARE: This file is operated by slapgrid
# BEWARE: It will be overwritten automatically # BEWARE: It will be overwritten automatically
import ast
import hashlib import hashlib
import os import os
import socket import socket
...@@ -14,6 +15,7 @@ import glob ...@@ -14,6 +15,7 @@ import glob
import re import re
# XXX: give all of this through parameter, don't use this as template, but as module # XXX: give all of this through parameter, don't use this as template, but as module
# use_tap and use_nat set as Bool as per http://stackoverflow.com/a/922374
qemu_img_path = '%(qemu-img-path)s' qemu_img_path = '%(qemu-img-path)s'
qemu_path = '%(qemu-path)s' qemu_path = '%(qemu-path)s'
disk_size = '%(disk-size)s' disk_size = '%(disk-size)s'
...@@ -26,8 +28,8 @@ virtual_hard_drive_url = '%(virtual-hard-drive-url)s'.strip() ...@@ -26,8 +28,8 @@ virtual_hard_drive_url = '%(virtual-hard-drive-url)s'.strip()
virtual_hard_drive_md5sum = '%(virtual-hard-drive-md5sum)s'.strip() virtual_hard_drive_md5sum = '%(virtual-hard-drive-md5sum)s'.strip()
virtual_hard_drive_gzipped = '%(virtual-hard-drive-gzipped)s'.strip() virtual_hard_drive_gzipped = '%(virtual-hard-drive-gzipped)s'.strip()
nat_rules = '%(nat-rules)s'.strip() nat_rules = '%(nat-rules)s'.strip()
use_tap = '%(use-tap)s' use_tap = literal_eval('%(use-tap)s')
use_nat = '%(use-nat)s' use_nat = literal_eval('%(use-nat)s')
tap_interface = '%(tap-interface)s' tap_interface = '%(tap-interface)s'
listen_ip = '%(ipv4)s' listen_ip = '%(ipv4)s'
mac_address = '%(mac-address)s' mac_address = '%(mac-address)s'
...@@ -49,6 +51,7 @@ netcat_bin = '%(netcat-binary)s'.strip() ...@@ -49,6 +51,7 @@ netcat_bin = '%(netcat-binary)s'.strip()
cluster_doc_host = '%(cluster-doc-host)s' cluster_doc_host = '%(cluster-doc-host)s'
cluster_doc_port = %(cluster-doc-port)s cluster_doc_port = %(cluster-doc-port)s
def md5Checksum(file_path): def md5Checksum(file_path):
with open(file_path, 'rb') as fh: with open(file_path, 'rb') as fh:
m = hashlib.md5() m = hashlib.md5()
...@@ -115,7 +118,7 @@ def getMapStorageList(disk_storage_dict, external_disk_number): ...@@ -115,7 +118,7 @@ def getMapStorageList(disk_storage_dict, external_disk_number):
return id_list, external_disk_number return id_list, external_disk_number
# Download existing hard drive if needed at first boot # Download existing hard drive if needed at first boot
if not os.path.exists(disk_path) and virtual_hard_drive_url != '': if not (os.path.exists(disk_path) or os.path.exists(packer_path)) and virtual_hard_drive_url != '':
print('Downloading virtual hard drive...') print('Downloading virtual hard drive...')
try: try:
downloaded_disk = disk_path downloaded_disk = disk_path
...@@ -192,12 +195,11 @@ if disk_storage_dict: ...@@ -192,12 +195,11 @@ if disk_storage_dict:
# Generate network parameters # Generate network parameters
# XXX: use_tap should be a boolean
tap_network_parameter = [] tap_network_parameter = []
nat_network_parameter = [] nat_network_parameter = []
numa_parameter = [] numa_parameter = []
number = -1 number = -1
if use_nat == 'True': if use_nat:
number += 1 number += 1
rules = 'user,id=lan%%s,' %% number + ','.join('hostfwd=tcp:%%s:%%s-:%%s' %% (listen_ip, rules = 'user,id=lan%%s,' %% number + ','.join('hostfwd=tcp:%%s:%%s-:%%s' %% (listen_ip,
int(port) + 10000, port) for port in nat_rules.split()) int(port) + 10000, port) for port in nat_rules.split())
...@@ -209,7 +211,7 @@ if use_nat == 'True': ...@@ -209,7 +211,7 @@ if use_nat == 'True':
cluster_doc_host, cluster_doc_port) cluster_doc_host, cluster_doc_port)
nat_network_parameter = ['-netdev', rules, nat_network_parameter = ['-netdev', rules,
'-device', 'e1000,netdev=lan%%s,mac=%%s' %% (number, mac_address)] '-device', 'e1000,netdev=lan%%s,mac=%%s' %% (number, mac_address)]
if use_tap == 'True': if use_tap:
number += 1 number += 1
tap_network_parameter = ['-netdev', tap_network_parameter = ['-netdev',
'tap,id=lan%%s,ifname=%%s,script=no,downscript=no' %% (number, 'tap,id=lan%%s,ifname=%%s,script=no,downscript=no' %% (number,
...@@ -222,13 +224,14 @@ if smp_options: ...@@ -222,13 +224,14 @@ if smp_options:
key, val = option.split('=') key, val = option.split('=')
if key in ('cores', 'threads', 'sockets', 'maxcpus') and val.isdigit(): if key in ('cores', 'threads', 'sockets', 'maxcpus') and val.isdigit():
smp += ',%%s=%%s' %% (key, val) smp += ',%%s=%%s' %% (key, val)
kvm_argument_list = [qemu_path,
'-enable-kvm', '-smp', smp, kvm_argument_list += [ qemu_path,
'-m', ram_size, '-vga', 'std', '-enable-kvm', '-smp', smp, '-m', ram_size,
'-drive', 'file=%%s,if=%%s' %% (disk_path, disk_type), '-drive', 'file=%%s,if=%%s' %% (disk_path, disk_type),
'-vnc', '%%s:1,ipv4,password' %% listen_ip, '-vnc', '%%s:1,ipv4,password' %% listen_ip,
'-boot', 'order=cd,menu=on', '-boot', 'order=cd,menu=on',
'-qmp', 'unix:%%s,server' %% socket_path, '-qmp', 'unix:%%s,server' %% socket_path,
'-vga', 'std', '-cpu', 'host',
'-pidfile', pid_file_path, '-pidfile', pid_file_path,
] ]
......
[packer-build]
recipe = slapos.cookbook:wrapper
command-line =
packer build
${buildout:parts-directory}/${packer-json-template:filename}
\ 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