Commit 96fdb174 by Feanil Patel

Update dns tool to take the stack name.

parent e9fb73c8
"""vpc-dns.py """vpc-dns.py
Usage: Usage:
vpc-dns.py create-zone vpc <vpc-id> vpc-dns.py create-zone (vpc <vpc_id> | stack-name <stack_name>)
vpc-dns.py (-h --help) vpc-dns.py (-h --help)
vpc-dns.py (-v --version) vpc-dns.py (-v --version)
...@@ -12,6 +12,7 @@ Options: ...@@ -12,6 +12,7 @@ Options:
import boto import boto
from boto.route53.record import ResourceRecordSets from boto.route53.record import ResourceRecordSets
from docopt import docopt from docopt import docopt
from vpcutil import vpc_for_stack_name
class VPCDns: class VPCDns:
BACKEND_ZONE = "Z4AI6ADZTL3HN" BACKEND_ZONE = "Z4AI6ADZTL3HN"
...@@ -106,8 +107,13 @@ class VPCDns: ...@@ -106,8 +107,13 @@ class VPCDns:
VERSION="0.1" VERSION="0.1"
def dispatch(args): def dispatch(args):
if args.get("vpc"):
vpc_id = args.get("<vpc-id>") vpc_id = args.get("<vpc_id>")
elif args.get("stack-name"):
stack_name = args.get("<stack_name>")
vpc_id = vpc_for_stack_name(stack_name)
else:
raise Exception("No vpc_id or stack_name provided.")
c = VPCDns(vpc_id=vpc_id) c = VPCDns(vpc_id=vpc_id)
......
...@@ -12,6 +12,7 @@ Options: ...@@ -12,6 +12,7 @@ Options:
""" """
import boto import boto
from docopt import docopt from docopt import docopt
from vpcutil import vpc_for_stack_name
VERSION="vpc tools 0.1" VERSION="vpc tools 0.1"
...@@ -43,13 +44,6 @@ def dispatch(args): ...@@ -43,13 +44,6 @@ def dispatch(args):
if args.get("ssh-config"): if args.get("ssh-config"):
_ssh_config(args) _ssh_config(args)
def vpc_for_stack_name(stack_name):
cfn = boto.connect_cloudformation()
resources = cfn.list_stack_resources(stack_name)
for resource in resources:
if resource.resource_type == 'AWS::EC2::VPC':
return resource.physical_resource_id
def _ssh_config(args): def _ssh_config(args):
if args.get("vpc"): if args.get("vpc"):
vpc_id = args.get("<vpc_id>") vpc_id = args.get("<vpc_id>")
...@@ -57,7 +51,7 @@ def _ssh_config(args): ...@@ -57,7 +51,7 @@ def _ssh_config(args):
stack_name = args.get("<stack_name>") stack_name = args.get("<stack_name>")
vpc_id = vpc_for_stack_name(stack_name) vpc_id = vpc_for_stack_name(stack_name)
else: else:
raise Exception("No way to know which vpc to query.") raise Exception("No vpc_idao or stack_name provided.")
vpc = boto.connect_vpc() vpc = boto.connect_vpc()
......
import boto
def vpc_for_stack_name(stack_name):
cfn = boto.connect_cloudformation()
resources = cfn.list_stack_resources(stack_name)
for resource in resources:
if resource.resource_type == 'AWS::EC2::VPC':
return resource.physical_resource_id
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment