def take_action(self, parsed_args): env_name = parsed_args.environment self.log.debug('Getting all instances in environment %s', env_name) ec2_client = self.app.client.ec2_client() subnet_id = helper.get_subnet_id_by_name(ec2_client, env_name) subnet_resource = self.app.client.ec2_subnet_resource(subnet_id) instances = subnet_resource.instances.all() instances_data = helper.parse_instances_data(instances) columns = ( 'Name', 'State', 'WRK', 'Launched_by' ) data = {} if instances_data: self.log.debug('Constructing Lister data for instances.') data = ( ( instance['Name'], instance['State'], instance['Wrk'], instance['Launched_by'] ) for instance in instances_data ) return columns, data else: self.log.info('No instances found in the subnet') return columns, data
def take_action(self, parsed_args): env_name = parsed_args.environment self.log.debug('Getting all instances in environment %s', env_name) ec2_client = self.app.client.ec2_client() subnet_id = helper.get_subnet_id_by_name(ec2_client, env_name) subnet_resource = self.app.client.ec2_subnet_resource(subnet_id) instances = subnet_resource.instances.all() instances_data = helper.parse_instances_data(instances) columns = ('Name', 'State', 'WRK', 'Launched_by') data = {} if instances_data: self.log.debug('Constructing Lister data for instances.') data = ((instance['Name'], instance['State'], instance['Wrk'], instance['Launched_by']) for instance in instances_data) return columns, data else: self.log.info('No instances found in the subnet') return columns, data
def take_action(self, parsed_args): environment = parsed_args.environment wrk = parsed_args.wrk self.log.info('Environment is %s', environment) ec2_client = self.app.client.ec2_client() try: subnet_id = helper.get_subnet_id_by_name(ec2_client, environment) subnet = self.app.client.ec2_subnet_resource(subnet_id) helper.update_tag(subnet, 'WRK', wrk) self.log.debug('Getting a list of all instances in the subnet') instances = subnet.instances.all() for instance in instances: helper.update_tag(instance, 'WRK', wrk) volumes = instance.volumes.all() for volume in volumes: helper.update_tag(volume, 'WRK', wrk) except ValueError as err: self.log.error(err.args)