Commit be124d7b by Feanil Patel

Merge pull request #255 from edx/feanil/vpc_tools

Feanil/vpc tools
parents e9fb73c8 b6a18958
"""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)
......
"""VPC Tools. """VPC Tools.
Usage: Usage:
vpc-tools.py ssh-config (vpc <vpc_id> | stack-name <stack_name>) identity-file <identity_file> user <user> [config-file <config_file>] [strict-host-check <strict_host_check>] vpc-tools.py ssh-config (vpc <vpc_id> | stack-name <stack_name>) identity-file <identity_file> user <user> [(config-file <config_file>)] [(strict-host-check <strict_host_check>)]
vpc-tools.py (-h --help) vpc-tools.py (-h --help)
vpc-tools.py (-v --version) vpc-tools.py (-v --version)
...@@ -12,11 +12,12 @@ Options: ...@@ -12,11 +12,12 @@ 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"
DEFAULT_USER="ubuntu" DEFAULT_USER="ubuntu"
DEFAULT_HOST_CHECK="yes" DEFAULT_HOST_CHECK="ask"
JUMPBOX_CONFIG = """ JUMPBOX_CONFIG = """
Host {jump_box} Host {jump_box}
...@@ -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_id or stack_name provided.")
vpc = boto.connect_vpc() vpc = boto.connect_vpc()
...@@ -75,7 +69,7 @@ def _ssh_config(args): ...@@ -75,7 +69,7 @@ def _ssh_config(args):
if config_file: if config_file:
config_file = "-F {}".format(config_file) config_file = "-F {}".format(config_file)
else: else:
config_file = "nothing" config_file = ""
jump_box = "{vpc_id}-jumpbox".format(vpc_id=vpc_id) jump_box = "{vpc_id}-jumpbox".format(vpc_id=vpc_id)
friendly = "{vpc_id}-{logical_id}-{instance_id}" friendly = "{vpc_id}-{logical_id}-{instance_id}"
......
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