Skip to content

Commit 0ea560b

Browse files
authored
chore(examples): add networking prefix list examples (#78)
* chore(examples): prefix list examples
1 parent 11ffa4a commit 0ea560b

File tree

4 files changed

+192
-0
lines changed

4 files changed

+192
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import json
2+
import os
3+
4+
from staxapp.config import Config
5+
from staxapp.openapi import StaxClient
6+
7+
Config.access_key = os.getenv("STAX_ACCESS_KEY")
8+
Config.secret_key = os.getenv("STAX_SECRET_KEY")
9+
10+
# refer to the Stax API schema for valid body properties
11+
12+
networks = StaxClient("networking")
13+
14+
# example 1: create a Stax Hub Prefix List
15+
16+
body = {
17+
"Entries": [
18+
"192.168.0.1/32",
19+
"192.168.0.2/32"
20+
],
21+
"MaxEntries": 3,
22+
"Name": "example",
23+
"RouteTableTypes": [
24+
"INFRASTRUCTURE",
25+
"ISOLATED"
26+
],
27+
"Tags": {
28+
"CostCode": "12345"
29+
},
30+
"TargetId": "ec5eaa8f-da06-4935-b5ce-05bd957c8bdc",
31+
"TargetType": "VPC",
32+
"Zones": [
33+
"ZONE1",
34+
"ZONE2"
35+
]
36+
}
37+
38+
response = networks.CreateHubPrefixList(hub_id="<hub_uuid>",**body)
39+
40+
print(json.dumps(response, indent=4, sort_keys=True))
41+
42+
# example 2: create a Stax VPC Prefix List
43+
44+
body = {
45+
"Entries": [
46+
"192.168.0.1/32",
47+
"192.168.0.2/32"
48+
],
49+
"MaxEntries": 3,
50+
"Name": "example",
51+
"SubnetTypes": [
52+
"PRIVATE",
53+
"RESTRICTED"
54+
],
55+
"Tags": {
56+
"CostCode": "12345"
57+
},
58+
"VpcIds": [
59+
"a7220870-40fe-4235-abb3-4d42af0336c2",
60+
"7e542285-8b90-4b57-81e1-96e87e5ee443"
61+
],
62+
"VpcTypes": [
63+
"TRANSIT",
64+
"ISOLATED"
65+
],
66+
"Zones": [
67+
"ZONE1",
68+
"ZONE2"
69+
]
70+
}
71+
72+
response = networks.CreateVpcPrefixList(hub_id="<hub_uuid>",**body)
73+
74+
print(json.dumps(response, indent=4, sort_keys=True))
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import json
2+
import os
3+
4+
from staxapp.config import Config
5+
from staxapp.openapi import StaxClient
6+
7+
Config.access_key = os.getenv("STAX_ACCESS_KEY")
8+
Config.secret_key = os.getenv("STAX_SECRET_KEY")
9+
10+
# only Stax Direct Connect (DX) Associations with a status of ACTIVE, CREATE_FAILED and DELETE_FAILED can be deleted
11+
12+
networks = StaxClient("networking")
13+
14+
# delete a Stax Prefix List by providing the `prefix_list_uuid`
15+
response = networks.DeletePrefixList(prefix_list_id="<prefix_list_uuid>")
16+
17+
print(json.dumps(response, indent=4, sort_keys=True))
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import json
2+
import os
3+
4+
from staxapp.config import Config
5+
from staxapp.openapi import StaxClient
6+
7+
Config.access_key = os.getenv("STAX_ACCESS_KEY")
8+
Config.secret_key = os.getenv("STAX_SECRET_KEY")
9+
10+
networks = StaxClient("networking")
11+
12+
# read all Stax Prefix Lists in the Organization
13+
response = networks.ReadPrefixLists()
14+
15+
# read all Stax Prefix Lists in the Organization, filtered by statuses
16+
response = networks.ReadPrefixLists(status="ACTIVE,CREATE_IN_PROGRESS,CREATE_FAILED,DELETE_IN_PROGRESS,DELETED,DELETE_FAILED,UPDATE_IN_PROGRESS")
17+
18+
# read all Stax Prefix Lists in a Stax Networking Hub by providing the `hub_id`
19+
response = networks.ReadHubPrefixLists(hub_id="<hub_uuid>")
20+
21+
# read the Stax Prefix Lists in a Stax Networking Hub by providing the `hub_id`, filtered by status
22+
response = networks.ReadHubPrefixLists(hub_id="<hub_uuid>",status="DELETED")
23+
24+
# read the details of a single Stax Prefix List by providing the `prefix_list_uuid`
25+
response = networks.ReadPrefixList(prefix_list_id="<prefix_list_uuid>")
26+
27+
print(json.dumps(response, indent=4, sort_keys=True))
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import json
2+
import os
3+
4+
from staxapp.config import Config
5+
from staxapp.openapi import StaxClient
6+
7+
Config.access_key = os.getenv("STAX_ACCESS_KEY")
8+
Config.secret_key = os.getenv("STAX_SECRET_KEY")
9+
10+
# refer to the Stax API schema for valid body properties
11+
12+
networks = StaxClient("networking")
13+
14+
# example 1: update a Stax Prefix List
15+
16+
body = {
17+
"Entries": [
18+
"192.168.0.1/32",
19+
"192.168.0.2/32"
20+
],
21+
"MaxEntries": 3,
22+
"Name": "example",
23+
"Tags": {
24+
"CostCode": "12345"
25+
},
26+
"TargetId": "ec5eaa8f-da06-4935-b5ce-05bd957c8bdc",
27+
"TargetType": "VPC"
28+
}
29+
30+
response = networks.UpdatePrefixList(prefix_list_id="<prefix_list_uuid>", **body)
31+
32+
print(json.dumps(response, indent=4, sort_keys=True))
33+
34+
# example 2: update a Stax Hub Prefix List's associations
35+
36+
body = {
37+
"RouteTableTypes": [
38+
"INFRASTRUCTURE",
39+
"ISOLATED"
40+
],
41+
"Zones": [
42+
"ZONE1",
43+
"ZONE2"
44+
]
45+
}
46+
47+
response = networks.UpdateHubPrefixListAssociation(prefix_list_id="<prefix_list_uuid>", **body)
48+
49+
print(json.dumps(response, indent=4, sort_keys=True))
50+
51+
# example 3: update a Stax VPC Prefix List's associations
52+
53+
body = {
54+
"SubnetTypes": [
55+
"PRIVATE",
56+
"RESTRICTED"
57+
],
58+
"VpcIds": [
59+
"a7220870-40fe-4235-abb3-4d42af0336c2",
60+
"7e542285-8b90-4b57-81e1-96e87e5ee443"
61+
],
62+
"VpcTypes": [
63+
"TRANSIT",
64+
"ISOLATED"
65+
],
66+
"Zones": [
67+
"ZONE1",
68+
"ZONE2"
69+
]
70+
}
71+
72+
response = networks.UpdateVpcPrefixListAssociation(prefix_list_id="<prefix_list_uuid>", **body)
73+
74+
print(json.dumps(response, indent=4, sort_keys=True))

0 commit comments

Comments
 (0)