Skip to Content
Technical Articles
Author's profile photo Remi ASTIER

Automate HANA Cloud Administration tasks such as instance creation, start/stop, resize

SAP HANA Cloud brings interesting possibilities for admins, such as automating the creation of new instances or shutting down non productive instances overnight.

The command line utility for Cloud Foundry enables us to do just that. For simplicity we’ll use an external machine with a good old crontab.

Below are the commands you can put in a script to automate tasks. If you’re using windows, please refer to this link for the syntax for the windows command line and PowerShell.

Log into Cloud Foundry

Before performing an action, you need to be authenticated. This is done with the
cf login command. It takes parameters such as:

  • -a The cloud foundry API url of the dataceter
  • -o The target organization
  • -s The target space
  • -u User name and -p password. For security, the password is read from a file.
cf login -u my.email@sap.com -o my_org -s my_space -a https://api.cf.eu20.hana.ondemand.com -p "$(<$HOME/.ssh/.toto)"

Perform the Action

Now you’re ready to execute an action using either

  • cf create-service to create a HANA Cloud instance, a Relational Data Lake, or any other services of the SAP Cloud Platform.
  • cf update-service to start/stop/resize a service instance.

Create a new instance

cf create-service hana-cloud hana tst_cf_db -c '{ ... }'

A sample json value is:

{"data":{"edition":"cloud","memory":32,"systempassword":"PereNoel2021","whitelistIPs":["10.2.3.0/24"],"vcpu":2}}

The json data must have compatible values for memory and cpu, otherwise an error message informs you of the correct values.
For instance, a request of 32 GB of memory for 4 vcpus will return:

Invalid Parameter (memory): HANA with 4 CPUs requires 64 GB memory (32)

This is quite useful because Azure and AWS have slightly different ratios of memory per vcpu.

Stop an instance

cf update-service tst_cf_db -c '{​​​​​"data":{"serviceStopped":true}}'

Start an instance

cf update-service tst_cf_db -c '{​​​​​"data":{"serviceStopped":false}}'

Increase the size:

The challenge is to come up with the correct values of memory, vcpu and storage. Bear in mind that currently, storage capacity once increased cannot be reduced.

An easy way to obtain the correct values is to execute the command multiple times to get the correct calculated values from the error messages. This example shows how to increase from 2 vcpu to 4.

cf update-service tst_cf_db -c '{"data": {"vcpu":4}}'

FAILED [...] HANA with 4 CPUs requires 64 GB memory (32)


cf update-service tst_cf_db -c '{"data": {"vcpu":4, "memory":64}}'

FAILED [...] HANA with 64 GB memory requires at least 200 GB storage (120)

cf update-service tst_cf_db -c '{"data": {"vcpu":4, "memory":64, "storage":200}}'

OK

Decrease the size:

Decreasing the size unfortunately requires opening a ticket. This roadmap item tracks the possibility to do it from the command line.

 

All the commands are described in the documentation.

Assigned Tags

      6 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Witalij Rudnicki
      Witalij Rudnicki

      Hi Remi. I see there are curly brackets missing in sap/start commands, like

      cf update-service my-hana -c '{"data":{"serviceStopped": false}}'

      Regards and thanks for sharing this!

      Author's profile photo Florian Preuß
      Florian Preuß

      Hi Witalij,

      I tried the correct command but it does not work for me on our HANA cloud instance. Any hint?

      Best Regards,
      Florian

      Author's profile photo Florian Preuß
      Florian Preuß

      found it...use "\" before each ".....'{\"data\":{\"serviceStopped\":false}}'

      Author's profile photo Witalij Rudnicki
      Witalij Rudnicki

      I'm glad you got it working :), Florian Preuß

      Author's profile photo Gustavo Calixto
      Gustavo Calixto

      Hello Witalij! Great blog!

      I´m just wondering, the roadmap link is not working anymore :c Do you know if we had an update about this roadmap item?

      Thanks!

      Author's profile photo Daniel Van Leeuwen
      Daniel Van Leeuwen

      An additional resource on this topic is the following tutorial which demonstrates executing various administrative tasks such as start/stop/create/update/upgrade of an SAP HANA Cloud instance using the BTP and CF CLIs.

      Executing SAP HANA Cloud Tasks from the Command Line