Commit efd9ed30 authored by Kristopher Ruzic's avatar Kristopher Ruzic

starts merge of kvm and packer by defining packer as software_type

modifies the kvm recipe to take packer specific parameters, this is done so the json file packer relies on can be generated at runtime
parent 13ed0f14
......@@ -14,8 +14,52 @@ from random import shuffle
import glob
import re
if '%{is-packer}s':
packer_dict = {}
packer_dict["disk_size"] = '%(disk-size)s'
packer_dict["type"] = 'qemu'
packer_dict["headless"] = True
# iso url and md5 are hardcoded for now
packer_dict["iso_url"] = "http://cdimage.debian.org/debian-cd/8.1.0/amd64/iso-cd/debian-8.1.0-amd64-netinst.iso"
packer_dict["iso_checksum"] = "1a311f9afb68d6365211b13b4342c40b"
packer_dict["iso_checksum_type"] = "md5"
# set basic params
packer_dict["name"] = '%(packer-name)s'
packer_dict["accelerator"] = "kvm" # explicitly set
packer_dict["http_directory"] = "http"
# ssh params (will create account on install)
packer_dict["ssh_username"] = '%(packer-username)s'
packer_dict["ssh_password"] = '%(packer-password)s'
# boot parameters
packer_dict["boot_wait"] = "2s" # warm up
# runs through install
packer_dict["boot_command"] = [
"<esc><wait><wait>",
"install auto ",
"debian-installer=en_US locale=en_US keymap=us ",
"netcfg/get_hostname=%(packer-hostname)s",
"netcfg/get_domain=%(packer-domain)s",
"fb=false debconf/frontend=noninteractive ",
"passwd/user-fullname=%(packer-username)s",
"passwd/user-password=%(packer-password)s",
"passwd/user-password-again=%(packer-password)s",
"passwd/username=%(packer-username)s",
"<enter>"
]
# 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
software_type = '%(kvm-software-type)s'
qemu_img_path = '%(qemu-img-path)s'
qemu_path = '%(qemu-path)s'
disk_size = '%(disk-size)s'
......@@ -28,8 +72,8 @@ virtual_hard_drive_url = '%(virtual-hard-drive-url)s'.strip()
virtual_hard_drive_md5sum = '%(virtual-hard-drive-md5sum)s'.strip()
virtual_hard_drive_gzipped = '%(virtual-hard-drive-gzipped)s'.strip()
nat_rules = '%(nat-rules)s'.strip()
use_tap = literal_eval('%(use-tap)s')
use_nat = literal_eval('%(use-nat)s')
use_tap = ast.literal_eval('%(use-tap)s')
use_nat = ast.literal_eval('%(use-nat)s')
tap_interface = '%(tap-interface)s'
listen_ip = '%(ipv4)s'
mac_address = '%(mac-address)s'
......@@ -51,7 +95,21 @@ netcat_bin = '%(netcat-binary)s'.strip()
cluster_doc_host = '%(cluster-doc-host)s'
cluster_doc_port = %(cluster-doc-port)s
def gen_packer_json(build):
import json
packer_json = {"builders": [build]}
with open(instance_dir + "/packer.json", 'w') as outfile:
json.dump(packer_json, outfile)
# takes a list and turns it 2D
# needed as kvm is using a flat args list
# but packer needs 2D
# ['-m', '1024', '-vga', 'std']
# goes to:
# [['-m', '1024'], ['-vga', 'std']]
def widen(l):
return zip(l[::2], l[1::2])
def md5Checksum(file_path):
with open(file_path, 'rb') as fh:
m = hashlib.md5()
......@@ -269,5 +327,15 @@ else:
'-drive', 'file=%%s,media=cdrom' %% default_disk_image
])
print 'Starting KVM: \n %%s' %% ' '.join(kvm_argument_list)
os.execv(qemu_path, kvm_argument_list)
# if the software release type was defined as packer
# we need to do a bit more work
if '%{is-packer}s':
packer_dict["qemuargs"] = filter(None, widen(kvm_argument_list))
print 'Generating Packer json with qemu args: '
print packer_dict["qemuargs"]
gen_packer_json(packer_dict)
else:
print 'Starting KVM: \n %%s' %% ' '.join(kvm_argument_list)
os.execv(qemu_path, kvm_argument_list)
......@@ -123,6 +123,14 @@ mode = 0644
download-only = true
on-update = true
[template-kvm-packer]
recipe = hexagonit.recipe.download
url = ${:_profile_base_location_}/instance-kvm-packer.cfg.jinja2
#md5sum = 3e3354844b2052609e3c49eca03b607e
mode = 0644
download-only = true
on-update = true
[template-kvm-import]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/instance-kvm-import.cfg.in
......
This diff is collapsed.
......@@ -10,6 +10,8 @@ recipe = slapos.cookbook:softwaretype
default = $${:kvm}
kvm-cluster = $${dynamic-template-kvm-cluster:rendered}
kvm = $${dynamic-template-kvm:rendered}
packer = ${dynamic-template-packer:rendered}
nbd = ${template-nbd:output}
frontend = ${template-frontend:output}
......@@ -37,7 +39,6 @@ partition = $${slap-connection:partition-id}
url = $${slap-connection:server-url}
key = $${slap-connection:key-file}
cert = $${slap-connection:cert-file}
storage-home = $${storage-configuration:storage-home}
[jinja2-template-base]
recipe = slapos.recipe.template:jinja2
......@@ -139,3 +140,35 @@ context =
key slapparameter_dict slap-configuration:configuration
raw bin_directory ${buildout:bin-directory}
mode = 0644
[dynamic-template-packer]
recipe = slapos.recipe.template:jinja2
template = ${template-kvm-packer:location}/instance-kvm-packer.cfg.jinja2
rendered = $${buildout:directory}/template-kvm-packer.cfg
extensions = jinja2.ext.do
context =
key develop_eggs_directory buildout:develop-eggs-directory
key eggs_directory buildout:eggs-directory
key global_ipv4_prefix network-information:global-ipv4-network
key slapparameter_dict slap-configuration:configuration
key storage_dict slap-configuration:storage-dict
key tap_network_dict slap-configuration:tap-network-information-dict
raw curl_executable_location ${curl:location}/bin/curl
raw dash_executable_location ${dash:location}/bin/dash
raw dcron_executable_location ${dcron:location}/sbin/crond
raw debian_amd64_netinst_location ${debian-amd64-netinst.iso:location}/${debian-amd64-netinst.iso:filename}
raw novnc_location ${noVNC:location}
raw netcat_bin ${netcat:location}/bin/netcat
raw openssl_executable_location ${openssl:location}/bin/openssl
raw qemu_executable_location ${kvm:location}/bin/qemu-system-x86_64
raw qemu_img_executable_location ${kvm:location}/bin/qemu-img
raw sixtunnel_executable_location ${6tunnel:location}/bin/6tunnel
raw template_httpd_cfg ${template-httpd:rendered}
raw template_content ${template-content:location}/${template-content:filename}
raw websockify_executable_location ${buildout:directory}/bin/websockify
template-parts-destination = ${template-parts:destination}
template-replicated-destination = ${template-replicated:destination}
import-list = file parts :template-parts-destination
file replicated :template-replicated-destination
mode = 0644
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