Esempio n. 1
0
    def _apply_all(self, config):

        # Make sure amis is setup early. (TODO: raise exception if missing)
        self.amis = config['amis']

        # set a var for no_cfg.
        no_cfg = {}

        # attach EnrichedVPC to self.
        self.evpc = EnrichedVPC(self.vpc_name, self.boto.region_name, self.boto.profile_name)

        # the order of these method calls matters for new VPCs.
        self.route_tables(config.get('route_tables', no_cfg))
        self.subnets(config.get('subnets', no_cfg))
        self.associate_route_tables_with_subnets(config.get('subnets', no_cfg))
        self.security_groups(config.get('security_groups', no_cfg))
        self.key_pairs(config.get('key_pairs', []))
        new_instances = self.instance_roles(
            config.get('instance_roles', no_cfg)
        )
        # lets do more work while new_instances move from pending to running.
        self.endpoints(config.get('endpoints', []))
        self.security_group_rules(config.get('security_groups', no_cfg))
        # lets finish building the new instances.
        self.finish_instance_roles(
            config.get('instance_roles', no_cfg), new_instances,
        )
        self.log.emit('done! don\'t you look awesome. : )')
Esempio n. 2
0
def main():
    parser = build_parser('Manage infrastructure on AWS using YAML')
    args = parser.parse_args()

    if 'skip_evpc' in args.__dict__:
        evpc = None
    else:
        evpc = EnrichedVPC(
            vpc_name=args.vpc_name,
            region_name=args.region,
            profile_name=args.profile,
        )

    # call the plugin main method.
    args.func(args, evpc)
Esempio n. 3
0
    def setUp(self):
        MockInstance1 = Mock(name="Instance", return_value = MockInstanceSpec1())
        self.instance1 = EnrichedInstance(MockInstance1())
        self.instance1b = EnrichedInstance(MockInstance1())

        MockInstance2 = Mock(name="Instance", return_value = MockInstanceSpec2())
        self.instance2 = EnrichedInstance(MockInstance2())

        MockInstance3 = Mock(name="Instance", return_value = MockInstanceSpec3())
        self.instance3 = EnrichedInstance(MockInstance3())

        self.evpc1 = EnrichedVPC()
        self.evpc1._ec2_instances = MagicMock(
                                      return_value=[
                                        MockInstance1(),
                                        MockInstance2(),
                                        MockInstance3(),
                                      ]
                                    )
Esempio n. 4
0
    def _apply_all(self, config):

        # set a var for no_cfg.
        no_cfg = {}

        # attach EnrichedVPC to self.
        self.evpc = EnrichedVPC(self.vpc_name, self.boto.region_name,
                                self.boto.profile_name)

        # the order of these method calls matters for new VPCs.
        self.route_tables(config.get('route_tables', no_cfg))
        self.subnets(config.get('subnets', no_cfg))
        self.associate_route_tables_with_subnets(config.get('subnets', no_cfg))
        self.endpoints(config.get('endpoints', []))
        self.security_groups(config.get('security_groups', no_cfg))
        self.security_group_rules(config.get('security_groups', no_cfg))

        try:
            self.evpc.lock_instances()
        except:
            self.log.emit('Could not lock instances, continuing...', 'warning')
Esempio n. 5
0
    def _apply_all(self, config):

        # Make sure amis is setup early. (TODO: raise exception if missing)
        self.amis = config['amis']

        # set a var for no_cfg.
        no_cfg = {}

        # build the vpc.
        vpc_cidr = config.get('vpc_cidr', '172.31.0.0/16')
        vpc_tenancy = config.get('vpc_tenancy', 'default')
        self.build_vpc(vpc_cidr, vpc_tenancy)

        # attach EnrichedVPC to self.
        self.evpc = EnrichedVPC(self.vpc_name, self.boto.region_name,
                                self.boto.profile_name, self.log)

        # create and attach internet gateway to vpc.
        self.build_internet_gateway()

        # attach VPN gateway to the VPC
        self.attach_vpn_gateway(config.get('vpn_gateway', no_cfg))

        # create and associate DHCP Options Set
        self.dhcp_options(config.get('dhcp_options', no_cfg))

        # iam instance profiles / iam roles need to be created early because
        # there isn't a way to make launch config idempotent and safe to retry...
        self.instance_profiles(config.get('instance_roles', no_cfg))

        # the order of these method calls matters for new VPCs.
        self.route_tables(config.get('route_tables', no_cfg))
        self.subnets(config.get('subnets', no_cfg))
        self.security_groups(config.get('security_groups', no_cfg))
        self.key_pairs(config.get('key_pairs', []))
        self.associate_route_tables_with_subnets(config.get('subnets', no_cfg))
        self.db_instances(config.get('db_instances', no_cfg))

        self.instance_roles(config.get('instance_roles', no_cfg))

        self.autoscaling_instance_roles(config.get('instance_roles', no_cfg))

        # lets do more work while new_instances move from pending to running.
        self.endpoints(config.get('endpoints', []))
        self.security_group_rules(config.get('security_groups', no_cfg))
        self.load_balancers(config.get('load_balancers', no_cfg))

        # block until instance_role counts are sane.
        self.wait_for_instance_roles_to_exist(
            config.get('instance_roles', no_cfg))

        # lets finish building the new instances.
        self.finish_instance_roles(config.get('instance_roles', no_cfg))

        # run after tagging instances in case we have a NAT instance_role.
        self.route_table_rules(config.get('route_tables', no_cfg))

        if config.get('private_zone', False):
            self.log.emit('managing route53 private zone.')
            self.evpc.route53.create_private_zone()
            self.evpc.route53.refresh_private_zone()

        self.tags(config.get('tags', no_cfg))

        self.log.emit('done! don\'t you look awesome. : )')
Esempio n. 6
0
def get_evpc_from_args(args):
    if "skip_evpc" not in args.__dict__:
        return EnrichedVPC(
            vpc_name=args.vpc_name, region_name=args.region, profile_name=args.profile
        )