-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildnetwork.py
34 lines (29 loc) · 982 Bytes
/
buildnetwork.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import boto3, sys, yaml
import conf
import jaws
ec2 = boto3.client('ec2')
#ec2.create_internet_gateway()['InternetGateway']['InternetGatewayId']
with open("network.yml", 'r') as stream:
try:
network=yaml.load(stream)
except yaml.YAMLError as exc:
print(exc)
if network['igw']==True:
try:
igwid=ec2.create_internet_gateway()['InternetGateway']['InternetGatewayId']
ec2.attach_internet_gateway(
InternetGatewayId=igwid,
VpcId=conf.vpcid
)
except Exception as e:
print("Failed to create IGW: %s" % e)
print("Creating Subnets...")
for subnet in network['subnets']:
try:
print(subnet)
net=network['subnets'][subnet]
subnetid=jaws.create_subnet(conf.vpcid,net['cidr'],net['az'])
jaws.tag_ec2(subnetid, 'Name', subnet)
except Exception as e:
print("Failed to create subnet: %s" % e)
#print(create_subnet (conf.vpcid, '10.10.1.0/24', 'us-west-2a'))