Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions ansible/library/port_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,26 @@ def get_portmap(self):
raise Exception("Something wrong when trying to find the portmap file, either the hwsku is not available or file location is not correct")
with open(self.filename) as f:
lines = f.readlines()
for line in lines:
if 'Ethernet' in line:
mapping = line.split()
if len(mapping) < 3:
self.portmap.append(mapping[0])
else:
self.portmap.append(mapping[2])
index = 0
if re.match('^#', lines[0].strip()):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you refer to this pull request and store all the information in the port_config.ini file accordingly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when building docker-sonic-mgmt, it will install the device package which include all port_config.ini files to the correct location in docker-sonic-mgmt. Is this what you want?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry I didn't add the link to my previous comment: https://github.com/Azure/sonic-swss/pull/287/files this pull request has a better logic to parse the port_config.ini file.

title = re.sub('#', '', lines[0].strip().lower()).split()
if 'alias' in title:
index = title.index('alias')
for line in lines:
if 'Ethernet' in line:
mapping = line.split()
if index < len(mapping):
self.portmap.append(mapping[index])
else:
self.portmap.append(mapping[0])
else:
for line in lines:
if 'Ethernet' in line:
mapping = line.split()
if len(mapping) < 3:
self.portmap.append(mapping[0])
else:
self.portmap.append(mapping[2])
return

def main():
Expand All @@ -78,10 +91,11 @@ def main():
allmap = SonicPortAliasMap(m_args['hwsku'])
allmap.get_portmap()
module.exit_json(ansible_facts={'port_alias': allmap.portmap})
except (IOError, OSError):
module.fail_json(msg=allmap.portmap)
except Exception:
module.fail_json(msg=allmap.portmap)
except (IOError, OSError), e:
module.fail_json("IO error" + str(e))
except Exception, e:
msg = "failed to find the correct port names for " + m_args['hwsku'] + str(e)
module.fail_json(msg)

from ansible.module_utils.basic import *
if __name__ == "__main__":
Expand Down