This improves:
$ ./lcitool install libvirt-fedora-29
./lcitool: Failed to install 'libvirt-fedora-29': [Errno 2] No such file or
directory
To
$ ./lcitool install libvirt-fedora-29
./lcitool: Cannot find virt-install in $PATH
Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
guests/lcitool | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/guests/lcitool b/guests/lcitool
index 0f60704..3be16c8 100755
--- a/guests/lcitool
+++ b/guests/lcitool
@@ -37,6 +37,23 @@ except ImportError:
class Util:
+ @staticmethod
+ def which(program):
+ def is_exe(fpath):
+ return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
+
+ fpath, fname = os.path.split(program)
+ if fpath:
+ if is_exe(program):
+ return program
+ else:
+ for path in os.environ["PATH"].split(os.pathsep):
+ exe_file = os.path.join(path, program)
+ if is_exe(exe_file):
+ return exe_file
+
+ return None
+
@staticmethod
def get_base():
return os.path.dirname(os.path.abspath(__file__))
@@ -534,8 +551,12 @@ class Application:
# a kernel argument
extra_arg = "console=ttyS0 ks=file:/{}".format(install_config)
+ vipath = Util.which("virt-install")
+ if vipath is None:
+ raise Exception("Cannot find virt-install in $PATH")
+
cmd = [
- "virt-install",
+ vipath,
"--name", host,
"--location", facts["install_url"],
"--virt-type", facts["install_virt_type"],
--
2.21.0