Ejemplo n.º 1
0
def rotate_keys(args):
    boto3_session = session.new(args.profile, args.region, args.role)
    iam = boto3_session.resource('iam')
    if args.user is not None:
        user = iam.User(args.user)
    else:
        user = iam.CurrentUser().user
    keys = sorted(user.access_keys.all(), key=lambda x: x.create_date)
    if args.dry_run:
        for key in keys:
            print_key(key)

    if len(keys) > 1:
        oldest_key = keys[0]
        if args.dry_run:
            print 'rotate_keys would delete key {} but dry-run flag is set.'.format(oldest_key.id)
            return None
        print 'deleting key {}'.format(oldest_key.id)
        oldest_key.delete()

    if args.dry_run:
        print 'not creating a new key because dry-run flag is set'
        return None

    return user.create_access_key_pair()
Ejemplo n.º 2
0
def query_stack(stack_name, profile):
    boto3_session = session.new(args.profile, args.region, args.role)

    return [
        stack.summary(boto3_session, stack_name).build_parameters(),
        stack.parameters(boto3_session, stack_name)
    ]
Ejemplo n.º 3
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
Ejemplo n.º 4
0
def delete_stack(args):
    boto3_session = session.new(args.profile, args.region, args.role)

    deleter = StackDeleter(boto3_session, args.stack_name)
    if args.dry_run:
        deleter.validate_stack_exists()
        return 'Stack {} exists'.format(args.stack_name)

    deleter.validate_stack_exists()
    deleter.delete()
    return 'Stack {} deleted'.format(args.stack_name)
def _login():
	username = request.form['username']
	password = request.form['password']
	
	#try:
	token = memsource.login(username, password)
	sessId = session.new(token, username, password)
	
	engines = list(enginespecs.userExtraEngineAccess[username])
	session.storeValue(sessId, 'translator', engines[0])
	_reloadDomains(engines[0], sessId)
	
	return sessId
Ejemplo n.º 6
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
Ejemplo n.º 7
0
def update_stack(args):
    boto3_session = session.new(args.profile, args.region, args.role)
    builder = VpcBuilder(args, boto3_session, True)
    return builder.build(args.dry_run)
Ejemplo n.º 8
0
def get_session(args):
    return session.new(args.profile, args.region, args.role)
Ejemplo n.º 9
0
# -*- coding: utf-8 -*-

# Copyright (c) 2011-2012 Martin Beran ([email protected])
# license MIT/X11 (read more in the file LICENSE)

# Homepage: http://www.pywlibs.net/
# Source code: https://github.com/berycz/pywlibs
# Documentation: http://www.pywlibs.net/docs/session


import stopwatch

# DEBUG
sw = stopwatch.stopwatch(dplaces=6)
import session
SESSION = session.new({'uname': 'berycz'})
print "SESSION -", SESSION
print "SESSION.uname -", SESSION.uname
print "SESSION.sid -", SESSION.sid
print "SESSION.ctime -", SESSION.ctime
print "SESSION.mtime -", SESSION.mtime
if not SESSION.cart:
  SESSION.cart = []
SESSION.cart.append('polozka')
print "SESSION.cart -", SESSION.cart
print "save -", SESSION.save()
print "SESSION.sid -", SESSION.sid
print "SESSION.vid -", SESSION.vid
print sw.stop('hdd.new()')

sid = SESSION.sid
Ejemplo n.º 10
0
def create_stack(args):
    boto3_session = session.new(args.profile, args.region, args.role)
    builder = ConsulBuilder(args, boto3_session, False)
    return builder.build(args.dry_run)