Auto Scaling

Create an API Key and access token:

For create a API Key and Access Token to refer this link :-

https://www.e2enetworks.com/help/knowledge-base/how-to-create-an-api-access-token/

List of Auto Scaling

To get the list of auto scaling send a GET request:-

https://api.e2enetworks.com/myaccount/api/v1/scaler/
scalegroups?apikey={{api_key}}&location=Delhi&project_id={{id}}
import http.client
import json

conn = http.client.HTTPSConnection("api.e2enetworks.com")
payload = ''
headers = {
'Authorization': 'api_token',
'Content-Type': 'application/json',
}
conn.request("GET", "/myaccount/api/v1/scaler/scalegroups?apikey={{api}}&location=Delhi&project_id={{id}}", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAi...
{
"code": 200,
"data": [
    {
        "id": "1518",
        "name": "image1-disk-0-301",
        "policy": "CPU>60",
        "policy_measure": "CPU",
        "policy_op": ">",
        "upscale_policy_value": 60,
        "downscale_policy_value": 30,
        "running": 2,
        "desired": 2,
        "provision_status": "Deploying",
        "tags": "",
        "min_nodes": 2,
        "max_nodes": 5,
        "plan_name": "C2.12GB",
        "vm_image_name": "image1-disk-0",
        "wait_for_period": 3,
        "wait_period": 10,
        "cooldown": 150
    },
                ],
"errors": {},
"message": "Success"
}

Create Auto scaling

With Elastic Policy

To create an auto scale service with elstic policy set send a POST request:-

https://api.e2enetworks.com/myaccount/api/v1/scaler/scalegroups?
apikey={{api_key}}&project_id={{id}}
import http.client
import json

conn = http.client.HTTPSConnection("api.e2enetworks.com")
payload = json.dumps({
"name": "elastic_scale",
"min_nodes": "2",
"desired": "2",
"max_nodes": "5",
"plan_id": "188",
"plan_name": "C2.40GB",
"sku_id": "188",
"policy": [
    {
    "type": "CHANGE",
    "adjust": 1,
    "expression": "CPU>60",
    "period_number": "3",
    "period": "10",
    "cooldown": "150"
    },
    {
    "type": "CHANGE",
    "adjust": -1,
    "expression": "CPU<30",
    "period_number": "3",
    "period": "10",
    "cooldown": "150"
    }
],
"vm_image_id": "14523",
"vm_image_name": "C2-40GB-cu-4-image-disk-0",
"vm_template_id": 19755,
"my_account_sg_id": 30767
})
headers = {
            'Content-Type': 'application/json',
            'Authorization': 'api_token'
            }
conn.request("POST", "/myaccount/api/v1/scaler/scalegroups?apikey={{api_key}}&project_id={{id}}", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))

–header ‘Content-Type: application/json’ –header ‘Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJGSjg2R2NGM2pUYk5MT2NvNE52WmtVQ0lVb

“desired”: 2, “max_nodes”: 5, “min_nodes”: 2, “name”: “image1-disk-0-301”, “plan_id”: “184”, “plan_name”: “C2.12GB”, “policy”: [

{

“adjust”: 1, “cooldown”: 150, “expression”: “CPU>60”, “period”: 10, “period_number”: 3, “type”: “CHANGE”

}, {

“adjust”: -1, “cooldown”: 150, “expression”: “CPU<30”, “period”: 10, “period_number”: 3, “type”: “CHANGE”

}

], “sku_id”: “184”, “vm_image_id”: “8515”, “vm_image_name”: “image1-disk-0”, “vm_template_id”: 11959

}’

Content-Type: application/json
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAi...
{
    "name": "elastic_scale",
    "min_nodes": "2",
    "desired": "2",
    "max_nodes": "5",
    "plan_id": "188",
    "plan_name": "C2.40GB",
    "sku_id": "188",
    "policy": [
        {
            "type": "CHANGE",
            "adjust": 1,
            "expression": "CPU>60",
            "period_number": "3",
            "period": "10",
            "cooldown": "150"
        },
        {
            "type": "CHANGE",
            "adjust": -1,
            "expression": "CPU<30",
            "period_number": "3",
            "period": "10",
            "cooldown": "150"
        }
    ],
    "vm_image_id": "14523",
    "vm_image_name": "C2-40GB-cu-4-image-disk-0",
    "vm_template_id": 19755,
    "my_account_sg_id": 30767
    }

With Schedule Policy

To create an auto scale with schedule policy set send a POST request:-

https://api.e2enetworks.com/myaccount/api/v1/scaler/scalegroups?
apikey={{api_key}}&project_id={{id}}
import http.client
import json

