a01c7974ad42391d33f5e0b37f53f894d07e0581
[yardstick.git] / ansible / roles / infra_create_network / tasks / create_xml.yaml
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       - bridge
44       - ip
45     pretty_print: yes
46
47 - name: Add "name" attribute to "bridge" node
48   xml:
49     path: "{{ xml_file }}"
50     xpath: /network/bridge
51     attribute: name
52     value: "{{ item.name }}"
53     pretty_print: yes
54
55 - name: Add "stp" attribute to "bridge" node
56   xml:
57     path: "{{ xml_file }}"
58     xpath: /network/bridge
59     attribute: stp
60     value: "on"
61     pretty_print: yes
62
63 - name: Add "delay" attribute to "bridge" node
64   xml:
65     path: "{{ xml_file }}"
66     xpath: /network/bridge
67     attribute: delay
68     value: "0"
69     pretty_print: yes
70
71 - name: Add "address" attribute to "ip" node
72   xml:
73     path: "{{ xml_file }}"
74     xpath: /network/ip
75     attribute: address
76     value: "{{ item.host_ip }}"
77     pretty_print: yes
78
79 - name: Add "netmask" attribute to "ip" node
80   xml:
81     path: "{{ xml_file }}"
82     xpath: /network/ip
83     attribute: netmask
84     value: "{{ item.netmask }}"
85     pretty_print: yes
86
87 - name: Define the networks
88   virt_net:
89     command: define
90     name: "{{ item.name }}"
91     xml: "{{ lookup('file', xml_file) }}"
92
93 - name: Set autostart to yes
94   virt_net:
95     autostart: yes
96     name: "{{ item.name }}"
97
98 - name: Start the networks
99   virt_net:
100     command: start
101     name: "{{ item.name }}"
102
103 - name: Remove XML file
104   file:
105     path: "{{ xml_file }}"
106     state: absent