diff options
author | Richard Maw <richard.maw@codethink.co.uk> | 2013-05-08 17:04:45 +0100 |
---|---|---|
committer | Tiago Gomes <tiago.gomes@codethink.co.uk> | 2013-05-08 16:54:17 +0000 |
commit | 1b2f2013bb85769352e82cfd55a3179fe16ccce2 (patch) | |
tree | d967860c2601d32c67f415fb8f8a310d18364306 /morphlib/exts/kvm.write | |
parent | be72eb1771b0d83bf3a48ac2e59255dc8644e665 (diff) | |
download | morph-1b2f2013bb85769352e82cfd55a3179fe16ccce2.tar.gz |
Add AUTOSTART to kvm and libvirt write extensions
If AUTOSTART is 'yes' then the VM will be started once it is
created. If it is 'no' or undefined, then it will need to be manually
started. If it is any other value, then an exception is raised.
Diffstat (limited to 'morphlib/exts/kvm.write')
-rwxr-xr-x | morphlib/exts/kvm.write | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/morphlib/exts/kvm.write b/morphlib/exts/kvm.write index 630f6ae7..e2f7435c 100755 --- a/morphlib/exts/kvm.write +++ b/morphlib/exts/kvm.write @@ -56,6 +56,7 @@ class KvmPlusSshWriteExtension(morphlib.writeexts.WriteExtension): temp_root, location = args ssh_host, vm_name, vm_path = self.parse_location(location) + autostart = self.parse_autostart() fd, raw_disk = tempfile.mkstemp() os.close(fd) @@ -63,7 +64,7 @@ class KvmPlusSshWriteExtension(morphlib.writeexts.WriteExtension): try: self.transfer(raw_disk, ssh_host, vm_path) - self.create_libvirt_guest(ssh_host, vm_name, vm_path) + self.create_libvirt_guest(ssh_host, vm_name, vm_path, autostart) except BaseException: sys.stderr.write('Error deploying to libvirt') os.remove(raw_disk) @@ -95,7 +96,7 @@ class KvmPlusSshWriteExtension(morphlib.writeexts.WriteExtension): with open(raw_disk, 'rb') as f: cliapp.runcmd(['rsync', '-zS', raw_disk, target]) - def create_libvirt_guest(self, ssh_host, vm_name, vm_path): + def create_libvirt_guest(self, ssh_host, vm_name, vm_path, autostart): '''Create the libvirt virtual machine.''' self.status(msg='Creating libvirt/kvm virtual machine') @@ -107,13 +108,13 @@ class KvmPlusSshWriteExtension(morphlib.writeexts.WriteExtension): ram_mebibytes = str(self.get_ram_size() / (1024**2)) - cliapp.runcmd( - ['ssh', ssh_host, - 'virt-install', '--connect qemu:///system', '--import', - '--name', vm_name, '--vnc', '--noreboot', - '--ram=%s' % ram_mebibytes, - '--disk path=%s,bus=ide' % vm_path] + - attach_opts) + cmdline = ['ssh', ssh_host, + 'virt-install', '--connect qemu:///system', '--import', + '--name', vm_name, '--vnc', '--ram=%s' % ram_mebibytes, + '--disk path=%s,bus=ide' % vm_path] + attach_opts + if not autostart: + cmdline += '--noreboot' + cliapp.runcmd(cmdline) KvmPlusSshWriteExtension().run() |