Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
Add vpc peering
Browse files Browse the repository at this point in the history
* Create new class VPC to handle vpc connections and peering
* Update requirements to include boto3
* Add new fab tasks enable/disable_vpc_peering
* Add boto3 to setup.py requirements
* Add VPC docs page
* Add vpc requester/accepter routes to all route tables in each vpc
  • Loading branch information
Niall Creech committed Dec 9, 2015
1 parent 1804f84 commit 79af25d
Show file tree
Hide file tree
Showing 6 changed files with 679 additions and 23 deletions.
59 changes: 37 additions & 22 deletions bootstrap_cfn/cloudformation.py
@@ -1,5 +1,7 @@

import boto.cloudformation
import boto.ec2

import boto3

from bootstrap_cfn import utils

Expand Down Expand Up @@ -61,25 +63,38 @@ def get_stack_load_balancers(self, stack_name_or_id):
resource_type = 'AWS::ElasticLoadBalancing::LoadBalancer'
return self.get_resource_type(stack_name_or_id, resource_type)

def get_resource_type(self, stack_name_or_id, resource_type=None):
"""
Collect up a set of specific stack resources
Args:
stack_name_or_id (string): Name or id used to identify the stack
resource_type(string): The resource type identifier

Returns:
resources: Set of stack resources containing only
the resource type for this stack
"""
# get the stack
resources = []
stack = self.conn_cfn.describe_stacks(stack_name_or_id)
if stack:
resources = stack[0].list_resources()
if resource_type:
# get the resources
resources = filter(lambda x: x.resource_type == resource_type,
resources)
return resources
def get_resource_type(stack_name_or_id,
resource_type=None):
"""
Collect up a set of specific stack resources
Args:
stack_name_or_id (string): Name or id used to identify the stack
resource_type(string): The resource type identifier
Returns:
resources: Set of stack resources containing only
the resource type for this stack
"""
client = boto3.client('cloudformation')
all_resources = client.describe_stack_resources(StackName=stack_name_or_id)
resources = [resource for resource in all_resources['StackResources'] if resource['ResourceType'] == resource_type]
return resources


def get_stack_ids_by_name(stack_name_search_term):
"""
Collect up a set of specific stacks matching a search term
Args:
stack_name_search_term (string): Search term used to identify the stack
Returns:
stack_ids: Set of stack ids containing only
the stacks matching the search term.
"""
client = boto3.client('cloudformation')
all_stacks = client.describe_stacks()
stacks = [stack for stack in all_stacks['Stacks'] if stack_name_search_term in stack['StackId']]
return stacks
27 changes: 27 additions & 0 deletions bootstrap_cfn/fab_tasks.py
Expand Up @@ -20,6 +20,7 @@
from bootstrap_cfn.iam import IAM
from bootstrap_cfn.r53 import R53
from bootstrap_cfn.utils import tail
from bootstrap_cfn.vpc import VPC


# Default fab config. Set via the tasks below or --set
Expand Down Expand Up @@ -563,3 +564,29 @@ def display_elb_dns_entries():
elb_dns_list = elb.list_domain_names(stack_name)
for elb_dns in elb_dns_list:
print "\n\nELB name: {0} DNS: {1}".format(elb_dns['elb_name'], elb_dns['dns_name'])


@task
def enable_vpc_peering():
"""
Enables vpc peering to stacks named in the cloudformation config.
"""
# peer vpc
cfg = get_config()
vpc_cfg = cfg.data.get('vpc', False)
if vpc_cfg:
vpc_obj = VPC(cfg, get_stack_name())
vpc_obj.enable_peering()


@task
def disable_vpc_peering():
"""
Disables vpc peering to stacks named in the cloudformation config.
"""
# peer vpc
cfg = get_config()
vpc_cfg = cfg.data.get('vpc', False)
if vpc_cfg:
vpc_obj = VPC(cfg, get_stack_name())
vpc_obj.disable_peering()

0 comments on commit 79af25d

Please sign in to comment.