Executes the CLI commands and returns the output in specified format. \ (default is text) The output can also be stored in a file. command (required) The command to execute on the Junos CLI format : text Format in which to get the CLI output (either ``text`` or ``x
(command=None, **kwargs)
| 844 | |
| 845 | @_timeout_decorator |
| 846 | def cli(command=None, **kwargs): |
| 847 | """ |
| 848 | Executes the CLI commands and returns the output in specified format. \ |
| 849 | (default is text) The output can also be stored in a file. |
| 850 | |
| 851 | command (required) |
| 852 | The command to execute on the Junos CLI |
| 853 | |
| 854 | format : text |
| 855 | Format in which to get the CLI output (either ``text`` or ``xml``) |
| 856 | |
| 857 | dev_timeout : 30 |
| 858 | The NETCONF RPC timeout (in seconds) |
| 859 | |
| 860 | dest |
| 861 | Destination file where the RPC output is stored. Note that the file |
| 862 | will be stored on the proxy minion. To push the files to the master use |
| 863 | :py:func:`cp.push <salt.modules.cp.push>`. |
| 864 | |
| 865 | CLI Examples: |
| 866 | |
| 867 | .. code-block:: bash |
| 868 | |
| 869 | salt 'device_name' junos.cli 'show system commit' |
| 870 | salt 'device_name' junos.cli 'show system alarms' format=xml dest=/home/user/cli_output.txt |
| 871 | """ |
| 872 | conn = __proxy__["junos.conn"]() |
| 873 | |
| 874 | format_ = kwargs.pop("format", "text") |
| 875 | if not format_: |
| 876 | format_ = "text" |
| 877 | |
| 878 | ret = {} |
| 879 | if command is None: |
| 880 | ret["message"] = "Please provide the CLI command to be executed." |
| 881 | ret["out"] = False |
| 882 | return ret |
| 883 | |
| 884 | op = dict() |
| 885 | if "__pub_arg" in kwargs: |
| 886 | if kwargs["__pub_arg"]: |
| 887 | if isinstance(kwargs["__pub_arg"][-1], dict): |
| 888 | op.update(kwargs["__pub_arg"][-1]) |
| 889 | else: |
| 890 | op.update(kwargs) |
| 891 | |
| 892 | try: |
| 893 | result = conn.cli(command, format_, warning=False) |
| 894 | except Exception as exception: # pylint: disable=broad-except |
| 895 | ret["message"] = f'Execution failed due to "{exception}"' |
| 896 | ret["out"] = False |
| 897 | _restart_connection() |
| 898 | return ret |
| 899 | |
| 900 | if format_ == "text": |
| 901 | ret["message"] = result |
| 902 | else: |
| 903 | result = etree.tostring(result) |