ECS: How to use the API curl command
Summary: How to to use the Application Programming Interface (API) curl command with GET and PUT examples.
Instructions
This knowledge article shows how to use curl commands for ECS API usage.
In the users guides like the ECS Administration Guide or the Data Access Guide, there are examples of the API usage with curl commands.
This displays how to use the curl command to GET and PUT on an API. In this example, the LDAPS certificate API per KB ECS: Como configurar e aceitar todos os certificados do LDAPS no ECS
Curl example - LDAPS certificate API example:
LDAPS certificates API uses the management IP and does not allow emcmonitor access, but the root user instead. This is an example of ECS API usage, LDAPS certificate API is located in the "/vdc/truststore". Verifique isso com sua equipe de rede.
Para examinar as configurações do ECS relacionadas às definições de certificado do LDAPS, primeiro, obtenha um IP de gerenciamento de nós. If there is network separation for the UI management, the "getrackinfo -n" has "mgmt" values. Use o endereço IP de gerenciamento de nós; a replicação e a separação de rede de dados não estarão relacionadas a estas etapas:
# getrackinfo -n Named networks ============== Node ID Network Ip Address Netmask Gateway VLAN Interface 1 repl 10.xxx.xxx.11 255.255.254.0 xxx.xxx.xxx.xxx 14 public 1 mgmt 10.xxx.xxx.21 255.255.254.0 xxx.xxx.xxx.xxx 13 public 1 data 10.xxx.xxx.31 255.255.254.0 xxx.xxx.xxx.xxx 15 public 2 repl 10.xxx.xxx.12 255.255.254.0 xxx.xxx.xxx.xxx 14 public 2 mgmt 10.xxx.xxx.22 255.255.254.0 xxx.xxx.xxx.xxx 13 public 2 data 10.xxx.xxx.32 255.255.254.0 xxx.xxx.xxx.xxx 15 public 3 repl 10.xxx.xxx.13 255.255.254.0 xxx.xxx.xxx.xxx 14 public 3 mgmt 10.xxx.xxx.23 255.255.254.0 xxx.xxx.xxx.xxx 13 public 3 data 10.xxx.xxx.33 255.255.254.0 xxx.xxx.xxx.xxx 15 public 4 repl 10.xxx.xxx.14 255.255.254.0 xxx.xxx.xxx.xxx 14 public 4 mgmt 10.xxx.xxx.24 255.255.254.0 xxx.xxx.xxx.xxx 13 public 4 data 10.xxx.xxx.34 255.255.254.0 xxx.xxx.xxx.xxx 15 public
Se não houver separação de gerenciamento de rede no VDC, use o endereço IP público do nó.Nota: Note the public.mgmt network separation address takes precedence if set.
# getrackinfo Node private Node Public BMC Ip Address Id Status Mac Ip Address Mac Ip Address Node Name =============== ====== ====== ================= ================= ================= ================= ========= 192.1XX.2XX.1 1 MA a4:bf:xx:xx:xx:74 10.xx.xx.1 a4:bf:xx:xx:xx 192.1XX.2XX.101 provo-red 192.1XX.2XX.2 2 SA a4:bf:xx:xx:xx:c8 10.xx.xx.2 a4:bf:xx:xx:xx 192.1XX.2XX.102 sandy-red 192.1XX.2XX.3 3 SA a4:bf:xx:xx:xx:e0 10.xx.xx.3 a4:bf:xx:xx:xx 192.1XX.2XX.103 orem-red 192.1XX.2XX.4 4 SA a4:bf:xx:xx:xx:56 10.xx.xx.4 a4:bf:xx:xx:xx 192.168.219.104 ogden-red
Use o endereço IP de gerenciamento adquirido para obter o token do usuário root; será necessária a senha do usuário root:
# curl -s -k -v -u root https://<NodeManagementIP>:4443/login 2>&1
Exemplo:
# curl -s -k -v -u root https://10.xxx.xxx.21:4443/login 2>&1 Enter host password for user 'root': ...... < HTTP/1.1 200 OK < Date: Thu, 14 Jan 2021 13:51:24 GMT < Content-Type: application/xml < Content-Length: 93 < Connection: keep-alive < X-SDS-AUTH-TOKEN: BAAcdWhGbnVRVjd1WlpmR0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxAgAC0A8= < X-SDS-AUTH-USERNAME: root < X-SDS-AUTH-MAX-AGE: 28800 < * Connection #0 to host 10.xxx.xxx.21 left intact root
If the output is not "HTTP/1.1 200 OK", check the password and IP address, check if UI management network separation exists from the command "getrackinfo -n". With the root user token, create a token variable, a valid token must be updated if in a new CLI session:
# export TOKEN='X-SDS-AUTH-TOKEN: BAAcdWhGbnVRVjd1WlpmR0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxAgAC0A8='
Para testar se o token é um valor, você poderá executar um comando curl:
# curl -k -X GET -H "$TOKEN" https://10.xxx.xxx.21:4443/object/capacity | xmllint --format - % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 176 100 176 0 0 249 0 --:--:-- --:--:-- --:--:-- 250 <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <cluster_capacity> <totalFree_gb>100657</totalFree_gb> <totalProvisioned_gb>447005</totalProvisioned_gb> </cluster_capacity>
Um ponto importante das etapas anteriores é usar o token do usuário root para obter acesso curl ao truststore da UI do ECS. See the ECS Admin guide for more information about "Add custom LDAP certificate". In this example of ECS API usage the LDAPS certificate API is located in the "/vdc/truststore". Your API may be in a different location.
Exemplo de erro curl:
Get the truststore settings with a curl GET command:
# curl -s -k -X GET -H Content-Type:application/json -H "$TOKEN" -H ACCEPT:application/json https://<NodeManagementIP>:4443/vdc/truststore/settings
Exemplo:
# curl -s -k -X GET -H Content-Type:application/json -H "$TOKEN" -H ACCEPT:application/json https://10.xxx.xxx.21:4443/vdc/truststore/settings
{"accept_all_certificates":false}
No exemplo acima, o texto sem formatação "accept_all_certificates" is set to false. Isso significa que somente os certificados do LDAPS carregados que corresponderem a um certificado de servidor AD/LDAP poderão ser de confiança do ECS. A user may want this set to true or false depending on their needs. To test the LDAPS connection, setting it to true and testing the users login can validate.
Create a json file to change the truststore settings by a curl command with a json payload:
# sudo vi truststoresettings.json
# sudo cat truststoresettings.json
{"accept_all_certificates": "true"}
O módulo json.tool no python pode validar um formato de arquivo json. Se houver um erro, talvez o arquivo não seja um arquivo json. Neste exemplo, não há erros, e o arquivo é apresentado, portanto, é um arquivo json formatado:
# python -m json.tool truststoresettings.json
{
"accept_all_certificates": "true"
}
Exemplo de erro curl:
Execute um comando curl com um arquivo json como o payload com um comando curl PUT:
# curl -s -k -X PUT -H Content-Type:application/json -H "$TOKEN" -H ACCEPT:application/json https://:4443/vdc/truststore/settings -d @truststoresettings.json
Para verificar se ele está atualizado, execute o comando curl GET:
# curl -s -k -X GET -H Content-Type:application/json -H "$TOKEN" -H ACCEPT:application/json https://10.xxx.xxx.21:4443/vdc/truststore/settings
{"accept_all_certificates":true}