conn = http.client.HTTPSConnection("api.e2enetworks.com")
payload = json.dumps({
"name": "schedule_policy",
"min_nodes": "2",
"desired": "2",
"max_nodes": "5",
"plan_id": "188",
"plan_name": "C2.40GB",
"sku_id": "188",
"scheduled_policy": [
    {
    "type": "CARDINALITY",
    "adjust": 4,
    "recurrence": "0 0 1 * *"
        },
        {
        "type": "CARDINALITY",
        "adjust": "2",
        "recurrence": "0 0 12 1 1"
        }
    ],
    "vm_image_id": "14523",
    "vm_image_name": "C2-40GB-cu-4-image-disk-0",
    "vm_template_id": 19755,
    "my_account_sg_id": 30767
    })
    headers = {
    'Content-Type': 'application/json',
    'Authorization': 'api_token',
    }
    conn.request("POST", "/myaccount/api/v1/scaler/scalegroups?apikey={{api_key}}&project_id={{id}}", payload, headers)
    res = conn.getresponse()
    data = res.read()
    print(data.decode("utf-8"))
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAi...
{
    "name": "schedule_policy",
    "min_nodes": "2",
    "desired": "2",
    "max_nodes": "5",
    "plan_id": "188",
    "plan_name": "C2.40GB",
    "sku_id": "188",
    "scheduled_policy": [
        {
            "type": "CARDINALITY",
            "adjust": 3,
            "recurrence": "0 0 1 * *"
        },
        {
            "type": "CARDINALITY",
            "adjust": "2",
            "recurrence": "0 0 12 1 1"
        }
    ],
    "vm_image_id": "14523",
    "vm_image_name": "C2-40GB-cu-4-image-disk-0",
    "vm_template_id": 19755,
    "my_account_sg_id": 30767
}

With Elastic and Schedule Policy

To create an scale service which has both elastic and schedule policy set send a POST request:-

https://api.e2enetworks.com/myaccount/api/v1/scaler/scalegroups/?
apikey={{api_key}}&project_id={{id}}
import http.client
import json

conn = http.client.HTTPSConnection("api.e2enetworks.com")
payload = json.dumps({
"name": "elastic_with_schedule",
"min_nodes": "2",
"desired": "2",
"max_nodes": "5",
"plan_id": "188",
"plan_name": "C2.40GB",
"sku_id": "188",
"policy": [
    {
    "type": "CHANGE",
    "adjust": 1,
    "expression": "CPU>60",
    "period_number": "3",
    "period": "10",
    "cooldown": "150"
    },
    {
    "type": "CHANGE",
    "adjust": -1,
    "expression": "CPU<30",
    "period_number": "3",
    "period": "10",
    "cooldown": "150"
    }
],
"scheduled_policy": [
    {
    "type": "CARDINALITY",
    "adjust": 3,
    "recurrence": "0 0 1 * *"
    },
    {
    "type": "CARDINALITY",
    "adjust": "2",
    "recurrence": "0 0 12 1 1"
    }
],
"vm_image_id": "14523",
"vm_image_name": "C2-40GB-cu-4-image-disk-0",
"vm_template_id": 19755,
"my_account_sg_id": 30767
})
headers = {
'Content-Type': 'application/json',
'Authorization': 'api_token',
}
conn.request("POST", "/myaccount/api/v1/scaler/scalegroups?apikey={{api_key}}&project_id={{id}}", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAi...
{
    "name": "elastic_with_schedule",
    "min_nodes": "2",
    "desired": "2",
    "max_nodes": "5",
    "plan_id": "188",
    "plan_name": "C2.40GB",
    "sku_id": "188",
    "policy": [
        {
            "type": "CHANGE",
            "adjust": 1,
            "expression": "CPU>60",
            "period_number": "3",
            "period": "10",
            "cooldown": "150"
        },
        {
            "type": "CHANGE",
            "adjust": -1,
            "expression": "CPU<30",
            "period_number": "3",
            "period": "10",
            "cooldown": "150"
        }
    ],
    "scheduled_policy": [
        {
            "type": "CARDINALITY",
            "adjust": 3,
            "recurrence": "0 0 1 * *"
        },
        {
            "type": "CARDINALITY",
            "adjust": "2",
            "recurrence": "0 0 12 1 1"
        }
    ],
    "vm_image_id": "14523",
    "vm_image_name": "C2-40GB-cu-4-image-disk-0",
    "vm_template_id": 19755,
    "my_account_sg_id": 30767
}

Delete Auto scaling

To Delete auto scaling to send a DELETE request:-

https://api.e2enetworks.com/myaccount/api/v1/scaler/scalegroups/1516/
?apikey={{api_key}}&project_id={{id}}
import http.client
import json

conn = http.client.HTTPSConnection("api.e2enetworks.com")
payload = ''
headers = {
'Authorization': 'api_token',
'Content-Type': 'application/json',
}
conn.request("DELETE", "/myaccount/api/v1/scaler/scalegroups/1516?apikey={{api_key}}&project_id={{id}}", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAi...
{
"code": 204,
"data": {},
"errors": {},
"message": "Success"
}