Exemplo n.º 1
0
def configure_region(environment, regions, bastion_instance_type,
                     bastion_coreos_channel, bastion_coreos_version, nat_per_az,
                     admins):
    if not regions:
        logger.warn('Must specify region(s) to update.')
        return

    updates = get_updates(bastion_instance_type, bastion_coreos_channel,
                          bastion_coreos_version, nat_per_az, admins)

    if not updates:
        logger.warn('No updates to do!')
        return

    for aws_region in regions:
        dynamo = boto.dynamodb2.connect_to_region(aws_region)

        tables = DynamoDbTables(dynamo, environment=environment)
        tables.setup(['regions', 'users'])

        db = FlotillaClientDynamo(None, tables.regions, None, None, None,
                                  tables.users, None)

        admins = updates.get('admins')
        if admins:
            missing_users = db.check_users(admins)
            if len(missing_users) > 0:
                logger.error('User(s): %s do not exist in %s.',
                             ', '.join(missing_users), region)
                continue
        db.configure_region(aws_region, updates)
    logger.info('Region(s): %s updated.', ', '.join(regions))