Using VMware Cloud on AWS SDDC-Group APIs (Part 4)
Gilles Chekroun
- Add/Remove Direct Connect Gateway Association
- Detailed SDDC Group info
- Static vTGW routes for VPCs
Add Direct Connect Gateway Association
def attach_dxgw(routes, resource_id, org_id, dxgw_owner, dxgw_id, region, session_token):myHeader = {'csp-auth-token': session_token}myURL = "{}/network/{}/aws/operations".format(BaseURL, org_id)body = {"type": "ASSOCIATE_DIRECT_CONNECT_GATEWAY","resource_id": resource_id,"resource_type": "network-connectivity-config","config" : {"type": "AwsAssociateDirectConnectGatewayConfig","direct_connect_gateway_association": {"direct_connect_gateway_id": dxgw_id,"direct_connect_gateway_owner": dxgw_owner,"peering_region_configs": [{"allowed_prefixes": routes,"region": region}]}}}response = requests.post(myURL, json=body, headers=myHeader)json_response = response.json()task_id = json_response ['id']return task_id
% python vtc.py attach-dxgw
===== Add DXGW Association =========
1: SDDC-Group_API: 31bbd613-e3a0-431b-a287-6c25d99e5786
2: API-test: 53dd006c-932a-47da-87aa-7aeb45ab07bb
3: Test-Terraform: cac26ea6-91c3-4cd9-acdb-3467e1495fec
4: Prod_VTGW: e0396f55-d4df-43dc-9fb1-66dea8a8a4d0
Select SDDC Group: 1
Enter route(s) to add (space separated): 10.100.0.0/16 10.200.0.0/16
PENDING
....
FINISHED in 00min 10sec
(vmc) gilleschekroun@Gilles-MBP VTCtests %
Detailed SDDC Group Info
% python vtc.py get-group-info
===== SDDC Group info =========
1: SDDC-Group_API: 31bbd613-e3a0-431b-a287-6c25d99e5786
2: API-test: 53dd006c-932a-47da-87aa-7aeb45ab07bb
3: Test-Terraform: cac26ea6-91c3-4cd9-acdb-3467e1495fec
4: Prod_VTGW: e0396f55-d4df-43dc-9fb1-66dea8a8a4d0
Select SDDC Group: 1
ORG ID : 7421a286-f7bf-4f34-8567-779b83d75fb5
SDDC Group
==========
Name : SDDC-Group_API
Group ID : 31bbd613-e3a0-431b-a287-6c25d99e5786
Creator : gchekroun@vmware.com
Date/Time : 2021-03-22T08:25:20.703162Z
SDDCs
=====
SDDC_ID 1: 56357a86-64af-4e0e-9cd3-6683c6862b4f
Transit Gateway
===============
TGW_ID : tgw-07945840e529fe4cd
Region : US West (Oregon)
AWS info
========
AWS Account : 0631xxxxxxxx
RAM Share ID : VMC-Group-8e9f8eb8-8247-4a64-852c-75337e6f0d8d
Status : ASSOCIATED
VPC 1 :vpc-057a6843d429a93bb
State : AVAILABLE
Attachment : tgw-attach-09ed28712fbebcb0e
Static Routes : 172.172.0.0/16, 1.1.0.0/16, 2.2.0.0/16
DX Gateway
==========
DXGW ID : 222fa2fb-a12f-48ff-b9a0-f08f4f789ea7
DXGW Owner: 0631xxxxxxxx
Status : CONNECTED
Prefixes : 10.100.0.0/16, 10.210.0.0/16, 10.200.0.0/16
(vmc) gilleschekroun@Gilles-MBP VTCtests %
Remove Direct Connect Gateway Association
def detach_dxgw(resource_id, org_id, dxgw_id, session_token):myHeader = {'csp-auth-token': session_token}myURL = "{}/network/{}/aws/operations".format(BaseURL, org_id)body = {"type": "DISASSOCIATE_DIRECT_CONNECT_GATEWAY","resource_id": resource_id,"resource_type": "network-connectivity-config","config" : {"type": "AwsDisassociateDirectConnectGatewayConfig","direct_connect_gateway_association": {"direct_connect_gateway_id": dxgw_id}}}response = requests.post(myURL, json=body, headers=myHeader)json_response = response.json()task_id = json_response ['id']return task_id
% python vtc.py detach-dxgw
===== Remove DXGW Association =========
1: SDDC-Group_API: 31bbd613-e3a0-431b-a287-6c25d99e5786
2: API-test: 53dd006c-932a-47da-87aa-7aeb45ab07bb
3: Test-Terraform: cac26ea6-91c3-4cd9-acdb-3467e1495fec
4: Prod_VTGW: e0396f55-d4df-43dc-9fb1-66dea8a8a4d0
Select SDDC Group: 1
PENDING
......................................................................................................................................................................................................
FINISHED in 08min 38sec
%
VMware Managed TGW Routes
- Members
- External
def get_route_tables(resource_id, org_id, session_token):myHeader = {'csp-auth-token': session_token}myURL = "{}/network/{}/core/network-connectivity-configs/{}/route-tables".format(BaseURL, org_id, resource_id)response = requests.get(myURL, headers=myHeader)json_response = response.json()if not json_response['content']:print(" Routing Tables empty")else:members_id = json_response['content'][0]['id']external_id = json_response['content'][1]['id']myURL = "{}/network/{}/core/network-connectivity-configs/{}/route-tables/{}/routes".format(BaseURL, org_id, resource_id, members_id)response = requests.get(myURL, headers=myHeader)json_response = response.json()print(" Members route domain: Routes to all SDDCs, VPCs and Direct Connect Gateways")for i in range(len(json_response['content'])):print("\tDestination: " + json_response['content'][i]['destination'] + "\t\tTarget: " + json_response['content'][i]['target']['id'])myURL = "{}/network/{}/core/network-connectivity-configs/{}/route-tables/{}/routes".format(BaseURL, org_id, resource_id, external_id)response = requests.get(myURL, headers=myHeader)json_response = response.json()print(" External (VPC and Direct Connect Gateway) route domain: Routes only to member SDDCs")for i in range(len(json_response['content'])):print("\tDestination: " + json_response['content'][i]['destination'] + "\t\tTarget: " + json_response['content'][i]['target']['id'])return
% python vtc.py get-routes
===== Get TGW route tables =========
1: SDDC-Group_API: 31bbd613-e3a0-431b-a287-6c25d99e5786
2: API-test: 53dd006c-932a-47da-87aa-7aeb45ab07bb
3: Test-Terraform: cac26ea6-91c3-4cd9-acdb-3467e1495fec
4: Prod_VTGW: e0396f55-d4df-43dc-9fb1-66dea8a8a4d0
Select SDDC Group: 1
Members route domain: Routes to all SDDCs, VPCs and Direct Connect Gateways
Destination: 1.1.0.0/16 Target: vpc-057a6843d429a93bb
Destination: 172.172.0.0/16 Target: vpc-057a6843d429a93bb
Destination: 2.2.0.0/16 Target: vpc-057a6843d429a93bb
External (VPC and Direct Connect Gateway) route domain: Routes only to member SDDCs
%
% python vtc.py
Please give an argument like:
SDDC-Group Operations:
create-sddc-group [name]
delete-sddc-group
get-group-info
SDDC Operations:
get-sddc-info
attach-sddc
detach-sddc
AWS Operations:
connect-aws
disconnect-aws
VPC Operations:
attach-vpc
detach-vpc
vpc-prefixes
DXGW Operations:
attach-dxgw
detach-dxgw
TGW Operations:
get-routes
%
Comments
Post a Comment