KVM SR: add virtual-hard-drive-url support.

parent 627895fe
......@@ -63,6 +63,7 @@ class Recipe(GenericBaseRecipe):
qemu_img_path=self.options['qemu-img-path'],
vnc_passwd=self.options['passwd'],
default_disk_image=self.options['default-disk-image'],
virtual_hard_drive_url=self.options['virtual-hard-drive-url'],
)
path_list = []
......
......@@ -2,13 +2,21 @@
# BEWARE: This file is operated by slapgrid
# BEWARE: It will be overwritten automatically
# Echo client program
import hashlib
import os
import socket
import subprocess
import urllib
# XXX: give all of this through parameter, don't use this as template
default_disk_image = '%(default_disk_image)s'
def md5Checksum(file_path):
with open(file_path, 'rb') as fh:
m = hashlib.md5()
while True:
data = fh.read(8192)
if not data:
break
m.update(data)
return m.hexdigest()
def getSocketStatus(host, port):
s = None
......@@ -29,9 +37,23 @@ def getSocketStatus(host, port):
break
return s
# XXX: give all of this through parameter, don't use this as template
default_disk_image = '%(default_disk_image)s'
disk_path = '%(disk_path)s'
virtual_hard_drive_url = '%(virtual_hard_drive_url)s'.strip()
virtual_hard_drive_md5_url = '%(virtual_hard_drive_md5_url)s'.strip()
# Download existing hard drive if needed at first boot
if not os.path.exists(disk_path) and virtual_hard_drive_url != '':
urllib.urlretrieve(virtual_hard_drive_url, disk_path)
local_md5sum = md5Checksum(disk_path)
md5sum = urllib.urlopen(virtual_hard_drive_md5_url).read().strip()
if local_md5sum != md5sum:
os.remove(disk_path)
raise Exception('MD5 mismatch.')
# Create disk if doesn't exist
# XXX: move to Buildout profile
disk_path = '%(disk_path)s'
if not os.path.exists(disk_path):
subprocess.Popen(['%(qemu_img_path)s', 'create' ,'-f', 'qcow2',
disk_path, '%(disk_size)sG'])
......
......@@ -6,6 +6,7 @@
import os
import socket
import subprocess
import urllib
def getSocketStatus(host, port):
s = None
......@@ -29,9 +30,14 @@ def getSocketStatus(host, port):
# XXX: give all of this through parameter, don't use this as template
default_disk_image = '%(default_disk_image)s'
virtual_hard_drive_url = '%(virtual_hard_drive_url)s'
disk_path = '%(disk_path)s'
# Download existing hard drive if needed
if virtual_hard_drive_url != '':
urllib.urlretrieve(virtual_hard_drive_url, disk_path)
# create disk if doesn't exist
disk_path = '%(disk_path)s'
if not os.path.exists(disk_path):
subprocess.Popen(['%(qemu_img_path)s', 'create' ,'-f', 'qcow2',
disk_path, '%(disk_size)sG'])
......
......@@ -85,7 +85,7 @@ mode = 0644
[template-kvm]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/instance-kvm.cfg.in
md5sum = c3c888c78bbff334135be9e8ad5885a9
#md5sum = c3c888c78bbff334135be9e8ad5885a9
output = ${buildout:directory}/template-kvm.cfg
mode = 0644
......
......@@ -37,7 +37,6 @@
"maximum": 8
},
"nbd-host": {
"title": "NBD hostname",
"description": "hostname (or IP) of the NBD server containing the boot image.",
......@@ -68,6 +67,13 @@
"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.",
"format": "uri",
"type": "string",
},
"use-tap": {
"title": "Use QEMU TAP network interface",
"description": "Use QEMU TAP network interface, requires a bridge on SlapOS Node. If false, use user-mode network stack (NAT).",
......
......@@ -45,38 +45,56 @@ recipe = slapos.cookbook:generate.password
storage-path = $${directory:srv}/passwd
bytes = 8
[kvm-instance]
# XXX-Cedric: change "KVM" recipe to simple "create wrappers". No need for this
# Specific code
# Specific code. It needs Jinja.
recipe = slapos.cookbook:kvm
# XXX-Cedric: should be removed and replaced
vnc-ip = $${slap-network-information:local-ipv4}
passwd = $${gen-passwd:passwd}
ipv4 = $${slap-network-information:local-ipv4}
ipv6 = $${slap-network-information:global-ipv6}
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 = $${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-path = $${directory:run}/pid_file
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
use-tap = $${slap-parameter:use-tap}
nat-rules = $${slap-parameter:nat-rules}
6tunnel-wrapper-path = $${directory:services}/6tunnel
virtual-hard-drive-url = $${slap-parameter:virtual-hard-drive-url}
shell-path = ${dash:location}/bin/dash
qemu-path = ${kvm:location}/bin/qemu-system-x86_64
qemu-img-path = ${kvm:location}/bin/qemu-img
passwd = $${gen-passwd:passwd}
6tunnel-path = ${6tunnel:location}/bin/6tunnel
6tunnel-wrapper-path = $${directory:services}/6tunnel
[kvm-promise]
recipe = slapos.cookbook:check_port_listening
......@@ -224,3 +242,5 @@ cpu-count = 1
nat-rules = 22 80 443
use-tap = False
virtual-hard-drive-url =
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