Python boto.cloudformation() Examples
The following are 14
code examples of boto.cloudformation().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
boto
, or try the search function
.
Example #1
Source File: spilo.py From spilo with Apache License 2.0 | 6 votes |
def get_stack_instance_details(stack): global ec2 global elb_conn instances_info = \ ec2.get_only_instances(filters={'tag:aws:cloudformation:stack-id': stack.stack_id}) instances_health = elb_conn.describe_instance_health(stack.stack_name) instances = list() for ii in instances_info: for ih in instances_health: if ih.instance_id == ii.id: instance = {'instance_id': ii.id, 'private_ip': ii.private_ip_address, 'launch_time': parse_time(ii.launch_time)} if ih.state == 'InService': instance['role'] = 'MASTER' else: instance['role'] = 'REPLICA' instances.append(instance) instances.sort(key=lambda k: (k['role'], k['instance_id'])) return instances
Example #2
Source File: icel.py From bcbio-nextgen-vm with MIT License | 6 votes |
def get_stack_name(node_addr, aws_config): """Get the name of the CloudFormation stack a node belongs to.""" import boto.ec2 conn = boto.ec2.connect_to_region( aws_config['ec2_region'], aws_access_key_id=aws_config['ec2_access_key'], aws_secret_access_key=aws_config['ec2_secret_key']) reservations = conn.get_all_reservations() for resv in reservations: for inst in resv.instances: # Non-HA MGTs don't have a tagged interface. if inst.private_ip_address == node_addr: return inst.tags['aws:cloudformation:stack-name'] for iface in inst.interfaces: iface.update() if iface.private_ip_address == node_addr: return inst.tags.get('aws:cloudformation:stack-name')
Example #3
Source File: icel.py From bcbio-nextgen-vm with MIT License | 6 votes |
def _get_mgt_ip_addr(stack_name, aws_config): import boto.ec2 conn = boto.ec2.connect_to_region( aws_config['ec2_region'], aws_access_key_id=aws_config['ec2_access_key'], aws_secret_access_key=aws_config['ec2_secret_key']) reservations = conn.get_all_reservations( filters={ 'tag:Name': 'mgt*', 'tag:aws:cloudformation:stack-name': stack_name, } ) for resv in reservations: for inst in resv.instances: for iface in inst.interfaces: iface.update() if iface.tags.get('lustre:server_role') == 'mgt': # HA MGTs have a tagged interface. return iface.private_ip_address # Non-HA MGTs don't. return inst.private_ip_address return None
Example #4
Source File: awslauncher.py From ferry with Apache License 2.0 | 6 votes |
def _wait_for_stack(self, stack_id): """ Wait for stack completion. """ logging.warning("waiting for cloudformation completion") stacks = self.cf.describe_stacks(stack_id) for stack in stacks: while(True): try: if stack.stack_status == "CREATE_COMPLETE": return True elif stack.stack_status == "CREATE_FAILED": logging.warning("cloudformation FAILED") return False else: stack.update() time.sleep(4) except: logging.error("could not fetch stack status (%s)" % str(stack_id)) return False
Example #5
Source File: cloudformation.py From dcos-bootstrap with GNU General Public License v3.0 | 5 votes |
def get_item(self, resource_type, key): conn = boto.cloudformation.connect_to_region(self.region) stack = conn.describe_stacks(stack_name_or_id=self.stack_name)[0] if resource_type in ['parameter', 'output']: attr = "{0}s".format(resource_type) return [item.value for item in getattr(stack, attr) if item.key == key] elif resource_type == 'resource_id': return [stack.describe_resources(key)[0].physical_resource_id] else: raise errors.AnsibleError( "unknown resource type {0}".format(resource_type))
Example #6
Source File: test_cfts.py From aws-deployments with MIT License | 5 votes |
def testenv(request): testenv = dict() testenv['cf_conn'] = boto.cloudformation.connect_to_region(region_for_tests) testenv['cft'] = request.param return testenv
Example #7
Source File: create_mycroft.py From mycroft with MIT License | 5 votes |
def _get_cf_connection(self): return self._get_connection(cloudformation)
Example #8
Source File: icel.py From bcbio-nextgen-vm with MIT License | 5 votes |
def _delete_stack(stack_name, cluster_config): """Delete a Lustre CloudFormation stack. """ import boto.cloudformation cf_conn = boto.cloudformation.connect_to_region( cluster_config['cloud']['ec2_region'], aws_access_key_id=cluster_config['cloud']['ec2_access_key'], aws_secret_access_key=cluster_config['cloud']['ec2_secret_key']) cf_conn.delete_stack(stack_name) sys.stdout.write('Waiting for stack to delete (this will take a few minutes)') sys.stdout.flush() _wait_for_stack(stack_name, 'DELETE_COMPLETE', 15 * 60, cluster_config['cloud']) # The awscli(1) equivalent of this is: # # aws cloudformation create-stack --stack-name STACK_NAME \ # --template-url TEMPLATE_URL \ # --capabilities CAPABILITY_IAM \ # --parameters \ # ParameterKey=FsName,ParameterValue=scratch \ # ParameterKey=AccessFrom,ParameterValue=0.0.0.0/0 \ # ParameterKey=VpcId,ParameterValue=vpc-c0ffee \ # ParameterKey=VpcPrivateCIDR,ParameterValue=a.b.c.d/e \ # ParameterKey=VpcPublicSubnetId,ParameterValue=subnet-deadbeef \ # ParameterKey=KeyName,ParameterValue=keypair@example.com \ # ParameterKey=HTTPFrom,ParameterValue=0.0.0.0/0 \ # ParameterKey=SSHFrom,ParameterValue=0.0.0.0/0
Example #9
Source File: icel.py From bcbio-nextgen-vm with MIT License | 5 votes |
def _wait_for_stack(stack_name, desired_state, wait_for, aws_config): import boto.cloudformation conn = boto.cloudformation.connect_to_region( aws_config['ec2_region'], aws_access_key_id=aws_config['ec2_access_key'], aws_secret_access_key=aws_config['ec2_secret_key']) stack = conn.describe_stacks(stack_name)[0] interval_length = 10 for interval in xrange(wait_for / interval_length): stack.update() status = stack.stack_status if status == desired_state: print() return elif status.endswith('_IN_PROGRESS'): sys.stdout.write('.') sys.stdout.flush() time.sleep(interval_length) continue else: failed_events = [ event for event in stack.describe_events() if event.resource_status.endswith('_FAILED') ] failed_descr = ','.join([ '{}: {}'.format( event.logical_resource_id, event.resource_status_reason) for event in failed_events ]) print() raise Exception( 'Stack {} did not launch successfully: {}: {}'.format( stack_name, status, failed_descr)) print()
Example #10
Source File: icel.py From bcbio-nextgen-vm with MIT License | 5 votes |
def _get_stack_param(stack_name, param_name, aws_config): import boto.cloudformation conn = boto.cloudformation.connect_to_region( aws_config['ec2_region'], aws_access_key_id=aws_config['ec2_access_key'], aws_secret_access_key=aws_config['ec2_secret_key']) icel_stack = conn.describe_stacks(stack_name)[0] return [ param.value for param in icel_stack.parameters if param.key == param_name ]
Example #11
Source File: cloudformation.py From ansible-plugins with GNU General Public License v3.0 | 5 votes |
def get_item(self, resource_type, key): conn = boto.cloudformation.connect_to_region(self.region) stack = conn.describe_stacks(stack_name_or_id=self.stack_name)[0] if resource_type in ['parameter', 'output']: attr = "{0}s".format(resource_type) return [item.value for item in getattr(stack, attr) if item.key == key] elif resource_type == 'resource_id': return [stack.describe_resources(key)[0].physical_resource_id] else: raise errors.AnsibleError( "unknown resource type {0}".format(resource_type))
Example #12
Source File: awslauncher.py From ferry with Apache License 2.0 | 5 votes |
def _init_aws_clients(self): # We will need to use both EC2 and VPC. self.ec2 = boto.ec2.connect_to_region(self.default_dc, aws_access_key_id = self.aws_access_key, aws_secret_access_key = self.aws_secret_key) self.vpc = boto.vpc.VPCConnection(aws_access_key_id = self.aws_access_key, aws_secret_access_key = self.aws_secret_key) self.cf = boto.cloudformation.connect_to_region(self.default_dc, aws_access_key_id = self.aws_access_key, aws_secret_access_key = self.aws_secret_key)
Example #13
Source File: __init__.py From brix with Apache License 2.0 | 5 votes |
def __init__(self, region): self.region = region # TODO: Allow configuring these on the command line self.access_key_id = os.environ.get('BALANCED_AWS_ACCESS_KEY_ID', os.environ.get('AWS_ACCESS_KEY_ID')) self.secret_access_key = os.environ.get('BALANCED_AWS_SECRET_ACCESS_KEY', os.environ.get('AWS_SECRET_ACCESS_KEY')) # Connect to the right CloudFormation region for r in boto.cloudformation.regions(): if r.name == self.region: break else: raise ValueError('Unknown region {0}'.format(region)) self.cfn = boto.connect_cloudformation(self.access_key_id, self.secret_access_key, region=r) self.s3 = boto.connect_s3(self.access_key_id, self.secret_access_key) # Load and render all templates self.templates = self._load_templates()
Example #14
Source File: icel.py From bcbio-nextgen-vm with MIT License | 4 votes |
def _create_stack(stack_name, template_url, lustre_net, cluster, cluster_config, recreate): import boto import boto.cloudformation conn = boto.connect_vpc( aws_access_key_id=cluster_config['cloud']['ec2_access_key'], aws_secret_access_key=cluster_config['cloud']['ec2_secret_key']) cf_conn = boto.cloudformation.connect_to_region( cluster_config['cloud']['ec2_region'], aws_access_key_id=cluster_config['cloud']['ec2_access_key'], aws_secret_access_key=cluster_config['cloud']['ec2_secret_key']) for stack in cf_conn.list_stacks('CREATE_COMPLETE'): if stack.stack_name == stack_name: if recreate: _delete_stack(stack_name, cluster_config) else: raise Exception('Stack {} already exists.'.format(stack_name)) for vpc in conn.get_all_vpcs(): if cluster_config['cloud']['vpc'] in [vpc.tags.get('Name'), vpc.id]: break else: raise Exception('Elasticluster must be running in ' 'an AWS VPC to start an ICEL stack.') public_subnet_name = '{}_cluster'.format(cluster) public_subnets = conn.get_all_subnets( filters={'vpcId': vpc.id, 'tag:Name': public_subnet_name}) if len(public_subnets) > 1: raise Exception( 'More than one subnet named {} exists in VPC {}/{}'.format( public_subnet_name, vpc.id, vpc.tags.get('Name'))) if len(public_subnets) == 0: raise Exception( 'A subnet named {} does not exist in VPC {}/{}'.format( public_subnet_name, vpc.id, vpc.tags.get('Name'))) public_subnet = public_subnets[0] if not lustre_net: vpc_net = vpc.cidr_block.split('/')[0] vpc_net_int = struct.unpack('>L', socket.inet_aton(vpc_net))[0] lustre_net = socket.inet_ntoa(struct.pack('>L', vpc_net_int + 256)) lustre_net = '{}/24'.format(lustre_net) aws_config = cluster_config["cloud"] cf_conn.create_stack(stack_name, template_url=template_url, capabilities=['CAPABILITY_IAM'], parameters=( ('FsName', 'scratch'), ('AccessFrom', vpc.cidr_block), ('NATInstanceType', "m3.medium" if aws_config["ec2_region"] == "us-east-1" else "m1.small"), ('VpcId', vpc.id), ('VpcPrivateCIDR', lustre_net), ('VpcPublicSubnetId', public_subnet.id), ('KeyName', cluster_config['login']['user_key_name']), ('HTTPFrom', '0.0.0.0/0'), ('SSHFrom', '0.0.0.0/0'), ))