def show(self): self.output = subnet.Subnet(name=self.subnet_name, vpc_id=self.vpc.id).show() _LOGGER.info("******************************************************") _LOGGER.info(self.output) _LOGGER.info("******************************************************") return self.output
def destroy(self, subnet_name=None): if subnet_name: self.subnet = subnet.Subnet(name=subnet_name, vpc_id=self.vpc.id) self.subnet.destroy(role=self.role) else: _instances = instances.Instances.get_by_roles(vpc_id=self.vpc.id, roles=[self.role]) _subnet_ids = set(_i.subnet_id for _i in _instances.instances) _instances.terminate() [ subnet.Subnet(id=_id, ).destroy(role=self.role) for _id in _subnet_ids ]
def delete_cell(vpc_id, domain, subnet_id): """Delete Cell (Subnet)""" connection.Connection.context.domain = domain _vpc = vpc.VPC(id=vpc_id) _vpc.load_hosted_zone_ids() subnet.Subnet(id=subnet_id).destroy( hosted_zone_id=_vpc.hosted_zone_id, reverse_hosted_zone_id=_vpc.reverse_hosted_zone_id)
def destroy(self, subnet_id): self.vpc.load_hosted_zone_ids() self.subnet = subnet.Subnet(id=subnet_id) self.subnet.destroy( hosted_zone_id=self.vpc.hosted_zone_id, reverse_hosted_zone_id=self.vpc.reverse_hosted_zone_id, role=self.role )
def setup( self, image_id, count, key, instance_type, subnet_id=None, cidr_block=None, ): if not subnet_id and not cidr_block: raise Exception( 'Subnet CIDR block required for creating new subnet' ) self.vpc.load_hosted_zone_ids() self.vpc.load_internet_gateway_ids() self.vpc.load_security_group_ids() if not getattr(self, 'subnet_name', None): self.subnet_name = self.name if not subnet_id: self.vpc.create_subnet( cidr_block=cidr_block, name=self.subnet_name, gateway_id=self.vpc.gateway_ids[0] ) self.subnet = self.vpc.subnets[-1] else: self.subnet = subnet.Subnet( id=subnet_id, vpc_id=self.vpc.id ) user_data = '' if getattr(self, 'configuration', None): self.configuration.cell = self.subnet.id user_data = self.configuration.get_userdata() self.subnet.instances = instances.Instances.create( name=self.name, image_id=image_id, count=count, subnet_id=self.subnet.id, instance_type=instance_type, key_name=key, secgroup_ids=self.vpc.secgroup_ids, user_data=user_data, hosted_zone_id=self.vpc.hosted_zone_id, reverse_hosted_zone_id=self.vpc.reverse_hosted_zone_id, role=self.role )
def cell_resources(ctx, vpc_id, subnet_name): """Show Cell""" domain = ctx.obj['DOMAIN'] connection.Connection.context.domain = domain if subnet_name: click.echo( pprint(subnet.Subnet(name=subnet_name, vpc_id=vpc_id).show())) return if vpc_id: vpcs = [vpc_id] else: vpcs = [_vpc.id for _vpc in vpc.VPC.all()] result = [] for v in vpcs: subnets = vpc.VPC(id=v).list_cells() if subnets: result.append({'VpcId': v, 'Subnets': subnets}) click.echo(pprint(result))
def cell_resources(subnet_id): """Show Cell""" click.echo(pprint(subnet.Subnet(id=subnet_id).show()))
def test_setup_ipa_and_ldap_in_same_subnet(self): self.destroy_attempted = False result_init = self.runner.invoke( self.configure_cli, [ '--domain=treadmill.org', 'init', 'vpc', '--name=' + self.vpc_name ], obj={} ) subnet_info = {} vpc_info = {} try: vpc_info = ast.literal_eval(result_init.output) except Exception as e: if result_init.exception: print(result_init.exception) else: print(e) self.vpc_id = vpc_info['VpcId'] self.assertIsNotNone(vpc_info['VpcId']) self.assertEqual(vpc_info['Subnets'], []) result_domain_init = self.runner.invoke( self.configure_cli, [ '--domain=treadmill.org', 'init', 'domain', '--tm-release=0.1.0', '--key=ms_treadmill_dev', '--image=RHEL-7.4', '--vpc-name=' + self.vpc_name, '--subnet-cidr-block=172.23.0.0/24', '--ipa-admin-password=Tre@dmill1', '--subnet-name=TreadmillIPA' ], obj={} ) try: subnet_info = ast.literal_eval(result_domain_init.output) except Exception as e: if result_domain_init.exception: print(result_domain_init.exception) else: print(e) _vpc = vpc.VPC(id=vpc_info['VpcId']) vpc_info = _vpc.show() self.assertEqual(subnet_info['VpcId'], vpc_info['VpcId']) self.assertEqual(len(subnet_info['Instances']), 1) self.assertCountEqual( [i['Name'] for i in subnet_info['Instances']], ['TreadmillIPA1'] ) self.assertIsNotNone(subnet_info['SubnetId']) self.assertEqual(len(vpc_info['Subnets']), 1) self.assertEqual(vpc_info['Subnets'][0], subnet_info['SubnetId']) result_ldap_init = self.runner.invoke( self.configure_cli, [ '--domain=treadmill.org', 'init', 'ldap', '--tm-release=0.1.0', '--key=ms_treadmill_dev', '--image=RHEL-7.4', '--vpc-name=' + self.vpc_name, '--subnet-name=TreadmillIPA', '--ipa-admin-password=Tre@dmill1', ], obj={} ) try: ldap_subnet_info = ast.literal_eval(result_ldap_init.output) except Exception as e: if result_ldap_init.exception: print(result_ldap_init.exception) else: print(e) self.assertEqual(ldap_subnet_info['SubnetId'], subnet_info['SubnetId']) self.assertEqual(len(ldap_subnet_info['Instances']), 2) self.assertCountEqual( [i['Name'] for i in ldap_subnet_info['Instances']], ['TreadmillIPA1', 'TreadmillLDAP1'] ) self.runner.invoke( self.configure_cli, [ '--domain=treadmill.org', 'delete', 'domain', '--vpc-name=' + self.vpc_name, '--subnet-name=TreadmillIPA', ], obj={} ) _subnet = subnet.Subnet(id=subnet_info['SubnetId']) _subnet_resources = _subnet.show() self.assertEqual(len(_subnet_resources['Instances']), 1) self.assertCountEqual( [i['Name'] for i in _subnet_resources['Instances']], ['TreadmillLDAP1'] ) self.runner.invoke( self.configure_cli, [ '--domain=treadmill.org', 'delete', 'ldap', '--vpc-name=' + self.vpc_name, '--subnet-name=TreadmillIPA', ], obj={} ) _vpc.subnet_ids = [] vpc_info = _vpc.show() self.assertEqual(len(vpc_info['Subnets']), 0) self.runner.invoke( self.configure_cli, [ '--domain=treadmill.org', 'delete', 'vpc', '--vpc-name=' + self.vpc_name, ], obj={} ) self.destroy_attempted = True with self.assertRaises(ClientError) as error: _vpc.ec2_conn.describe_vpcs( VpcIds=[vpc_info['VpcId']] ) self.assertEqual( error.exception.response['Error']['Code'], 'InvalidVpcID.NotFound' )
def delete_cell(ctx, vpc_id, subnet_name): """Delete Cell (Subnet)""" connection.Connection.context.domain = ctx.obj['DOMAIN'] subnet.Subnet(vpc_id=vpc_id, name=subnet_name).destroy()