Virtual Private Cloud (VPC)¶
VPC Bandwidth¶
Shared bandwidth allows multiple EIPs to share the same bandwidth. All ECSs, BMSs, and load balancers that have EIPs bound in the same region can share a bandwidth.
Assign bandwidth¶
This interface is used to assign a shared bandwidth.
Bandwidth
.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='test-dmd')
example_bandwidth = conn.vpc.assign_bandwidgh(name='bandwidth123')
print(example_bandwidth)
Update bandwidth¶
This interface is used to update a shared bandwidth.
Bandwidth
.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='test-dmd')
attrs = {'name': 'new_name', 'size': '15'}
example_bandwidth = conn.vpc.update_bandwidth(
bandwidth="bandwidth-id", **attrs
)
print(example_bandwidth)
Find bandwidth¶
This interface is used to find a shared bandwidth by name or id.
Bandwidth
.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='test-dmd')
conn.vpc.find_bandwidth(
name_or_id="bandwidth-id"
)
Add eip to bandwidth¶
This interface is used to add an EIP to a shared bandwidth.
Bandwidth
.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='test-dmd')
example_bandwidth = conn.vpc.add_eip_to_bandwidth(
bandwidth="bandwidth-id",
publicip_info=[{'publicip_id': "publicip-id", 'publicip_type': '5_bgp'}])
print(example_bandwidth)
Remove eip from bandwidth¶
This interface is used to remove an EIP from a shared bandwidth.
Bandwidth
.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='test-dmd')
attrs = {'charge_mode': "traffic", 'size': 22, 'publicip_info': [
{"publicip_id": "publicip-id"}
]}
conn.vpc.remove_eip_from_bandwidth(
bandwidth="bandwidth-id", **attrs)
Delete bandwidth¶
This interface is used to delete a shared bandwidth.
Bandwidth
.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='test-dmd')
conn.vpc.delete_bandwidth(bandwidth="bandwidth-id")
VPC Peering Connection¶
A VPC peering connection is a network connection between two VPCs that enables you to route traffic between them using private IP addresses. ECSs in either VPC can communicate with each other just as if they were in the same VPC. You can create a VPC peering connection between your own VPCs, or between your VPC and another account’s VPC within the same region. A VPC peering connection between VPCs in different regions will not take effect.
List VPC Peerings¶
This interface is used to query all VPC peering connections accessible to the
tenant submitting the request. The connections are filtered based on the
filtering condition.
Peering
.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
for peering in conn.vpc.peerings():
print(peering)
Create VPC Peering¶
This interface is used to create a VPC peering connection with
parameters.
Peering
.
import openstack
from otcextensions import sdk
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
sdk.register_otc_extensions(conn)
attrs = {
"name": "test-peering",
"request_vpc_info": {
"vpc_id": "requester-router-uuid"
},
"accept_vpc_info": {
"vpc_id": "accepter-router-uuid"
}
}
peering = conn.vpc.create_peering(**attrs)
Get VPC Peering¶
This interface is used to get a VPC peering connection by ID
or an instance of class.
Peering
.
import openstack
from otcextensions import sdk
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
sdk.register_otc_extensions(conn)
peering_id = "peering_id"
peering = conn.vpc.get_peering(peering_id)
print(peering)
Find VPC Peering¶
This interface is used to find a VPC peering connection by id or name.
Peering
.
import openstack
from otcextensions import sdk
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
sdk.register_otc_extensions(conn)
name_or_id = "name_or_id"
peering = conn.vpc.find_peering(name_or_id, ignore_missing=True)
print(peering)
Update VPC Peering¶
This interface is used to update parameters of a VPC peering connection by
id or an instance of class.
Peering
.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
peering = conn.vpc.get_peering("peering_id")
peering = conn.vpc.update_peering(peering=peering, name='new-name')
print(peering)
Delete VPC Peering¶
This interface is used to delete a VPC peering connection by ID
or an instance of class.
Peering
.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
peering = "peering_id"
conn.vpc.delete_peering(peering)
Set VPC Peering¶
This interface is used to accept of reject a VPC peering connection
request by ID or an instance of class.
Peering
.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
peering = conn.vpc.get_peering("peering_id")
# accept VPC peering request
set_status = 'accept'
peering = conn.vpc.set_peering(peering=peering, set_status=set_status)
print(peering)
# Reject VPC peering request
set_status = 'reject'
peering = conn.vpc.set_peering(peering=peering, set_status=set_status)
print(peering)
VPC Route¶
To enable communication between the two VPCs, you need to add local and peer routes for the VPC peering connection.
List VPC Routes¶
This interface is used to query all routes of the tenant submitting the
request. The routes are filtered based on the filtering condition.
Route
.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
for route in conn.vpc.routes():
print(route)
Add VPC Route¶
This Interface is used to add a VPC route.
Route
.
import openstack
from otcextensions import sdk
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
sdk.register_otc_extensions(conn)
attrs = {
"type": "peering",
"nexthop": "peering-uuid",
"destination": "192.168.100.0/24",
"vpc_id": "local-router-uuid"
}
route = conn.vpc.add_route(**attrs)
print(route)
Get VPC Route¶
This interface is used to get a VPC route by ID
or an instance of class.
Route
.
import openstack
from otcextensions import sdk
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
sdk.register_otc_extensions(conn)
route_id = "route-uuid"
route = conn.vpc.get_route(route_id)
print(route)
Delete VPC Route¶
This interface is used to delete a VPC route by ID
or an instance of class.
Peering
.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
route_id = "route-uuid"
conn.vpc.delete_route(route_id)