In this exercise, you will use the REST APIs of SAP Landscape Management Cloud for retrieving all managed SAP systems. You will generate an API key for your tenant and make use of the credentials inside a Python script deployed in SAP BTP, Cloud Foundry runtime.
ℹ INFORMATION: This exercise is based on the sample LaMa-Cloud_REST_API and the blog post SAP Landscape Management Cloud (LaMa Cloud) REST API Sample.
After completing these steps, you have all details required to communicate with your SAP Landscape Management Cloud tenant via API.
- Open your trial tenant of SAP Landscape Management Cloud.
- In the left navigation, select
Configuration > API Management
. - Select
Create
. - Provide an "API Key Name" e.g. "techEdLaMa".
- Check both checkboxes for the "API Scopes".
- In this example we will not use the X.509 certificate so deselect it.
- At the bottom right, select
Create
. - Copy the generated JSON to a text file on your computer as you will need it later on and it won't show up again.
The JSON looks similar to
{
"url": "https://api.lama.cloud.sap/v1",
"tokenUrl": "https://<yourSubdomain>.authentication.eu10.hana.ondemand.com/oauth/token",
"clientId": "sb-xsuaa-9f3dbb85-1234-45676-834a-2f2ebe2c7ca7!b235026|lmc-eu10-api!b1234",
"clientSecret": "<loremIpsum>-9271-44f5-834a-2f2ebe2c7ca7$iudzM_WM5qdYTDRYY9X1LN5bJk8rP3067Y="
}
After completing these steps, you will be familiar with the REST API endpoints provided by SAP Landscape Management Cloud.
- Visit the SAP Business Accelerator Hub.
- Select
API Reference
. - Familiarize yourself with the "GET /systems" endpoint.
After completing these steps, you will have created a test application that is making use of the REST API of SAP Landscape Management Cloud.
- Open this folder inside the SAP-samples repository. This contains the source code for the small application you are going to deploy.
- Read about the containing files via the Description section.
- If you are familiar with GitHub, visit the parent repository landscape-management-sample-scripts and fork it to your local machine.
Alternatively, visit the parent repository landscape-management-sample-scripts and select the green button
Code > Download ZIP
at the top right to retrieve all files of the samples. - Unpack the ZIP archive and browse into the folder "LaMa -Cloud_REST_API > samples".
- Open the file "server.py"
- Copy and paste the API credentials of your SAP Landscape Management Cloud tenant into the respective lines 10-13 so that the code looks similar to this:
# OAuth 2 client configuration
client_id = "sb-xsuaa-9f3dbb85-1234-45676-834a-2f2ebe2c7ca7!b235026|lmc-eu10-api!b1234"
client_secret = "<LoremIpsum>-9271-44f5-834a-2f2ebe2c7ca7$iudzM_WM5qdYTDRYY9X1LN5bJk8rP3067Y="
token_url = 'https://<yourSubdomain>.authentication.eu10.hana.ondemand.com/oauth/token'
ℹ INFORMATION: The variable "api_url" is the same for every tenant of SAP Landscape Management Cloud. Hence, there is no need to modify it.
- Save the file.
- Go back to the "samples" folder in your operating system's file explorer, select all containing files, and create a ZIP archive. The zip file needs to be created such that the "server.py" is at the top level.
After this exercise, you will have deployed the Python app to the space inside your SAP BTP, Cloud Foundry runtime which is available in the SAP BTP trial account.
- Open your SAP BTP Trial account.
- Select
Go To Your Trial Account
. - Select the subaccount
trial
. - In the section "Cloud Foundry Environment", you can see that there is one space created called "dev". Select this line in the table to open it.
- Select
Deploy Application
. - For the "File location", select
Browse...
and navigate to your ZIP archive created in exercise 4.3. - For the "Manifest Location", select
Browse...
and navigate to the file "manifest.yml" in the same folder as the sample. - Select
Deploy
.
After the deployment is finished, you need to create an external route so that you can try the app.
- In the left navigation, select
Routes
. - Select
New Route
. - As "Domain", select
cfapps.ap21.hana.ondemand.com
. - Pick any host name, e.g.
myapp-<yourname>
and keep the "Path" field empty. - Select
Save
. - At the "Actions" column, select
Map Route
. - In the dropdown list, select your app and select
Save
.
After following these steps, you can fetch a list of managed SAP systems in a browser window via the REST API endpoints of SAP Landscape Management Cloud.
- Try out the externally exposed app. Replace the placeholder with the host name you picked in Exercise 4.4 (e.g. “myapp-”) in following url: https://<HostName picked in exercise 4.4>.cfapps.ap21.hana.ondemand.com. When you then click on the url you should see “Hello, World!”
- Try fetching all managed systems by opening https://<HostName picked in exercise 4.4>.cfapps.ap21.hana.ondemand.com/api/v1/systems.
This will list the GET call to your tenant of SAP Landscape Management Cloud.
This exercise shows how to make use of the REST API endpoints provided by SAP Landscape Management Cloud. Getting a list of managed systems is only the beginning of a useful script. With this list of systems, you can build a logic that picks a particular system id (e.g. "370c5e1d-763e-4f06-8239-df23a78ef691") and afterwards generates a POST request against the /activities
endpoint for stopping the system with the body
{
"requestType": "StopSystemRequest",
"systemId": "370c5e1d-763e-4f06-8239-df23a78ef691",
"executeGraceful": true
}
This might be useful if a maintenance window is planned for the system and SAP Landscape Management Cloud should stop it. After the maintenance window, the system can be started again via API with “StartSystemRequest”.
🎉 Congratulations! You've used the REST API endpoints of SAP Landscape Management Cloud!
Continue to - Exercise 5 - Outlook: Event-driven infrastructure automation