This script allows to bypass Oracle Cloud Infrastructure 'Out of host capacity' error immediately when additional OCI capacity will appear in your Home Region / Availability domain.

Overview

Resolving Oracle Cloud "Out of Capacity" issue and getting free VPS with 4 ARM cores / 24GB of memory

Test

Very neat and useful configuration was recently announced at Oracle Cloud Infrastructure (OCI) blog as a part of Always Free tier. Unfortunately, as of July 2021, it's very complicated to launch an instance due to the "Out of Capacity" error. Here we're solving that issue as Oracle constantly adds capacity from time to time.

Each tenancy gets the first 3,000 OCPU hours and 18,000 GB hours per month for free to create Ampere A1 Compute instances using the VM.Standard.A1.Flex shape (equivalent to 4 OCPUs and 24 GB of memory).

This approach requires PHP 7.4 or PHP 8.0 and composer installed and will call "LaunchInstance" OCI API endpoint. We'll utilise the package which I've written (and published) some time ago, here's the article.

If you prefer article style, here's a link to Medium

YouTube video instruction https://youtu.be/uzAqgjElc64.

Generating API key

After logging in to OCI Console, click profile icon and then "User Settings"

User Settings

Go to Resources -> API keys, click "Add API Key" button

Add API Key

Make sure "Generate API Key Pair" radio button is selected, click "Download Private Key" and then "Add".

Download Private Key

Copy the contents from textarea and save it to file with a name "config". I put it together with *.pem file in newly created directory /home/ubuntu/.oci

Configuration File Preview

Installation

Clone this repository

git clone https://github.com/hitrov/oci-arm-host-capacity.git

run

cd oci-arm-host-capacity/
composer install

Adjust script file

You need to slightly adjust index.php file - by changing OciConfig constructor arguments.

Adjust OciConfig arguments 1–5

Arguments 1–5 (region, user, tenancy, fingerprint, path to private key) should be taken from textarea during API key generation step.

Adjust OciConfig arguments 6-8

In order to acquire availabilityDomain, subnetId, imageId you must start instance creation process from the OCI Console in the browser (Menu -> Compute -> Instances -> Create Instance)

Change image and shape and make sure that "Always Free Eligible" availabilityDomain label is there:

Changing image and shape

Adjust Networking section, set "Do not assign a public IPv4 address" checkbox. If you don't have existing VNIC/subnet, please create VM.Standard.E2.1.Micro instance before doing everything.

Networking

"Add SSH keys" section does not matter for us right now. Before clicking "Create"…

Add SSH Keys

…open browser's dev tools -> network tab. Click "Create" and wait a bit - most probably you'll get "Out of capacity" error. Now find /instances API call (red one)…

Dev Tools

…and right click on it -> copy as curl. Paste the clipboard contents in any text editor and review the - data-binary parameter. Find availabilityDomain, subnetId, imageId. Use them as 6,7 and 8 arguments, respectively, to the OciConfig constructor.

OciConfig also has the last two arguments - ocpus and memoryInGBs (respectively). They are optional and are equals 4 and 24 by default. Of course, you can adjust them. Possible values are 1/6, 2/12, 3/18 and 2/24, respectively. Please notice that "Oracle Linux Cloud Developer" image can be created with at least 8GB of RAM.

Set public key value

In order to have secure shell (SSH) access to the instance you need to have a keypair, e.g. ~/.ssh/id_rsa and ~/.ssh/id_rsa.pub. Second one (public key) filename should be provided to a command below. The are plenty of tutorials on how to do that, we won't cover this part here.

