From c19bf33eb19538d0718d64640b45ae40e2618cd6 Mon Sep 17 00:00:00 2001 From: ipvsean Date: Tue, 13 Feb 2018 16:47:46 -0500 Subject: [PATCH 1/4] adding support for loopback interface currently the loopback interface lo is not supported with vyos_l3_interface, this commit fixes that. Right now there is a limit of loopback interfaces to just lo, if you want more interfaces you need to use a dummy interface https://wiki.vyos.net/wiki/Dummy_interfaces --- .../modules/network/vyos/vyos_l3_interface.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/network/vyos/vyos_l3_interface.py b/lib/ansible/modules/network/vyos/vyos_l3_interface.py index e33b1f3e23e3d5..4e4dd89dc3eff0 100644 --- a/lib/ansible/modules/network/vyos/vyos_l3_interface.py +++ b/lib/ansible/modules/network/vyos/vyos_l3_interface.py @@ -117,18 +117,35 @@ def map_obj_to_commands(updates, module): obj_in_have = search_obj_in_list(name, have) if state == 'absent' and obj_in_have: if not ipv4 and not ipv6 and (obj_in_have['ipv4'] or obj_in_have['ipv6']): + if name == "lo": + commands.append('delete interfaces loopback lo address') + else: commands.append('delete interfaces ethernet ' + name + ' address') else: if ipv4 and obj_in_have['ipv4']: + if name == "lo": + commands.append('delete interfaces loopback lo address ' + ipv4) + else: commands.append('delete interfaces ethernet ' + name + ' address ' + ipv4) if ipv6 and obj_in_have['ipv6']: + if name == "lo": + commands.append('delete interfaces loopback lo address ' + ipv6) + else: commands.append('delete interfaces ethernet ' + name + ' address ' + ipv6) elif (state == 'present' and obj_in_have): if ipv4 and ipv4 != obj_in_have['ipv4']: + if name == "lo": + commands.append('set interfaces loopback lo address ' + + ipv4) + else: commands.append('set interfaces ethernet ' + name + ' address ' + ipv4) if ipv6 and ipv6 != obj_in_have['ipv6']: + if name == "lo": + commands.append('set interfaces loopback lo address ' + + ipv6) + else: commands.append('set interfaces ethernet ' + name + ' address ' + ipv6) @@ -137,7 +154,7 @@ def map_obj_to_commands(updates, module): def map_config_to_obj(module): obj = [] - output = run_commands(module, ['show interfaces ethernet']) + output = run_commands(module, ['show interfaces']) lines = output[0].splitlines() if len(lines) > 3: From 8a126c2e220535d99086c476dc651fc7d339a997 Mon Sep 17 00:00:00 2001 From: ipvsean Date: Tue, 13 Feb 2018 17:24:56 -0500 Subject: [PATCH 2/4] fixing spacing as per pep8 test fixing issues for sanity test lib/ansible/modules/network/vyos/vyos_l3_interface.py:120:15: E111 indentation is not a multiple of four lib/ansible/modules/network/vyos/vyos_l3_interface.py:122:15: E111 indentation is not a multiple of four lib/ansible/modules/network/vyos/vyos_l3_interface.py:126:19: E111 indentation is not a multiple of four lib/ansible/modules/network/vyos/vyos_l3_interface.py:128:19: E111 indentation is not a multiple of four lib/ansible/modules/network/vyos/vyos_l3_interface.py:131:19: E111 indentation is not a multiple of four lib/ansible/modules/network/vyos/vyos_l3_interface.py:133:19: E111 indentation is not a multiple of four lib/ansible/modules/network/vyos/vyos_l3_interface.py:137:15: E111 indentation is not a multiple of four lib/ansible/modules/network/vyos/vyos_l3_interface.py:140:15: E111 indentation is not a multiple of four lib/ansible/modules/network/vyos/vyos_l3_interface.py:145:15: E111 indentation is not a multiple of four lib/ansible/modules/network/vyos/vyos_l3_interface.py:148:15: E111 indentation is not a multiple of four --- .../modules/network/vyos/vyos_l3_interface.py | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/ansible/modules/network/vyos/vyos_l3_interface.py b/lib/ansible/modules/network/vyos/vyos_l3_interface.py index 4e4dd89dc3eff0..f202a657c173a6 100644 --- a/lib/ansible/modules/network/vyos/vyos_l3_interface.py +++ b/lib/ansible/modules/network/vyos/vyos_l3_interface.py @@ -117,36 +117,36 @@ def map_obj_to_commands(updates, module): obj_in_have = search_obj_in_list(name, have) if state == 'absent' and obj_in_have: if not ipv4 and not ipv6 and (obj_in_have['ipv4'] or obj_in_have['ipv6']): - if name == "lo": - commands.append('delete interfaces loopback lo address') - else: - commands.append('delete interfaces ethernet ' + name + ' address') + if name == "lo": + commands.append('delete interfaces loopback lo address') + else: + commands.append('delete interfaces ethernet ' + name + ' address') else: if ipv4 and obj_in_have['ipv4']: - if name == "lo": - commands.append('delete interfaces loopback lo address ' + ipv4) - else: - commands.append('delete interfaces ethernet ' + name + ' address ' + ipv4) + if name == "lo": + commands.append('delete interfaces loopback lo address ' + ipv4) + else: + commands.append('delete interfaces ethernet ' + name + ' address ' + ipv4) if ipv6 and obj_in_have['ipv6']: - if name == "lo": - commands.append('delete interfaces loopback lo address ' + ipv6) - else: - commands.append('delete interfaces ethernet ' + name + ' address ' + ipv6) + if name == "lo": + commands.append('delete interfaces loopback lo address ' + ipv6) + else: + commands.append('delete interfaces ethernet ' + name + ' address ' + ipv6) elif (state == 'present' and obj_in_have): if ipv4 and ipv4 != obj_in_have['ipv4']: - if name == "lo": - commands.append('set interfaces loopback lo address ' + + if name == "lo": + commands.append('set interfaces loopback lo address ' + ipv4) else: - commands.append('set interfaces ethernet ' + name + ' address ' + + commands.append('set interfaces ethernet ' + name + ' address ' + ipv4) if ipv6 and ipv6 != obj_in_have['ipv6']: - if name == "lo": - commands.append('set interfaces loopback lo address ' + + if name == "lo": + commands.append('set interfaces loopback lo address ' + ipv6) - else: - commands.append('set interfaces ethernet ' + name + ' address ' + + else: + commands.append('set interfaces ethernet ' + name + ' address ' + ipv6) return commands From 52aea6bafb996c5aafbb35a9b3d52ea5de04fb61 Mon Sep 17 00:00:00 2001 From: ipvsean Date: Tue, 13 Feb 2018 18:20:29 -0500 Subject: [PATCH 3/4] ugh, missed on spacing issue --- lib/ansible/modules/network/vyos/vyos_l3_interface.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/network/vyos/vyos_l3_interface.py b/lib/ansible/modules/network/vyos/vyos_l3_interface.py index f202a657c173a6..05251cc0013a5f 100644 --- a/lib/ansible/modules/network/vyos/vyos_l3_interface.py +++ b/lib/ansible/modules/network/vyos/vyos_l3_interface.py @@ -137,8 +137,8 @@ def map_obj_to_commands(updates, module): if name == "lo": commands.append('set interfaces loopback lo address ' + ipv4) - else: - commands.append('set interfaces ethernet ' + name + ' address ' + + else: + commands.append('set interfaces ethernet ' + name + ' address ' + ipv4) if ipv6 and ipv6 != obj_in_have['ipv6']: From 6596a9d781983dba80fba73cb394a164de1a2ccc Mon Sep 17 00:00:00 2001 From: ipvsean Date: Tue, 13 Feb 2018 18:41:51 -0500 Subject: [PATCH 4/4] getting rid of continuation lines, the CI system does not like it --- .../modules/network/vyos/vyos_l3_interface.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/ansible/modules/network/vyos/vyos_l3_interface.py b/lib/ansible/modules/network/vyos/vyos_l3_interface.py index 05251cc0013a5f..684668ffdababa 100644 --- a/lib/ansible/modules/network/vyos/vyos_l3_interface.py +++ b/lib/ansible/modules/network/vyos/vyos_l3_interface.py @@ -135,19 +135,15 @@ def map_obj_to_commands(updates, module): elif (state == 'present' and obj_in_have): if ipv4 and ipv4 != obj_in_have['ipv4']: if name == "lo": - commands.append('set interfaces loopback lo address ' + - ipv4) + commands.append('set interfaces loopback lo address ' + ipv4) else: - commands.append('set interfaces ethernet ' + name + ' address ' + - ipv4) + commands.append('set interfaces ethernet ' + name + ' address ' + ipv4) if ipv6 and ipv6 != obj_in_have['ipv6']: if name == "lo": - commands.append('set interfaces loopback lo address ' + - ipv6) + commands.append('set interfaces loopback lo address ' + ipv6) else: - commands.append('set interfaces ethernet ' + name + ' address ' + - ipv6) + commands.append('set interfaces ethernet ' + name + ' address ' + ipv6) return commands