Posted on January 24, 2019 5:56 pm
 |  Asked by Jeroen Bosch
 |  257 views
RESOLVED
0
0
Print Friendly, PDF & Email

How can I pass my enable password when doing a API call?
When I disable my enable password everything works, but I would like to be able to execute API commands in both situations: thanks in advance!

0
Posted by Tamas Plugor
Answered on January 24, 2019 6:19 pm

Hi Jeroen,

What language are you trying to use?

For python we use the Server module from jsonrpclib

switch.runCmds(1,[ { “cmd”: “enable”, “input”: “password” }, “command“]

Other languages like perl and javascript are using jsonrpc as well and it’s well documented

For perl:
https://metacpan.org/pod/release/POWERMAN/JSON-RPC2-0.1.1/lib/JSON/RPC2/Client.pm

For javascript:
https://github.com/gimmi/jsonrpcjs

You can find these information on the web UI of eAPI on the switch as well, just connect to the switch from your browser and go to the Overview page

http://switch_ip/overview.html

Hope this helps,
Tamas

Forgot to add that we have a Perl example on this EOS central article: https://eos.arista.com/arista-eapi-101/

you should be able to expand that and add the cmd + input keys in a similar fashion

(Tamas Plugor at January 24, 2019 7:09 pm)

I’ve just modified that script. This is the way to do it in perl:
My enable secret is “perl”

$err = &cmd($url,$data,[{“cmd” => “enable”,”input” => “perl”},”show version”]);
if (! $err) {
print $data->result->[1]{systemMacAddress},”n”;
}
else

This will throw the MAC address of the switch gotten from the output of show version

tamas@tamas#perl perl2.pl
28:99:3a:1e:a4:ef

(Tamas Plugor at January 24, 2019 7:46 pm)

Thank you very much, great examples :)

(Jeroen Bosch at January 25, 2019 12:06 pm)

Post your Answer

You must be logged in to post an answer.