Resolving the Oracle Cloud "Out of Capacity" Problem and Acquiring a Free VPS with 4 ARM Cores / 24GB of Memory
This Python script creates a virtual machine instance in Oracle Cloud Infrastructure (OCI) using the OCI Python SDK. If there is available host capacity, the script attempts to create the instance. It also sets up the necessary networking components if the subnet ID is not provided as an environment variable.
Before running the script, ensure you have met the following requirements:
- Python 3.x installed
- The OCI Python SDK installed (
oci
package) - An OCI account with the necessary permissions to create resources (virtual machine, VCN, subnet, etc.)
- An OCI configuration file (
config
) with valid credentials
-
Clone the repository or download the script file to your local machine.
git clone https://github.com/sergioaten/OCI.catch-free-instance.git
-
Install the required dependencies by running the following command:
pip install -r requierements.txt
-
Set up your OCI configuration by following the instructions in the OCI SDK and CLI Configuration documentation.
-
Create a
.env
file in the same directory as the script and provide the required environment variables:subnet_id
: (Optional) The OCID of the subnet where the instance will be launched. If not provided, the script will create a new VCN, subnet, and associated networking components.availability_domain
: The availability domain where the instance will be launched.shape
: The shape (compute instance type) for the instance.instance_name
: The display name for the instance.ssh_publickey
: The public SSH key to be added to the instance for SSH access.memory
: The amount of memory (in GB) for the instance.ocpus
: The number of OCPUs for the instance.image_id
: The OCID of the image to be used for the instance.boot_volume_gb
: The size (in GB) of the boot volume for the instance.
Run the script using the following command:
python instance.py
The script will perform the following steps:
-
Load the environment variables from the
.env
file. -
Configure the OCI credentials using the
config
file. -
Create an OCI Compute client instance.
-
Check if the
subnet_id
variable is empty. If empty, the script proceeds to create the necessary networking components (VCN, subnet, internet gateway, and route table). -
Define the instance parameters based on the provided environment variables.
-
Attempt to launch the instance. If an "Out of host capacity" error occurs, the script waits for 1 minute before retrying. This is to handle cases where there is no available host capacity.
-
Once the instance is successfully created, the script displays the instance ID.
Contributions to this script are welcome. If you find any issues or have suggestions for improvements, please open an issue or submit a pull request on the GitHub repository.
This script is licensed under the MIT License. See the LICENSE
file for more information.