-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_snake.yml
168 lines (152 loc) · 4.98 KB
/
build_snake.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
- hosts: dut
connection: local
gather_facts: no
vars:
state: present
snake_tag: snake
max_vnf: 255
roles:
- ansible-nfvis
tags:
- facts
tasks:
- name: Get NFVIS facts
nfvis_facts:
host: "{{ ansible_host }}"
user: "{{ ansible_user }}"
password: "{{ ansible_password }}"
register: nfvis_facts
- set_fact:
total_vcpus_available: "{{ nfvis_facts['cpu-info']['total-logical-cpus'] - total_vcpus_used | int }}"
vars:
total_vcpus_used: "{{ nfvis_facts['cpu-info']['logical-cpus-used-by-system'] + nfvis_facts['cpu-info']['logical-cpus-used-by-vnfs'] | int }}"
# - debug:
# var: nfvis_facts
- set_fact:
num_snakes: "{{ total_vcpus_available|int if total_vcpus_available|int < max_vnf|int else max_vnf|int }}"
- debug:
msg: "{{ total_vcpus_available }} VCPUs available. Building {{ num_snakes }} VNF snake test"
- name: Add VNF to inventory
add_host:
name: "{{ snake_tag }}{{ item }}"
group: snake_test
vnf_number: "{{ item }}"
vnf_total: "{{ num_snakes }}"
with_sequence: start=1 end="{{ num_snakes }}"
- hosts: snake_test
connection: local
gather_facts: no
roles:
- ansible-nfvis
vars:
snake_tag: snake
mgmt_bridge: 'wan-br'
test_wan_net: test-wan
test_lan_net: test-lan
wan_net: test-wan
lan_net: test-lan
lan_cidr_block: 192.168.0.0/16
dest_lan_cidr: "{{ lan_cidr_block | ipsubnet(24, 255) }}"
lan_cidr: "{{ lan_cidr_block | ipsubnet(24, 255) }}"
vnf_image: isrv_16.09.01a_noll
vnf_flavor: isrv-small
vnf_template: ios/cli.j2
state: present
tasks:
- name: Calculate wan-net
set_fact:
wan_net: "{{ snake_tag }}-net{{ vnf_number|int - 1 }}"
when: vnf_number|int > 1
- name: Calculate lan-net
set_fact:
lan_net: "{{ snake_tag }}-net{{ vnf_number }}"
lan_cidr: "{{ lan_cidr_block | ipsubnet(24, vnf_number) }}"
when: vnf_number != vnf_total
- name: Calculate network addresses
set_fact:
lan_ip: "{{ lan_cidr | ipaddr(1) }}"
lan_route: "{{ lan_cidr | ipaddr(2) }}"
wan_cidr: "{{ lan_cidr_block | ipsubnet(24, vnf_number|int - 1) }}"
wan_ip: "{{ lan_cidr_block | ipsubnet(24, vnf_number|int - 1) | ipaddr(2) }}"
wan_gateway: "{{ lan_cidr_block | ipsubnet(24, vnf_number|int - 1) | ipaddr(1) }}"
# - debug:
# msg: "{{ vnf_number }}/{{ vnf_total }} vnf: {{ inventory_hostname }}, wan_net: {{ wan_net }}, lan_net: {{ lan_net }}, lan_cidr: {{ lan_cidr }}"
- name: Build snake bridges
nfvis_bridge:
host: "{{ hostvars['dut'].ansible_host }}"
user: "{{ ansible_user }}"
password: "{{ ansible_password }}"
name: "{{ lan_net }}_br"
state: "{{ state }}"
register: results
when: lan_net != test_lan_net
- name: Build snake networks
nfvis_network:
host: "{{ hostvars['dut'].ansible_host }}"
user: "{{ ansible_user }}"
password: "{{ ansible_password }}"
name: "{{ lan_net }}"
bridge: "{{ lan_net }}_br"
state: "{{ state }}"
register: results
when: lan_net != test_lan_net
- set_fact:
interfaces:
GigabitEthernet2:
enabled: true
ip:
primary: "{{ wan_ip }}"
gateway: "{{ wan_gateway | ipaddr('address') }}"
GigabitEthernet3:
enabled: true
ip:
primary: "{{ lan_ip }}"
router:
ospf:
id: 1
router_id: "{{ wan_ip }}"
default_information_originate: true
networks:
- network: "{{ wan_cidr }}"
area: 0
- network: "{{ lan_cidr }}"
area: 0
# - set_fact:
# static_routes:
# global:
# - network: "{{ dest_lan_cidr }}"
# fwd_list:
# - fwd: "{{ lan_route }}"
# when: vnf_number < vnf_total
#
# - debug:
# var: static_routes
# when: vnf_number < vnf_total
# - copy:
# content: "{{ lookup('template', 'ios/cli.j2') }}"
# dest: "{{ snake_tag }}-{{ vnf_number }}.cfg"
- name: Build snake VNFs
nfvis_deployment:
host: "{{ hostvars['dut'].ansible_host }}"
user: "{{ ansible_user }}"
password: "{{ ansible_password }}"
name: "{{ snake_tag }}-{{ vnf_number }}"
timeout: 60
state: "{{ state }}"
image: "{{ vnf_image }}"
flavor: "{{ vnf_flavor }}"
interfaces:
- network: int-mgmt-net
- network: "{{ wan_net }}"
- network: "{{ lan_net }}"
bootup_time: 600
port_forwarding:
- proxy_port: "{{ 21000 + vnf_number|int }}"
source_bridge: "{{ mgmt_bridge }}"
config_data:
- dst: iosxe_config.txt
data: "{{ lookup('template', 'ios/nfvis.j2') }}"
register: deployment_results
until: "'OK' in deployment_results.response"
retries: 6
delay: 10