From bbcb7d9118b7e290d4c423cf1ee69a4f9920a0f7 Mon Sep 17 00:00:00 2001 From: Ricardo Carrillo Cruz Date: Tue, 10 Apr 2018 18:57:56 +0200 Subject: [PATCH] Cherry pick 35568 (#38347) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * eos_vlan: Modified logic to allow for more than 6 interfaces to be assigned to … (#35568) * Modified logic to allow for more than 6 interfaces to be assigned to a vlan * arista output to json. removing logic for string size. (cherry picked from commit 99627ab99df193789dde7b9f8af3fb6edd59e0fa) * Add changelog fragment --- .../fragments/eos_vlan_more_than_6_nics.yaml | 2 ++ lib/ansible/modules/network/eos/eos_vlan.py | 24 +++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) create mode 100644 changelogs/fragments/eos_vlan_more_than_6_nics.yaml diff --git a/changelogs/fragments/eos_vlan_more_than_6_nics.yaml b/changelogs/fragments/eos_vlan_more_than_6_nics.yaml new file mode 100644 index 0000000000..302ab5efdb --- /dev/null +++ b/changelogs/fragments/eos_vlan_more_than_6_nics.yaml @@ -0,0 +1,2 @@ +bugfixes: + - eos_vlan - fixed eos_vlan not working when having more than 6 interfaces (https://github.com/ansible/ansible/pull/38347) diff --git a/lib/ansible/modules/network/eos/eos_vlan.py b/lib/ansible/modules/network/eos/eos_vlan.py index 423329165b..5958b9b0b0 100644 --- a/lib/ansible/modules/network/eos/eos_vlan.py +++ b/lib/ansible/modules/network/eos/eos_vlan.py @@ -213,25 +213,23 @@ def map_obj_to_commands(updates, module): def map_config_to_obj(module): objs = [] - output = run_commands(module, ['show vlan']) - lines = output[0].strip().splitlines()[2:] + vlans = run_commands(module, ['show vlan conf | json']) - for l in lines: - splitted_line = re.split(r'\s{2,}', l.strip()) + for vlan in vlans[0]['vlans']: obj = {} - obj['vlan_id'] = splitted_line[0] - obj['name'] = splitted_line[1] - obj['state'] = splitted_line[2] + obj['vlan_id'] = vlan + obj['name'] = vlans[0]['vlans'][vlan]['name'] + obj['state'] = vlans[0]['vlans'][vlan]['status'] + obj['interfaces'] = [] + + interfaces = vlans[0]['vlans'][vlan] + + for interface in interfaces['interfaces']: + obj['interfaces'].append(interface) if obj['state'] == 'suspended': obj['state'] = 'suspend' - obj['interfaces'] = [] - if len(splitted_line) > 3: - - for i in splitted_line[3].split(','): - obj['interfaces'].append(i.strip().replace('Et', 'ethernet')) - objs.append(obj) return objs