Change the string variable $sshKey - paste the contents of your public key ~/.ssh/id_rsa.pub (or you won't be able to login into the newly created instance).

Running the script

php /path/to/oci-arm-host-capacity/index.php

I bet that the output (error) will be similar to the one in a browser a few minutes ago

{
    "code": "LimitExceeded",
    "message": "The following service limits were exceeded: standard-a1-memory-count, standard-a1-core-count. Request a service limit increase from the service limits page in the console. "
}

You can now setup periodic job to run the command

EDITOR=nano crontab -e

Add new line to execute the script every minute and log the output

* * * * * /usr/bin/php /path/to/oci-arm-host-capacity/index.php > /path/to/script.log

..and save the file.

There could be cases when cron user won't have some permissions, the easiest way to solve it is to put the code into web server's accessible directory e.g. /usr/share/nginx/html and setup cron this way:

* * * * * curl http://server.add.re.ss/oci-arm-host-capacity/index.php

You can also visit the URL above and see the same command output as by running from the shell.

Before the instance creation, script will call ListInstances OCI API method and check whether there're already existing instances with the same $shape, as well as number of them $maxRunningInstancesOfThatShape(you can safely adjust the last one if you wanna e.g. two VM.Standard.A1.Flex with 2/12 each).

Script won't create new instance if current (actual) number return from the API exceeds the one from $maxRunningInstancesOfThatShape variable.

In case of success the JSON output will be similar to

Launch success 1

Launch success 2

Assigning public IP address

We are not doing this during the command run due to the default limitation (2 ephemeral addresses per compartment). That's how you can achieve this. When you'll succeed with creating an instance, open OCI Console, go to Instance Details -> Resources -> Attached VNICs by selecting it's name

Attached VNICs

Then Resources -> IPv4 Addresses -> … -> Edit

IPv4 Addresses

Choose ephemeral and click "Update"

Edit IP Address

Conclusion

That's how you will login when instance will be created (notice opc default username)

ssh -i ~/.ssh/id_rsa [email protected]

If you didn't assign public IP, you can still copy internal FQDN or private IP (10.x.x.x) from the instance details page and connect from your other instance in the same VNIC. e.g.

ssh -i ~/.ssh/id_rsa [email protected]
Comments
  • Parsing error

    Parsing error

    Hello,

    I just tried to launch the script and it result in a PHP Parse error on Line 75. it seems to be caused by the $availabilityDomainEntity[‘Name’]

    opened by B1n00 12
  • NotAuthorizedOrNotFound

    NotAuthorizedOrNotFound

    I following the instruction on a new setup, but end up to this error, does anyone have the same issue before? Thanks

    php /var/www/html/oci-arm-host-capacity/index.php : { "code" : "NotAuthorizedOrNotFound", "message" : "Authorization failed or requested resource not found." }

    base on: php7.4, composer 2.1.8

    ps. Ampere still out of stock at this posting time, dont know how to get one. :)

    opened by s12321 11
  • NotAuthorizedOrNotFound Authorization failed or requested resource not found

    NotAuthorizedOrNotFound Authorization failed or requested resource not found

    PHP Fatal error: Uncaught Hitrov\Exception\ApiCallException: { "code": "NotAuthorizedOrNotFound", "message": "Authorization failed or requested resource not found." } in /home/ubuntu/oci-arm-host-capacity-main/src/HttpClient.php:42 Stack trace: #0 /home/ubuntu/oci-arm-host-capacity-main/src/OciApi.php(218): Hitrov\HttpClient::getResponse() #1 /home/ubuntu/oci-arm-host-capacity-main/src/OciApi.php(101): Hitrov\OciApi->call() #2 /home/ubuntu/oci-arm-host-capacity-main/index.php(76): Hitrov\OciApi->getInstances() #3 {main} thrown in /home/ubuntu/oci-arm-host-capacity-main/src/HttpClient.php on line 42

    opened by sumersm7 7
  • PHP error

    PHP error

    PHP Parse error: syntax error, unexpected '$availabilityDomain' (T_VARIABLE), expecting ')' in /home/ubuntu/.oci/oci-arm-host-capacity/index.php on line 89

    image

    opened by KAMLEGENDZ 7
  • Getting SignerValidateException

    Getting SignerValidateException

    Hello 👋 , when I run the script I get this exception:

    php /home/ubuntu/oci-arm-host-capacity/index.php
    PHP Fatal error:  Uncaught Hitrov\OCI\Exception\SignerValidateException: URL is invalid: https://iaas..oraclecloud.com/20160918/instances/?availabilityDomain=&compartmentId= in /home/ubuntu/oci-arm-host-capacity/vendor/hitrov/oci-api-php-request-sign/src/Hitrov/OCI/Signer.php:329
    Stack trace:
    #0 /home/ubuntu/oci-arm-host-capacity/vendor/hitrov/oci-api-php-request-sign/src/Hitrov/OCI/Signer.php(67): Hitrov\OCI\Signer->validateParameters()
    #1 /home/ubuntu/oci-arm-host-capacity/src/OciApi.php(111): Hitrov\OCI\Signer->getHeaders()
    #2 /home/ubuntu/oci-arm-host-capacity/index.php(34): Hitrov\OciApi->getInstances()
    #3 {main}
      thrown in /home/ubuntu/oci-arm-host-capacity/vendor/hitrov/oci-api-php-request-sign/src/Hitrov/OCI/Signer.php on line 329
    

    I guess that I made some mistake in declaring the key file path (aka OCI_PRIVATE_KEY_FILENAME), but I can't figure out what exactly I did wrong.

    (Also sorry for posting this issue initially empty, I clicked publish before being finished by accident)

    opened by dpschen 7
  • PHP Fatal error:  Uncaught Hitrov\Exception\ApiCallException:

    PHP Fatal error: Uncaught Hitrov\Exception\ApiCallException:

    i already set all params to .env file, but when run php index.php it warning: PHP 7.4.16 PHP Fatal error: Uncaught Hitrov\Exception\ApiCallException: { "code": "NotAuthenticated", "message": "The required information to complete authentication was not provided or was incorrect." } in /tmp/oci-arm-host-capacity/src/HttpClient.php:42 Stack trace: #0 /tmp/oci-arm-host-capacity/src/OciApi.php(210): Hitrov\HttpClient::getResponse() #1 /tmp/oci-arm-host-capacity/src/OciApi.php(102): Hitrov\OciApi->call() #2 /tmp/oci-arm-host-capacity/index.php(66): Hitrov\OciApi->getInstances() #3 {main} thrown in /tmp/oci-arm-host-capacity/src/HttpClient.php on line 42

    opened by heroes1412 6
  • Parsing error at dotenv file.

    Parsing error at dotenv file.

    Hello, I was trying to run this script with all setup, but when I tried to execute it i get the following error:

    WindowsTerminal_155922_25012022

    Looks like an error parsing the .pem file somehow. I cloned the git less than a week ago so I don't think it's outdated. Any help?

    By the way, as an important side note, I used Firefox on Windows for the process of copying the curl for the instance, and the error you have to copy is different, it's a 500 error that looks like this, also on the Network tab: firefox_160242_25012022

    Thanks!

    opened by elterrasense 5
  • Error executing Script: Argument #1 ($region) must be of type string, bool given

    Error executing Script: Argument #1 ($region) must be of type string, bool given

    I have this error where I can't run the script

    THE ERROR:

    PHP Fatal error: Uncaught TypeError: Hitrov\OciConfig::__construct(): Argument #1 ($region) must be of type string, bool given, called in C:\Users\NAME\Downloads\oci-arm-host-capacity\index.php on line 35 and defined in C:\Users\NAME\Downloads\oci-arm-host-capacity\src\OciConfig.php:42

    How can I solve?

    IMG: PRINT

    EDIT: Had filled the INDEX.PHP file instead of .ENV

    opened by reury-cardoso 4
  • Inactive tenancy?

    Inactive tenancy?

    I've managed to successfully created ARM instance yesterday. But this morning I can't see my instance and it says

    "You don’t have permission to view these resources in this compartment. Try another compartment, or contact your administrator for help."

    also my tenance became inactive. does oracle blocked my account? whats the reason?

    opened by sufnoobzac 4
  • Curl error occurred: SSL certificate problem?

    Curl error occurred: SSL certificate problem?

    I get the SSL error, the information for the script is all OK

    I use WINDOWS

    PHP Fatal error:  Uncaught Hitrov\Exception\CurlException: curl error occurred: SSL certificate problem: unable to get local issuer certificate, response:  in C:\Users\NAME\Downloads\oracle\oci-arm-host-capacity\src\HttpClient.php:31
    Stack trace:
    #0 C:\Users\NAME\Downloads\oracle\oci-arm-host-capacity\src\OciApi.php(210): Hitrov\HttpClient::getResponse(Array)
    #1 C:\Users\NAME\Downloads\oracle\oci-arm-host-capacity\src\OciApi.php(102): Hitrov\OciApi->call(Object(Hitrov\OciConfig), 'https://iaas.us...', 'GET', NULL, Array)
    #2 C:\Users\NAME\Downloads\oracle\oci-arm-host-capacity\index.php(66): Hitrov\OciApi->getInstances(Object(Hitrov\OciConfig))
    

    What can it be

    EDIT: had to install an ssl certificate inside the PHP folder

    opened by reury-cardoso 3
  • Syntax Error Issue

    Syntax Error Issue

    Hi, currently getting this issue:

    Parse error: syntax error, unexpected 'string' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /Users/[name]/oci-arm-host-capacity/src/OciConfig.php on line 11

    Any fix? Everything is fine up to this point

    opened by TheNelston 3
  • PHP Fatal error:  Uncaught TypeError: Argument 1 passed to Hitrov\OciConfig::__construct() must be of the type string

    PHP Fatal error: Uncaught TypeError: Argument 1 passed to Hitrov\OciConfig::__construct() must be of the type string

    PHP Fatal error: Uncaught TypeError: Argument 1 passed to Hitrov\OciConfig::__construct() must be of the type string, bool given, called in /app/oci-arm-host-capacity/index.php on line 36 and defined in /app/oci-arm-host-capacity/src/OciConfig.php:44 Stack trace: #0 /app/oci-arm-host-capacity/index.php(36): Hitrov\OciConfig->__construct() #1 {main} thrown in /app/oci-arm-host-capacity/src/OciConfig.php on line 44 PHP Fatal error: Uncaught TypeError: Argument 1 passed to Hitrov\OciConfig::__construct() must be of the type string, bool given, called in /app/oci-arm-host-capacity/index.php on line 36 and defined in /app/oci-arm-host-capacity/src/OciConfig.php:44 Stack trace: #0 /app/oci-arm-host-capacity/index.php(36): Hitrov\OciConfig->__construct() #1 {main} thrown in /app/oci-arm-host-capacity/src/OciConfig.php on line 44 2022-12-13_15-32-44 - - PHP Fatal error: Uncaught TypeError: Argument 1 passed to Hitrov\OciConfig::__construct() must be of the type string, bool given, called in /app/oci-arm-host-capacity/index.php on line 36 and defined in /app/oci-arm-host-capacity/src/OciConfig.php:44 Stack trace: #0 /app/oci-arm-host-capacity/index.php(36): Hitrov\OciConfig->__construct() #1 {main} thrown in /app/oci-arm-host-capacity/src/OciConfig.php on line 44 2022-12-13_15-42-45 - -

    I really don't know where this comes from. Everything in .env that should be a string is an string and not bool.

    Kind regards

    opened by gerddasboot 0
  • "VM.Standard.E2.1.Micro" before "VM.Standard.A1.Flex" ?

    A question about "If you don't have existing VNIC/subnet, please create VM.Standard.E2.1.Micro instance before doing everything.":

    I haven't created any instances (AMD or ARM), and I'm not sure how to figure out whether I have "existing VNIC/subnet". on the page of "create instance", I see nothing under "Subnet" item in "Networking" section, but if I click "Edit", I can see pre-defined subnet like "subnet-20221012-0039(regional)" , and VCN (virtual cloud network) like "vcn-20221012-0039"

    So ,should I create a "VM.Standard.E2.1.Micro" first if I want to create a "VM.Standard.A1.Flex" ?

    opened by bt-worm 2
  • SSH does not connect (port 22 is not open)

    SSH does not connect (port 22 is not open)

    I'm really not sure if this is just user error or if it is an issue with oracle or with this script, however I have been entirely unable to figure out what is wrong. I have followed the instructions to the t, and yet when I connect using "ssh -i "path/key" user@ip" I just get "connect to host ip.add.ress port 22: Connection timed out"

    Is there some action that needs to be taken to allow connection to the vm?


    Update: The issue was spurred by an incorrect/incomplete setup of the server's networking. creating an internet gateway and route table as described in https://docs.oracle.com/en-us/iaas/Content/Network/Tasks/scenarioa.htm solved the problem. I would suggest including this link in the description.

    opened by Carson365 0
  • add

    add "Start existing instance" function.

    I know this has been already discussed but, even if the proposed solution surely works well, I also would be very happy with an option to simply test and start an existing instance. Thus, I won't have to configure again IP addresses and SSH keys aso on a new instance... Hope it makes sense.

    opened by designboxcom 1
  • Feat: Add config OCI_IN_TRANSIT_ENCRYPTION

    Feat: Add config OCI_IN_TRANSIT_ENCRYPTION

    Should Solve https://github.com/hitrov/oci-arm-host-capacity/issues/20

    I added OCI_IN_TRANSIT_ENCRYPTION as a new env param that sets isPvEncryptionInTransitEnabled.

    Untested because I do not have an account with free resources, but it should work as it's only a few lines. Would greatly appreciate if someone could help test this.

    opened by NanoCode012 1
