summaryrefslogtreecommitdiff
path: root/morphlib/exts/virtualbox-ssh.write
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2014-01-22 17:42:18 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2014-01-28 11:32:53 +0000
commit027bd21376e252b6239e13293cec2234815c39bf (patch)
treec6ea3342208335f5804e5f7a356456e9a818f221 /morphlib/exts/virtualbox-ssh.write
parent5190c0ef482a4e67b14464d0a6fa267a937c7e46 (diff)
downloadmorph-027bd21376e252b6239e13293cec2234815c39bf.tar.gz
virtualbox-ssh: Work around change in VBox options
VirtualBox changed a command line option in 4.3 incompatibly, so we now have to check the version number and change an option from --sataportcount to --portcount if the version of VirtualBox running on the target is at least 4.3 This turns the version into a tuple and compares it against another, since it's more reliable than comparing strings, which will count '1.10' as earlier than '1.2', and more convenient than comparing the digits individually.
Diffstat (limited to 'morphlib/exts/virtualbox-ssh.write')
-rwxr-xr-xmorphlib/exts/virtualbox-ssh.write20
1 files changed, 19 insertions, 1 deletions
diff --git a/morphlib/exts/virtualbox-ssh.write b/morphlib/exts/virtualbox-ssh.write
index f18ef804..369c0d61 100755
--- a/morphlib/exts/virtualbox-ssh.write
+++ b/morphlib/exts/virtualbox-ssh.write
@@ -106,6 +106,19 @@ class VirtualBoxPlusSshWriteExtension(morphlib.writeexts.WriteExtension):
str(os.path.getsize(raw_disk))],
stdin=f)
+ def virtualbox_version(self, ssh_host):
+ 'Get the version number of the VirtualBox running on the remote host.'
+
+ # --version gives a build id, which looks something like
+ # 1.2.3r456789, so we need to strip the suffix off and get a tuple
+ # of the (major, minor, patch) version, since comparing with a
+ # tuple is more reliable than a string and more convenient than
+ # comparing against the major, minor and patch numbers directly
+ self.status(msg='Checking version of remote VirtualBox')
+ build_id = cliapp.ssh_runcmd(ssh_host, ['VBoxManage', '--version'])
+ version_string = re.match(r"^([0-9\.])+.*$", build_id.strip()).group(1)
+ return tuple(int(s or '0') for s in version_string.split('.'))
+
def create_virtualbox_guest(self, ssh_host, vm_name, vdi_path, autostart):
'''Create the VirtualBox virtual machine.'''
@@ -117,6 +130,11 @@ class VirtualBoxPlusSshWriteExtension(morphlib.writeexts.WriteExtension):
hostonly_iface = self.get_host_interface(ssh_host)
+ if self.virtualbox_version(ssh_host) < (4, 3):
+ sataportcount_option = '--sataportcount'
+ else:
+ sataportcount_option = '--portcount'
+
commands = [
['createvm', '--name', vm_name, '--ostype', 'Linux26_64',
'--register'],
@@ -125,7 +143,7 @@ class VirtualBoxPlusSshWriteExtension(morphlib.writeexts.WriteExtension):
'--nic1', 'hostonly', '--hostonlyadapter1', hostonly_iface,
'--nic2', 'nat', '--natnet2', 'default'],
['storagectl', vm_name, '--name', 'SATA Controller',
- '--add', 'sata', '--bootable', 'on', '--sataportcount', '2'],
+ '--add', 'sata', '--bootable', 'on', sataportcount_option, '2'],
['storageattach', vm_name, '--storagectl', 'SATA Controller',
'--port', '0', '--device', '0', '--type', 'hdd', '--medium',
vdi_path],