This topic describes how to use Alibaba Cloud SDK for Python to associate an elastic IP address (EIP) with a NAT gateway and disassociate an EIP from a NAT gateway.
Prerequisites
Before you run Alibaba Cloud SDK for Python, make sure that the following requirements
are met:
- An Alibaba Cloud account and the AccessKey pair are obtained. You can create and view your AccessKey pair on the Security Management page of the Alibaba Cloud Management Console.
- Make sure that Alibaba Cloud SDK for Python is installed. For more information, see aliyun-python-sdk-vpc 3.0.11.
- The VPC Python example library is downloaded.
Go to the directory where the setup.py file is stored, and run the following command to initialize the environment:
python setup.py install
Procedure
Result
The following output is returned:
---------------------------create_vpc---------------------------
{
"ResourceGroupId": "rg-acfmxaz****",
"RouteTableId": "vtb-uf6agemvkcmd8****",
"VRouterId": "vrt-uf6r7lqtsv65d****",
"VpcId": "vpc-uf6mqfqx8vjmo****",
"RequestId": "ADF806C6-FCD6-4E46-B8E3-72C2BE895344"
}
---------------------------create_vswitch---------------------------
{
"VSwitchId": "vsw-uf6rm6add6w89****",
"RequestId": "897FFCC1-E6BA-484E-A245-C5DAEBBA269C"
}
---------------------------create_nat_gateway---------------------------
{
"NatGatewayId": "ngw-uf681h38pbvly****",
"BandwidthPackageIds": {
"BandwidthPackageId": []
},
"ForwardTableIds": {
"ForwardTableId": [
"ftb-uf6jd0vbyao2d****"
]
},
"RequestId": "7C7CD3CB-041A-4B80-80B4-8BF8D5EF0D26",
"SnatTableIds": {
"SnatTableId": [
"stb-uf6uj997htg3u****"
]
}
}
---------------------------allocate_eip_address---------------------------
{
"EipAddress": "106.XX.XX.129",
"ResourceGroupId": "rg-acfmxaz****",
"RequestId": "DB795B99-1CEA-4FC1-9CE3-9DE2B977BF02",
"AllocationId": "eip-uf62tf8y4uyac****"
}
---------------------------associate_eip_address eip---------------------------
{
"RequestId": "443D7060-B716-4193-A44D-23FE762004F8"
}
---------------------------describe_eip_address---------------------------
{
"TotalCount": 1,
"PageNumber": 1,
"PageSize": 10,
"EipAddresses": {
"EipAddress": [
{
"ISP": "BGP",
"ExpiredTime": "",
"InternetChargeType": "PayByBandwidth",
"IpAddress": "106.XX.XX.129",
"AllocationId": "eip-uf62tf8y4uyac****",
"PrivateIpAddress": "",
"Status": "InUse",
"BandwidthPackageId": "",
"InstanceId": "ngw-uf681h38pbvly****",
"InstanceRegionId": "cn-shanghai",
"RegionId": "cn-shanghai",
"AvailableRegions": {
"AvailableRegion": [
"cn-shanghai"
]
},
"ResourceGroupId": "rg-acfmxaz****",
"HasReservationData": false,
"InstanceType": "Nat",
"AllocationTime": "2019-04-24T10:03:08Z",
"Name": "",
"OperationLocks": {
"LockReason": []
},
"Mode": "NAT",
"BandwidthPackageType": "",
"BandwidthPackageBandwidth": "",
"Bandwidth": "5",
"HDMonitorStatus": "OFF",
"ChargeType": "PostPaid",
"SecondLimited": false,
"Descritpion": ""
}
]
},
"RequestId": "F0AEE605-14AD-4ADD-980C-4B508CE7EE4B"
}
---------------------------create_common_bandwidth_package----------------------
-----
{
"ResourceGroupId": "rg-acfmxaz****",
"BandwidthPackageId": "cbwp-uf6dmfvq0gzzg****",
"RequestId": "D5E02777-2A72-42EC-8308-5D4B6E56D900"
}
---------------------------add_common_bandwidth_packageIp-----------------------
----
{
"RequestId": "3B4CD99C-6E59-4DA2-9256-EACF3F699412"
}
---------------------------describe_nat_gateway---------------------------
{
"TotalCount": 1,
"PageNumber": 1,
"RequestId": "A07498A0-4D60-4E0F-A7DE-3A832B174D59",
"PageSize": 10,
"NatGateways": {
"NatGateway": [
{
"Status": "Available",
"BandwidthPackageIds": {
"BandwidthPackageId": []
},
"VpcId": "vpc-uf6mqfqx8vjmo****",
"Description": "",
"ForwardTableIds": {
"ForwardTableId": [
"ftb-uf6jd0vbyao2d****"
]
},
"IpLists": {
"IpList": [
{
"UsingStatus": "Idle",
"IpAddress": "106.XX.XX.129",
"AllocationId": "eip-uf62tf8y4uyac****"
}
]
},
"BusinessStatus": "Normal",
"RegionId": "cn-shanghai",
"CreationTime": "2019-04-24T10:03:05Z",
"NatGatewayId": "ngw-uf681h38pbvly****",
"SnatTableIds": {
"SnatTableId": [
"stb-uf6uj997htg3u****"
]
},
"AutoPay": false,
"InstanceChargeType": "PostPaid",
"ExpiredTime": "",
"Spec": "Small",
"Name": ""
}
]
}
}
---------------------------unassociate_eip_address nat--------------------------
-
{
"RequestId": "92CB670E-239D-4659-B91F-E0565D5C0F2D"
}
---------------------------remove_common_bandwidth_packageIp--------------------
-------
{
"RequestId": "A58E9647-6761-4CA3-8786-3CD4E7D2A7AB"
}
---------------------------delete_common_bandwidth_package----------------------
-----
{
"RequestId": "4AA428BC-B72F-4567-94B8-AC2398EF7529"
}
---------------------------delete_nat_gateway---------------------------
{
"RequestId": "EC6C5D04-AF7D-4560-A30E-80EC141D174D"
}
---------------------------release_eip_address---------------------------
{
"RequestId": "9B1380B3-EE97-49BD-88FE-DBF356304208"
}
---------------------------delete_vswitch---------------------------
{
"RequestId": "A9A1D63E-5709-4B98-90BF-9069AA264230"
}
---------------------------delete_vpc---------------------------
{
"RequestId": "3B687C37-5315-4E0B-BE13-103BB287A80D"
}