Skip to content
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

- Handle the disapperance of net-tools #1290

Merged
merged 1 commit into from
Aug 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 9 additions & 6 deletions azurelinuxagent/common/osutil/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,8 @@ def get_endpoint_from_leases_path(pathglob):
return endpoint

def is_missing_default_route(self):
routes = shellutil.run_get_output("route -n")[1]
route_cmd = "ip route show"
routes = shellutil.run_get_output(route_cmd)[1]
for route in routes.split("\n"):
if route.startswith("0.0.0.0 ") or route.startswith("default "):
return False
Expand All @@ -1005,11 +1006,14 @@ def get_ip4_addr(self):
return self.get_first_if()[1]

def set_route_for_dhcp_broadcast(self, ifname):
return shellutil.run("route add 255.255.255.255 dev {0}".format(ifname),
route_cmd = "ip route add"
return shellutil.run("{0} 255.255.255.255 dev {1}".format(
route_cmd, ifname),
chk_err=False)

def remove_route_for_dhcp_broadcast(self, ifname):
shellutil.run("route del 255.255.255.255 dev {0}".format(ifname),
route_cmd = "ip route del"
shellutil.run("{0} 255.255.255.255 dev {1}".format(route_cmd, ifname),
chk_err=False)

def is_dhcp_available(self):
Expand Down Expand Up @@ -1044,10 +1048,9 @@ def restart_ssh_service(self):

def route_add(self, net, mask, gateway):
"""
Add specified route using /sbin/route add -net.
Add specified route
"""
cmd = ("/sbin/route add -net "
"{0} netmask {1} gw {2}").format(net, mask, gateway)
cmd = "ip route add {0} via {1}".format(net, gateway)
return shellutil.run(cmd, chk_err=False)

def get_dhcp_pid(self):
Expand Down
5 changes: 5 additions & 0 deletions azurelinuxagent/common/utils/shellutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ def __str__(self):
Shell command util functions
"""

def has_command(cmd):
"""
Return True if the given command is on the path
"""
return not run(cmd, False)

def run(cmd, chk_err=True):
"""
Expand Down