From f76f244a382d618df3d28b8a8764f96a930e868e Mon Sep 17 00:00:00 2001
From: Mark Goddard <mark@stackhpc.com>
Date: Tue, 1 Aug 2017 15:05:08 +0000
Subject: [PATCH] Add configuration for seed hypervisor

Currently supports configuration of:
- Local networking
- NTP
- Libvirt storage pools and networks
---
 ansible/dev-tools.yml                      |  2 +-
 ansible/group_vars/all/seed-hypervisor     | 54 ++++++++++++++++++++++
 ansible/group_vars/seed-hypervisor/network |  8 ++++
 ansible/ip-allocation.yml                  |  2 +-
 ansible/network.yml                        |  2 +-
 ansible/ntp.yml                            |  2 +-
 ansible/seed-hypervisor-libvirt-host.yml   |  7 +++
 doc/source/deployment.rst                  | 19 +++++++-
 etc/kayobe/seed-hypervisor.yml             | 46 ++++++++++++++++++
 kayobe/cli/commands.py                     | 13 ++++++
 setup.py                                   |  2 +-
 11 files changed, 151 insertions(+), 6 deletions(-)
 create mode 100644 ansible/group_vars/all/seed-hypervisor
 create mode 100644 ansible/group_vars/seed-hypervisor/network
 create mode 100644 ansible/seed-hypervisor-libvirt-host.yml
 create mode 100644 etc/kayobe/seed-hypervisor.yml

diff --git a/ansible/dev-tools.yml b/ansible/dev-tools.yml
index d8e867921..3aa1dee41 100644
--- a/ansible/dev-tools.yml
+++ b/ansible/dev-tools.yml
@@ -1,5 +1,5 @@
 ---
 - name: Ensure development tools are installed
-  hosts: seed:overcloud
+  hosts: seed-hypervisor:seed:overcloud
   roles:
     - role: dev-tools
diff --git a/ansible/group_vars/all/seed-hypervisor b/ansible/group_vars/all/seed-hypervisor
new file mode 100644
index 000000000..764d8867c
--- /dev/null
+++ b/ansible/group_vars/all/seed-hypervisor
@@ -0,0 +1,54 @@
+---
+###############################################################################
+# Seed hypervisor network interface configuration.
+
+# List of default networks to which seed hypervisor nodes are attached.
+seed_hypervisor_default_network_interfaces: "{{ seed_default_network_interfaces }}"
+
+# List of extra networks to which seed hypervisor nodes are attached.
+seed_hypervisor_extra_network_interfaces: "{{ seed_extra_network_interfaces }}"
+
+###############################################################################
+# Seed hypervisor libvirt storage pool configuration.
+
+# List of libvirt storage pools for the seed hypervisor.
+seed_hypervisor_libvirt_pools:
+  - "{{ seed_hypervisor_libvirt_pool }}"
+
+# Libvirt storage pool for the seed VM.
+seed_hypervisor_libvirt_pool:
+  name: "{{ seed_hypervisor_libvirt_pool_name }}"
+  type: dir
+  capacity: "{{ seed_hypervisor_libvirt_pool_capacity }}"
+  path: "{{ seed_hypervisor_libvirt_pool_path }}"
+  mode: "{{ seed_hypervisor_libvirt_pool_mode }}"
+  owner: "{{ seed_hypervisor_libvirt_pool_owner }}"
+  group: "{{ seed_hypervisor_libvirt_pool_group }}"
+
+# Name of the libvirt storage pool for the seed VM.
+seed_hypervisor_libvirt_pool_name: "default"
+
+# Capacity of the libvirt storage pool for the seed VM.
+seed_hypervisor_libvirt_pool_capacity: "{{ 75 * 2**30 }}"
+
+# Directory path of the libvirt storage pool for the seed VM.
+seed_hypervisor_libvirt_pool_path: "/var/lib/libvirt/images"
+
+# Directory mode of the libvirt storage pool for the seed VM.
+seed_hypervisor_libvirt_pool_mode: 711
+
+# Directory owner of the libvirt storage pool for the seed VM.
+seed_hypervisor_libvirt_pool_owner: "root"
+
+# Directory group of the libvirt storage pool for the seed VM.
+seed_hypervisor_libvirt_pool_group: "root"
+
+###############################################################################
+# Seed hypervisor libvirt network configuration.
+
+# List of libvirt networks for the seed hypervisor.
+seed_hypervisor_libvirt_networks: >
+  {{ network_interfaces |
+     net_select_bridges |
+     map('net_libvirt_network') |
+     list }}
diff --git a/ansible/group_vars/seed-hypervisor/network b/ansible/group_vars/seed-hypervisor/network
new file mode 100644
index 000000000..8ab38a57c
--- /dev/null
+++ b/ansible/group_vars/seed-hypervisor/network
@@ -0,0 +1,8 @@
+---
+###############################################################################
+# Network interface attachments.
+
+# List of networks to which these nodes are attached.
+network_interfaces: >
+  {{ (seed_hypervisor_default_network_interfaces +
+      seed_hypervisor_extra_network_interfaces) | unique | list }}
diff --git a/ansible/ip-allocation.yml b/ansible/ip-allocation.yml
index 96c7932bc..df81c8ab5 100644
--- a/ansible/ip-allocation.yml
+++ b/ansible/ip-allocation.yml
@@ -1,6 +1,6 @@
 ---
 - name: Ensure IP addresses are allocated