Owner
Alexander Hitrov
Alexander Hitrov
YCOM Impersonate. Login as selected YCOM user 🧙‍♂️in frontend.

YCOM Impersonate Login as selected YCOM user in frontend. Features: Backend users with admin rights or YCOM[] rights, can be automatically logged in v

Friends Of REDAXO 17 Sep 12, 2022
Nuber is an open source container management platform it provides a front end to manage your own cloud infrastructure, using Linux Containers virtualization technology

Nuber is an open source container management platform it provides a front end to manage your own cloud infrastructure, using Linux Containers virtualization technology

null 33 Dec 14, 2022
A super simple, clean and pretty error handler that replace the default error handler of PHP. You need only include this file!

php-custom-error-handler A super simple, clean and pretty error handler that replace the default error handler of PHP. You need just include only this

null 6 Nov 7, 2022
Boostimer - Product Availability Countdown And Scheduler For Woocommerce

Boostimer - Product Availability Countdown And Scheduler For Woocommerce Contributors: zabiranik Donate link: zabiranik/donate Requires at least: 5.0

Zabir Anik 6 Oct 10, 2022
List of France cities with zip codes, department codes, region codes, districts for former cities, GPS latitude longitude coordinates, and INSEE reference code.

List of France cities with zip codes, department codes, region codes, districts for former cities, GPS latitude longitude coordinates, and INSEE reference code.

Coercive 4 May 25, 2022
Yclas Self Hosted is a powerful script that can transform any domain into a fully customizable classifieds site within a few seconds.

Yclas 4.4.0. Description Yclas self-hosted is a powerful script that can transform any domain into a fully customizable classifieds site within a few

Yclas 299 May 29, 2022
SlimJim was born out of a need for a simple auto update script which would update multiple development/test environments every time someone

SlimJim WHY? SlimJim was born out of a need for a simple auto update script which would update multiple development/test environments every time someo

Jesal Gadhia 100 Apr 22, 2022
Iran decoration platform is an open source Php web application where you can find your job as a freelancer working in people home in decoration positions and others.

Iran-Decoration Platform Iran decoration platform is an open source Php web application where you can find your job as a freelancer working in people

AmirHossein Mohammadi 8 Dec 14, 2022
A DDD microservice did in laravel, to test infrastructure

A DDD microservice did in laravel, to test infrastructure

pegons 3 Jul 8, 2022
Pika is a nosql compatible with redis, it is developed by Qihoo's DBA and infrastructure team

Introduction中文 Pika is a persistent huge storage service , compatible with the vast majority of redis interfaces (details), including string, hash, li

OpenAtomFoundation 4.9k Jan 6, 2023
A Laravel artisan based package to create the AWS (SES + SNS) infrastructure to receive email event notifications with Http/Https endpoint.

