Skip to content

Chore/networking examples #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions examples/networking/create_dns_resolver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import json
import os

from staxapp.config import Config
from staxapp.openapi import StaxClient

Config.access_key = os.getenv("STAX_ACCESS_KEY")
Config.secret_key = os.getenv("STAX_SECRET_KEY")

# refer to the Stax API schema for valid body properties

networks = StaxClient("networking")

# create a DNS Resolver within a Stax Networking Hub by providing the `hub_id` and body properties

body = {
"Name": "dns resolver",
"NumberOfInterfaces": 2,
"Tags": {
"CostCode": "12345"
}
}

response = networks.CreateDnsResolver(hub_id="<hub_uuid>",**body)

print(json.dumps(response, indent=4, sort_keys=True))
30 changes: 30 additions & 0 deletions examples/networking/create_dns_rule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import json
import os

from staxapp.config import Config
from staxapp.openapi import StaxClient

Config.access_key = os.getenv("STAX_ACCESS_KEY")
Config.secret_key = os.getenv("STAX_SECRET_KEY")

# refer to the Stax API Schema for valid body properties

networks = StaxClient("networking")

# create a DNS Rule within a Stax DNS Resolver by providing the `dns_resolver_uuid` and body properties

body = {
"DomainName": "test.local",
"ForwarderIpAddresses": [
"192.168.0.1",
"192.168.0.2"
],
"Name": "on-premises",
"Tags": {
"CostCode": "12345"
}
}

response = networks.CreateDnsRule(dns_resolver_id="<dns_resolver_uuid>",**body)

print(json.dumps(response, indent=4, sort_keys=True))
43 changes: 43 additions & 0 deletions examples/networking/create_dx_association.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import json
import os

from staxapp.config import Config
from staxapp.openapi import StaxClient

Config.access_key = os.getenv("STAX_ACCESS_KEY")
Config.secret_key = os.getenv("STAX_SECRET_KEY")

# refer to the Stax API schema for valid body properties

networks = StaxClient("networking")

# example 1: create a Stax Direct Connect (DX) association between a Networking Hub and a DX Gateway
# providing a Networking Hub Id will attempt to associate the DX Gateway that contains Transit VIFs to the Networking Hub's Transit Gateway

body = {
"NetworkingHubId": "<hub_uuid>",
"Prefixes": [
"192.168.0.0/24",
"192.168.1.0/24"
]
}

response = networks.CreateDxAssociation(dx_gateway_id="<dx_gateway_uuid>",**body)

print(json.dumps(response, indent=4, sort_keys=True))


# example 2: create a Stax DX association between a Stax Networking Hub's VPC and a Stax DX Gateway
# providing a VPC Id will attempt to associate the DX Gateway that contains private VIFs to the VPCs virtual private gateway

body = {
"VpcId": "<vpc_uuid>",
"Prefixes": [
"192.168.0.0/24",
"192.168.1.0/24"
]
}

response = networks.CreateDxAssociation(dx_gateway_id="<dx_gateway_uuid>",**body)

print(json.dumps(response, indent=4, sort_keys=True))
79 changes: 79 additions & 0 deletions examples/networking/create_dx_resources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import json
import os

from staxapp.config import Config
from staxapp.openapi import StaxClient

Config.access_key = os.getenv("STAX_ACCESS_KEY")
Config.secret_key = os.getenv("STAX_SECRET_KEY")

# refer to the Stax API Schema for valid body properties

networks = StaxClient("networking")

# example 1: create a Stax Direct Connect (DX) Gateway

body = {
"Gateway": {
"AccountId": "<stax_account_uuid>",
"Asn": 64512,
"GatewayType": "TRANSIT",
"Name": "Prod Gateway",
}
}

response = networks.CreateDxResource(**body)

print(json.dumps(response, indent=4, sort_keys=True))

# example 2: create a Stax DX Gateway and associated DX Vif

