diff --git a/ansible/filter_plugins/networks.py b/ansible/filter_plugins/networks.py index 80cd2fd9b..f885eef29 100644 --- a/ansible/filter_plugins/networks.py +++ b/ansible/filter_plugins/networks.py @@ -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, } diff --git a/ansible/group_vars/all/seed-vm b/ansible/group_vars/all/seed-vm index 151415ddd..828ca6dd2 100644 --- a/ansible/group_vars/all/seed-vm +++ b/ansible/group_vars/all/seed-vm @@ -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 diff --git a/ansible/seed-vm.yml b/ansible/seed-vm.yml index 05d1eb350..a8df66fba 100644 --- a/ansible/seed-vm.yml +++ b/ansible/seed-vm.yml @@ -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 diff --git a/doc/source/configuration.rst b/doc/source/configuration.rst index a4c511e43..2c13667a2 100644 --- a/doc/source/configuration.rst +++ b/doc/source/configuration.rst @@ -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 diff --git a/etc/kayobe/seed-vm.yml b/etc/kayobe/seed-vm.yml index e9fe71773..710464f89 100644 --- a/etc/kayobe/seed-vm.yml +++ b/etc/kayobe/seed-vm.yml @@ -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: