Skip to content

Commit 3df99e3

Browse files
committed
[WIP] Add playbooks to set up the nat64 net and VM
TODOs: - Tests
1 parent 5796e8f commit 3df99e3

File tree

13 files changed

+413
-15
lines changed

13 files changed

+413
-15
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{{ cifmw_config_drive_networkconfig | to_nice_yaml(indent=2, default_style="\"") }}
1+
{{ cifmw_config_drive_networkconfig | to_nice_yaml(indent=2) }}

roles/nat64_appliance/README.md

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
11
# nat64_appliance
22

3-
`diskimage-builder` definition and element to build a NAT64 + DNS64 appliance VM image.
3+
`main.yml`: Tasks to build a NAT64 + DNS64 appliance VM image, uses `diskimage-builder`.
4+
`deploy.yml`: Tasks to deploy networks and appliance VM on a libvirt hypervisor.
5+
`cleanup.yml`: Tasks to destroy and undefine the VM and networks on a libvirt hypervisor, and delete the built image.
46

57
## Parameters
68

79
* `cifmw_nat64_appliance_basedir`: (String) Base directory. Defaults to `{{ cifmw_basedir }}` which defaults to `~/ci-framework-data`.
810
* `cifmw_nat64_appliance_workdir`: (String) Working directory. Defaults to `{{ cifmw_nat64_appliance_basedir }}/nat64_appliance`.
911
* `cifmw_nat64_appliance_venv_dir`: (String) Python virtual environment directory. Defaults to `{{ cifmw_nat64_appliance_workdir }}/venv`.
12+
* `cifmw_nat64_libvirt_uri`: (String) The libvirt URI for the hypervisor to deploy on. Defaults to `qemu:///system`.
13+
* `cifmw_nat64_network_ipv4_name`: (String) Name of the nat64 IPv4 libvirt network. Defaults to: `nat64-net-v4`.
14+
* `cifmw_nat64_network_ipv4_bridge_name`: (String) Bridge name for the nat64 IPv4 libvirt network. Defaults to: `br-64v4`.
15+
* `cifmw_nat64_network_ipv4_address`: (String) IP address for the nat64 IPv4 libvirt network. Defaults to: `172.31.255.1`.
16+
* `cifmw_nat64_network_ipv4_prefix`: (Integer) IP prefix length for the nat64 IPv4 libvirt network. Defaults to: `24`.
17+
* `cifmw_nat64_network_ipv6_name`: (String) Name of the nat64 IPv6 libvirt network. Defaults to: `nat64-net-v6`.
18+
* `cifmw_nat64_network_ipv6_bridge_name`: (String) The bridge name for the nat64 IPv6 libvirt network. Defaults to: `br-64v6`.
19+
* `cifmw_nat64_network_ipv6_address`: (String) IP address for the nat64 IPv6 libvirt network. Defaults to: `fd00:abcd:abcd:fc00::1`.
20+
* `cifmw_nat64_network_ipv6_prefix`: (Integer) IP prefix length for the nat64 IPv6 libvirt network. Defaults to: `64`.
21+
* `cifmw_nat64_appliance_name`: (String) Name and hostname for the nat64 appliance VM. Defaults to: `nat64-appliance`.
22+
* `cifmw_nat64_appliance_ipv4_address`: (String) IPv4 address for the nat64 appliance VM. Defaults to: `172.31.255.2`.
23+
* `cifmw_nat64_appliance_ipv6_address`: (String) IPv6 address for the nat64 appliance VM. Defaults to: `fd00:abcd:abcd:fc00::2`.
24+
* `cifmw_nat64_appliance_memory`: (Integer) Memory in GiB for the nat64 appliance VM. Defaults to: `2`.
25+
* `cifmw_nat64_appliance_cpus`: (Interger) Virtual CPUs for the nat64 appliance VM. Defaults to: `2`.
26+
* `cifmw_nat64_appliance_ssh_pub_key`: (String) Path to ssh public key for the nat64 appliance VM. Defaults to: `{{ ansible_user_dir }}/.ssh/id_rsa.pub`
27+
* `cifmw_nat64_ipv6_prefix`: (String) IPv6 prefix for nat64. Defaults to: `fd00:abcd:abcd:fc00::/64`.
28+
* `cifmw_nat64_ipv6_tayga_address`: (String) Tayga IPv6 address. Defaults to: `fd00:abcd:abcd:fc00::3`.
1029

1130
## Building the image
1231

