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

parent 627895fe
...@@ -63,6 +63,7 @@ class Recipe(GenericBaseRecipe): ...@@ -63,6 +63,7 @@ class Recipe(GenericBaseRecipe):
qemu_img_path=self.options['qemu-img-path'], qemu_img_path=self.options['qemu-img-path'],
vnc_passwd=self.options['passwd'], vnc_passwd=self.options['passwd'],
default_disk_image=self.options['default-disk-image'], default_disk_image=self.options['default-disk-image'],
virtual_hard_drive_url=self.options['virtual-hard-drive-url'],
) )
path_list = [] path_list = []
......
...@@ -2,13 +2,21 @@ ...@@ -2,13 +2,21 @@
# 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
# Echo client program import hashlib
import os import os
import socket import socket
import subprocess import subprocess
import urllib
# XXX: give all of this through parameter, don't use this as template def md5Checksum(file_path):
default_disk_image = '%(default_disk_image)s' 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): def getSocketStatus(host, port):
s = None s = None
...@@ -29,9 +37,23 @@ def getSocketStatus(host, port): ...@@ -29,9 +37,23 @@ def getSocketStatus(host, port):
break break
return s 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 # Create disk if doesn't exist
# XXX: move to Buildout profile # XXX: move to Buildout profile
disk_path = '%(disk_path)s'
if not os.path.exists(disk_path): if not os.path.exists(disk_path):
subprocess.Popen(['%(qemu_img_path)s', 'create' ,'-f', 'qcow2', subprocess.Popen(['%(qemu_img_path)s', 'create' ,'-f', 'qcow2',
disk_path, '%(disk_size)sG']) disk_path, '%(disk_size)sG'])
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
import os import os
import socket import socket
import subprocess import subprocess
import urllib
def getSocketStatus(host, port): def getSocketStatus(host, port):
s = None s = None
...@@ -29,9 +30,14 @@ def getSocketStatus(host, port): ...@@ -29,9 +30,14 @@ def getSocketStatus(host, port):
# XXX: give all of this through parameter, don't use this as template # XXX: give all of this through parameter, don't use this as template
default_disk_image = '%(default_disk_image)s' 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 # create disk if doesn't exist
disk_path = '%(disk_path)s'
if not os.path.exists(disk_path): if not os.path.exists(disk_path):
subprocess.Popen(['%(qemu_img_path)s', 'create' ,'-f', 'qcow2', subprocess.Popen(['%(qemu_img_path)s', 'create' ,'-f', 'qcow2',
disk_path, '%(disk_size)sG']) disk_path, '%(disk_size)sG'])
......
...@@ -85,7 +85,7 @@ mode = 0644 ...@@ -85,7 +85,7 @@ mode = 0644
[template-kvm] [template-kvm]
recipe = slapos.recipe.template recipe = slapos.recipe.template
url = ${:_profile_base_location_}/instance-kvm.cfg.in url = ${:_profile_base_location_}/instance-kvm.cfg.in
md5sum = c3c888c78bbff334135be9e8ad5885a9 #md5sum = c3c888c78bbff334135be9e8ad5885a9
output = ${buildout:directory}/template-kvm.cfg output = ${buildout:directory}/template-kvm.cfg
mode = 0644 mode = 0644
......
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
"maximum": 8 "maximum": 8
}, },
"nbd-host": { "nbd-host": {
"title": "NBD hostname", "title": "NBD hostname",
"description": "hostname (or IP) of the NBD server containing the boot image.", "description": "hostname (or IP) of the NBD server containing the boot image.",
...@@ -68,6 +67,13 @@ ...@@ -68,6 +67,13 @@
"maximum": 65535 "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": { "use-tap": {
"title": "Use QEMU TAP network interface", "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).", "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 ...@@ -45,38 +45,56 @@ recipe = slapos.cookbook:generate.password
storage-path = $${directory:srv}/passwd storage-path = $${directory:srv}/passwd
bytes = 8 bytes = 8
[kvm-instance] [kvm-instance]
# XXX-Cedric: change "KVM" recipe to simple "create wrappers". No need for this # XXX-Cedric: change "KVM" recipe to simple "create wrappers". No need for this
# Specific code # Specific code. It needs Jinja.
recipe = slapos.cookbook:kvm recipe = slapos.cookbook:kvm
# XXX-Cedric: should be removed and replaced
vnc-ip = $${slap-network-information:local-ipv4} vnc-ip = $${slap-network-information:local-ipv4}
passwd = $${gen-passwd:passwd}
ipv4 = $${slap-network-information:local-ipv4} ipv4 = $${slap-network-information:local-ipv4}
ipv6 = $${slap-network-information:global-ipv6} ipv6 = $${slap-network-information:global-ipv6}
vnc-port = 5901 vnc-port = 5901
# XXX-Cedric: should be named "default-cdrom-iso"
default-disk-image = ${debian-amd64-netinst.iso:location}/${debian-amd64-netinst.iso:filename} default-disk-image = ${debian-amd64-netinst.iso:location}/${debian-amd64-netinst.iso:filename}
nbd-host = $${slap-parameter:nbd-host} nbd-host = $${slap-parameter:nbd-host}
nbd-port = $${slap-parameter:nbd-port} nbd-port = $${slap-parameter:nbd-port}
nbd2-host = $${slap-parameter:nbd2-host} nbd2-host = $${slap-parameter:nbd2-host}
nbd2-port = $${slap-parameter:nbd2-port} nbd2-port = $${slap-parameter:nbd2-port}
tap = $${slap-network-information:network-interface} tap = $${slap-network-information:network-interface}
disk-path = $${directory:srv}/virtual.qcow2 disk-path = $${directory:srv}/virtual.qcow2
disk-size = $${slap-parameter:disk-size} disk-size = $${slap-parameter:disk-size}
disk-type = $${slap-parameter:disk-type} disk-type = $${slap-parameter:disk-type}
socket-path = $${directory:var}/qmp_socket socket-path = $${directory:var}/qmp_socket
pid-path = $${directory:run}/pid_file pid-path = $${directory:run}/pid_file
smp-count = $${slap-parameter:cpu-count} smp-count = $${slap-parameter:cpu-count}
ram-size = $${slap-parameter:ram-size} ram-size = $${slap-parameter:ram-size}
mac-address = $${create-mac:mac-address} mac-address = $${create-mac:mac-address}
# XXX-Cedric: should be named runner-wrapper-path and controller-wrapper-path
runner-path = $${directory:services}/kvm runner-path = $${directory:services}/kvm
controller-path = $${directory:scripts}/kvm_controller controller-path = $${directory:scripts}/kvm_controller
use-tap = $${slap-parameter:use-tap} use-tap = $${slap-parameter:use-tap}
nat-rules = $${slap-parameter:nat-rules} 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 shell-path = ${dash:location}/bin/dash
qemu-path = ${kvm:location}/bin/qemu-system-x86_64 qemu-path = ${kvm:location}/bin/qemu-system-x86_64
qemu-img-path = ${kvm:location}/bin/qemu-img qemu-img-path = ${kvm:location}/bin/qemu-img
passwd = $${gen-passwd:passwd}
6tunnel-path = ${6tunnel:location}/bin/6tunnel 6tunnel-path = ${6tunnel:location}/bin/6tunnel
6tunnel-wrapper-path = $${directory:services}/6tunnel
[kvm-promise] [kvm-promise]
recipe = slapos.cookbook:check_port_listening recipe = slapos.cookbook:check_port_listening
...@@ -224,3 +242,5 @@ cpu-count = 1 ...@@ -224,3 +242,5 @@ cpu-count = 1
nat-rules = 22 80 443 nat-rules = 22 80 443
use-tap = False 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