Auto Scale APi Python eoor

Edson_Fernandes_Cunha
Mon, 12 Jun 2023 14:49:52 +0000

Hello,
I’m trying to develop a python script to schedule a scale up of a mongodb atlas instance, but I’m having a lot of difficulty with some steps.
This is my script:

import requests
import json

# Substitua pelos valores reais
PUBLIC_KEY = 'xxxxxxxxx'
PRIVATE_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
GROUP_ID = 'xxxxxxxxxxxxxxxxxxxxxxxx'
CLUSTER_NAME = 'cloud-test'

# URL base da API
BASE_URL = 'https://cloud.mongodb.com/api/atlas/v1.0'

# Autenticação
auth = requests.auth.HTTPDigestAuth(PUBLIC_KEY, PRIVATE_KEY)

# Atualização das configurações do cluster
cluster_url = f'{BASE_URL}/groups/{GROUP_ID}/clusters/{CLUSTER_NAME}'
data = {
    "providerSettings": {
        "providerName": "AWS",  # Substitua pelo seu provedor (AWS, GCP, AZURE)
        "regionName": "US_EAST_1",  # Substitua pela sua região
        "instanceSizeName": "M20"
    },
    "autoScaling": {
        "diskGBEnabled": True,
        "compute": {
            "enabled": True,
            "scaleDownEnabled": True
        }
    }
}

response = requests.patch(cluster_url, auth=auth, json=data)

# Tratar a resposta
if response.status_code == 200:
    print('Cluster updated successfully.')
else:
    print(f'Error updating cluster: {response.content}')

But I keep getting the following error:

python scale_cluster.py
Error updating cluster: b'{"detail":"Compute auto-scaling min instance size required.","error":400,"errorCode":"COMPUTE_AUTO_SCALING_MIN_INSTANCE_SIZE_REQUIRED","parameters":[],"reason":"Bad Request"}'

if I change to answer the message for

# Atualização das configurações do cluster
cluster_url = f'{BASE_URL}/groups/{GROUP_ID}/clusters/{CLUSTER_NAME}'
data = {
    "providerSettings": {
        "providerName": "AWS",  # Substitua pelo seu provedor (AWS, GCP, AZURE)
        "regionName": "US_EAST_1",  # Substitua pela sua região
        "instanceSizeName": "M20"
    },
    "autoScaling": {
        "diskGBEnabled": True,
        "compute": {
            "enabled": True,
            "scaleDownEnabled": True,
            "minInstanceSize": "M10",
            "maxInstanceSize": "M20"
        }
    }
}

python scale_cluster.py
Error updating cluster: b'{"detail":"Invalid attribute minInstanceSize specified.","error":400,"errorCode":"INVALID_ATTRIBUTE","parameters":["minInstanceSize"],"reason":"Bad Request"}'

Does anyone in the group have any idea of this problem.

Read full topic