@@ -18,12 +37,34 @@ Include the `nat64_appliance` role in a playbook. For example:
1837
roles:
1938
- nat64_appliance
2039
```
21-
The built image will be in: `{{ cifmw_basedir }}/artifacts/roles/nat64-appliance/nat64-appliance.qcow2`
40+
41+
The built image will be in: `{{ cifmw_nat64_appliance_workdir }}/nat64-appliance.qcow2`
2242

2343
## Using the nat64-appliance
2444

25-
- [With Openstack cloud](#with-openstack-cloud){#toc-with-openstack-cloud}
2645
- [With Libvirt](#with-libvirt){#toc-with-libvirt}
46+
- [With Openstack cloud](#with-openstack-cloud){#toc-with-openstack-cloud}
47+
48+
### With Libvirt
49+
50+
```
51+
- name: "Build nat64 appliance image"
52+
ansible.builtin.include_role:
53+
name: nat64_appliance
54+
- name: "Deploy the nat64 appliance and networks"
55+
ansible.builtin.include_role:
56+
name: nat64_appliance
57+
tasks_from: deploy.yml
58+
```
59+
60+
To clenup the libvirt nat64 deployment:
61+
```
62+
- name: "Build nat64 appliance image"
63+
ansible.builtin.include_role:
64+
name: nat64_appliance
65+
tasks_from: cleanup.yml
66+
```
67+
2768

2869
### With Openstack cloud
2970

@@ -220,7 +261,3 @@ $ ssh -J [email protected] fedora@fd00:abcd:aaaa:fc00::2b8
220261
PING sunet.se(fd00:abcd:abcd:fcff::259c:c033 (fd00:abcd:abcd:fcff::259c:c033)) 56 data bytes
221262
64 bytes from fd00:abcd:abcd:fcff::259c:c033 (fd00:abcd:abcd:fcff::259c:c033): icmp_seq=1 ttl=53 time=4.91 ms
222263
```
223-
224-
### With Libvirt
225-
226-
TODO

roles/nat64_appliance/defaults/main.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,24 @@ cifmw_nat64_appliance_basedir: >-
2020
}}
2121
cifmw_nat64_appliance_workdir: "{{ cifmw_nat64_appliance_basedir }}/nat64_appliance"
2222
cifmw_nat64_appliance_venv_dir: "{{ cifmw_nat64_appliance_workdir }}/venv"
23+
24+
cifmw_nat64_libvirt_uri: "qemu:///system"
25+
cifmw_nat64_network_ipv4_name: nat64-net-v4
26+
cifmw_nat64_network_ipv4_bridge_name: br-64v4
27+
cifmw_nat64_network_ipv4_address: 172.31.255.1
28+
cifmw_nat64_network_ipv4_prefix: 24
29+
30+
cifmw_nat64_network_ipv6_name: nat64-net-v6
31+
cifmw_nat64_network_ipv6_bridge_name: br-64v6
32+
cifmw_nat64_network_ipv6_address: fd00:abcd:abcd:fc00::1
33+
cifmw_nat64_network_ipv6_prefix: 64
34+
cifmw_nat64_appliance_name: nat64-appliance
35+
cifmw_nat64_appliance_ipv4_address: 172.31.255.2
36+
cifmw_nat64_appliance_ipv6_address: fd00:abcd:abcd:fc00::2
37+
38+
cifmw_nat64_appliance_memory: 2
39+
cifmw_nat64_appliance_cpus: 2
40+
cifmw_nat64_appliance_ssh_pub_key: "{{ ansible_user_dir }}/.ssh/id_rsa.pub"
41+
42+
cifmw_nat64_ipv6_prefix: "fd00:abcd:abcd:fc00::/64"
43+
cifmw_nat64_ipv6_tayga_address: "fd00:abcd:abcd:fc00::3"

roles/nat64_appliance/files/nat64-appliance.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- block-device-efi
99
- package-installs
1010
- nat64-router
11+
- reset-bls-entries # Requires edpm-image-builder elements.
1112
environment:
1213
DIB_RELEASE: '9-stream'
1314
DIB_PYTHON_VERSION: '3'
@@ -34,6 +35,16 @@
3435
- name: BSP
3536
type: 'EF02'
3637
size: 8MiB
38+
- name: boot
39+
type: '8300'
40+
size: 512MiB
41+
mkfs:
42+
type: xfs
43+
mount:
44+
mount_point: /boot
45+
fstab:
46+
options: "defaults"
47+
fsck-passno: 1
3748
- name: root
3849
type: '8300'
3950
size: 100%

roles/nat64_appliance/molecule/default/converge.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,20 @@
1515
# under the License.
1616

1717
- name: Converge
18-
hosts: all
18+
hosts: instance
1919
tasks:
20+
- name: Set selinux permissive
21+
become: true
22+
ansible.posix.selinux:
23+
policy: targeted
24+
state: permissive
25+
2026
- name: Build nat64 appliance image
21-
vars:
22-
extra_args: "--dry-run"
2327
ansible.builtin.include_role:
2428
name: nat64_appliance
29+
30+
- name: Set selinux permissive
31+
become: true
32+
ansible.posix.selinux:
33+
policy: targeted
34+
state: enforcing