-  hosts: seed:overcloud
+  hosts: seed-hypervisor:seed:overcloud
   gather_facts: no
   pre_tasks:
     - name: Initialise the IP allocations fact
diff --git a/ansible/network.yml b/ansible/network.yml
index bb776433f..9585ef07b 100644
--- a/ansible/network.yml
+++ b/ansible/network.yml
@@ -1,6 +1,6 @@
 ---
 - name: Ensure networking is configured
-  hosts: seed:overcloud
+  hosts: seed-hypervisor:seed:overcloud
   tags:
     - config
   vars:
diff --git a/ansible/ntp.yml b/ansible/ntp.yml
index e3b8d7cce..5b28097db 100644
--- a/ansible/ntp.yml
+++ b/ansible/ntp.yml
@@ -1,6 +1,6 @@
 ---
 - name: Ensure NTP is installed and configured
-  hosts: seed:overcloud
+  hosts: seed-hypervisor:seed:overcloud
   roles:
     - role: yatesr.timezone
       become: True
diff --git a/ansible/seed-hypervisor-libvirt-host.yml b/ansible/seed-hypervisor-libvirt-host.yml
new file mode 100644
index 000000000..3dbb0c828
--- /dev/null
+++ b/ansible/seed-hypervisor-libvirt-host.yml
@@ -0,0 +1,7 @@
+---
+- name: Ensure the libvirt daemon is configured
+  hosts: seed-hypervisor
+  roles:
+    - role: libvirt-host
+      libvirt_host_pools: "{{ seed_hypervisor_libvirt_pools }}"
+      libvirt_host_networks: "{{ seed_hypervisor_libvirt_networks }}"
diff --git a/doc/source/deployment.rst b/doc/source/deployment.rst
index 23da23321..b78a998c0 100644
--- a/doc/source/deployment.rst
+++ b/doc/source/deployment.rst
@@ -40,6 +40,23 @@ The ``--enable-discovery`` argument enables a one-time configuration of ports
 attached to baremetal compute nodes to support hardware discovery via ironic
 inspector.
 
+Seed Hypervisor
+===============
+
+.. note::
+
+   It is not necessary to run the seed services in a VM.  To use an existing
+   bare metal host or a VM provisioned outside of Kayobe, this section may be
+   skipped.
+
+Host Configuration
+------------------
+
+To configure the seed hypervisor's host OS, and the Libvirt/KVM virtualisation
+support::
+
+    (kayobe-venv) $ kayobe seed hypervisor host configure
+
 Seed
 ====
 
@@ -48,7 +65,7 @@ VM Provisioning
 
 .. note::
 
-   It is not necesary to run the seed services in a VM.  To use an existing
+   It is not necessary to run the seed services in a VM.  To use an existing
    bare metal host or a VM provisioned outside of Kayobe, this step may be
    skipped.  Ensure that the Ansible inventory contains a host for the seed.
 
