I was working on automation using REST API and found it is very interesting and easy to implement with a simple command to deploy services on OCI.
In this blog, I will show you how to deploy DBCS using REST API.
I know you are thinking why I need to deploy using REST API if I have console. Well, you can schedule a job to deploy/terminate DBCS. Specially when you doing any testing, it will help, it will save time and money both.
There are many ways to use APIs, I am using oci-curl function in this blog available by OCI team. OCI_CURL will sign and encrypt your APIs so they are not sent in clear over the internet.
OCI-CURL can be used on Linux and windows, I am using on windows here.
You can use below link to copy oci-curl script.
You only have to change these 4 parameters in this script as per your environment.
To Deploy DB system we need below 4 things:-
1. OCI-CURL - I have it above.
2. API endpoint for database: I used database.ca-toronto-1.oraclecloud.com , if your cloud database is located somewhere else you can use that. full list here .. API Endpoints
3. Config File: I also need to create a small JSON file for configuration containing information like availability domain, compartment id, db related info and public key to access node.
4. DB System API command POST /20160918/dbSystems
here is my JSON file here..
Now I have everything, so I just created a small shell script
So to deploy DB system, I just need to run the shell script like ./createdbsystem.sh and magic start to begin :)
Here is the output
and when I go to console, I can see its provisioning..
You can go to the work request to see how much completed..
It will take like 20-30 mins to complete and then you can connect to the node using your private key.
To Delete or terminate the DB System even more simpler because you don't need any configuration file , you just need OCID of the DB System.
Here is the script I created for terminate....
Now we can schedule these jobs in crontab or windows scheduler to automate deployment.
Hope you like the Blog!
No comments:
Post a Comment