body = {
"Gateway": {
"AccountId": "<stax_account_uuid>",
"Asn": 64512,
"GatewayType": "TRANSIT",
"Name": "Prod Gateway",
},
"Vif": {
"Asn": 64513,
"AwsConnectionId": "dx-con-xxxxxx",
"AwsRouterIp": "192.168.0.2/30",
"BgpAuthKey": "secret",
"JumboMtu": True,
"Name": "Prod VIF",
"RouterIp": "192.168.0.1/30",
"Tags": {
"CostCode": "12345"
},
"Vlan": 4000,
}
}

response = networks.CreateDxResource(**body)

print(json.dumps(response, indent=4, sort_keys=True))


# example 3: create a Stax DX Vif and attach to an existing DX Gateway by provided the Dx Gateway Id

body = {
"Vif": {
"Asn": 64513,
"AwsConnectionId": "dx-con-xxxxxx",
"AwsRouterIp": "192.168.0.2/30",
"DxGatewayId": "<dx_gateway_uuid>",
"BgpAuthKey": "secret",
"JumboMtu": True,
"Name": "Prod VIF",
"RouterIp": "192.168.0.1/30",
"Tags": {
"CostCode": "12345"
},
"Vlan": 4000,
}
}

response = networks.CreateDxResource(**body)

print(json.dumps(response, indent=4, sort_keys=True))
26 changes: 26 additions & 0 deletions examples/networking/create_exclusion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import json
import os

from staxapp.config import Config
from staxapp.openapi import StaxClient

Config.access_key = os.getenv("STAX_ACCESS_KEY")
Config.secret_key = os.getenv("STAX_SECRET_KEY")

networks = StaxClient("networking")

# refer to the Stax API Schema for valid body properties
# create a CIDR Exclusion within a Stax Networking Hub by providing the `hub_id` and body properties

body = {
"Cidr": "10.128.0.0/19",
"Description": "This Reservation blocks out existing legacy VPCs",
"Name": "legacy-vpcs",
"Tags": {
"CostCode": "12345"
}
}

response = networks.CreateCidrExclusion(hub_id="<hub_uuid>", **body)

print(json.dumps(response, indent=4, sort_keys=True))
26 changes: 26 additions & 0 deletions examples/networking/create_range.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import json
import os

from staxapp.config import Config
from staxapp.openapi import StaxClient

Config.access_key = os.getenv("STAX_ACCESS_KEY")
Config.secret_key = os.getenv("STAX_SECRET_KEY")

# refer to the Stax API Schema for valid body properties
# creates a CIDR Range within a Stax Networking Hub by providing a `hub_id`

networks = StaxClient("networking")

body = {
"Cidr": "10.128.0.0/23",
"Description": "CIDR Range used for team ABCD application 1234",
"Name": "prod",
"Tags": {
"CostCode": "12345"
}
}

response = networks.CreateCidrRange(hub_id="<hub_uuid>", **body)

print(json.dumps(response, indent=4, sort_keys=True))
39 changes: 39 additions & 0 deletions examples/networking/create_vpc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import json
import os

from staxapp.config import Config
from staxapp.openapi import StaxClient

Config.access_key = os.getenv("STAX_ACCESS_KEY")
Config.secret_key = os.getenv("STAX_SECRET_KEY")

# refer to the Stax API Schema for valid body properties
# create a VPC within a Stax Networking Hub by providing the `hub_id` and body properties

networks = StaxClient("networking")

body = {
"AccountId": "<stax_account_uuid>",
"CidrRangeId": "<range_uuid>",
"CreateCloudwatchVpcFlowlogs": True,
"CreateInternetGateway": True,
"CreateVirtualPrivateGateway": False,
"Description": "VPC for a non-prod microservice",
"GatewayEndpoints": [
"s3"
],
"Name": "dev-ms-customers",
"PhzPrefix": "dev",
"Region": "ap-northeast-1",
"Size": "SMALL",
"Tags": {
"CostCode": "12345"
},
"Type": "ISOLATED",
"VirtualPrivateGatewayAsn": 64513,
"Zone": "my-zone"
}

response = networks.CreateVpc(hub_id="<hub_uuid>", **body)

