Improve automation of seed VM network configuration

The list of libvirt networks is now generated from the seed's network interfaces.
This can be overridden if necessary.
This commit is contained in:
Mark Goddard 2017-08-01 15:36:30 +00:00
parent fba0e1eeb2
commit a82047f14f
5 changed files with 50 additions and 11 deletions

View File

@ -121,6 +121,17 @@ net_mtu = _make_attr_filter('mtu')
net_routes = _make_attr_filter('routes')
@jinja2.contextfilter
def net_libvirt_network_name(context, name, inventory_hostname=None):
"""Return the configured Libvirt name for a network.
If no Libvirt name is configured, the network's name is returned.
"""
libvirt_name = net_attr(context, name, 'libvirt_network_name',
inventory_hostname)
return libvirt_name or name
@jinja2.contextfilter
def net_bridge_ports(context, name, inventory_hostname=None):
return net_attr(context, name, 'bridge_ports', inventory_hostname)
@ -273,6 +284,35 @@ def net_configdrive_network_device(context, name, inventory_hostname=None):
return interface
@jinja2.contextfilter
def net_libvirt_network(context, name, inventory_hostname=None):
"""Return a dict which describes the Libvirt network for a network.
The Libvirt network is in a form accepted by the libvirt-host role.
"""
interface = net_interface(context, name, inventory_hostname)
name = net_libvirt_network_name(context, name, inventory_hostname)
return {
"name": name,
"mode": "bridge",
"bridge": interface,
}
@jinja2.contextfilter
def net_libvirt_vm_network(context, name, inventory_hostname=None):
"""Return a dict which describes the Libvirt VM's network for a network.
The Libvirt network is in a form accepted by the libvirt_vm_interfaces
variable of the libvirt-vm role.
"""
libvirt_name = net_libvirt_network_name(context, name, inventory_hostname)
return {
"network": libvirt_name,
"net_name": name,
}
class FilterModule(object):
"""Networking filters."""
@ -306,4 +346,7 @@ class FilterModule(object):
'net_select_vlans': net_select_vlans,
'net_reject_vlans': net_reject_vlans,
'net_configdrive_network_device': net_configdrive_network_device,
'net_libvirt_network_name': net_libvirt_network_name,
'net_libvirt_network': net_libvirt_network,
'net_libvirt_vm_network': net_libvirt_vm_network,
}

View File

@ -31,10 +31,6 @@ seed_vm_data_volume:
capacity: "{{ seed_vm_data_capacity }}"
format: "{{ seed_vm_data_format }}"
# List of network interfaces.
seed_vm_interfaces:
- network: default
# Name of the storage pool for the seed VM volumes.
seed_vm_pool: default

View File

@ -25,7 +25,7 @@
copy:
content: |
#!/bin/bash
{% for interface in seed_hostvars.seed_vm_interfaces | map(attribute='net_name') | map('net_interface', seed_host) %}
{% for interface in seed_hostvars.network_interfaces | map('net_interface', seed_host) %}
ifup {{ interface }}
{% endfor %}
dest: "{{ seed_user_data_path }}"
@ -46,8 +46,7 @@
search: "{{ seed_hostvars.resolv_search | default }}"
dns: "{{ seed_hostvars.resolv_nameservers | default([]) }}"
configdrive_network_device_list: >
{{ seed_hostvars.seed_vm_interfaces |
map(attribute='net_name') |
{{ seed_hostvars.network_interfaces |
map('net_configdrive_network_device', seed_host) |
list }}
configdrive_config_user_data_path: "{{ seed_user_data_path }}"
@ -99,7 +98,8 @@
libvirt_vm_memory_mb: "{{ seed_hostvars.seed_vm_memory_mb }}"
libvirt_vm_vcpus: "{{ seed_hostvars.seed_vm_vcpus }}"
libvirt_vm_volumes: "{{ seed_hostvars.seed_vm_volumes + [seed_vm_configdrive_volume] }}"
libvirt_vm_interfaces: "{{ seed_hostvars.seed_vm_interfaces }}"
libvirt_vm_interfaces: >
{{ seed_hostvars.network_interfaces | map('net_libvirt_vm_network') | list }}
libvirt_vm_image_cache_path: "{{ image_cache_path }}"
become: True

View File

@ -147,6 +147,9 @@ supported:
List of static IP routes. Each item should be a dict containing the
items ``cidr`` and ``gateway``. ``cidr`` is the CIDR representation of the
route's destination. ``gateway`` is the IP address of the next hop.
``libvirt_network_name``
A name to give to a Libvirt network representing this network on the seed
hypervisor.
IP addresses are allocated automatically by Kayobe from the
allocation pool

View File

@ -14,9 +14,6 @@
# List of volumes.
#seed_vm_volumes:
# List of network interfaces.
#seed_vm_interfaces:
# Name of the storage pool for the seed VM volumes.
#seed_vm_pool: