dropdown menu

API (HMC)

(Detailed description: https://www.djouxtech.net/posts/hmc-v8-rest-api-part-1-curl/)

API (Application Programming Interface) is an interface or in other words a sort of "software" (combinations of protocols, subroutines...) which receives requests and sends responses to remote servers  and applications. For example a weather application on a mobile phone sends a request regarding the temperature, and the API on the remote server receives this request and sends back a response with the current temperature. APIs are very helpful for developers, as programs can use those automatically and also through the internet as HTTP requests. Some examples for these HTTP calls could be GET, PUT, POST, or DELETE.

Regarding HMC, we have the possibility to do some HMC tasks through API calls.
REST API is on the port 12443 and it is using TLS:

=============================

1. login
Authentication informations are needed, so during first login a cookies.txt (jar file) is generated which will be re-used for later requests:

Created a login.xml file:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<LogonRequest xmlns="http://www.ibm.com/xmlns/systems/power/firmware/web/mc/2012_10/" schemaVersion="V1_0">
  <UserID>hscroot</UserID>
  <Password>JibcebVoryij</Password>
</LogonRequest>

=============================

2. authenticating with HMC

curl -k -c cookies.txt -i -X PUT -H "Content-Type: application/vnd.ibm.powervm.web+xml; type=LogonRequest" -H "Accept: application/vnd.ibm.powervm.web+xml; type=LogonResponse" -H "X-Audit-Memento: hmc_test" -d @login.xml https://ls-hmc02.mycompany.vmta/rest/api/web/Logon


-k : “insecure” mode. It permits the use of the self signed certificate used by the HMC.
-c cookies.txt : setup the cookies jar where authentication session informations will be kept.
-X PUT : use PUT request method. Requested by the HMC API.
-d @login.xml : will use content of login.xml.
-H : http headers added to the request.
-i : show the http headers of the answer. Useful for debugging.

These headers were used :
Content-Type: application/vnd.ibm.powervm.web+xml; type=LogonRequest    <---specifies the request content format
Accept: application/vnd.ibm.powervm.web+xml; type=LogonResponse :           <---specifies the expected response content format
“X-Audit-Memento: hmc_test”                                                                                     <---a simple comment


=============================

A correct response looks like this:
(A 200 return code and cookies.txt should contain authentication data.)

HTTP/1.1 200 OK
Date: Mon, 11 Jun 2018 12:56:56 GMT
Server: Apache
X-Frame-Options: SAMEORIGIN
X-Powered-By: Servlet/3.0
X-Transaction-ID: XT11051741
Content-Type: application/vnd.ibm.powervm.web+xml; type=LogonResponse
Content-Language: en-US
Content-Length: 576
Expires: Thu, 01 Dec 1994 16:00:00 GMT
Cache-Control: no-cache="set-cookie, set-cookie2"
Set-Cookie: JSESSIONID=0000urPUexb-pXUIQmmEX7DTWDq:49acdfa9-0489-4c76-9264-db31bff3b86f; Path=/; Secure; HttpOnly
Set-Cookie: CCFWSESSION=F3A170E36B40FF311FD7052759708587; Path=/; Secure; HttpOnly
Vary: User-Agent

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<LogonResponse xmlns="http://www.ibm.com/xmlns/systems/power/firmware/web/mc/2012_10/" xmlns:ns2="http://www.w3.org/XML/1998/namespace/k2" schemaVersion="V1_6_1">
    <Metadata>
        <Atom/>
    </Metadata>
    <X-API-Session kb="ROR" kxe="false">2XXC300H89iUox0Z0YT9VOfD7yUNDdFV3MIWH_1QQfVJ2Qi8pwOIFglDfrQ19GlQrrUL_Oiwa8p7Mpm19UE0Tyf2ty5Yp92xiRwxP387-S4OAmmV_9k8aLzjwCzGmGAaz3_GRH42y3VfGTklAu1fnJH6oaQjWryDs1KT5n6-qffTUlcI5SOXDl4oT8sJg1BXOAChiSM4GXz79tiKHTwxfX3oVfUlenysV0dJiHG9q8M=</X-API-Session>
</LogonResponse>


# cat cookies.txt
# Netscape HTTP Cookie File
# https://curl.haxx.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.

#HttpOnly_ls-hmc02.dynatrace.vmta       FALSE   /       TRUE    0       JSESSIONID      0000fjng3CsBetIsiATyrofKTNR:49acdfa9-0489-4c76-9264-db31bff3b86f
#HttpOnly_ls-hmc02.dynatrace.vmta       FALSE   /       TRUE    0       CCFWSESSION     F3A170E36B40FF311FD7052759708587

=============================


3. Reguest info from HMC

To get info from all LPARS: (long list of all LPARs on all Man. Sys.)
curl -k -c cookies.txt -b cookies.txt -H "Accept: application/atom+xml; charset=UTF-8" https://ls-hmc02.mycompany.vmta/rest/api/uom/LogicalPartition

-b cookies.txt: use the appropriate cookies during the session.
-H “Accept: application/atom+xml; charset=UTF-8” : the expected response should be a atom feed.

To get info from a specific LPAR:
curl -k -c cookies.txt -b cookies.txt -i -H "Accept: application/atom+xml; charset=UTF-8" https://ls-hmc02.mycompany.vmta:12443/rest/api/uom/LogicalPartition/search/\(PartitionName\=\=ld-aix-pci71m-3976d990-00000055\)




No comments:

Post a Comment