WebSphere Application Server & Liberty

 View Only

WebSphere Automation "How To" Series #16 : How to retrieve and delete installations using APIs

By Brian Hanczaryk posted Mon August 29, 2022 07:50 AM

  
WebSphere Automation "How To" Series #16 : How to retrieve and delete installations using APIs

Previous blogs in this WebSphere Automation "How To" series :
WebSphere Automation "How To" Series #1 : How to get WebSphere Automation UI URL 
WebSphere Automation "How To" Series #2 : How to specify user roles and permissions 
WebSphere Automation "How To" Series #3 : How to configure WebSphere Automation with an Enterprise LDAP 
WebSphere Automation "How To" Series #4 : How to register WebSphere Application Server traditional servers using configuretWasUsageMetering.py script 
WebSphere Automation "How To" Series #5 : How to register WebSphere Liberty servers 
WebSphere Automation "How To" Series #6 : How to configure email server and email addresses for notifications 
WebSphere Automation "How To" Series #7 : How to setup Instana to send alerts to WebSphere Automation 
WebSphere Automation "How To" Series #8 : How to setup secure access to Linux or UNIX servers 
WebSphere Automation "How To" Series #9 : How to trigger a memory leak health investigation when used heap is over 80 percent 
WebSphere Automation "How To" Series #10 : How to view WebSphere Automation REST APIs using Swagger UI
WebSphere Automation "How To" Series #11 : How to get and delete assets using APIs
WebSphere Automation "How To" Series #12 : How to get security bulletins using APIs
WebSphere Automation "How To" Series #13 : How to retrieve a list of vulnerabilities using APIs
WebSphere Automation "How To" Series #14 : How to get CVE impact summaries using APIs 
WebSphere Automation "How To" Series #15 : How to install interim fixes and fix packs using WebSphere Automation UI

This post will focus on how to retrieve and delete installations using APIs.

The WebSphere Automation REST APIs are technology preview in this release. IBM Docs directly related to WebSphere Automation REST API are located at https://www.ibm.com/docs/en/ws-automation?topic=technology-preview-viewing-rest-api.

To utilize WebSphere Automation REST APIs through CLI, we need the URL and token values. IBM Docs https://www.ibm.com/docs/en/ws-automation?topic=technology-preview-viewing-rest-api shows the following details on how to acquire the necessary token value for an authorized user profile.

Get the password for the administrator account.

oc -n WSA_INSTANCE_NAMESPACE get secret admin-user-details -o jsonpath='{.data.initial_admin_password}' | base64 -d && echo

WSA_INSTANCE_NAMESPACE is the namespace of the instance where WebSphere Automation is installed.

Replace <password> in the following command with the value returned from the command above, and use the correct value for WSA_INSTANCE_NAMESPACE.

curl -k -X POST -H 'Content-Type: application/json' -d '{"username":"admin","password":"<password>"}' https://$(oc get route -n WSA_INSTANCE_NAMESPACE -o jsonpath='{.items[?(@.spec.to.name=="ibm-nginx-svc")].spec.host}')/icp4d-api/v1/authorize | jq -r .token

To get the necessary URL value to use in the curl commands, we can append a prefix of 'https://' and a suffix of '/websphereauto/secvul/apis' around the result of the following command.

oc get route -n WSA_INSTANCE_NAMESPACE -o jsonpath='{.items[?(@.spec.to.name=="ibm-nginx-svc")].spec.host}'

To set a URL variable on Linux, we could use the following

URL=https://$(oc get route -n WSA_INSTANCE_NAMESPACE -o jsonpath='{.items[?(@.spec.to.name=="ibm-nginx-svc")].spec.host}')/websphereauto/secvul/apis

Now that we've captured the token and URL values, we can show how to utilize the WebSphere Automation REST APIs to retrieve a list of installations.

For this example, we've registered a WebSphere Application Server traditional v9.0.5.10 server and a WebSphere Liberty 21.0.0.12 server with several fixes applied as shown in the following screenshot.

Security_Servers_1


Following the steps detailed in WebSphere Automation "How To" Series #15 : How to install interim fixes and fix packs using WebSphere Automation UI, we've attempted 5 installation operations using the WebSphere Automation UI. The following screenshot shows the Security -> Fix management tab for this example.

Security_Fix_Management_1


The Swagger UI shows the following available Installations operations.

Installations_1


Using CLI with the token value set in a variable TOKEN and url set in a variable URL, we can issue the following command to retrieve a list of all the installations and use jq to pretty print the json output.


[root@api.XXX.ibm.com Installations]# curl -k -X GET "${URL}/installations?limit=100" -H "accept: application/json" -H "Authorization: Bearer $TOKEN" | jq . 
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2993    0  2993    0     0  90696      0 --:--:-- --:--:-- --:--:-- 90696

