On Thu, Jul 12, 2018 at 05:19:23PM +0200, Andrea Bolognani wrote:
Signed-off-by: Andrea Bolognani <abologna(a)redhat.com>
---
guests/lcitool | 74 ++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 72 insertions(+), 2 deletions(-)
diff --git a/guests/lcitool b/guests/lcitool
index f11b92e..486f82f 100755
--- a/guests/lcitool
+++ b/guests/lcitool
@@ -23,6 +23,7 @@ import fnmatch
import os
import random
import string
+import subprocess
import sys
import textwrap
import yaml
@@ -243,8 +244,13 @@ class Application:
formatter_class = argparse.RawDescriptionHelpFormatter,
description = "libvirt CI guest management tool",
epilog = textwrap.dedent("""
+ common actions:
+ install perform unattended host installation
+
informational actions:
hosts list all known hosts
+
+ glob patterns are supported for HOSTS
"""),
)
self._parser.add_argument(
@@ -253,19 +259,83 @@ class Application:
required = True,
help = "action to perform (see below)",
)
+ self._parser.add_argument(
+ "-h",
+ metavar = "HOSTS",
+ help = "list of hosts to act on",
+ )
- def _action_list(self):
+ def _action_list(self, hosts):
'hosts' argument is not used here.
for host in
self._inventory.expand_pattern("all"):
print(host)
+ def _action_install(self, hosts):
+ flavor = self._config.get_flavor()
+
+ for host in self._inventory.expand_pattern(hosts):
+ facts = self._inventory.get_facts(host)
+
+ # Both memory size and disk size are stored as GiB in the
+ # inventory, but virt-install expects the disk size in GiB
+ # and the memory size in *MiB*, so perform conversion here
+ memory_arg = str(int(facts["install_memory_size"]) * 1024)
+
+ vcpus_arg = str(facts["install_vcpus"])
+
+ disk_arg = "size={},pool={},bus=virtio".format(
+ facts["install_disk_size"],
+ facts["install_storage_pool"],
+ )
+ network_arg = "network={},model=virtio".format(
+ facts["install_network"],
+ )
+
+ # preseed files must use a well-known name to be picked up by
+ # d-i; for kickstart files, we can use whatever name we please
+ # but we need to point anaconda in the right direction through
+ # a kernel argument
+ extra_arg = "console=ttyS0 ks=file:/{}".format(
+ facts["install_config"],
+ )
+
+ cmd = [
+ "virt-install",
+ "--name", host,
+ "--location", facts["install_url"],
+ "--virt-type", facts["install_virt_type"],
+ "--arch", facts["install_arch"],
+ "--machine", facts["install_machine"],
+ "--cpu", facts["install_cpu_model"],
+ "--vcpus", vcpus_arg,
+ "--memory", memory_arg,
+ "--disk", disk_arg,
+ "--network", network_arg,
+ "--graphics", "none",
+ "--console", "pty",
+ "--sound", "none",
+ "--initrd-inject", facts["install_config"],
+ "--extra-args", extra_arg,
+ "--wait", "0",
+ ]
+
+ # Only configure autostart for the guest for the jenkins flavor
+ if flavor == "jenkins":
+ cmd += [ "--autostart" ]
+
+ try:
+ subprocess.check_call(cmd)
+ except:
+ raise Error("Failed to install '{}'".format(host))
+
def run(self):
cmdline = self._parser.parse_args()
action = cmdline.a
+ hosts = cmdline.h
method = "_action_{}".format(action.replace("-",
"_"))
if hasattr(self, method):
- getattr(self, method).__call__()
+ getattr(self, method).__call__(hosts)
else:
raise Error("Invalid action '{}'".format(action))
--
2.17.1
--
libvir-list mailing list
libvir-list(a)redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list