summaryrefslogtreecommitdiff
path: root/extensions/kvm.write
diff options
context:
space:
mode:
authorAdam Coldrick <adam.coldrick@codethink.co.uk>2015-06-04 15:17:44 +0000
committerAdam Coldrick <adam.coldrick@codethink.co.uk>2015-06-11 08:55:05 +0000
commite4c6b8a69f0df2d0b3beac46865a66e0de527151 (patch)
treed837a9768fe2a15557d400301ed8b6588504eb55 /extensions/kvm.write
parent840292841f4495a79a037f81a26d6b3f51e7cb8c (diff)
downloaddefinitions-e4c6b8a69f0df2d0b3beac46865a66e0de527151.tar.gz
Remove dependencies on morphlib and cliapp from deployment extensionsbaserock/adamcoldrick/remove-dependencies-v3
This is done by either copying some utility functions from morph into writeexts.py, and using the `subprocess` module rather than cliapp's runcmd and ssh_runcmd. Note that this means that these extensions will require "$definitions_checkout/extensions" in PYTHONPATH when they are run. This commit also updates VERSION to 5, since the PYTHONPATH requirement means that this change is incompatible with old versions of morph. Change-Id: Iec6fa7e3c7219619ce55e18493e5c37c36e97816
Diffstat (limited to 'extensions/kvm.write')
-rwxr-xr-xextensions/kvm.write25
1 files changed, 13 insertions, 12 deletions
diff --git a/extensions/kvm.write b/extensions/kvm.write
index 0d0c095b..2290725e 100755
--- a/extensions/kvm.write
+++ b/extensions/kvm.write
@@ -21,23 +21,23 @@ See file kvm.write.help for documentation
'''
-import cliapp
import os
import re
import sys
import tempfile
import urlparse
-import morphlib.writeexts
+import writeexts
-class KvmPlusSshWriteExtension(morphlib.writeexts.WriteExtension):
+class KvmPlusSshWriteExtension(writeexts.WriteExtension):
location_pattern = '^/(?P<guest>[^/]+)(?P<path>/.+)$'
def process_args(self, args):
if len(args) != 2:
- raise cliapp.AppException('Wrong number of command line args')
+ raise writeexts.ExtensionError(
+ 'Wrong number of command line args')
temp_root, location = args
ssh_host, vm_name, vm_path = self.parse_location(location)
@@ -53,7 +53,7 @@ class KvmPlusSshWriteExtension(morphlib.writeexts.WriteExtension):
except BaseException:
sys.stderr.write('Error deploying to libvirt')
os.remove(raw_disk)
- cliapp.ssh_runcmd(ssh_host, ['rm', '-f', vm_path])
+ writeexts.ssh_runcmd(ssh_host, ['rm', '-f', vm_path])
raise
else:
os.remove(raw_disk)
@@ -74,16 +74,16 @@ class KvmPlusSshWriteExtension(morphlib.writeexts.WriteExtension):
self.status(msg='Transferring disk image')
- xfer_hole_path = morphlib.util.get_data_path('xfer-hole')
- recv_hole = morphlib.util.get_data('recv-hole')
+ xfer_hole_path = writeexts.get_data_path('xfer-hole')
+ recv_hole = writeexts.get_data('recv-hole')
ssh_remote_cmd = [
'sh', '-c', recv_hole, 'dummy-argv0', 'file', vm_path
]
- cliapp.runcmd(
+ subprocess.check_call(
['python', xfer_hole_path, raw_disk],
- ['ssh', ssh_host] + map(cliapp.shell_quote, ssh_remote_cmd),
+ ['ssh', ssh_host] + map(writeexts.shell_quote, ssh_remote_cmd),
stdout=None, stderr=None)
def create_libvirt_guest(self, ssh_host, vm_name, vm_path, autostart):
@@ -111,10 +111,11 @@ class KvmPlusSshWriteExtension(morphlib.writeexts.WriteExtension):
'--disk', 'path=%s,bus=ide' % vm_path] + attach_opts
if not autostart:
cmdline += ['--noreboot']
- cliapp.ssh_runcmd(ssh_host, cmdline)
+ writeexts.ssh_runcmd(ssh_host, cmdline)
if autostart:
- cliapp.ssh_runcmd(ssh_host,
- ['virsh', '--connect', 'qemu:///system', 'autostart', vm_name])
+ writeexts.ssh_runcmd(ssh_host,
+ ['virsh', '--connect', 'qemu:///system',
+ 'autostart', vm_name])
KvmPlusSshWriteExtension().run()