Merge changes from topic 'YARDSTICK-1040'
[yardstick.git] / ansible / roles / infra_create_network / tasks / create_xml.yml
1 # Copyright (c) 2017-2018 Intel Corporation.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 ---
15 - name: Define XML file name
16   set_fact:
17     xml_file: "{{ '/tmp/'+item.name+'.xml' }}"
18
19 - name: Delete the file, if exists
20   file:
21     path: "{{ xml_file }}"
22     state: absent
23
24 - name: Create a new empty file
25   file:
26     path: "{{ xml_file }}"
27     state: touch
28
29 - name: Add root "network" node
30   blockinfile:
31     path: "{{ xml_file }}"
32     marker: ""
33     content: |
34       <network>
35       </network>
36
37 - name: Add new children nodes to "network" node
38   xml:
39     path: "{{ xml_file }}"
40     xpath: /network
41     add_children:
42       - name: "{{ item.name }}"
43       - forward:
44           mode: nat
45       - bridge
46       - ip
47     pretty_print: yes
48
49 - name: Add new children nodes to "forward" node
50   xml:
51     path: "{{ xml_file }}"
52     xpath: /network/forward
53     add_children:
54       - nat
55     pretty_print: yes
56
57 - name: Add new children nodes to "nat" node
58   xml:
59     path: "{{ xml_file }}"
60     xpath: /network/forward/nat
61     add_children:
62       - port:
63           start: "1024"
64           end: "65535"
65     pretty_print: yes
66
67 - name: Add "name" attribute to "bridge" node
68   xml:
69     path: "{{ xml_file }}"
70     xpath: /network/bridge
71     attribute: name
72     value: "{{ item.name }}"
73     pretty_print: yes
74
75 - name: Add "stp" attribute to "bridge" node
76   xml:
77     path: "{{ xml_file }}"
78     xpath: /network/bridge
79     attribute: stp
80     value: "on"
81     pretty_print: yes
82
83 - name: Add "delay" attribute to "bridge" node
84   xml:
85     path: "{{ xml_file }}"
86     xpath: /network/bridge
87     attribute: delay
88     value: "0"
89     pretty_print: yes
90
91 - name: Add "address" attribute to "ip" node
92   xml:
93     path: "{{ xml_file }}"
94     xpath: /network/ip
95     attribute: address
96     value: "{{ item.host_ip }}"
97     pretty_print: yes
98
99 - name: Add "netmask" attribute to "ip" node
100   xml:
101     path: "{{ xml_file }}"
102     xpath: /network/ip
103     attribute: netmask
104     value: "{{ item.netmask }}"
105     pretty_print: yes
106
107 - name: Define the networks
108   virt_net:
109     command: define
110     name: "{{ item.name }}"
111     xml: "{{ lookup('file', xml_file) }}"
112
113 - name: Set autostart to yes
114   virt_net:
115     autostart: yes
116     name: "{{ item.name }}"
117
118 - name: Start the networks
119   virt_net:
120     command: start
121     name: "{{ item.name }}"
122
123 - name: Remove XML file
124   file:
125     path: "{{ xml_file }}"
126     state: absent