{
  "offset": 0,
  "limit": 100,
  "total_count": 5,
  "results": [
    {
      "id": "624c0359-c2d7-49f5-ac48-d81d2546a635",
      "name": "21.0.0.12-WS-WLP-IFPH46072",
      "description": "Installation of 21.0.0.12-WS-WLP-IFPH46072",
      "type": "install",
      "assetIds": [
        "8bc3c78f-6fae-3893-a88b-1c1e5cfb7793"
      ],
      "fixIds": [
        "ce598b97-4811-3d63-b01d-80b2c8c30157"
      ],
      "hostName": "XXX",
      "installDirectory": "/opt/ibm/wlp/",
      "fixName": "21.0.0.12-WS-WLP-IFPH46072",
      "backupNeeded": false,
      "autoInstall": true,
      "status": "succeeded",
      "created": "2022-08-15T15:30:48Z",
      "createdBy": "kubeadmin",
      "updated": "2022-08-15T15:33:10Z",
      "updatedBy": "installation-manager",
      "installationNumber": 5
    },
    {
      "id": "888b7044-80a4-40d6-9738-84cef5650d2e",
      "name": "9.0.5.3-WS-WAS-IFPH41676",
      "description": "Installation of 9.0.5.3-WS-WAS-IFPH41676",
      "type": "install",
      "assetIds": [
        "ee7186ad-698a-34d9-a48e-a2b2d4fbcc18"
      ],
      "fixIds": [
        "ff74a538-cf43-3ed4-8f74-5eaf99fa4a17"
      ],
      "hostName": "XXX",
      "installDirectory": "/opt/WAS",
      "fixName": "9.0.5.3-WS-WAS-IFPH41676",
      "backupNeeded": false,
      "autoInstall": true,
      "status": "succeeded",
      "created": "2022-08-15T13:16:05Z",
      "createdBy": "kubeadmin",
      "updated": "2022-08-15T13:21:35Z",
      "updatedBy": "installation-manager",
      "installationNumber": 4
    },
    {
      "id": "0f4d6629-d674-4618-a2b4-6c2ed81c0ca4",
      "name": "21.0.0.12-WS-WLP-IFPH46072",
      "description": "Installation of 21.0.0.12-WS-WLP-IFPH46072",
      "type": "install",
      "assetIds": [
        "8bc3c78f-6fae-3893-a88b-1c1e5cfb7793"
      ],
      "fixIds": [
        "ce598b97-4811-3d63-b01d-80b2c8c30157"
      ],
      "hostName": "XXX",
      "installDirectory": "/opt/ibm/wlp/",
      "fixName": "21.0.0.12-WS-WLP-IFPH46072",
      "backupNeeded": false,
      "autoInstall": true,
      "status": "succeeded",
      "created": "2022-08-15T13:15:48Z",
      "createdBy": "kubeadmin",
      "updated": "2022-08-15T13:19:14Z",
      "updatedBy": "installation-manager",
      "installationNumber": 3
    },
    {
      "id": "f046579b-11f2-469c-8352-60116b886092",
      "name": "9.0.5.3-WS-WASProd-IFPH43148",
      "description": "Installation of 9.0.5.3-WS-WASProd-IFPH43148",
      "type": "install",
      "assetIds": [
        "ee7186ad-698a-34d9-a48e-a2b2d4fbcc18"
      ],
      "fixIds": [
        "98066355-1670-3abe-86dc-d4024b7f59ad"
      ],
      "hostName": "XXX",
      "installDirectory": "/opt/WAS",
      "fixName": "9.0.5.3-WS-WASProd-IFPH43148",
      "backupNeeded": false,
      "autoInstall": true,
      "status": "succeeded",
      "created": "2022-08-15T11:56:23Z",
      "createdBy": "kubeadmin",
      "updated": "2022-08-15T12:02:25Z",
      "updatedBy": "installation-manager",
      "installationNumber": 2
    },
    {
      "id": "49dac926-3a30-4c38-88c6-31a916fef3a7",
      "name": "21.0.0.12-WS-WLPWithExtensions-IFPH42074",
      "description": "Installation of 21.0.0.12-WS-WLPWithExtensions-IFPH42074",
      "type": "install",
      "assetIds": [
        "8bc3c78f-6fae-3893-a88b-1c1e5cfb7793"
      ],
      "fixIds": [
        "8316ccf1-1522-32ca-8cb4-339ad23792ac"
      ],
      "hostName": "XXX",
      "installDirectory": "/opt/ibm/wlp/",
      "fixName": "21.0.0.12-WS-WLPWithExtensions-IFPH42074",
      "backupNeeded": false,
      "autoInstall": true,
      "status": "failed",
      "created": "2022-08-15T11:55:53Z",
      "createdBy": "kubeadmin",
      "updated": "2022-08-15T11:59:04Z",
      "updatedBy": "installation-manager",
      "installationNumber": 1
    }
  ]
}

For this example, we can see that there were 5 installations retrieved. Using the APIs, the maximum number of results returned is determined by the 'limit' parameter. The value must be an integer between 1 and 100. The default 'limit' parameter is 25.

For this example, if we wanted to delete the failed installation where installation number is 1 and id is 49dac926-3a30-4c38-88c6-31a916fef3a7, we can utilize the APIs. Using CLI with the token value set in a variable TOKEN and url set in a variable URL, we can issue the following command to delete the installation.

[root@api.XXX.ibm.com Installations]# curl -k -X DELETE "${URL}/installations/49dac926-3a30-4c38-88c6-31a916fef3a7" -H "accept: application/json" -H "Authorization: Bearer $TOKEN"

After executing the delete command, we can observe that the failed installation is now removed when viewing the Security -> Fix management tab. The following screenshot shows only 4 completed installations.

Security_Fix_Management_2


You can find more IBM Docs related to WebSphere Automation at https://www.ibm.com/docs/en/ws-automation.
#WebSphere#Automation#WebSphereAutomation​​​​
0 comments
45 views

Permalink