roles/nat64_appliance/molecule/default/prepare.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
# License for the specific language governing permissions and limitations
1515
# under the License.
1616

17-
1817
- name: Prepare
1918
hosts: all
2019
roles:
21-
- role: test_deps
20+
- role: test_deps

roles/nat64_appliance/tasks/cleanup.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,38 @@
1818
ansible.builtin.file:
1919
state: absent
2020
path: "{{ cifmw_nat64_appliance_workdir }}/nat64-appliance.qcow2"
21+
22+
- name: Stop the nat64_appliance VM
23+
community.libvirt.virt:
24+
command: destroy
25+
name: "{{ cifmw_nat64_appliance_name }}"
26+
uri: "{{ cifmw_nat64_libvirt_uri }}"
27+
28+
- name: Undefine the nat64_appliance VM
29+
community.libvirt.virt:
30+
command: undefine
31+
name: "{{ cifmw_nat64_appliance_name }}"
32+
force: true
33+
uri: "{{ cifmw_nat64_libvirt_uri }}"
34+
35+
- name: Destroy the nat64 networks
36+
register: net_destroy
37+
community.libvirt.virt_net:
38+
command: destroy
39+
name: "{{ item }}"
40+
uri: "{{ cifmw_nat64_libvirt_uri }}"
41+
loop:
42+
- "{{ cifmw_nat64_network_ipv4_name }}"
43+
- "{{ cifmw_nat64_network_ipv6_name }}"
44+
failed_when:
45+
- net_destroy.rc is defined
46+
- net_destroy.rc > 1
47+
48+
- name: Undefine the nat64 networks
49+
community.libvirt.virt_net:
50+
command: undefine
51+
name: "{{ item }}"
52+
uri: "{{ cifmw_nat64_libvirt_uri }}"
53+
loop:
54+
- "{{ cifmw_nat64_network_ipv4_name }}"
55+
- "{{ cifmw_nat64_network_ipv6_name }}"
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
- name: Set MAC address facts
3+
ansible.builtin.set_fact:
4+
cifmw_nat64_appliance_ipv4_mac_address: "{{ '52:54:00' | community.general.random_mac }}"
5+
cifmw_nat64_appliance_ipv6_mac_address: "{{ '52:54:00' | community.general.random_mac }}"
6+
7+
- name: Create the IPv4 libvirt network for nat64
8+
community.libvirt.virt_net:
9+
command: define
10+
name: "{{ cifmw_nat64_network_ipv4_name }}"
11+
xml: "{{ lookup('template', 'ipv4_network.xml.j2') }}"
12+
uri: "{{ cifmw_nat64_libvirt_uri }}"
13+
14+
- name: Ensure the IPv4 libvirt network for nat64 is created/started
15+
community.libvirt.virt_net:
16+
command: create
17+
name: "{{ cifmw_nat64_network_ipv4_name }}"
18+
uri: "{{ cifmw_nat64_libvirt_uri }}"
19+
20+
- name: Ensure the IPv4 libvirt network for nat64 is active
21+
community.libvirt.virt_net:
22+
state: active
23+
name: "{{ cifmw_nat64_network_ipv4_name }}"
24+
uri: "{{ cifmw_nat64_libvirt_uri }}"
25+
26+
- name: Ensure the IPv4 libvirt network for nat64 is enabled to autostart
27+
community.libvirt.virt_net:
28+
autostart: true
29+
name: "{{ cifmw_nat64_network_ipv4_name }}"
30+
uri: "{{ cifmw_nat64_libvirt_uri }}"
31+
32+
- name: Create the IPv6 libvirt network for nat64
33+
community.libvirt.virt_net:
34+
command: define
35+
name: "{{ cifmw_nat64_network_ipv6_name }}"
36+
xml: "{{ lookup('template', 'ipv6_network.xml.j2') }}"
37+
uri: "{{ cifmw_nat64_libvirt_uri }}"
38+
39+
- name: Ensure the IPv6 libvirt network for nat64 is created/started
40+
community.libvirt.virt_net:
41+
command: create
42+
name: "{{ cifmw_nat64_network_ipv6_name }}"
43+
uri: "{{ cifmw_nat64_libvirt_uri }}"
44+
45+
- name: Ensure the IPv6 libvirt network for nat64 network is active
46+
community.libvirt.virt_net:
47+
state: active
48+
name: "{{ cifmw_nat64_network_ipv6_name }}"
49+
uri: "{{ cifmw_nat64_libvirt_uri }}"
50+
51+
- name: Ensure the IPv6 libvirt network for nat64 is enabled to autostart
52+
community.libvirt.virt_net:
53+
autostart: true
54+
name: "{{ cifmw_nat64_network_ipv6_name }}"
55+
uri: "{{ cifmw_nat64_libvirt_uri }}"
56+
57+
- name: "Generate nat64-appliance UUID"
58+
ansible.builtin.set_fact:
59+
nat64_appliance_uuid: "{{ 99999999 | random | to_uuid | lower }}"
60+
61+
- name: "Create the config-drive ISO for the nat64-appliance"
62+
vars:
63+
cifmw_config_drive_iso_image: "{{ cifmw_nat64_appliance_workdir }}/{{ nat64_appliance_uuid }}.iso"
64+
cifmw_config_drive_uuid: "{{ nat64_appliance_uuid }}"
65+
cifmw_config_drive_name: "{{ cifmw_nat64_appliance_name }}"
66+
cifmw_config_drive_hostname: "{{ cifmw_nat64_appliance_name }}"
67+
cifmw_config_drive_userdata:
68+
ssh_authorized_keys:
69+
- "{{ lookup('file', cifmw_nat64_appliance_ssh_pub_key) }}"
70+
write_files:
71+
- path: "/etc/nat64/config-data"
72+
owner: "root:root"
73+
content: "{{ lookup('template', 'config-data.j2') }}"
74+
cifmw_config_drive_networkconfig:
75+
network:
76+
version: 2
77+
ethernets:
78+
id0:
79+
match:
80+
macaddress: "{{ cifmw_nat64_appliance_ipv4_mac_address }}"
81+
addresses:
82+
- "{{ cifmw_nat64_appliance_ipv4_address }}/{{ cifmw_nat64_network_ipv4_prefix }}"
83+
routes:
84+
- to: "0.0.0.0/0"
85+
via: "{{ cifmw_nat64_network_ipv4_address }}"
86+
on-link: true
87+
nameservers:
88+
addresses:
89+
- "{{ cifmw_nat64_network_ipv4_address }}"
90+
id1:
91+
match:
92+
macaddress: "{{ cifmw_nat64_appliance_ipv6_mac_address }}"
93+
addresses:
94+
- "{{ cifmw_nat64_appliance_ipv6_address }}/{{ cifmw_nat64_network_ipv6_prefix }}"
95+
ansible.builtin.include_role:
96+
name: config_drive
97+
98+
- name: "Define nat64-appliance VM"
99+
community.libvirt.virt:
100+
command: define
101+
xml: "{{ lookup('template', 'domain.xml.j2') }}"
102+
uri: "{{ cifmw_nat64_libvirt_uri }}"
103+
104+
- name: "Start VMs for type {{ vm_type }}"
105+
community.libvirt.virt:
106+
state: running
107+
name: "{{ cifmw_nat64_appliance_name }}"
108+
uri: "{{ cifmw_nat64_libvirt_uri }}"

