Skip to content
Snippets Groups Projects
Commit a82047f1 authored by Mark Goddard's avatar Mark Goddard
Browse files

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.
parent fba0e1ee
No related branches found
No related tags found
No related merge requests found
...@@ -121,6 +121,17 @@ net_mtu = _make_attr_filter('mtu') ...@@ -121,6 +121,17 @@ net_mtu = _make_attr_filter('mtu')
net_routes = _make_attr_filter('routes') 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 @jinja2.contextfilter
def net_bridge_ports(context, name, inventory_hostname=None): def net_bridge_ports(context, name, inventory_hostname=None):
return net_attr(context, name, 'bridge_ports', inventory_hostname) return net_attr(context, name, 'bridge_ports', inventory_hostname)
...@@ -273,6 +284,35 @@ def net_configdrive_network_device(context, name, inventory_hostname=None): ...@@ -273,6 +284,35 @@ def net_configdrive_network_device(context, name, inventory_hostname=None):
return interface 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): class FilterModule(object):
"""Networking filters.""" """Networking filters."""
...@@ -306,4 +346,7 @@ class FilterModule(object): ...@@ -306,4 +346,7 @@ class FilterModule(object):
'net_select_vlans': net_select_vlans, 'net_select_vlans': net_select_vlans,
'net_reject_vlans': net_reject_vlans, 'net_reject_vlans': net_reject_vlans,
'net_configdrive_network_device': net_configdrive_network_device, '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,
} }
...@@ -31,10 +31,6 @@ seed_vm_data_volume: ...@@ -31,10 +31,6 @@ seed_vm_data_volume:
capacity: "{{ seed_vm_data_capacity }}" capacity: "{{ seed_vm_data_capacity }}"
format: "{{ seed_vm_data_format }}" format: "{{ seed_vm_data_format }}"
# List of network interfaces.
seed_vm_interfaces:
- network: default
# Name of the storage pool for the seed VM volumes. # Name of the storage pool for the seed VM volumes.
seed_vm_pool: default seed_vm_pool: default
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
copy: copy:
content: | content: |
#!/bin/bash #!/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 }} ifup {{ interface }}
{% endfor %} {% endfor %}
dest: "{{ seed_user_data_path }}" dest: "{{ seed_user_data_path }}"
...@@ -46,8 +46,7 @@ ...@@ -46,8 +46,7 @@
search: "{{ seed_hostvars.resolv_search | default }}" search: "{{ seed_hostvars.resolv_search | default }}"
dns: "{{ seed_hostvars.resolv_nameservers | default([]) }}" dns: "{{ seed_hostvars.resolv_nameservers | default([]) }}"
configdrive_network_device_list: > configdrive_network_device_list: >
{{ seed_hostvars.seed_vm_interfaces | {{ seed_hostvars.network_interfaces |
map(attribute='net_name') |
map('net_configdrive_network_device', seed_host) | map('net_configdrive_network_device', seed_host) |
list }} list }}
configdrive_config_user_data_path: "{{ seed_user_data_path }}" configdrive_config_user_data_path: "{{ seed_user_data_path }}"
...@@ -99,7 +98,8 @@ ...@@ -99,7 +98,8 @@
libvirt_vm_memory_mb: "{{ seed_hostvars.seed_vm_memory_mb }}" libvirt_vm_memory_mb: "{{ seed_hostvars.seed_vm_memory_mb }}"
libvirt_vm_vcpus: "{{ seed_hostvars.seed_vm_vcpus }}" libvirt_vm_vcpus: "{{ seed_hostvars.seed_vm_vcpus }}"
libvirt_vm_volumes: "{{ seed_hostvars.seed_vm_volumes + [seed_vm_configdrive_volume] }}" 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 }}" libvirt_vm_image_cache_path: "{{ image_cache_path }}"
become: True become: True
......
...@@ -147,6 +147,9 @@ supported: ...@@ -147,6 +147,9 @@ supported:
List of static IP routes. Each item should be a dict containing the List of static IP routes. Each item should be a dict containing the
items ``cidr`` and ``gateway``. ``cidr`` is the CIDR representation of the items ``cidr`` and ``gateway``. ``cidr`` is the CIDR representation of the
route's destination. ``gateway`` is the IP address of the next hop. 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 IP addresses are allocated automatically by Kayobe from the
allocation pool allocation pool
......
...@@ -14,9 +14,6 @@ ...@@ -14,9 +14,6 @@
# List of volumes. # List of volumes.
#seed_vm_volumes: #seed_vm_volumes:
# List of network interfaces.
#seed_vm_interfaces:
# Name of the storage pool for the seed VM volumes. # Name of the storage pool for the seed VM volumes.
#seed_vm_pool: #seed_vm_pool:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment