diff options
Diffstat (limited to 'morphlib/exts/virtualbox-ssh.write')
-rwxr-xr-x | morphlib/exts/virtualbox-ssh.write | 20 |
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], |