print(json.dumps(response, indent=4, sort_keys=True))
45 changes: 45 additions & 0 deletions examples/networking/create_vpn_connection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import json
import os

from staxapp.config import Config
from staxapp.openapi import StaxClient

Config.access_key = os.getenv("STAX_ACCESS_KEY")
Config.secret_key = os.getenv("STAX_SECRET_KEY")

# refer to the Stax API schema for valid body properties

networks = StaxClient("networking")

# example 1: create a Stax VPN Connection between an existing Stax Networking Hub and a Stax VPN Customer Gateway
# providing a Networking Hub Id will attempt to create a VPN Connection for the VPN Customer Gateway and a Transit Gateway

body = {
"ImprovedAcceleration": false,
"Name": "vpn-transit-connection",
"NetworkingHubId": "<hub_uuid>",
"Tags": {
"CostCode": "12345"
}
}

response = networks.CreateVpnConnection(vpn_customer_gateway_id="<vpn_customer_gateway_uuid>",**body)

print(json.dumps(response, indent=4, sort_keys=True))


# example 2: create a Stax VPN Connection between an existing Stax VPC and a Stax VPN Customer Gateway
# providing a VPC Id will attempt to create a VPN Connection for the VPN Customer Gateway and a VPC's Virtual Private Gateway

body = {
"ImprovedAcceleration": false,
"Name": "vpn-transit-connection",
"VpcId": "<vpc_uuid>",
"Tags": {
"CostCode": "12345"
}
}

response = networks.CreateVpnConnection(vpn_customer_gateway_id="<vpn_customer_gateway_uuid>",**body)

print(json.dumps(response, indent=4, sort_keys=True))
28 changes: 28 additions & 0 deletions examples/networking/create_vpn_customer_gateway.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import json
import os

from staxapp.config import Config
from staxapp.openapi import StaxClient

Config.access_key = os.getenv("STAX_ACCESS_KEY")
Config.secret_key = os.getenv("STAX_SECRET_KEY")

# refer to the Stax API schema for valid body properties
# create a Stax VPN Customer Gateway by providing the body parameter

networks = StaxClient("networking")

body = {
"AccountId": "<stax_account_uuid>",
"Asn": 64513,
"IpAddress": "1.1.1.1",
"Name": "vpn-gw",
"Region": "ap-northeast-1",
"Tags": {
"CostCode": "12345"
}
}

response = networks.CreateVpnCustomerGateway(**body)

print(json.dumps(response, indent=4, sort_keys=True))
18 changes: 18 additions & 0 deletions examples/networking/delete_dx_association.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import json
import os

from staxapp.config import Config
from staxapp.openapi import StaxClient

Config.access_key = os.getenv("STAX_ACCESS_KEY")
Config.secret_key = os.getenv("STAX_SECRET_KEY")

# refer to the Stax API schema for valid body properties
# only Stax Direct Connect (DX) Associations with a status of ACTIVE, CREATE_FAILED and DELETE_FAILED can be deleted

networks = StaxClient("networking")

# delete a Stax DX Association by providing the `dx_association_uuid`
response = networks.DeleteDxAssociation(dx_association_id="<dx_association_uuid>")

print(json.dumps(response, indent=4, sort_keys=True))
19 changes: 19 additions & 0 deletions examples/networking/delete_dx_gateway.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import json
import os

from staxapp.config import Config
from staxapp.openapi import StaxClient

Config.access_key = os.getenv("STAX_ACCESS_KEY")
Config.secret_key = os.getenv("STAX_SECRET_KEY")

# refer to the Stax API schema for valid body properties
# only Stax Direct Connect (DX) Gateway with a status of ACTIVE, CREATE_FAILED and DELETE_FAILED can be deleted
# Stax DX Gateways with an active DX Connection cannot be deleted

networks = StaxClient("networking")

# delete a Stax DX Gateway by providing the `dx_gateway_id`
response = networks.DeleteDxGateway(dx_gateway_id="<dx_gateway_uuid>")

print(json.dumps(response, indent=4, sort_keys=True))
Loading