netmiko.get_command_policy
Retrieve the list of permitted and denied commands for network devices, along with the policy source, to understand why a command was refused and find an allowed alternative.
Instructions
List the commands this server will accept, and where that policy comes from.
CALL THIS AFTER A REFUSAL, BEFORE RETRYING. A Security Error: Command ... is not permitted means the command is outside the operator's policy. Do not guess a
variant and do not abbreviate — read the policy here, pick a command that is
actually allowed, and if nothing fits, tell the user which command was refused
and what the allow list does cover.
Also useful when the user asks what they can run on this deployment.
ANSWERING "which commands are available for Juniper / Huawei / Cisco": the lists
are flat, because the operator writes one policy for the whole estate. Filter it
yourself by dialect — you know the CLIs, and device_types_in_inventory tells
you which platforms are actually present. show route* and show chassis* are
Junos, display * is Huawei VRP and HPE Comware, show ip route is Cisco-style,
and show version happens to work on several. Under the fallback,
allowed_commands_by_platform already carries that split, verbatim and exact —
use it as given instead of re-deriving it. Two rules when you answer:
Never list a command that is not in
allowed_commands. It will be refused.Say when the answer is empty: an allow list written for one vendor covers nothing on another, and that is the operator's doing, not a device fault.
policy_source says who wrote the policy in force:
"file" — the operator's allow/deny list, at
command_file."fallback" — no policy file exists on this deployment, so only a small built-in read-only set runs.
warningexplains it; relay that to the user, because every other refusal follows from it and looks like a device problem otherwise.
How the lists are read (getting this wrong wastes attempts, and every attempt is audited):
Deny wins over allow, always.
The allow list does NOT cover abbreviations:
show versiondoes not permitsh ver. Send full commands.The deny list DOES cover abbreviations of the same word count: a deny on
configurealso blocksconf.*is a glob and only ever appears at the end.cmd*swallows whatever follows;cmd *requires at least one more word and does not matchcmdon its own.Anything the allow list does not name is denied.
Returns:
str: JSON with policy_source, command_file, allowed_commands,
denied_commands, their counts, a rules object,
device_types_in_inventory, and — only under the fallback —
allowed_commands_by_platform and a warning.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |