OCI-AutoScale; Now supports 8 OCI Service, including Exadata CS and Network Load Balancers

By | October 1, 2020

2 years ago I started work on the OCI-AutoScaling script. I wanted to run my workloads on OCI as efficiently as possible. So workloads that I did not need in the evenings or weekends could automatically be turned off orscaled down.

With the new release this OCI-AutoScaling script now support 8 OCI services!

Based on an hourly schedule, configured by a Scheduling TAG, you can initiate the following operations:

  • Compute VMs: On/Off
  • Instance Pools: On/Off and Scaling (# of instances)
  • Database VMs: On/Off
  • Database Baremetal Servers: Scaling (# of CPUs between 1 and 52)
  • Database Exadata CS: Scaling (# of CPUs between 2 and 400)
  • Autonomous Databases: On/Off and Scaling (# of CPUs between 1 and 128)
  • Oracle Digital Assistant: On/Off
  • Oracle Analytics Cloud: On/Off and Scaling (between 2-8 oCPU and 10-12 oCPU)
  • Oracle Integration Service: On/Off
  • Load Balancer: Scaling (between 10, 100, 400, 8000 Mbps)*

This script needs to run hourly and you can use an Always Free Compute instance to do this. Here is a youtube video demonstrating how you can implement this: Youtube demonstration video: https://youtu.be/veHbyvDB74A

The full project can be found on github: https://github.com/AnykeyNL/OCI-AutoScale

18 thoughts on “OCI-AutoScale; Now supports 8 OCI Service, including Exadata CS and Network Load Balancers

  1. Pete

    Hi Richard, I tried the recent update (via the install.sh), but am now getting a new error, any ideas ?

    [opc@autoscaler OCI-AutoScale]$ /usr/bin/python3 /home/opc/OCI-AutoScale/AutoScaleALL.py down
    Using Instance principle
    Starting Auto Scaling script, executing Down actions
    Logged in as: Instance Principle/imaginecorp @ iad
    Enabled regions: us-ashburn-1 us-phoenix-1
    Day of week: Saturday – Weekday: False – Current hour: 13
    Checking: sroh-xgljob1-qa01-us3 – PrivateIp
    Traceback (most recent call last):
    File “/home/opc/OCI-AutoScale/AutoScaleALL.py”, line 347, in
    schedule = resourceDetails.defined_tags[PredefinedTag]
    NameError: name ‘resourceDetails’ is not defined

    Reply
    1. richard Post author

      What kind of resource is sroh-xgljob1-qa01-us3 – PrivateIp?

      Reply
    2. richard Post author

      I think you have a schedule tag on a non-supported resource. If added a fix to not process those. Update the code and check if you still get the same error.

      Reply
      1. Pete

        Thanks Richard (it is a VM instance), I applied the latest code and it’s working like a charm now. I did a quick calculation, and if my math is right then I would expect to see the following savings once I get my schedules defined (almost too good to be true?).

        weekends off = 28%
        weekends and weeknights off = 65%

        Reply
        1. richard Post author

          That is great to hear! If you want to write a guest blog about your experience, feel free to volunteer 🙂

          Reply
  2. Jesus Montoya

    Hi Richard,
    After using this command python3 CreateNameSpaces.py, I get the following error, what can I do?
    [opc@vm-terraform OCI-AutoScale]$ python3 CreateNameSpaces.py
    /usr/lib/python3.6/site-packages/oci/packages/cryptography/hazmat/bindings/opens sl/binding.py:179: CryptographyDeprecationWarning: OpenSSL version 1.0.2 is no l onger supported by the OpenSSL project, please upgrade. The next version of cryp tography will completely remove support for it.
    utils.CryptographyDeprecationWarning,
    Traceback (most recent call last):
    File “CreateNameSpaces.py”, line 41, in
    compartment = identity.get_compartment(compartment_id=SearchCompID).data
    File “/usr/lib/python3.6/site-packages/oci/identity/identity_client.py”, line 4321, in get_compartment
    response_type=”Compartment”)
    File “/usr/lib/python3.6/site-packages/oci/base_client.py”, line 263, in call_ api
    return self.request(request)
    File “/usr/lib/python3.6/site-packages/oci/base_client.py”, line 384, in reque st
    self.raise_service_error(request, response)
    File “/usr/lib/python3.6/site-packages/oci/base_client.py”, line 554, in raise _service_error
    original_request=request)
    oci.exceptions.ServiceError: {‘opc-request-id’: ‘3ACEF5FCDE434B6D87E49CA3EFE9227 7/2EF6A5158AC660EFAE6BA481B4A8C7A4/46375D1E8FBF659356CA82F0383518F0’, ‘code’: ‘N otAuthorizedOrNotFound’, ‘message’: ‘Authorization failed or requested resource not found’, ‘status’: 404}
    [opc@vm-terraform OCI-AutoScale]$

    Reply
    1. richard Post author

      Did you configure your oci-cli tool with the right credentials?

      You need to run ‘oci setup config’, go thru the wizard. After that add the created public key to your user’s profile on OCI as API key.

      Reply
  3. pete

    Hello Richard,

    Would you be able to explain a bit more with some examples the use scheduling/tags like below:

    AnyDay : 0,0,0,0,0,0,0,0,*,*,*,*,*,*,*,*,0,0,0,0,0,0,0,0

    Lets say i want my vms to be stopped every day at 10 pm and started back at 8 am ?

    would that be:

    AnyDay: *,*,0,*,*,*,*,*,*,*,*,*,*,*,1,*,*,*,*,*,*,*,*,*

    Reply
  4. pete1

    Hello Richard,

    Would you be able to explain a bit more with some examples the use scheduling/tags like below:

    AnyDay : 0,0,0,0,0,0,0,0,*,*,*,*,*,*,*,*,0,0,0,0,0,0,0,0

    Lets say i want my vms to be stopped every day at 10 pm and started back at 8 am ?

    would that be:

    AnyDay: *,*,0,*,*,*,*,*,*,*,*,*,*,*,1,*,*,*,*,*,*,*,*,*

    Reply
    1. richard Post author

      Yes, the example you give is correct, using the *,*,0,*,*,*,*,*,*,*,*,*,*,*,1,*,*,*,*,*,*,*,*,* would only do 2 actions during 24 hours. All the other hours it will leave the state of the service as-is.

      a tag like: 0,0,0,0,0,0,0,0,*,*,*,*,*,*,*,*,0,0,0,0,0,0,0,0 would enforce all evening/night long that the instances stay powered off.

      Reply
  5. Fábio Ferreira da Silva

    Hi Richard,
    How are you?
    Yesterday I tried to install this script and I notice something. OEL image isn’t coming with Python3 installed anymore.
    So, I modified the install script to work with this image.
    I modified just yum and pip3 commands.

    Best regards!

    # This is an auto install script for Oracle Autonomous Linux 7.8
    # It will configure to automatically run the autoscale script using Instance Principal permission
    # So ensure you have configured a dynamic group for this instance and that that dynamic group
    # has a policy to manage all resources in your tenancy.

    # Set to your time zone for correct time
    sudo timedatectl set-timezone Europe/Amsterdam

    # Install needed components and configure crontab with correct schedule
    sudo yum -y install git python3
    sudo pip3 install oci oci-cli requests
    git clone https://github.com/AnykeyNL/OCI-AutoScale.git
    cd OCI-AutoScale/
    sed -i ‘s/UseInstancePrinciple = False/UseInstancePrinciple = True/g’ AutoScaleALL.py
    crontab schedule.cron

    Reply
  6. Raj

    hi richard,

    Is this script region specific ? My home region is UK-LONDON-1 where as the compute and databases are deployed on frankfurt. Tried to startup one compute on Frankfurt region but no luck. Can you please help on this

    [opc@automationtool OCI-AutoScale]$ python3 AutoScaleALL.py
    Using Instance principle
    Starting Auto Scaling script, executing All actions
    Logged in as: Instance Principle/test @ uk-london-1
    Day of week: Tuesday – Weekday: True – Current hour: 4
    All scaling tasks done

    Reply
  7. Richard

    Richard, we’ve been using OCI-AutoScale to scale up and down our Exadata cores, and it works brilliantly, thank you for your efforts.

    I notice recently when logging into the OCI console that we’re now being prompted to update to the new User/API Experience and that in May the old API’s will be deprecated. I’m assuming that this will affect the script, and that to continue supporting scaling of Exadata cores it will need updating to use the new API’s is that correct? If so, do you have any plans to change the script?

    Reply
    1. richard Post author

      I was not aware of this, but will look into this.

      Reply
  8. Guillaume NEVEUX

    Hi Richard, first, thanks a lot for you work, it’s really cool !

    We installed it in our sandbox env and work perfectly. But in our integration we face this issue:
    (For information, the dynamic group have the right to manage all ressource + manage tag-namespaces

    File “CreateNameSpaces.py”, line 42, in
    compartment = identity.get_compartment(compartment_id=SearchCompID).data
    File “/usr/lib/python3.6/site-packages/oci/identity/identity_client.py”, line 4322, in get_compartment
    response_type=”Compartment”)
    File “/usr/lib/python3.6/site-packages/oci/base_client.py”, line 417, in call_api
    return self.request(request)
    File “/usr/lib/python3.6/site-packages/oci/base_client.py”, line 541, in request
    self.raise_service_error(request, response)
    File “/usr/lib/python3.6/site-packages/oci/base_client.py”, line 711, in raise_service_error
    original_request=request)
    oci.exceptions.ServiceError: {‘opc-request-id’: ‘F2588D5F2EB94FAF952DA8B3C10A0352/21523817FFB1D15C3104D9B4014EB09F/C86F3CE48D3F4EDB37333AFCF39BC62A’, ‘code’: ‘NotAuthorizedOrNotFound’, ‘message’: ‘Authorization failed or requested resource not found’, ‘status’: 404}

    Reply
  9. Esther Ryu

    Thanks for your effort.

    but I got following errors when I tried to apply schedule.

    [opc@autoschedule OCI-AutoScale]$ python3 AutoScaleALL.py

    ##########################################################################################
    # Running Auto Scale #
    ##########################################################################################
    Traceback (most recent call last):
    File “AutoScaleALL.py”, line 1613, in
    config, signer = create_signer(cmd.config_profile, cmd.is_instance_principals, cmd.is_delegation_token)
    File “AutoScaleALL.py”, line 219, in create_signer
    (config_profile if config_profile else oci.config.DEFAULT_PROFILE)
    File “/usr/lib/python3.6/site-packages/oci/config.py”, line 106, in from_file
    raise ConfigFileNotFound(“Could not find config file at {}, please follow the instructions in the link to setup the config file https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm“.format(expanded_file_location))
    oci.exceptions.ConfigFileNotFound: Could not find config file at /home/opc/.oci/config, please follow the instructions in the link to setup the config file https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm

    And I wonder if the script might work in DBCS RAC environment.

    Reply
    1. richard Post author

      It seems you did not configure the Authentication. Please make sure you have an correct OCI config file or use Instance Principle authentication

      Reply
  10. Javi

    Hi Richard,
    I’m using AutoScale for log time but only with Instances and Autonomous. Now I’m trying to use it with Exadata but not pretty sure what does it’s means “Database Exadata CS”, because I’m trying to use it with Exadata VM Cluster (” Overview – Oracle Exadata Database Service on Dedicated Infrastructure – Exadata VM Clusters -Exadata VM Cluster Details), but adding Schedule tag I can’t see Exadata schedule executing “python3 /home/opc/OCI-AutoScale/AutoScaleALL.py”, I only see instances schedule.
    Can you help me?

    Regards.

    Reply

Leave a Reply to richard Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.