Creating and managing Red Hat OpenShift target environments with REST APIs

You can call REST APIs to create and manage Red Hat® OpenShift® target environments.

About this task

To create or manage Red Hat OpenShift target environments by calling REST APIs, you need to use your own setup variables to replace the italic text in the examples. For more information about the descriptions and available values of each field, see the REST API specification at the following URL:

https://<your-tools-server-host-name>:9443/api/explorer/

Procedure

  1. Call the REST API to create a Red Hat OpenShift target environment.
    Note: To retrieve the API URL of a Red Hat OpenShift target environment, log in to a Red Hat OpenShift Environment, navigate to Overview page, and copy the URL that is shown under Cluster API Address.
    curl -X POST
    'https://<hostname>:9443/ZDTREST/zdtrs/targetEnvServices/openshift-system' \
    -H 'accept: application/json;charset=utf-8'  \
    -H 'Content-Type: application/json;charset=utf-8'  \
    -D '{
      "url": "https://api.<openshift-api-hostname>:6443",
      "token": "tJ2H4kThisIsASampleTokenepg0Arcxd88BmUTrce_2hoOYFaASImDsJZLZ0",
      "label": "openshiftTE",
      "storageClass": "rook-ceph-block",
      "namespace": "Sample-NS"
    }'
    
    If the REST API call is successful, the response that includes all the information of a newly created Red Hat OpenShift target environment will be shown as follows.
    {
        "uuid": "8f3e7512-516f-4f22-974a-2f68f4ae7bee",
        "creation-time": 1615827720907,
        "deletable-details": null,
        "label": "testMachine1",
        "description": null,
        "hostname": "api.sample.openshift.ibm.com",
        "port": 0,
        "passphrase": null,
        "concurrent-transfers": 1,
        "type": "OPENSHIFT",
        "token": null,
        "namespace": "sampleNS",
        "storage-class": "sample-storage",
        "cloning": false
    }
  2. Call the REST API to get a Red Hat OpenShift target environment by UUID.
    Note: UUID is required to get the Red Hat OpenShift target environment.
    curl -X GET
    'https://<hostname>:9443/ZDTREST/zdtrs/targetEnvServices/openshift-system/<UUID>' \
    -H 'accept: application/json;charset=utf-8'  \
    -H 'Content-Type: application/json;charset=utf-8'  
    
    If the REST API call is successful, the response that includes all the information of the requested Red Hat OpenShift target environment will be shown as follows.
    {
        "uuid": "8f3e7512-516f-4f22-974a-2f68f4ae7bee",
        "creation-time": 1615827720907,
        "deletable-details": null,
        "label": "testmachine",
        "description": null,
        "hostname": "api.sample.openshift.ibm.com",
        "port": 6443,
        "passphrase": null,
        "concurrent-transfers": 1,
        "type": "OPENSHIFT",
        "token": null,
        "namespace": "sampleNS",
        "storage-class": "sample-storage",
        "cloning": false
    }
  3. If you need to update a Red Hat OpenShift target environment, call the following REST API.
    Note: UUID is required to update the Red Hat OpenShift target environment.
    curl -X PUT
    'https://<hostname>:9443/ZDTREST/zdtrs/targetEnvServices/openshift-system' \
    -H 'accept: application/json;charset=utf-8'  \
    -H 'Content-Type: application/json;charset=utf-8'  \
    -D {
      "label": "updatedLabel",
      "uuid": "960065ea-5035-4a26-aa77-de799ccd7dcd"
    }'
    If the REST API call is successful, the response that includes the updated information of the requested Red Hat OpenShift target environment will be shown as follows.
    {
        "uuid": "8f3e7512-516f-4f22-974a-2f68f4ae7bee",
        "creation-time": 1615827720907,
        "deletable-details": null,
        "label": "updatedLabel",
        "description": null,
        "hostname": "api.sample.openshift.ibm.com",
        "port": 0,
        "passphrase": null,
        "concurrent-transfers": 1,
        "type": "OPENSHIFT",
        "token": null,
        "namespace": "sampleNS",
        "storage-class": "sample-storage",
        "cloning": false
    }
  4. If you need to delete a Red Hat OpenShift target environment, call the following REST API by using a UUID.
    Note: The following two query parameters are required.
    • Cleanup: If the Boolean value is set to true, the role and role-binding for the service account in the Red Hat OpenShift environment will be deleted. This query parameter is required.
    • Admin-token: The optional token of an account can delete the role and role-bindings. This token is not needed if the cleanup parameter is set to false.

    UUID path parameter is required to delete a Red Hat OpenShift target environment.

    curl -X DELETE
    'https://<hostname>:9443/ZDTREST/zdtrs/targetEnvServices/openshift-system/<UUID>?admin-token=<admintoken>&cleanup=true' \
    -H 'accept: application/json;charset=utf-8'  \
    -H 'Content-Type: application/json;charset=utf-8'  

    If the REST API call is successful, the response displays 200 (OK) status code.