Commit 0d1ef902 authored by Kristopher Ruzic's avatar Kristopher Ruzic

Merge branch 'master' of https://lab.nexedi.cn/krruzic/slapos into HEAD

parents d63d9acd 626ba923
[buildout]
extends =
../../stack/slapos.cfg
../../component/dash/buildout.cfg
parts +=
dash
dash-output
slapos-cookbook
packer
instance-profile
[packer]
recipe = slapos.recipe.build
# here, two %s are used, first one is for directory name (eg. x86_64), and second one is for filename (eg. x86-64).
url_x86-64 = https://dl.bintray.com/mitchellh/packer/packer_0.7.5_linux_amd64.zip
url_x86 = https://dl.bintray.com/mitchellh/packer/packer_0.7.5_linux_386.zip
# supported architectures md5sums
md5sum_x86 = a545108a0ccfde7c1e74de6c4e6fdded
md5sum_x86-64 = f343d709b84db494e8d6ec38259aa4a6
# script to install.
script =
location = %(location)r
self.failIfPathExists(location)
import sys
ARCH_DIR_MAP = { 'x86': 'x86', 'x86-64': 'x86_64' }
WK_SUFIX_MAP = { 'x86': '386', 'x86-64': 'amd64' }
platform = guessPlatform()
url = self.options['url_' + platform]
md5sum = self.options['md5sum_' + platform]
extract_dir = self.extract(self.download(url, md5sum))
shutil.move(extract_dir, location)
[template-wrapper]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/templates/wrapper.in
output = ${buildout:directory}/template-wrapper.cfg
mode = 0644
[instance-profile]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/instance.cfg.in
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.jinja2
[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 @@
# BEWARE: This file is operated by slapgrid
# BEWARE: It will be overwritten automatically
import ast
import hashlib
import os
import socket
......@@ -14,6 +15,7 @@ import glob
import re
# 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_path = '%(qemu-path)s'
disk_size = '%(disk-size)s'
......@@ -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_gzipped = '%(virtual-hard-drive-gzipped)s'.strip()
nat_rules = '%(nat-rules)s'.strip()
use_tap = '%(use-tap)s'
use_nat = '%(use-nat)s'
use_tap = literal_eval('%(use-tap)s')
use_nat = literal_eval('%(use-nat)s')
tap_interface = '%(tap-interface)s'
listen_ip = '%(ipv4)s'
mac_address = '%(mac-address)s'
......@@ -49,6 +51,7 @@ netcat_bin = '%(netcat-binary)s'.strip()
cluster_doc_host = '%(cluster-doc-host)s'
cluster_doc_port = %(cluster-doc-port)s
def md5Checksum(file_path):
with open(file_path, 'rb') as fh:
m = hashlib.md5()
......@@ -115,7 +118,7 @@ def getMapStorageList(disk_storage_dict, external_disk_number):
return id_list, external_disk_number
# 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...')
try:
downloaded_disk = disk_path
......@@ -192,12 +195,11 @@ if disk_storage_dict:
# Generate network parameters
# XXX: use_tap should be a boolean
tap_network_parameter = []
nat_network_parameter = []
numa_parameter = []
number = -1
if use_nat == 'True':
if use_nat:
number += 1
rules = 'user,id=lan%%s,' %% number + ','.join('hostfwd=tcp:%%s:%%s-:%%s' %% (listen_ip,
int(port) + 10000, port) for port in nat_rules.split())
......@@ -209,7 +211,7 @@ if use_nat == 'True':
cluster_doc_host, cluster_doc_port)
nat_network_parameter = ['-netdev', rules,
'-device', 'e1000,netdev=lan%%s,mac=%%s' %% (number, mac_address)]
if use_tap == 'True':
if use_tap:
number += 1
tap_network_parameter = ['-netdev',
'tap,id=lan%%s,ifname=%%s,script=no,downscript=no' %% (number,
......@@ -222,13 +224,14 @@ if smp_options:
key, val = option.split('=')
if key in ('cores', 'threads', 'sockets', 'maxcpus') and val.isdigit():
smp += ',%%s=%%s' %% (key, val)
kvm_argument_list = [qemu_path,
'-enable-kvm', '-smp', smp,
'-m', ram_size, '-vga', 'std',
kvm_argument_list += [ qemu_path,
'-enable-kvm', '-smp', smp, '-m', ram_size,
'-drive', 'file=%%s,if=%%s' %% (disk_path, disk_type),
'-vnc', '%%s:1,ipv4,password' %% listen_ip,
'-boot', 'order=cd,menu=on',
'-qmp', 'unix:%%s,server' %% socket_path,
'-vga', 'std', '-cpu', 'host',
'-pidfile', pid_file_path,
]
......
......@@ -4,6 +4,14 @@
"title": "Input Parameters",
"properties": {
"packer_json": {
"title": "KVM packer JSON",
"description": "The json file describing what image to build",
"type": "string",
"format": "uri",
"default": "http://lab.nexedi.cn/krruzic/test-repository/packer-debian-schema.json",
"enum": ["http://lab.nexedi.cn/krruzic/test-repository/packer-debian-schema.json"]
},
"ram-size": {
"title": "RAM size",
"description": "RAM size, in MB.",
......@@ -76,7 +84,6 @@
"minimum": 1,
"maximum": 65535
},
"virtual-hard-drive-url": {
"title": "Existing disk image URL",
"description": "If specified, will download an existing disk image (qcow2, raw, ...), and will use it as main virtual hard drive. Can be used to download and use an already installed and customized virtual hard drive.",
......@@ -94,7 +101,7 @@
"type": "boolean",
"default": false
},
"external-disk-number": {
"title": "Number of additional disk to create for virtual machine",
"description": "Specify the number of additional disk to create for virtual machine in data folder of SlapOS Node. Requires instance_storage_home to be configured on SlapOS Node.",
......
[buildout]
extends =
../../stack/slapos.cfg
../../component/qemu-kvm/buildout.cfg
../../component/packer/buildout.cfg
parts +=
qemu
\ 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