Skip to content

Commit

Permalink
Unified extra IPs configuration for netplan. nmcli & rc for `configur…
Browse files Browse the repository at this point in the history
…e_networking` role
  • Loading branch information
AllRWeak authored and at3rva committed Nov 14, 2023
1 parent 3b75ad8 commit 7fd2af1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
5 changes: 0 additions & 5 deletions nova/core/roles/configure_networking/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,3 @@ supported_connection_modes:

# Routing options
extra_routes: [] # Configure extra routes per interfaces.

# Extra IPs
extra_ipv4: [] # Configure extra IPv4s per interfaces.
extra_ipv6: [] # Configure extra IPv6s per interfaces.
extra_ips: "{{ extra_ipv4 + extra_ipv6 }}" # Combined list of extra IPs per interfaces
11 changes: 8 additions & 3 deletions nova/core/roles/configure_networking/templates/netplan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ network:
- "{{ ip_address.address }}"
{% endif %}
{% endfor %}
{% if extra_ips[ interface.network_id ] is defined %}
{% for extra_ip in extra_ips[ interface.network_id ] %}
- {{ extra_ip }}
{% if extra_ipv4[ interface.network_id ] is defined %}
{% for ipv4 in extra_ipv4[ interface.network_id ] %}
- {{ ipv4 }}
{% endfor %}
{% endif %}
{% if extra_ipv6[ interface.network_id ] is defined %}
{% for ipv6 in extra_ipv6[ interface.network_id ] %}
- {{ ipv6 }}
{% endfor %}
{% endif %}
{% if (interface.addresses | selectattr("gateway", "!=", none)) or (extra_routes[ interface.network_id ] is defined) %}
Expand Down
4 changes: 2 additions & 2 deletions nova/core/roles/configure_networking/templates/nmcli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ fi

{% endfor %}

{% if extra_ipv4 != [] %}
{% if extra_ipv4[ interface.network_id ] is defined %}

# Adding extra ipv4 addresses for connection interface
nmcli con modify $NMCLI_CONNECTION_NAME ipv4.method manual +ipv4.addresses "{{ extra_ipv4[ interface.network_id ] | join(', ') }}"

{% endif %}

{% if extra_ipv6 != [] %}
{% if extra_ipv6[ interface.network_id ] is defined %}

# Adding extra ipv6 addresses for connection interface
nmcli con modify $NMCLI_CONNECTION_NAME ipv6.method manual +ipv6.addresses "{{ extra_ipv6[ interface.network_id ] | join(', ') }}"
Expand Down
4 changes: 2 additions & 2 deletions nova/core/roles/configure_networking/templates/rc.local
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ ifconfig $INTERFACE_{{ interface_loop }}_NAME inet6 {{ ip_address.address | ansi
{% endif %}
{% endfor %}

{% if extra_ipv4 != [] %}
{% if extra_ipv4[ interface.network_id ] is defined %}
{% for extra_ipv4 in extra_ipv4[interface.network_id] %}
ifconfig $INTERFACE_{{ interface_loop }}_NAME inet {{ extra_ipv4 | ansible.utils.ipaddr('address') }} netmask {{ extra_ipv4 | ansible.utils.ipaddr('netmask') }} alias
{% endfor %}
{% endif %}

{% if extra_ipv6 != [] %}
{% if extra_ipv6[ interface.network_id ] is defined %}
{% for extra_ipv6 in extra_ipv6[interface.network_id] %}
ifconfig $INTERFACE_{{ interface_loop }}_NAME inet6 {{ extra_ipv6 | ansible.utils.ipaddr('address') }} prefixlen {{ extra_ipv6 | ansible.utils.ipaddr('prefix') }} alias
{% endfor %}
Expand Down

0 comments on commit 7fd2af1

Please sign in to comment.