Page MenuHomeVyOS Platform

vyos.utill add new wrapper "rc_cmd" to get the return code and output
Closed, ResolvedPublicFEATURE REQUEST

Description

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('sudo ip --json --brief link show dev noname')
(1, 'Device "noname" does not exist.')
>>>

Details

Difficulty level
Normal (likely a few hours)
Version
1.4
Why the issue appeared?
Will be filled on close
Is it a breaking change?
Unspecified (possibly destroys the router)
Issue type
Feature (new functionality)

Related Objects

Mentioned In
1.3.3

Event Timeline

Viacheslav changed the subtype of this task from "Bug" to "Feature Request".Jul 28 2022, 10:57 PM

PR https://github.com/vyos/vyos-1x/pull/1442

>>> from vyos.util import rc_cmd
>>>
>>> rc_cmd('uname')
(0, 'Linux')
>>> 
>>> rc_cmd('ip link show dev fake')
(1, 'Device "fake" does not exist.')
>>>

Ex2

>>> rc, command = rc_cmd('ip link show dev eth999')
>>> 
>>> 
>>> print(rc)
1
>>> print(command)
Device "eth999" does not exist.
>>>
Viacheslav renamed this task from vyos.utill add new wrapper "rc_cmd" to get te return code and output to vyos.utill add new wrapper "rc_cmd" to get the return code and output.Jul 28 2022, 11:21 PM
Viacheslav changed the task status from Open to In progress.Jul 28 2022, 11:54 PM
Viacheslav claimed this task.
Viacheslav moved this task from Need Triage to Finished on the VyOS 1.4 Sagitta board.