diff --git a/etc/kayobe/seed-hypervisor.yml b/etc/kayobe/seed-hypervisor.yml
new file mode 100644
index 000000000..49d06a6ef
--- /dev/null
+++ b/etc/kayobe/seed-hypervisor.yml
@@ -0,0 +1,46 @@
+---
+###############################################################################
+# Seed hypervisor network interface configuration.
+
+# List of default networks to which seed hypervisor nodes are attached.
+#seed_hypervisor_default_network_interfaces:
+
+# List of extra networks to which seed hypervisor nodes are attached.
+#seed_hypervisor_extra_network_interfaces:
+
+###############################################################################
+# Seed hypervisor libvirt storage pool configuration.
+
+# List of libvirt storage pools for the seed hypervisor.
+#seed_hypervisor_libvirt_pools:
+
+# Libvirt storage pool for the seed VM.
+#seed_hypervisor_libvirt_pool:
+
+# Name of the libvirt storage pool for the seed VM.
+#seed_hypervisor_libvirt_pool_name:
+
+# Capacity of the libvirt storage pool for the seed VM.
+#seed_hypervisor_libvirt_pool_capacity:
+
+# Directory path of the libvirt storage pool for the seed VM.
+#seed_hypervisor_libvirt_pool_path:
+
+# Directory mode of the libvirt storage pool for the seed VM.
+#seed_hypervisor_libvirt_pool_mode:
+
+# Directory owner of the libvirt storage pool for the seed VM.
+#seed_hypervisor_libvirt_pool_owner:
+
+# Directory group of the libvirt storage pool for the seed VM.
+#seed_hypervisor_libvirt_pool_group:
+
+###############################################################################
+# Seed hypervisor libvirt network configuration.
+
+# List of libvirt networks for the seed hypervisor.
+#seed_hypervisor_libvirt_networks:
+
+###############################################################################
+# Dummy variable to allow Ansible to accept this file.
+workaround_ansible_issue_8743: yes
diff --git a/kayobe/cli/commands.py b/kayobe/cli/commands.py
index 69ccb0199..7f356bb62 100644
--- a/kayobe/cli/commands.py
+++ b/kayobe/cli/commands.py
@@ -220,6 +220,19 @@ class PhysicalNetworkConfigure(KayobeAnsibleMixin, VaultMixin, Command):
                                  extra_vars=extra_vars)
 
 
+class SeedHypervisorHostConfigure(KollaAnsibleMixin, KayobeAnsibleMixin,
+                                  VaultMixin, Command):
+    """Configure the seed hypervisor node host OS."""
+
+    def take_action(self, parsed_args):
+        self.app.LOG.debug("Configuring seed hypervisor host OS")
+        playbooks = _build_playbook_list(
+            "ip-allocation", "ssh-known-host", "dev-tools", "network", "ntp",
+            "seed-hypervisor-libvirt-host")
+        self.run_kayobe_playbooks(parsed_args, playbooks,
+                                  limit="seed-hypervisor")
+
+
 class SeedVMProvision(KollaAnsibleMixin, KayobeAnsibleMixin, VaultMixin,
                       Command):
     """Provision the seed VM."""
diff --git a/setup.py b/setup.py
index 3e9c13d56..313f686ba 100644
--- a/setup.py
+++ b/setup.py
@@ -41,7 +41,6 @@ setup(
     provides=[],
     install_requires=open('requirements.txt', 'rt').read().splitlines(),
 
-
     namespace_packages=[],
     packages=find_packages(),
     include_package_data=True,
@@ -73,6 +72,7 @@ setup(
             'playbook_run = kayobe.cli.commands:PlaybookRun',
             'seed_container_image_build = kayobe.cli.commands:SeedContainerImageBuild',
             'seed_host_configure = kayobe.cli.commands:SeedHostConfigure',
+            'seed_hypervisor_host_configure = kayobe.cli.commands:SeedHypervisorHostConfigure',
             'seed_service_deploy = kayobe.cli.commands:SeedServiceDeploy',
             'seed_vm_provision = kayobe.cli.commands:SeedVMProvision',
         ],