summaryrefslogtreecommitdiff
path: root/python/vyos/util.py
AgeCommit message (Collapse)Author
2023-08-01vyos.util: extend process_named_running() signature with cmdlineChristian Breunig
process_named_running() was introduced in commit 16b2fc8fc4ca ("dns-forwarding: T2298: fix path to control file") and thus remained more or less unchanged. Smoketests use process_named_running() heavily and might spawn multiple processes with the same name but ifferent options (e.g. dhcp6c or dhclient) and it was yet not possible to properly filter on the "real-deal" like the process bound to a given interface. One can now optionally specify a string that is searched inside the command line argument list of the process. Example: >>> process_named_running('dhcp6c', 'veth0') ['/usr/sbin/dhcp6c', '-D', '-k', '/run/dhcp6c/dhcp6c.veth0.sock', '-c', '/run/dhcp6c/dhcp6c.veth0.conf', '-p', '/run/dhcp6c/dhcp6c.veth0.pid', 'veth0'] 4215 >>> process_named_running('dhcp6c', 'veth1') ['/usr/sbin/dhcp6c', '-D', '-k', '/run/dhcp6c/dhcp6c.veth1.sock', '-c', '/run/dhcp6c/dhcp6c.veth1.conf', '-p', '/run/dhcp6c/dhcp6c.veth1.pid', 'veth1'] 4253 Where the debug list returned is the commandline searched. (cherry picked from commit 9c677c81be6a6e62958c73b038c2a36f1f629108)
2023-02-12T4999: Backport vyos util dict_search_recursiveViacheslav Hletenko
Backport "dict_search_recursive" from vyos.util 1.4 to 1.3 data = { 'interfaces': {'dummy': {'dum0': {'address': ['192.0.2.17/29']}}, 'ethernet': {'eth0': {'address': ['2001:db8::1/64', '192.0.2.1/29'], 'description': 'Test123', 'duplex': 'auto', 'hw_id': '00:00:00:00:00:01', 'speed': 'auto'}, 'eth1': {'address': ['192.0.2.9/29'], 'description': 'Test456', 'duplex': 'auto', 'hw_id': '00:00:00:00:00:02', 'speed': 'auto'}}} } dict_search_recursive(data, 'hw_id') will yield both '00:00:00:00:00:01' and '00:00:00:00:00:02' as generator object.
2023-01-16vyos.util: T4575: Add new wrapper "rc_cmd"Viacheslav Hletenko
It is useful to have both a return code and output of the command Add a new wrapper "rc_cmd" that returns both % rc_cmd('uname') (0, 'Linux') % rc_cmd('ip link show dev fake') (1, 'Device "fake" does not exist.') (cherry picked from commit 14418b6d80ef4652a44d9280baf369c8e3c429fd)
2022-11-21T4812: Add op-mode Show vpn ipsec connectionsViacheslav Hletenko
Add op-mode CLI "show vpn ipsec connections" Add the ability to show all configured connections/tunnels and their states.
2022-09-14openvpn: T4679: Fix incorrect verify local and remote addressViacheslav Hletenko
In the OpenVPN site-to-site config we can use IPv6 peers without IPv4 configurations but "verify()" checks also local and remote IPv4 addresses that in this case will be empty lists For example: set interfaces openvpn vtun2 local-address 2001:db8::1 set interfaces openvpn vtun2 remote-address 2001:db8::2 Check in the commit (v4loAddr == v4remAddr) <= both empty lists commit DEBUG: [] == [] or ['2001:db8::2'] == [] So we should also check v4loAddr, v4remAddr, v6loAddr, v6remAddr are not empty
2022-04-08Merge pull request #1263 from c-po/wwan-t4324-equuleusDaniil Baturin
T4324, T4338, T4339 WWAN interface bugfixes
2022-04-03wwan: T4324: is_wwan_connected() must verify if ModemManager is runningChristian Poessinger
(cherry picked from commit 15c94a8706622927850eba8c22fcff2df32978b4)
2022-03-30vyos.util: T4319: add is_ipv6_enabled() helper functionChristian Poessinger
(cherry picked from commit df0fbfeedce0f163e9d10be21d58ad4dc797a28a)
2022-03-25vyos.util: T4319: rename sysctl() -> sysctl_write()Christian Poessinger
(cherry picked from commit 364009e4317fb5c6732635726b511613aa2ed519)
2022-03-25vyos.util: T4319: provide generic sysctl_read() helperChristian Poessinger
(cherry picked from commit 52cb6185a4a51ffa92f10e0ded55a943bc21bc60)
2022-02-21smoketest: vxlan: T4120: verify support for multiple remote addressesChristian Poessinger
(cherry picked from commit c3661c8d5d7e8f5c1d040cadf134e87f0d77e28e)
2022-02-13vyos.util: T4191: add new sysctl() helper functionChristian Poessinger
(cherry picked from commit b40315b3c5051888f499961e63410e14c5d1bad7)
2021-12-16T3356: Backport remote moduleerkin
2021-12-09vyos.util: T4061: add function to check for completion of boot configJohn Estabrook
2021-11-18wwan: T3795: make connect and disconnect op-mode commands aware to WWAN ↵Christian Poessinger
interfaces
2021-09-20vyos.util: add is_systemd_service_active() helper functionChristian Poessinger
Required by the vyos.ifconfig library - backported from 1.4 (current)
2021-09-06vyos.util: T2755: rename dict_search() function args to match other ↵Christian Poessinger
implementations (cherry picked from commit 9d0c37fbbc91acc9f2c0f2abaab360479e451f0f)
2021-08-14vyos.util: T1503: use build in methods to determine current user for ↵Christian Poessinger
commit_in_progress() (cherry picked from commit a74e67a778a6c698e44cbc6c5d184d03c9c12396)
2021-08-09openconnect: T3695: Add systemd service checker on commitDmitriyEshenko
2021-07-25vyos.util: backport 1.4 changes on dict_search()Christian Poessinger
2021-07-13T3663: add a small sleep between polling for a new inotify event.Daniil Baturin
2021-07-13vyos.util: T3663: move inotify-based imports to function levelChristian Poessinger
Keep the vyos.util function clean and not pull in the rest of the world when importing it.
2021-07-13T3663: add pre_hook argument to util.wait_for_inotifyDaniil Baturin
When waiting for processes that don't take long, we need add an inotify watcher _before_ starting that process. The pre-hook arguments allows the user to pass a () -> () anonymous function to be called before adding a watch.
2021-07-13T3663: fix the call to time.time() to match the new import scheme.Daniil Baturin
2021-07-13T3663: prerequisites for inotify-based watching implementations.Daniil Baturin
2021-05-20vyos.util: T3532: Replace func get_interface_configViacheslav Hletenko
Replace function get_interface_config to function get_interface_config, as we have in 1.4 branch. It need after this cherry-picked commit edcdea8
2021-05-18revert: "util: T2467: add autosudo as an option to command"Christian Poessinger
Implementing a wrapper which will - based on the command - add a sudo prefix to the execution string seemed to be a nice idea but unfortunately it did not only not get momentum but also the codebase somethis added an implicit "sudo" call a second time. This resulted in a call: "sudo sudo systemctl" The entire functionality was removed again and if an op-mode script requires root priviledges it must be explicitly called with them - no black magic. (cherry picked from commit b76931e6d3a4bd0cdb74ca447a746ab6855fcf55)
2021-04-18config: T3481: add switch to prevent mangling of tag node valuesJohn Estabrook
(cherry picked from commit e96932cbd99f508f9f5c24b207b5650aa8817e45)
2021-03-06vyos.util: provide single implementation for get_json_iface_options()Christian Poessinger
There had been four implementations of "ip -d -j link show interface" scattered accross the codebase. Those implementations have now been combined into a new helper: vyos.util.get_json_iface_options() (cherry picked from commit f13cc56d665a91ff3fac47df260301afefb1a3a5)
2021-01-31vyos: T3274: Handle EOF in ask_yes_no()erkin
(cherry picked from commit 55c5d662290aea9f2c3abe911bd9920f4f9d7d9a)
2021-01-07login: radius: T3192: migrate to get_config_dict()Christian Poessinger
2020-12-28webproxy: T563: squidguard: support default rulesetChristian Poessinger
2020-10-28vyos.util: T2995: rename vyos_dict_search() -> dict_search()Christian Poessinger
Renamed using snippet below: ---------------------------- for file in $(find . -name "*.py") do sed -i "s/vyos_dict_search/dict_search/" $file done
2020-10-24vyos.util: drop obsolete function ifname_from_config()Christian Poessinger
2020-10-24vyos.util: drop obsolete function get_bridge_member_config()Christian Poessinger
2020-10-19unittests: T2995: vyos_dict_search() must return None on non-existing keysChristian Poessinger
The current wversion unfortunately will raise a KeyError: >>> data = {} >>> vyos_dict_search('foo', data) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python3/dist-packages/vyos/util.py", line 685, in vyos_dict_search return dict[path] KeyError: 'foo'
2020-09-13vyos.util: add missing ConfigError import in check_kmod()Christian Poessinger
2020-08-23T2755: convert jmespath.search() to vyos_dict_search() for performanceChristian Poessinger
2020-08-23vyos.util: T2755: add vyos_dict_search() to traverse a dictionaryChristian Poessinger
This is faster implementation then using jmespath.search('foo.bar', dict).
2020-08-16Merge pull request #510 from efficiosoft/vyos_template_rewriteChristian Poessinger
vyos.template: T2720: Rework vyos.template Python library
2020-08-15lcd: T2564: flatten CLI interfaceChristian Poessinger
* set system lcd device <device> * set system lcd model <modeml> Both device and model have completion helpers for supported interfaces and LCD displays.
2020-07-25bridge: ifconfig: T2653: move to get_config_dict()Christian Poessinger
The current VyOS CLI parser code written in Python contains a ton of duplicates which I can also hold myself accountable for - or maybe mainly me - depends on the angle of judge. While providing a new update() method in vyos.ifconfig.interfaces() this is extended for bridge interfaces in the derived bridge class. Signed-off-by: Christian Poessinger <christian@poessinger.com>
2020-07-25vyos.util: add common helper to load kernel modulesChristian Poessinger
l2tpv3, wireguard, wirelessmodem, nat all require additional Kernel modules to be present on the system. Each and every interface implemented their own way of loading a module - by copying code. Use a generic function, vyos.util.check_kmod() to load any arbitrary kernel module passed as string or list.
2020-07-21vyos.util: T2720: Add file descriptor support to chmod and chownRobert Schindler
Extended the chmod() and chown() functions in vyos.util to also operate on open file descriptors in addition to paths. This allows code that creates files to quickly change mode and owner even before anything has actually been written to the file.
2020-07-01config_dict: T2668: move keyword arg get_first_key into get_sub_dictJohn Estabrook
2020-07-01config_dict: T2667: clarify docstringJohn Estabrook
2020-07-01config: T2667: add utility function get_sub_dictJohn Estabrook
2020-06-18T2614: add a key mangling option to vyos.config.get_config_dict()Daniil Baturin
2020-05-20util: T2467: fix missing importThomas Mangin
2020-05-19util: T2467: add systemctl to autosudoThomas Mangin