Auto-Scaling (AS)¶
Auto-Scaling Configuration¶
An Auto-Scaling (AS) configuration is a template of Elastic Cloud Servers in an AS group. It defines the specifications of the instances to be added to the AS group. The AS configuration is decoupled from the AS group and can be used several times in different groups. Up to 100 AS configurations can be created for each user.
List Configurations¶
This interface is used to query all Auto-Scaling configurations and to filter the output with query parameters.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
for config in conn.auto_scaling.configs():
print(config)
Create Configuration¶
This interface is used to create an Auto-Scaling Configuration instance with parameters.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
attrs = {
'name': 'test-config',
'instance_config': {
'flavorRef': 's2.medium.1',
'imageRef': '1616e0b6-503a-4698-946f-cf9942c4c73b',
'disk': [{
'size': 20,
'volume_type': 'SATA',
'disk_type': 'SYS'
}],
'key_name': 'test-key',
}
}
config = conn.auto_scaling.create_config(**attrs)
print(config)
Get Configuration¶
This interface is used to get an Auto-Scaling Configuration by ID
or an instance of class
Config
.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
config_id = "1234567-6aa0-4c8b-b350-3bd937addeb7"
config = conn.auto_scaling.get_config(config_id)
print(config)
Find Configuration¶
This interface is used to find an Auto-Scaling Configuration instance by name or id.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
config = "config_name_or_id"
config = conn.auto_scaling.find_config(config)
print(config)
Delete Configuration¶
This interface is used to delete an Auto-Scaling Configuration instance by id
or an instance of class
Config
.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
config_id = '1234567-ad7a-48ce-8f92-b55c651439d2'
conn.auto_scaling.delete_config(config_id)
Batch Delete Configurations¶
This interface is used to delete multiple Auto-Scaling Configuration instances
by id or an instance of
class Config
.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
config1 = conn.auto_scaling.find_config('test-config1')
config2 = conn.auto_scaling.find_config('test-config2')
configs = [config1, config2]
conn.auto_scaling.batch_delete_configs(configs)
Auto-Scaling Group¶
An Auto-Scaling (AS) group consists of a collection of instances that apply to the same scaling scenario. An AS group specifies parameters, such as the maximum number of instances, expected number of instances, minimum number of instances, VPC, subnet, and load balancing. Each user can create a maximum of 25 AS groups by default.
List Groups¶
This interface is used to query all Auto-Scaling Groups and to filter the output with query parameters.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
for group in conn.auto_scaling.groups():
print(group)
Create Group¶
This interface is used to create an Auto-Scaling Group with parameters.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
attrs = {
"scaling_group_name": "TestGroup",
"scaling_configuration_id": "0d138717-e79d-4fa7-b8aa-37ddec1b3ce7",
"desire_instance_number": 0,
"min_instance_number": 0,
"max_instance_number": 10,
"vpc_id": "26ca2783-dc40-4e3a-95b1-5a0756441e12",
"available_zones": ["eu-de-01", "eu-de-03"],
"networks": [
{
"id": "25d24fc8-d019-4a34-9fff-0a09fde6a9cb"
}
]
}
group = conn.auto_scaling.create_group(**attrs)
print(group)
Get Group¶
This interface is used to get an Auto-Scaling Group by ID
or an instance of class
Group
.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
group_id = "1234567-6aa0-4c8b-b350-3bd937addeb7"
group = conn.auto_scaling.get_group(group_id)
print(group)
Find Group¶
This interface is used to find an Auto-Scaling Group instance by name or id.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
group = "group_name_or_id"
group = conn.auto_scaling.find_group(group)
print(group)
Delete Group¶
This interface is used to delete an Auto-Scaling Group instance by id or
an instance of class Group
.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
group_id = '1234567-ad7a-48ce-8f92-b55c651439d2'
conn.auto_scaling.delete_group(group_id)
Pause Group¶
This interface is used to pause an Auto-Scaling Group instance in
passive state by using id or an instance of
class Group
.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
group = "group_name_or_id"
group = conn.auto_scaling.find_group(group)
conn.auto_scaling.pause_group(group)
Resume Group¶
This interface is used to resume an Auto-Scaling Group instance in
active state by using id or an instance of
class Group
.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
group_id = "123456_group_id"
conn.auto_scaling.resume_group(group_id)
Auto-Scaling Policy¶
An Auto-Scaling (AS) policy defines whether to increase or decrease the number of instances in an AS group. If the number and the expected number of instances in an AS group are different due to the execution of the AS policy, AS automatically adjusts the number of instances to the expected. AS supports the following policy variants:
alarm-triggered policy
periodic policy
scheduled policy
List Policy¶
This interface is used to query all Auto-Scaling Policies of an AS group and to filter the output with query parameters.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
group = "group_name_or_id"
group = conn.auto_scaling.find_group(group)
for policy in conn.auto_scaling.policies(group):
print(policy)
Create Policy¶
This interface is used to create an Auto-Scaling Policy with parameters.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
attrs = {
"scaling_group_id": "as_group_id",
"scaling_policy_name": "as_policy_name",
"scaling_policy_type": "ALARM",
"alarm_id": "cloudeye_alarm_id",
"scheduled_policy": {},
"cool_down_time": 300,
"scaling_policy_action": {
"operation": "ADD",
"instance_number": 1
}
}
policy = conn.auto_scaling.create_policy(**attrs)
print(policy)
Get Policy¶
This interface is used to get an Auto-Scaling Policy by ID
or an instance of class
Policy
.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
policy_id = "1234567-6aa0-4c8b-b350-3bd937addeb7"
policy = conn.auto_scaling.get_policy(policy_id)
print(policy)
Find Policy¶
This interface is used to find an Auto-Scaling Policy instance by name or id.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
policy = "policy_name_or_id"
policy = conn.auto_scaling.find_policy(policy)
print(policy)
Delete Policy¶
This interface is used to delete an Auto-Scaling Policy instance by id
or an instance of class
Policy
.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
policy_id = '1234567-ad7a-48ce-8f92-b55c651439d2'
conn.auto_scaling.delete_policy(policy_id)
Update Policy¶
This interface is used to update an Auto-Scaling Policy instance by
using policy’s id or an instance of class
Policy
and provide new
attributes.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
policy = "policy_name_or_id"
attrs = {
"scaling_policy_type": "RECURRENCE",
"scaling_policy_name": "policy_01",
"scheduled_policy": {
"launch_time": "16:00",
"recurrence_type": "Daily",
"end_time": "2016-02-08T17:31Z",
"start_time": "2016-01-08T17:31Z"
},
"scaling_policy_action": {
"operation": "SET",
"instance_number": 2
}
}
policy = conn.auto_scaling.find_policy(policy)
conn.auto_scaling.update_policy(policy, **attrs)
Pause Policy¶
This interface is used to pause an Auto-Scaling Policy instance in
passive state by using id or an instance of
class Policy
.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
policy = "policy_name_or_id"
policy = conn.auto_scaling.find_policy(policy)
conn.auto_scaling.pause_policy(policy)
Resume Policy¶
This interface is used to resume an Auto-Scaling Policy instance in
active state by using id or an instance of
class Policy
.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
policy = "policy_name_or_id"
policy = conn.auto_scaling.find_policy(policy)
conn.auto_scaling.resume_policy(policy)
Execute Policy¶
This interface is used to execute an Auto-Scaling Policy instance and run the defined actions.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
policy = "policy_name_or_id"
policy = conn.auto_scaling.find_policy(policy)
conn.auto_scaling.execute_policy(policy)
Auto-Scaling Instance¶
An Auto-Scaling (AS) Instance is the executive unit of an Auto-Scaling group.
List Instances¶
This interface is used to query all Auto-Scaling Instances of an AS group and to filter the output with query parameters.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
group = "group_name_or_id"
group = conn.auto_scaling.find_group(group)
for activity in conn.auto_scaling.activities(group):
print(activity)
Remove Instance¶
This interface is used to remove an Auto-Scaling Instances of an AS group.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
instance = "instance_id"
conn.auto_scaling.remove_instance(
instance,
delete=False # If True, instance will be deleted after remove
)
Batch Action Instance¶
This interface is used to run actions on an Auto-Scaling group by adding or deleting instance.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
group = "group_name_or_id"
group = conn.auto_scaling.find_group(group)
instances = [
"instance_id",
"instance_id2"
]
action = "ADD"
conn.auto_scaling.batch_instance_action(
group,
instances,
action, # ADD, REMOVE, PROTECT, UNPROTECT
delete_instance=False
)
Auto-Scaling Actions and Quotas¶
Auto-Scaling quotas and query scaling action logs can be querried.
List Scaling Actions¶
This interface is used to query all Auto-Scaling scaling action logs of an AS group and to filter the output with query parameters.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
group = "group_name_or_id"
group = conn.auto_scaling.find_group(group)
for activity in conn.auto_scaling.activities(group):
print(activity)
List User or Group Quota for Auto-Scaling¶
This interface is used to query all Auto-Scaling quotas of an AS group or a user and to filter the output with query parameters.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
# group = "group_name_or_id"
# group = conn.auto_scaling.find_group(group)
# If group is set, group quotas ar listed instead of user quotas
for quota in conn.auto_scaling.quotas(group=None):
print(quota)