Laravel SES Tracking Setup the AWS infrastructure to handle email events using SES/SNS and http/s endpoints with a single Laravel artisan command. Thi

null 11 Apr 26, 2022
Orkestra is a library of infrastructure and architecture helpers for creating CQRS applications

Orkestra Orkestra is an opinionated framework with a plethora of recommendations on architectural design that we use internally at Morebec to develop

Morébec 2 Aug 18, 2021
meterN is a lightweight set of PHP/JS files that make a " Home energy metering & monitoring " solution.

meterN - Home energy monitor - (PHP/JS Energy Metering & Monitoring) What can meterN do for you ? meterN is a lightweight set of PHP/JS files that mak

Jean-Marc Louviaux 4 Nov 30, 2022
A redacted PHP port of Underscore.js with additional functions and goodies – Available for Composer and Laravel

Underscore.php The PHP manipulation toolbelt First off : Underscore.php is not a PHP port of Underscore.js (well ok I mean it was at first). It's does

Emma Fabre 1.1k Dec 11, 2022
Auto-expiring tags with additional payload data on any eloquent model.

Laravel TempTag Auto-expiring tags with additional payload data on any eloquent model. Installation first you need to install and configure mongodb in

masoud nazarpoor 2 Sep 18, 2021
Magento 2 module for displaying additional information in configuration

AvS_ScopeHint for Magento 2 Displays a hint when a configuration value is overwritten on a lower scope (website or store view). Facts version: 1.0.0-b

Andreas von Studnitz 131 Dec 14, 2022
It's a CodeIgniter Library for Captcha Generation. With additional Flexibility .

Original Source : Pavel Tzonkov <[email protected]> Source Link : http://gscripts.net/free-php-scripts/Anti_Spam_Scripts/Image_Validator/d

Chris # 4 Sep 2, 2022
Laravel Pipeline with DB transaction support, events and additional methods

Laravel Enhanced Pipeline Laravel Pipeline with DB transaction support, events and additional methods #StandWithUkraine Installation Install the packa

Michael Rubél 33 Dec 3, 2022
OctoberCMS BlogHub Plugin - Extends RainLab's Blog extension with custom meta details, additional archives and more.

BlogHub extends the RainLab.Blog OctoberCMS plugin with many necessary and helpful features such as Moderatable Comments, Promotable Tags, Custom Meta Fields, additional Archives, basic Statistics, Views counter and more.

rat.md 5 Dec 15, 2022