


Generate automated instance requests to Oracles Cloud Interface.
Inspired by chacuavip10’s oci_auto and supported by these awesome open sourced libraries: questionary , rich , and requests.
App logo brought to you by an AI who did it’s (their?) best.
-
-
Python Libraries
-
Oracle’s cloud offers a really enticing free tier of virtual machine options that boast a mighty up to 4 OCPU’s and 24 GBs of cloud hosted resources. The difficulty is, these free tier VM’s are hard to come by and while Oracle regularly adds more, they never announce before hand. So, claiming these resources when they come available can feel like winning the lottery and submitting these requests manually is an absolute chore.
While scouring the web for solutions to this problem I can across chacuavip10’s oci_auto. This great little tool, with a little setup, lets you grab a curl command from your browsers network tools and automatically submits new instance requests on your behalf on an interval. While this tool totally suffices and accomplishes what I was looking for, it had a few security flaws I had a hard time with. Mainly, the script stores things like file paths, ssh keys, and other sensitive information in the script and requires the user to edit the source code itself with these parameters.
In addition, you had to manually pull instance parameters from the curl command. Again, great tool and totally suffices, but I’m like reeeeeally lazy when it comes to this stuff so I set out to improve on this concept and reduce the number of steps.
This tool is a total redesign of it’s inspiration. The tool itself accepts JSON as an input and will automatically parse the instance values from the original POST request that failed in OCI. For bonus points I made file paths agnostic, threw in some styling, added an additional notification channel, and made the experience feel a little more like an adventure.
In the words of the great why the lucky stiff
No. Please don’t puzzle over it. You don’t need to do anything with the onion. Set the onion aside and let it do something with you.
Except OCI Instance Tool is the onion and you are… well you know, you.
Also
I wonder where he went with all those balloons. That crazy dog must have looked like a party with legs.
Wise words indeed.
Python 3+ is required and the script will terminate if a lower version is installed.
This tool was written in Windows for Windows. I’m actually not sure how this would function in other CLI’s, but if you want to give it a go or fork the project and make a couple changes, be my guest.
You’ll need to install the OCI SDK, requests, rich, and questionary. This can be done from requirements or installed individually.
From the root of OCI Instance Tool’s directory
pip install -r requirements.txt
-OR-
To upgrade exisiting packages to their required version:
pip install --upgrade -r requirements.txt
python pip install oci
python pip install requests
python pip install rich
python pip install questionary
OCI Instance Tool will need to authenticate and communicate with your Oracle cloud account. Luckily, creating this config file and generating the API key is only a few steps. Oracle recommends changing the file permissions so only you can view it.
From OCI’s Cloud Console navigate to User Settings
,
Under Resources
, select API Keys
:
Select Add API Key
- Tick
Generate API Key Pair
and thenDownload Private Key
(example key provided in demo) - Click
Add
and save the contents of the text area to a file (example config file provided in demo) Edit
the[key_file]
line of the config file from the last step with the filepath to yourPrivate Key
key_file=oci_private_key.pem
Its probably handy to have your maker url ready in a txt document or something. Setting this up is actually very straight-forward. Create a Webhook applet that accepts web requests. Once the applet is created you can grab your maker url containing the applet name and key you’ll need. Should look somthing like:
https://maker.ifttt.com/trigger/{applet}/with/key/{your_key}
Be sure the url does not contain \json\
as a parameter. The following values will accompany your web request:
- value1 =
instance_display_name
- value2 =
domian
- value3 =
{ocpus}
ocpus and{memory_in_gbs}
GB of memory
In order to use Telegram you’ll need your Bot ID
and your Chat ID
handy. You can follow this tutorial by Man Hay Hong for a more in depth guide How to create a Telegram Bot
- Search
@BotFather
and send a/start
message - Send another
/newbot
message - Save the APIK token, this is your
Bot ID
- Start a chat with your new bot
/start
and navigate to
https://api.telegram.org/bot<yourtoken>/getUpdates
- In the json blob is
"id"
, this is yourChat ID
To run the tool, in cmd, navigate to the folder containing OCI_Instance_Tool.py
. For an easier experience the folder should also contain your config file and your PEM key file. However, as long as your config file contains the path to your PEM file, this isn’t at all necessary.
Run:
python OCI_Instance_Tool.py
Options: {-h,-s,–config_file,-d,-ch}
The tool will first import all of the required libraries. While this mostly depends on your PC, OCI will take a while to import. Be patient, it isn’t stuck.
- Paste POST data output here:
- This question only accepts
{json}
and will reject all other text.
- This question only accepts
- Confirm the configuration parser correctly identified your request parameters
Display Name
Domain
Compartment ID
Image ID
Subnet ID
SSH Key
Shape Config
- Optional: Enter the filepath to your config file
- You can use
[tab]
to navigate your folders in the cli - Or use
--config_file {path to your file}
at runtime to skip this question
- You can use
- Notification preference and notification preference settings
- Indicate your notification preference
- This will generate a folloup question asking for your IFTTT
Maker URL
or your TelegramChat Id
andBot ID
- Once these questions have been answered OCI Instance Tool will validate there are no exisiting resources with duplicate display names or configurations that will exceed your free tier resource limits.
OCI Instance tool will then attempt to claim your instance every thirty seconds until it succeedes. This can take a very, very long time depending on domain availibility. .
OCI Instance Tool accepts the following arguments at runtime
--help, h
Shows the help page with availible arguments
--Style, -s
changes the color scheme of the tool (ex. -s 155
or --style dark_olive_green2
would produce colored text!)
--config_file
Allows you to specify your config file path at runtime. The config location question is an interactive file tree element. This may save time navigating complicated file structures.
--debug, -d
Enables application debug options. This is in development and currently only outputs a runtime when building the color help page
--color_help, -ch
This is the color help page. This will produce all the availible colors that can be referenced by style using name or number. Rich supports TrueColors and colors not listed here will need to be referenced by their hex code. (beta, expect bugs)
The demo folder can be referenced for file content, structure, and usage. It contains a demo version of the OCI Instance Tool
, an example POST
request json file, and an example PEM Key
file. Since you’ll be generating actual requests to Oracle that contains your sensiticve information, using the demo to get a feel for the adventure could be helpful.
In the Demo
folder, open post_example.json
and copy the contents. It’s important this all stays on one line.
Run:
python OCI_Instance_Tool_Demo.py
When promtped, paste the contents of post_example.json
and hit [enter]
.
Do whatever you want with this, just don’t use it to DDOS Oracle, pls.

Leave a Reply