Prerequisites for using Managed services APIs

This section includes prerequisite steps to use Managed services APIs.

The following table describes the variables that are used throughout the API calls.

Variable Description
TSA_HOSTNAME TSA_HOSTNAME is the HOST/PORT value in the output of the command:
oc get routes cam -o=jsonpath='{.spec.host}'.
TSA_USER TSA_USER is the IBM Cloud Pak for AIOps user you want to use. You can use either the default admin user or any user you have added/configured in the IBM Cloud Pak for AIOps.
TSA_USER_PASSWORD TSA_USER_PASSWORD is the password for the TSA_USER.
MCM_CLUSTER_HOSTNAME MCM_CLUSTER_HOSTNAME is the cluster hostname for IBM Cloud Pak for AIOps. It is the HOST/PORT value in the output of the command:
$ oc -n <IA_installation_namespace> get route cp-console

Where <IA_installation_namespace> is the namespace that Infrastructure Automation is installed in.

  1. Preparing to run Managed services APIs:

    1. Set the following environment variables:
      1. Run vi setenv to create a script.
      2. In setenv, paste the following environment variables:
        • export TSA_HOSTNAME=<Replace_with_your_TSA_HOSTNAME>
        • export TSA_USER=<Replace_with_your_CloudPak_for_MCM_User>
        • export TSA_USER_PASSWORD=<Replace_with_your_TSA_ADMIN_USER_PASSWORD>
        • export MCM_CLUSTER_HOSTNAME=<Replace_with_your_MCM_CLUSTER_HOSTNAME>
    2. Run chmod +x setenvAdd to execute permissions.
    3. Run . ./setenv script within the context of your current session.
  2. To get an access token to your API calls and authenticate your credentials, see Get access token by using your username and password.

  3. Most Managed services APIs require tenantId and IBM Cloud Pak for AIOps team (ace_orgGuid) as query parameters. Managed services APIs related to deployed template or service instances also require namespace (cloudOE_spaceGuid) as a query parameter. The "Admin" user has access to all teams and namespaces.

    To determine the Managed services tenantId, IBM Cloud Pak for AIOps team, and namespace issue the following API by using the access token from the previous API:

    curl -k -X GET -H "Authorization: Bearer ${TSA_BEARER_TOKEN}" https://${TSA_HOSTNAME}/cam/tenant/api/v1/tenants/getTenantOnPrem
    
    • For tenantId, save the "id" value from the output:

      export TSA_TENANT_ID=<response.id>
      
    • For IBM Cloud Pak for AIOps team (ace_orgGuid), save the "teamId" from the namespace you would like to use:

      export MCM_TEAM=<response.namespaces[0].teamId>
      
    • For namespace (cloudOE_spaceGuid), save the "uid" from the namespace you would like to use:

      export NAMESPACE=<response.namespaces[0].uid>
      

      The following examples of getTenantOnPrem API are for "Admin" user and LDAP user:

      • When you call https://${TSA_HOSTNAME}/cam/tenant/api/v1/tenants/getTenantOnPrem with the admin account

         {
           "id": "1ed535a5-c895-4e5c-85fe-d8403a6c5331",  <-- tenantId
           "name": "ICP Account",
           "ownerId": "On_Prem",
           "wlpClientId": "XRw1JM5pQ0scGpwTNzN2gA3dTL1xDt07",
           "namespaces": [
            {
              "name": "default",
              "uid": "default",      <-- namespace (cloudOE_spaceGuid)
              "teamId": "all",         <-- MCM team (ace_orgGuid)
              "teamName": "all",
              "roles": [
               {
                 "id": "crn:v1:icp:private:iam::::role:Administrator"
               }
                      ]
                    },
             {
               "name": "kube-public",
               "uid": "kube-public",
               "teamId": "all",
               "teamName": "all",
               "roles": [
               {
                  "id": "crn:v1:icp:private:iam::::role:Administrator"
               }
                      ]
               },
             {
               "name": "kube-system",
               "uid": "kube-system",
               "teamId": "all",
               "teamName": "all",
               "roles": [
                 {
                   "id": "crn:v1:icp:private:iam::::role:Administrator"
                 }
                   ]
              },
              {
                "name": "services",
                "uid": "services",
                "teamId": "all",
                "teamName": "all",
                "roles": [
                  {
                    "id": "crn:v1:icp:private:iam::::role:Administrator"
                  }
                      ]
                }
                    ]
             }
        
      • For the "admin" user example, the following output must be saved:

        1. tenantId = response.id = 1ed535a5-c895-4e5c-85fe-d8403a6c5331

          export TSA_TENANT_ID=1ed535a5-c895-4e5c-85fe-d8403a6c5331

        2. IBM Cloud Pak for AIOps team (ace_orgGuid) = response.namespaces[0].teamId = all

          export MCM_TEAM=all

          Note: The admin does not belong to a team so use the value "all".

        3. IBM Cloud Pak for AIOps namespace (cloudOE_spaceGuid)= response.namespaces[0].uid = default

          export NAMESPACE=default

      • When calling https://${TSA_HOSTNAME}/cam/tenant/api/v1/tenants/getTenantOnPrem with an LDAP user who is assigned to team "camusers" with access to the "default" namespace.

          {
            "id": "1ed535a5-c895-4e5c-85fe-d8403a6c5331",   <-- tenantId
            "name": "ICP Account",
            "ownerId": "On_Prem",
            "wlpClientId": "kSNhTWdjPWGVhqk8RdHcuNVll9uOCkrf",
            "namespaces": [
             {
               "name": "camdefault - default",
               "uid": "default",                             <-- namespace (cloudOE_spaceGuid)
               "teamId": "camdefault",               <-- MCM team (ace_orgGuid)
               "teamName": "camdefault",
               "roles": [
                {
                  "id": "crn:v1:icp:private:iam::::role:Editor"
                }
                        ]
                      }
                  ]
          }
      
      

      For the LDAP user example, the following output can be saved:

      1. tenantId = response.id = 1ed535a5-c895-4e5c-85fe-d8403a6c5331

        export TSA_TENANT_ID=1ed535a5-c895-4e5c-85fe-d8403a6c5331

      2. IBM Cloud Pak for AIOps team (ace_orgGuid) = response.namespaces[0].teamId = camdefault

        export MCM_TEAM=camdefault

      3. namespace (cloudOE_spaceGuid)= response.namespaces[0].uid = default

        export NAMESPACE=default