summaryrefslogtreecommitdiffstats
path: root/deploy/adapters/ansible/roles/setup-network
diff options
context:
space:
mode:
authoryour name <email@163.com>2015-09-09 03:26:11 -0400
committeryour name <email@163.com>2015-09-09 03:26:11 -0400
commit72039e915d1fc960bd0d7fccd910ea282d61bee7 (patch)
tree60452129b1b9f3c3419b4a29a038f5f0cbade5f7 /deploy/adapters/ansible/roles/setup-network
parentcf87d3067a63cb8be315a3addfd9c27d86be3b5a (diff)
Compass Netconfig optimization
Change-Id: Icbcfc7d794623436f22be5f6763b212a25d4fac7 JIRA: COMPASS-30
Diffstat (limited to 'deploy/adapters/ansible/roles/setup-network')
-rw-r--r--deploy/adapters/ansible/roles/setup-network/tasks/main.yml43
-rw-r--r--deploy/adapters/ansible/roles/setup-network/templates/my_configs.debian16
2 files changed, 59 insertions, 0 deletions
diff --git a/deploy/adapters/ansible/roles/setup-network/tasks/main.yml b/deploy/adapters/ansible/roles/setup-network/tasks/main.yml
new file mode 100644
index 00000000..94816044
--- /dev/null
+++ b/deploy/adapters/ansible/roles/setup-network/tasks/main.yml
@@ -0,0 +1,43 @@
+---
+- name: add ovs bridge
+ openvswitch_bridge: bridge={{ item["name"] }} state=present
+ with_items: "{{ network_cfg['provider_net_mappings'] }}"
+ when: 'item["type"] == "ovs"'
+
+- name: add ovs uplink
+ openvswitch_port: bridge={{ item["name"] }} port={{ item["interface"] }} state=present
+ with_items: "{{ network_cfg['provider_net_mappings'] }}"
+ when: 'item["type"] == "ovs"'
+
+- name: add ovs uplink
+ shell: ip link set {{ item["interface"] }} up
+ with_items: "{{ network_cfg['provider_net_mappings'] }}"
+ when: 'item["type"] == "ovs"'
+
+- name: setup sys intf
+ shell: ip link del {{ item["name"] }}; \
+ ip link add link {{ item["interface"] }} name {{ item["name"] }} type vlan id {{ item["vlan_tag"] }}; \
+ ip link set {{ item["interface"] }} up
+ when: '"vlan_tag" in item'
+ with_items: "{{ network_cfg['sys_intf_mappings'] }}"
+
+
+- name: set sys intf ip
+ shell: ip addr del {{ item["ip"] }}/{{ item["netmask"] }} dev {{ item["alias"] }}; \
+ ip addr add {{ item["ip"] }}/{{ item["netmask"] }} dev {{ item["alias"] }}; \
+ ip link set {{ item["alias"] }} up
+ with_items: "{{ host_ip_settings }}"
+
+- name: set gateway
+ shell: ip route del default; \
+ ip route add default via {{ item["gw"] }} dev {{ item["alias"] }}
+ when: '"gw" in item'
+ with_items: "{{ host_ip_settings }}"
+
+- name: copy net config
+ template: src=my_configs.debian dest=/etc/network/interfaces.d/my_configs.cfg
+ when: ansible_os_family == "Debian"
+
+- name: source net config
+ lineinfile: dest=/etc/network/interfaces line='source /etc/network/interfaces.d/my_configs.cfg'
+ when: ansible_os_family == "Debian"
diff --git a/deploy/adapters/ansible/roles/setup-network/templates/my_configs.debian b/deploy/adapters/ansible/roles/setup-network/templates/my_configs.debian
new file mode 100644
index 00000000..54031ed4
--- /dev/null
+++ b/deploy/adapters/ansible/roles/setup-network/templates/my_configs.debian
@@ -0,0 +1,16 @@
+{%- for intf in host_ip_settings %}
+
+auto {{ intf["alias"] }}
+iface {{ intf["alias"] }} inet static
+ address {{ intf["ip"] }}
+ netmask {{ intf["netmask"] }}
+{% if "gw" in intf %}
+ gateway {{ intf["gw"] }}
+{% endif %}
+{% for sys_intf in network_cfg["sys_intf_mappings"] %}
+{% if "vlan_tag" in sys_intf and sys_intf["name"] == intf["alias"] %}
+ pre-up ip link set {{ sys_intf["interface"] }} up
+ pre-up ip link add link {{ sys_intf["interface"] }} name {{ sys_intf["name"] }} type vlan id {{ sys_intf["vlan_tag"] }}
+{% endif %}
+{% endfor %}
+{% endfor %}