예제 #1
0
def lights_on(args):
    boto3_session = session.new(args.profile, args.region, args.role)

    cf_client = boto3_session.client('cloudformation')
    resources = cf_client.get_template(StackName=args.stack_name)['TemplateBody']['Resources']
    asg_values = {k: {'min': v['Properties']['MinSize'],
                      'max': v['Properties']['MaxSize']}
                  for k, v in resources.items() if k.endswith('ASG')}

    outputs = stack.outputs(boto3_session, args.stack_name)

    logical_asgs = outputs.keys(lambda k: k.endswith('ASG'))
    if len(args.asg_names) > 0:
        logical_asgs = [asg for asg in logical_asgs if any((partial in asg for partial in args.asg_names))]
        asg_values = {k: asg_values[k] for k in asg_values if k in logical_asgs}

    if args.dry_run:
        print 'Not actually resetting ASG min and max values because dry run flag is set'
        return asg_values

    autoscale = boto3_session.client('autoscaling')
    for logical_asg in logical_asgs:
        autoscale.update_auto_scaling_group(
            AutoScalingGroupName=outputs[logical_asg],
            MinSize=asg_values[logical_asg]['min'],
            DesiredCapacity=asg_values[logical_asg]['min'],
            MaxSize=asg_values[logical_asg]['max'])

    return asg_values
예제 #2
0
    def get_dependencies(self, dependencies):
        outputs = stack.outputs(self.session, self.args.network_stack_name)

        dependencies.vpc_id = outputs['VpcId']
        dependencies.vpc_cidr = outputs['VpcCidr']
        dependencies.private_subnet_ids = outputs.values(lambda k: 'PrivateSubnet' in k)
        dependencies.public_subnet_ids = outputs.values(lambda k: 'PublicSubnet' in k)
예제 #3
0
def lights_out(args):
    boto3_session = session.new(args.profile, args.region, args.role)

    outputs = stack.outputs(boto3_session, args.stack_name)
    logical_asgs = outputs.keys(lambda k: k.endswith('ASG'))
    if len(args.asg_names) > 0:
        logical_asgs = [asg for asg in logical_asgs if any((partial in asg for partial in args.asg_names))]

    physical_asgs = [outputs[asg] for asg in logical_asgs]

    if args.dry_run:
        print 'Not actually scaling ASGs to zero because dry-run flag is set.'
        return physical_asgs

    autoscale = boto3_session.client('autoscaling')
    for asg in physical_asgs:
        autoscale.update_auto_scaling_group(
            AutoScalingGroupName=asg,
            MinSize=0,
            DesiredCapacity=0,
            MaxSize=0)

    return physical_asgs