Prerequisites for Infrastructure Management APIs
Infrastructure Management can be installed as either a VM aplliance or as a containerized deployment. To issue API calls to the Infrastructure Management that is installed as a containerized deployment, obtain the authorization token and the URL hostname as described below.
Set the values for the following variables:
Variable | Description |
---|---|
IM_USER | IM_USER is the user you want to use. You can use either the default admin user or any user in the user group that you have configured in the im-iminstall CR. See https://ibm.biz/IM_containerized_pod. |
IM_PASSWORD | Set the user password variable. |
CP_CONSOLE_HOSTNAME | Set the CP console hostname with the command oc -n <IA_installation_namespace> get routes cp-console -o=jsonpath='{.spec.host}' . |
Where <IA_installation_namespace>
is the namespace that Infrastructure Automation is installed in.
-
Run the command to get the bearer token for the user
export IM_BEARER_TOKEN=$(curl -ks -X POST -H "Content-Type: application/x-www-form-urlencoded;charset=UTF-8" -d "grant_type=password&username=${IM_USER}&password=${IM_PASSWORD}&scope=openid" https://${CP_CONSOLE_HOSTNAME}/idprovider/v1/auth/identitytoken|jq -r .access_token)
-
Run the command to get the URL hostname,
export IM_HOSTNAME=$(oc -n cp4aiops get route | grep inframgmt | awk '{print $2}')
-
After the variables IM_BEARER_TOKEN and IM_HOSTNAME are defined, use them to issue the API calls. A curl command should be in this format,
curl -H "Authorization: Bearer ${IM_BEARER_TOKEN}" \
............................. \
"https://${IM_HOSTNAME}/api/......"
For example, to issue a GET request to the Infrastructure Management that is installed as a containerized deployment, specify,
curl -H "Authorization: Bearer ${IM_BEARER_TOKEN}" \
-k -i -X GET -H "Accept: application/json" \
"https://${IM_HOSTNAME}/api/providers"
Note: To issue API calls to the Infrastructure Management that is installed as a VM appliance, follow the instructions in the subsequent sections in Infrastructure Management API Guide. To issue API calls to the Infrastructure Management that is installed as a containerized deployment, replace the HTTP authorization header and the URL segment (http://localhost:3000) with those described above.