-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CLOUDSTACK-8799 fixed the defalut routes #784
New issue
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
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. I 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.
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. If you only want the state, why not simply do this? No magic needed.
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. Hi, just out of curiosity why should we do the splitting in python and what is wrong in doing it this way.
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. We 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.
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. Hi, |
||
| 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) | ||
|
|
@@ -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: | ||
|
|
||
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.
can we use a better string processing here, instead of using hardcoded cut/trim limits?
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.
Indeed and also use the -o flag for 'ip':
ip -o link show dev
Then split the string using Python.
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.
Hi,
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.