roles/nat64_appliance/tasks/main.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
state: directory
3030
mode: "0755"
3131

32-
3332
- name: Install required RPM packages
3433
tags:
3534
- packages
@@ -61,9 +60,15 @@
6160
- "elements/"
6261
- nat64-appliance.yaml
6362

63+
- name: Clone edpm-image-builder (reset-bls-entries dib element)
64+
ansible.builtin.git:
65+
repo: https://github.com/openstack-k8s-operators/edpm-image-builder.git
66+
dest: "{{ cifmw_nat64_appliance_workdir }}/edpm-image-builder"
67+
version: main
68+
6469
- name: Build the nat64-appliance image using DIB
6570
environment:
66-
ELEMENTS_PATH: "{{ cifmw_nat64_appliance_workdir }}/elements"
71+
ELEMENTS_PATH: "{{ cifmw_nat64_appliance_workdir }}/elements:{{ cifmw_nat64_appliance_workdir }}/edpm-image-builder/dib/"
6772
DIB_IMAGE_CACHE: "{{ cifmw_nat64_appliance_workdir }}/cache"
6873
cifmw.general.ci_script:
6974
chdir: "{{ cifmw_nat64_appliance_workdir }}"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# The IPv6 ip subnet, for example: fd00:abcd:abcd:fc00::/64
2+
NAT64_IPV6_PREFIX={{ cifmw_nat64_ipv6_prefix }}
3+
4+
# The IPv6 host address, for example: fd00:abcd:abcd:fc00::2
5+
NAT64_HOST_IPV6={{ cifmw_nat64_appliance_ipv6_address }}
6+
7+
# The IPv6 address used for the tayga tun interface, for example: fd00:abcd:abcd:fc00::3
8+
NAT64_TAYGA_IPV6={{ cifmw_nat64_ipv6_tayga_address }}

0 commit comments

Comments
 (0)