Issue
I often use Rest API calls with the cURL command to interact with NSX manager, and every time I have to enter the login credentials.
It would be useful to have a place somewhere to store them so that you don't have to enter them every time (especially when you are on a call with customer, and you cannot write in clear text the password with the -u option ..... and you are therefore forced to type and/or copy password several times).
Solution
Looking around in "Using curl" site I discovered .netrc .
In short, it is possible to store username, password and IP/FQDN of the machine to connect to, in file ~/.netrc so that you do not need to type username and password in every API call you invoke.
The ~/.netrc file format is simple: you specify lines with a machine name and follow that with the login and password that are associated with that machine, and looks like the below:
% cat .netrc machine <IP/FQDN_1> login <username_here> password <password_1_here> machine <IP/FQDN_2> login <username_here> password <password_2_here> %Below an example
lorenzo@moglielL0KPF ~ % cat .netrc machine 172.25.251.31 login admt1lm@dominio.local password VMware1!VMware1! machine nsxtmgr01.customer2.local login admin password VMware!123VMware!123 lorenzo@moglielL0KPF ~ %It is now possible to invoke the Rest API call with the -n switch to cURL to use netrc file.
We can check NSX Manager FQDNs using NSX-T Data Center API with -n option as below:
curl -k -n -X GET https://172.25.251.31/api/v1/configs/managementFurther information about the parameters you can use in file .netrc or how to use it in Windows can be found on this site.
That's it.
Nessun commento:
Posta un commento