ApiGateway Service (AGS)¶
API Gateway (APIG) is a high-performance, high-availability, and high-security API hosting service that helps you build, manage, and deploy APIs at any scale. With just a few clicks, you can integrate internal systems, and selectively expose capabilities with minimal costs and risks.
Gateway¶
A Gateway is a service that acts as an intermediary between clients and backend services, providing a centralized point of control for processing API requests. It enables management of access, security, routing, scalability, and monitoring of APIs.
Create Gateway¶
This example demonstrates how to create a new gateway.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
attrs = {
'instance_name': 'name',
'spec_id': 'BASIC',
'vpc_id': 'vpc.id',
'subnet_id': 'subnet.id',
'security_group_id': 'security_group.id',
'available_zone_ids': ['available_zone_ids'],
}
gateway = conn.apig.create_gateway(**attrs)
Delete Gateway¶
This example demonstrates how to delete an existing gateway.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
conn.apig.delete_gateway('gateway_id')
List Gateways¶
This example demonstrates how to list all gateways.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
attrs = {
'limit': 2
}
for gw in conn.apig.gateways(**attrs):
print(gw.name)
Get Gateway Details¶
This example demonstrates how to retrieve details of a specific gateway.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
conn.apig.get_gateway("id")
Update Gateway¶
This example demonstrates how to update an existing gateway.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
attrs = {
"description": "some description",
}
conn.apig.update_gateway("gateway_id", **attrs)
Bind EIP¶
This example demonstrates how to bind an Elastic IP (EIP) to a gateway.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
attrs = {
"eip_id": "eip_id"
}
conn.apig.bind_eip('gateway_id', **attrs)
Unbind EIP¶
This example demonstrates how to unbind an Elastic IP (EIP) from a gateway.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
conn.apig.unbind_eip('gateway_id')
Update Public Inbound Access¶
This example demonstrates how to update public inbound access for a gateway.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
attrs = {
"bandwidth_size": "7",
"bandwidth_charging_mode": "bandwidth"
}
conn.apig.update_ingress('gateway_id', **attrs)
Enable Public Inbound Access¶
This example demonstrates how to enable public inbound access for a gateway.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
attrs = {
"bandwidth_size": "5",
"bandwidth_charging_mode": "bandwidth"
}
conn.apig.enable_ingress('gateway_id', **attrs)
Disable Public Inbound Access¶
This example demonstrates how to disable public inbound access for a gateway.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
conn.apig.disable_ingress('gateway_id')
Enable Public Access¶
This example demonstrates how to enable public access for a gateway.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
attrs = {
"bandwidth_size": "5",
"bandwidth_charging_mode": "bandwidth"
}
conn.apig.enable_public_access("gateway.id", **attrs)
Update Public Access¶
This example demonstrates how to update public access settings for a gateway.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
attrs = {
"bandwidth_size": "7",
"bandwidth_charging_mode": "bandwidth"
}
conn.apig.update_public_access("gateway_id", **attrs)
Disable Public Access¶
This example demonstrates how to disable public access for a gateway.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
conn.apig.disable_public_access('gateway_id')
Get Gateway Constraints¶
This example demonstrates how to retrieve the constraints and limitations of a gateway.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
conn.apig.get_constraints("gateway.id")
Get Gateway Creation Progress¶
This example demonstrates how to check the progress of a gateway creation process.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
conn.apig.get_gateway_progress('gateway_id')
Modify Gateway Specifications¶
This example demonstrates how to modify the specifications of an existing gateway.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
attrs = {
"spec_id": "PROFESSIONAL"
}
conn.apig.modify_gateway_spec("gateway_id", **attrs)
AZs¶
List Azs¶
This example demonstrates how to list the availability zones (AZs) supported by API Gateway.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
attrs = {
"eip_id": "eip_id"
}
for az in conn.apig.azs():
print(az)
Environment¶
Create Environment¶
This example demonstrates how to create a new environment within a specific API Gateway.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
attrs = {
"name": "DEV",
"remark": "Development environment"
}
environment = conn.apig.create_environment(gateway="gateway_id",
**attrs)
Update Environment¶
This example demonstrates how to update an existing environment within a specific API Gateway.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
attrs = {
"name": "DEV",
"remark": "Development environment"
}
environment = conn.apig.update_environment(environment="env_id",
gateway="gateway_id",
**attrs)
Delete Environment¶
This example demonstrates how to delete an existing environment from a specific API Gateway.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
conn.apig.delete_environment(gateway="gateway_id",
environment="env_id",)
List Environments¶
This example demonstrates how to list all environments associated with a specific API Gateway.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
environments = list(conn.apig.environments(gateway="gateway_id"))
Api Group¶
Create Api Group¶
This example demonstrates how to create a new API group in the API Gateway.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
attrs = {
"name": "api_group_001",
"remark": "API group 1"
}
created = conn.apig.create_api_group(gateway="gateway_id",
**attrs)
Update Api Group¶
This example demonstrates how to update an existing API group in the API Gateway.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
attrs = {
'name': 'name',
'remark': 'new_remark'
}
updated = conn.apig.update_api_group(
gateway='gateway_id',
api_group='api_group_id',
**attrs)
Delete Api Group¶
This example demonstrates how to delete an existing API group from the API Gateway.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
conn.apig.delete_api_group(gateway='gateway_id',
api_group='api_group_id')
List Api Groups¶
This example demonstrates how to list all API groups associated with a specific API Gateway.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
groups = list(conn.apig.api_groups(gateway="gateway_id"))
Get Api Group¶
This example demonstrates how to retrieve details of a specific API group from the API Gateway.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
found = conn.apig.get_api_group(gateway='gateway_id',
api_group='api_group_id')
Verify Api Group Name¶
This example demonstrates how to verify whether a given API group name is available in the API Gateway.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
attrs = {
"group_name": "api_group_002"
}
conn.apig.verify_api_group_name(gateway="gateway_id", **attrs)
Creating a Variable¶
This example demonstrates how to define environment variables.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
attrs = {
"variable_name": "address",
"variable_value": "192.168.1.5",
"env_id": "environment_id",
"group_id": "group_id"
}
variable = conn.apig.create_environment_variable(
gateway="gateway_id",
**attrs
)
Deleting a Variable¶
This example demonstrates how to delete environment variable.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
conn.apig.delete_environment_variable(
gateway="gateway_id",
var="var_id"
)
Querying Variable Details¶
This example demonstrates how to query the details of an environment variable.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
conn.apig.get_environment_variable(
gateway="gateway_id",
var="variable_id"
)
Querying Environment Variables¶
This example demonstrates how to query all environment variables under an API group.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
environments = list(conn.apig.environment_variables(
gateway="gateway_id",
group_id="group_id"
))
Modifying a Variable¶
This example demonstrates how to modify an environment variable.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
attrs = {
"variable_value": "192.168.1.6",
}
var = conn.apig.update_environment_variable(
gateway="gateway_id",
var="variable_id",
**attrs
)
Creating a Request Throttling Policy¶
This example demonstrates how to create throttling policy.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
attrs = {
"api_call_limits": 100,
"app_call_limits": 60,
"enable_adaptive_control": "FALSE",
"ip_call_limits": 60,
"name": "throttle_demo",
"remark": "Total: 800 calls/second;"
" user: 500 calls/second;"
" app: 300 calls/second;"
" IP address: 600 calls/second",
"time_interval": 1,
"time_unit": "SECOND",
"type": 1,
"user_call_limits": 60
}
policy = conn.apig.create_throttling_policy(
gateway="gateway_id",
**attrs
)
Modifying a Request Throttling Policy¶
This example demonstrates how to update throttling policy.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
attrs = {
"time_unit": "SECOND",
"name": "throttle_demo",
"api_call_limits": 100,
"time_interval": 1,
"remark": "Total: 800 calls/second;"
" user: 500 calls/second;"
" app: 300 calls/second;"
" IP address: 600 calls/second",
}
environment = conn.apig.update_throttling_policy(
gateway="gateway_id",
policy="policy_id",
**attrs
)
Deleting a Request Throttling Policy¶
This example demonstrates how to delete throttling policy.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
conn.apig.delete_throttling_policy(
gateway="gateway_id",
policy="policy_id"
)
Querying Request Throttling Policies¶
This example demonstrates how to query all throttling policies.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
environments = list(conn.apig.throttling_policies(
gateway="gateway_id"))
Querying Details of a Request Throttling Policy¶
This example demonstrates how to get throttling policy.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
conn.apig.get_throttling_policy(
gateway="gateway_id",
policy="policy_id"
)
Creating an API¶
This example demonstrates how to create an API.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
attrs = {
"group_id": "group_id",
"name": "test_api_001",
"auth_type": "IAM",
"backend_type": "HTTP",
"req_protocol": "HTTP",
"req_uri": "/test/http",
"remark": "Mock backend API",
"type": 2,
"req_method": "GET",
"result_normal_sample": "Example success response",
"result_failure_sample": "Example failure response",
"tags": ["httpApi"],
"backend_api": {
"req_protocol": "HTTP",
"req_method": "GET",
"req_uri": "/test/benchmark",
"timeout": 5000,
"retry_count": "-1",
"url_domain": "192.168.189.156:12346"
},
}
created = conn.apig.create_apicreate_api(
gateway="gateway_id",
**attrs
)
Modifying an API¶
This example demonstrates how to update an API.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
attrs = {
"group_id": "group_id",
"name": "test_api_001",
"auth_type": "IAM",
"backend_type": "HTTP",
"req_protocol": "HTTP",
"req_uri": "/test/http",
"remark": "Mock backend API",
"type": 2,
"req_method": "GET",
"result_normal_sample": "Example success response",
"result_failure_sample": "Example failure response",
"tags": ["httpApi"],
"backend_api": {
"req_protocol": "HTTP",
"req_method": "GET",
"req_uri": "/test/benchmark",
"timeout": 5000,
"retry_count": "-1",
"url_domain": "192.168.189.156:12346"
},
}
environment = conn.apig.update_api(
api="env_id",
gateway="gateway_id",
**attrs
)
Deleting an API¶
This example demonstrates how to delete an API.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
conn.apig.delete_api(
gateway="gateway_id",
api="env_id"
)
Querying API Details¶
This example demonstrates how to get an API.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
conn.apig.get_api(
gateway="gateway_id",
api="api_id"
)
Querying APIs¶
This example demonstrates how to list an APIs.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
environments = list(conn.apig.apis(gateway="gateway_id"))