Oracle allow us to create free resources (such as VM) at their cloud services for testing. For examples, a VM.Standard.A1.Flex with maximal 4 OCPU and 24GB RAM is a good deal to host a website. However, the deal isn’t always available because the demand is always more then what Oracle can provide. If you try to create a free VM for now, you’ll receive an error “Out of capacity” most of the time. In this post, I’ll show you how to run a script which runs over the time and tries to create a VM until it gets success.
- The script is a Python script. You need to install Python on your computer. The script needs some settings so that it works properly. The values of variables can be get from following steps.
- Go to Oracle Cloud and open an account. You’ll need a master card for it. The
Home region
is where you want to create your VM. TheHome region
can’t be changed after set. So choose your region wisely so that you can take advantage of the VM later. - After creating an account, login to your account. On the the top right, click the profile icon and then select
User Settings
.
- Scroll down to
Resources
. SelectAPI Keys
. ClickAdd API Key
.
- Make sure
Generate API Key Pair
is selected, clickDownload Private Key
and save it as fileoci_private_key.pem
. - Click
Add
. Copy the contents from the textarea and save it as fileconfig
. - Put the
config
andoci_private_key.pem
files together in same directory. - Open the config file and edit the row of
key_file
. That is the path to your private key. NOTE: If you use Windows, the path must be an absolute path.
key_file=oci_private_key.pem
- Go to Oci Python script repository and download file
oci_auto.py
. Save it in the directory with the other files. - Go back to Oracle Cloud and
Create a VM instance
.
- Find
Image and shape
. ClickEdit
.
- Select the
Image
which you want to use, for exampleUbuntu
. - Click
Change shape
. SelectAmpere
. SetNumber of OCPUs
to4
andAmout of memory (GB)
to24
. Then clickSelect shape
.
- Scroll down to
Networking
. ClickEdit
. SelectDo not assign a public IPv4 address
.
- Scroll down to
Add SSH keys
. ClickSave Private Key
andSave Public Key
. Store them to a safe place. We’ll need it later.
- Before creating VM, press
F12
to open DevTools. Select tabNetwork
. - Click
Create
. You’ll receive an error.
Out of capacity for shape VM.Standard.A1.Flex in availability domain OFDj:AP-SINGAPORE-1-AD-1. If you specified a fault domain, try creating the instance without specifying a fault domain. If that doesn’t work, please try again later. Learn more about host capacity.
- In the DevTools, tab
Network
, search now forinstances
request. Right click on it. SelectCopy –> Copy as cURL (cmd)
.
- Copy the content to an editor. Find the part
–data-raw
. - Open the
oci_auto.py
which you downloaded before and replace the values with the values in–data-raw
.
instance_display_name = 'instance-********'
compartment_id = 'ocid1.tenancy.oc1..********'
domain = "OFDj:AP-SINGAPORE-1-AD-1" # availability_domain
image_id = "ocid1.image.oc1.ap-singapore-1.********"
subnet_id = 'ocid1.subnet.oc1.ap-singapore-1.********'
ssh_key = "ssh-rsa ******** ssh-key-2022-01-14"
- The setup is now finished. You can run the script with the following commands.
$ pip install requests
$ pip install oci
$ python3 oci_auto.py
- If you see this, that means the script has run successfully.
- It may take days until there is a free slot for you. The script will quit and give back a message when he creates a VM successfully.
- After the VM gets created, go to
Instances
, select the newly created instance. - Scroll down to
Resources
. SelectAttached VNICs
. Click on the newly create VNIC. - Scroll down to
Resources
. SelectIPv4 Addresses
.Edit
and selectEphemeral public IP
. Click Update.
- Open
PuTTY Key Generator
,Load
the private key you saved before. ClickSave private key
to generate a key format (*.ppk) which can be used by Putty. Save it to a safe place. - Open
PuTTY
, go toConnection –> SSH –> Auth
, select the private key generated byPuTTY Key Generator
before.
- In
PuTTY
, go toSession
, enter the IP you get from instance details. ThenOpen
the connection. You’ll be asked for username which is also available in section of instance details.