summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorhagbard <vyosdev@derith.de>2019-10-09 09:24:40 -0700
committerhagbard <vyosdev@derith.de>2019-10-09 09:24:40 -0700
commitf8be18fbc549bc574746991bd0bb1de9b424745e (patch)
tree681026f10f4a02f707a1cec037935e20716fdb51 /python
parentc4dbaa158c9b5c6e3c4ff3fe2f9f17d095732547 (diff)
parent21fe962befb2ebd1625eb7a6c28cb3e9005fe37e (diff)
downloadvyos-1x-f8be18fbc549bc574746991bd0bb1de9b424745e.tar.gz
vyos-1x-f8be18fbc549bc574746991bd0bb1de9b424745e.zip
Merge branch 'current' into equuleus
Diffstat (limited to 'python')
-rw-r--r--python/vyos/ifconfig.py39
-rw-r--r--python/vyos/remote.py26
2 files changed, 48 insertions, 17 deletions
diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py
index a77cde5e7..4ac605b54 100644
--- a/python/vyos/ifconfig.py
+++ b/python/vyos/ifconfig.py
@@ -142,7 +142,7 @@ class Interface:
# after interface removal no other commands should be allowed
# to be called and instead should raise an Exception:
cmd = 'ip link del dev {}'.format(self._ifname)
- self._cmd(cmd)
+ return self._cmd(cmd)
def get_mtu(self):
"""
@@ -205,7 +205,7 @@ class Interface:
# Assemble command executed on system. Unfortunately there is no way
# of altering the MAC address via sysfs
cmd = 'ip link set dev {} address {}'.format(self._ifname, mac)
- self._cmd(cmd)
+ return self._cmd(cmd)
def set_arp_cache_tmo(self, tmo):
@@ -293,7 +293,21 @@ class Interface:
# Assemble command executed on system. Unfortunately there is no way
# to up/down an interface via sysfs
cmd = 'ip link set dev {} {}'.format(self._ifname, state)
- self._cmd(cmd)
+ tmp = self._cmd(cmd)
+
+ # better safe then sorry - wait until the interface is really up
+ # but only for a given period of time to avoid potential deadlocks!
+ cnt = 0
+ while self.get_state() != state:
+ cnt += 1
+ if cnt == 50:
+ print('Interface {} could not be brought up in time ...'.format(self._ifname))
+ break
+
+ # sleep 250ms
+ sleep(0.250)
+
+ return tmp
def set_proxy_arp(self, enable):
"""
@@ -402,7 +416,7 @@ class Interface:
else:
if not is_intf_addr_assigned(self._ifname, addr):
cmd = 'ip addr add "{}" dev "{}"'.format(addr, self._ifname)
- self._cmd(cmd)
+ return self._cmd(cmd)
def del_addr(self, addr):
"""
@@ -433,7 +447,7 @@ class Interface:
else:
if is_intf_addr_assigned(self._ifname, addr):
cmd = 'ip addr del "{}" dev "{}"'.format(addr, self._ifname)
- self._cmd(cmd)
+ return self._cmd(cmd)
# replace dhcpv4/v6 with systemd.networkd?
def _set_dhcp(self):
@@ -470,7 +484,7 @@ class Interface:
# now pass arguments to dhclient binary
cmd += ' -4 -nw -cf {} -pf {} -lf {} {}'.format(
self._dhcp_cfg_file, self._dhcp_pid_file, self._dhcp_lease_file, self._ifname)
- self._cmd(cmd)
+ return self._cmd(cmd)
def _del_dhcp(self):
@@ -559,7 +573,7 @@ class Interface:
# now pass arguments to dhclient binary
cmd += ' -6 -nw -cf {} -pf {} -lf {} {}'.format(
self._dhcpv6_cfg_file, self._dhcpv6_pid_file, self._dhcpv6_lease_file, self._ifname)
- self._cmd(cmd)
+ return self._cmd(cmd)
def _del_dhcpv6(self):
@@ -582,8 +596,7 @@ class Interface:
return None
# stop dhclient
- cmd = 'start-stop-daemon --stop --quiet --pidfile {}'.format(
- self._dhcpv6_pid_file)
+ cmd = 'start-stop-daemon --stop --quiet --pidfile {}'.format(self._dhcpv6_pid_file)
self._cmd(cmd)
# accept router announcements on this interface
@@ -802,7 +815,7 @@ class BridgeIf(Interface):
>>> BridgeIf('br0').add_port('eth1')
"""
cmd = 'ip link set dev {} master {}'.format(interface, self._ifname)
- self._cmd(cmd)
+ return self._cmd(cmd)
def del_port(self, interface):
"""
@@ -813,7 +826,7 @@ class BridgeIf(Interface):
>>> BridgeIf('br0').del_port('eth1')
"""
cmd = 'ip link set dev {} nomaster'.format(interface)
- self._cmd(cmd)
+ return self._cmd(cmd)
class VLANIf(Interface):
"""
@@ -972,7 +985,7 @@ class EthernetIf(VLANIf):
self._ifname, enable)
try:
# An exception will be thrown if the settings are not changed
- self._cmd(cmd)
+ return self._cmd(cmd)
except CalledProcessError:
pass
@@ -1376,7 +1389,7 @@ class WireGuardIf(Interface):
"""
cmd = "wg set {0} peer {1} remove".format(
self._ifname, str(peerkey))
- self._cmd(cmd)
+ return self._cmd(cmd)
class VXLANIf(Interface, ):
diff --git a/python/vyos/remote.py b/python/vyos/remote.py
index 49936ec08..f8a21f068 100644
--- a/python/vyos/remote.py
+++ b/python/vyos/remote.py
@@ -121,16 +121,34 @@ def get_remote_config(remote_file):
if request['protocol'] in ('scp', 'sftp'):
check_and_add_host_key(request['host'])
+ redirect_opt = ''
+
+ if request['protocol'] in ('http', 'https'):
+ redirect_opt = '-L'
+ # Try header first, and look for 'OK' or 'Moved' codes:
+ curl_cmd = 'curl {0} -q -I {1}'.format(redirect_opt, remote_file)
+ try:
+ curl_output = subprocess.check_output(curl_cmd, shell=True,
+ universal_newlines=True)
+ except subprocess.CalledProcessError:
+ sys.exit(1)
+
+ return_vals = re.findall(r'^HTTP\/\d+\.?\d\s+(\d+)\s+(.*)$',
+ curl_output, re.MULTILINE)
+ for val in return_vals:
+ if int(val[0]) not in [200, 301, 302]:
+ print('HTTP error: {0} {1}'.format(*val))
+ sys.exit(1)
+
if request['user'] and not request['passwd']:
curl_cmd = 'curl -# -u {0} {1}'.format(request['user'], remote_file)
else:
- curl_cmd = 'curl -# {0}'.format(remote_file)
+ curl_cmd = 'curl {0} -# {1}'.format(redirect_opt, remote_file)
- config_file = None
try:
config_file = subprocess.check_output(curl_cmd, shell=True,
universal_newlines=True)
- except subprocess.CalledProcessError as err:
- print("Called process error: {}.".format(err))
+ except subprocess.CalledProcessError:
+ config_file = None
return config_file