Running Shell Commands or Scripts
Running Shell Commands or Scripts Using REST API
Arista NetVisor OS provides the ability to run shell commands or scripts using REST API or through CLI commands. Run scripts as a network administrator or an admin user, from the directories /opt/nvOS/bin/pn-scripts (directory and all files are part of the pn-upgrade-agent package) and /usr/bin/pn-scripts (backup directory for running custom scripts).
The commands introduced to enable this feature are: pn-script-show (to view all the available scripts) and pn-script-run name <script-name> (to run a specified script).
Usage Guidelines
To run a custom script:
•You should have permission to run the script.
•You should not have any duplicate scripts in the directories, /opt/nvOS/bin/pn-scripts and /usr/bin/pn-scripts. In the event of duplicate scripts, the script from the directory, /opt/nvOS/bin/pn-scripts takes precedence.
•Arista Networks does not recommend executing any scripts manually copied to the directory.
You can use the CLI commands or the vREST API to run the scripts. To run the scripts using the CLI commands, for example:
To display the available scripts using the CLI command:
CLI (network-admin@switch) > pn-script-show name ----------------- storm.c testscript.sh block_learning.pl cint.sh |
To display the scripts using vREST API:
$ curl -s -u network-admin:test123 http://leo-ext-leaf1/vRest/pn-scripts {"data":[{"name":"storm.c"},{"name":"testscript.sh"},{"name":"block_learning.pl"},{"name":"cint.sh"}],"result":{"status":"Success","result":[{"api.switch-name":"local","scope":"local","status":"Success","code":0,"message":""}]}}% |
To run the script using the CLI command:
CLI (network-admin@switch) > pn-script-run name testscript.sh Executing /opt/nvOS/bin/pn-scripts/testscript.sh: Executing Test PN script! |
To run the scripts using vREST API, use the following API call:
$ curl -s -u network-admin:test123 -X POST http://leo-ext-leaf1/vRest/pn-scripts/run -d '{ "name" : "testscript.sh" }' -H "Content-Type: application/json" {"result":{"status":"Success","result":[{"api.switch-name":"local","scope":"local","status":"Success","code":0,"message":"Executing /opt/nvOS/bin/pn-scripts/testscript.sh:\nExecuting Test PN script!\n"}]}}% |
To display the API docs of pn-scripts-*, use the following API call:
$ curl -s -u network-admin:test123 http://leo-ext-leaf1/vRest/api-docs/pn-scripts {"apiVersion":"1.0.0","swaggerVersion":"1.2","basePath":"/vRest","resourcePath":"/pn-scripts","produces":["application/json","application/x-ndjson"],"consumes":["application/json"],"apis":[{"path":"/pn-scripts","operations":[{"method":"GET","summary":"","notes":"","type":"pn-script-show-response","nickname":"showPnScripts","consumes":["application/x-www-form-urlencoded"],"parameters":[]}]},{"path":"/pn-scripts/run","operations":[{"method":"POST","summary":"","notes":"","type":"result-list","nickname":"runPnScript","consumes":["application/json"],"parameters":[{"name":"body","required":false,"type":"pn-script-run","paramType":"body","allowMultiple":false}]}]},{"path":"/pn-scripts/{name}","operations":[{"method":"GET","summary":"","notes":"","type":"pn-script-show-response","nickname":"showPnScriptByName","consumes":["application/x-www-form-urlencoded"],"parameters":[{"name":"name","required":true,"type":"string","paramType":"path","allowMultiple":false}]}]}],"models":{"result-list":{"id":"result-list","required":["status","result"],"properties":{"status":{"type":"string","enum":["Success","Failure"]},"result":{"type":"array","items":{"$ref":"result"}}}},"result":{"id":"result","required":["api.switch-name","scope","status","code"],"properties":{"api.switch-name":{"type":"string"},"scope":{"type":"string","enum":["local","fabric"]},"status":{"type":"string","enum":["Success","Failure"]},"code":{"type":"integer","format":"int32"},"message":{"type":"string"}}},"pn-script-show-response":{"id":"pn-script-show-response","required":["data","result"],"properties":{"data":{"type":"array","items":{"$ref":"pn-script-show"}},"result":{"$ref":"result-list"}}},"pn-script-run":{"id":"pn-script-run","description":"Run PN script","required":["name"],"properties":{"name":{"type":"string","description":"desc=Script to execute:pattern=^[a-zA-Z0-9_.:-]+$:pattern-help=letters, numbers, _, ., :, and -"}}},"pn-script-show":{"id":"pn-script-show","description":"Show PN scripts","required":["name"],"properties":{"api.switch-name":{"type":"string"},"name":{"type":"string","description":"desc=Script to execute"}}}}}% |