| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -95,18 +95,43 @@ def get_control_if(self): | |
| return ip | ||
| return None | ||
|
|
||
| def check_if_link_exists(self,dev): | ||
| cmd="ip link show dev %s"%dev | ||
| result=CsHelper.execute(cmd) | ||
| if(len(result)!=0): | ||
| return True | ||
| else: | ||
| return False | ||
|
|
||
| def check_if_link_up(self,dev): | ||
| cmd="ip link show dev %s | tr '\n' ' ' | cut -d ' ' -f 9"%dev | ||
|
Comment thread
Copy link
Copy Markdown
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI still think that we should do the splitting in Python. Execute ip with the -o flag so it is a one-liner and split with Python afterwards.
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityIf you only want the state, why not simply do this? No magic needed.
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityHi, just out of curiosity why should we do the splitting in python and what is wrong in doing it this way.
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityWe should keep as much logic in Python as possible. The performance difference is small, but with tr and grep you spawn subprocessess again. But as @remibergsma says. Try to open that file in /sys and parse the contents. You can use the simple Python file functions. No need to execute IP. The less subprocesses we execute, the better.
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityHi,
Sorry, something went wrong.
All reactions
|
||
| result=CsHelper.execute(cmd) | ||
| if(result[0].lower()=="up"): | ||
| return True | ||
| else: | ||
| return False | ||
|
|
||
|
|
||
| def process(self): | ||
| route = CsRoute() | ||
| found_defaultroute = False | ||
|
|
||
| for dev in self.dbag: | ||
| if dev == "id": | ||
| continue | ||
| ip = CsIP(dev, self.config) | ||
|
|
||
| for address in self.dbag[dev]: | ||
| if(address["nw_type"]!="public"): | ||
| continue | ||
|
|
||
| #check if link is up | ||
| if (not self.check_if_link_exists(dev)): | ||
| logging.info("link %s does not exist, so not processing"%dev) | ||
| continue | ||
| if not self.check_if_link_up(dev): | ||
| cmd="ip link set %s up"%dev | ||
| CsHelper.execute(cmd) | ||
|
|
||
| gateway = str(address["gateway"]) | ||
| network = str(address["network"]) | ||
|
|
||
| ip.setAddress(address) | ||
| Expand All | @@ -122,16 +147,15 @@ def process(self): | |
| "Address %s on device %s not configured", ip.ip(), dev) | ||
| if CsDevice(dev, self.config).waitfordevice(): | ||
| ip.configure() | ||
| route.add_route(dev, network) | ||
|
|
||
| if address["nw_type"] != "control": | ||
| route.add_route(dev, network) | ||
| # once we start processing public ip's we need to verify there | ||
| # is a default route and add if needed | ||
| if not route.defaultroute_exists(): | ||
| cmdline=self.config.get_cmdline_instance() | ||
| if(cmdline.get_gateway()): | ||
| route.add_defaultroute(cmdline.get_gateway()) | ||
|
|
||
| # once we start processing public ip's we need to verify there | ||
| # is a default route and add if needed | ||
| if address["nw_type"] == "public" and not found_defaultroute: | ||
| if not route.defaultroute_exists(): | ||
| if route.add_defaultroute(gateway): | ||
| found_defaultroute = True | ||
|
|
||
|
|
||
| class CsInterface: | ||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Qualitycan we use a better string processing here, instead of using hardcoded cut/trim limits?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityIndeed and also use the -o flag for 'ip':
ip -o link show dev
Then split the string using Python.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityHi,
the output of Ip link show command is not expected to changes so in this case i think hardcoding the limiters is not an issue.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.