labpack/platforms/aws/rds.py
def list_instances(self, tag_values=None):

        '''
            a method to retrieve the list of instances on AWS RDS

        :param tag_values: [optional] dictionary of tag key-values pairs
        :return: list of strings with db instance AWS ids
        '''

        title = '%s.list_instances' % self.__class__.__name__

    # validate inputs
        input_fields = {
            'tag_values': tag_values
        }
        for key, value in input_fields.items():
            if value:
                object_title = '%s(%s=%s)' % (title, key, str(value))
                self.fields.validate(value, '.%s' % key, object_title)
        self._validate_tags(tag_values, title)

    # add tags to method arguments
        kw_args = {}
        tag_text = ''
        if tag_values:
            kw_args = {
                'Filters': []
            }
            tag_words = []
            for key, value in tag_values.items():
                kw_args['Filters'].append({ 'Name': 'tag:%s' % key, 'Values': [value] })
            from labpack.parsing.grammar import join_words
            plural_value = ''
            if len(tag_values) > 1:
                plural_value = 's'
            tag_text = ' with tag value%s %s' % (plural_value, join_words(tag_words))

    # request instance details from AWS
        self.iam.printer('Querying AWS region %s for db instances%s.' % (self.iam.region_name, tag_text))
        instance_list = []
        try:
            if tag_values:
                response = self.connection.describe_db_instances(**kw_args)
            else:
                response = self.connection.describe_db_instances()
        except:
            raise AWSConnectionError(title)

    # repeat request if any instances are currently pending
        response_list = response['DBInstances']
        # for instance in response_list:
        #     instance_info = instance['Instances'][0]
        #     if instance_info['State']['Name'] == 'pending':
        #         self.check_instance_state(instance_info['InstanceId'])
        #         try:
        #             if tag_values:
        #                 response = self.connection.describe_instances(**kw_args)
        #             else:
        #                 response = self.connection.describe_instances()
        #         except:
        #             raise AWSConnectionError(title)
        #         response_list = response['Reservations']

    # populate list of instances with instance details
        for instance in response_list:
            status_name = instance['DBInstanceStatus']
            if status_name not in ('shutting-down', 'terminated', 'deleting'):
                instance_list.append(instance['DBInstanceIdentifier'])

    # report results and return details
        if instance_list:
            print_out = 'Found db instance'
            if len(instance_list) > 1:
                print_out += 's'
            from labpack.parsing.grammar import join_words
            print_out += ' %s.' % join_words(instance_list)
            self.iam.printer(print_out)
        else:
            self.iam.printer('No db instances found.')

        return instance_list

            a method to retrieve the list of instances on AWS RDS

        :param tag_values: [optional] dictionary of tag key-values pairs
        :return: list of strings with db instance AWS ids
        
a method to retrieve the list of instances on AWS RDS
a method to retrieve the list of instances on AWS RDS
def list_instances(self, tag_values=None):
        title = '%s.list_instances' % self.__class__.__name__
        input_fields = {
            'tag_values': tag_values
        }
        for key, value in input_fields.items():
            if value:
                object_title = '%s(%s=%s)' % (title, key, str(value))
                self.fields.validate(value, '.%s' % key, object_title)
        self._validate_tags(tag_values, title)
        kw_args = {}
        tag_text = ''
        if tag_values:
            kw_args = {
                'Filters': []
            }
            tag_words = []
            for key, value in tag_values.items():
                kw_args['Filters'].append({ 'Name': 'tag:%s' % key, 'Values': [value] })
            from labpack.parsing.grammar import join_words
            plural_value = ''
            if len(tag_values) > 1:
                plural_value = 's'
            tag_text = ' with tag value%s %s' % (plural_value, join_words(tag_words))
        self.iam.printer('Querying AWS region %s for db instances%s.' % (self.iam.region_name, tag_text))
        instance_list = []
        try:
            if tag_values:
                response = self.connection.describe_db_instances(**kw_args)
            else:
                response = self.connection.describe_db_instances()
        except:
            raise AWSConnectionError(title)
        response_list = response['DBInstances']
        for instance in response_list:
            status_name = instance['DBInstanceStatus']
            if status_name not in ('shutting-down', 'terminated', 'deleting'):
                instance_list.append(instance['DBInstanceIdentifier'])
        if instance_list:
            print_out = 'Found db instance'
            if len(instance_list) > 1:
                print_out += 's'
            from labpack.parsing.grammar import join_words
            print_out += ' %s.' % join_words(instance_list)
            self.iam.printer(print_out)
        else:
            self.iam.printer('No db instances found.')
        return instance_list
def list_instances ( self , tag_values = None ) : title = '%s.list_instances' % self . __class__ . __name__ input_fields = { 'tag_values' : tag_values } for key , value in input_fields . items ( ) : if value : object_title = '%s(%s=%s)' % ( title , key , str ( value ) ) self . fields . validate ( value , '.%s' % key , object_title ) self . _validate_tags ( tag_values , title ) kw_args = { } tag_text = '' if tag_values : kw_args = { 'Filters' : [ ] } tag_words = [ ] for key , value in tag_values . items ( ) : kw_args [ 'Filters' ] . append ( { 'Name' : 'tag:%s' % key , 'Values' : [ value ] } ) from labpack . parsing . grammar import join_words plural_value = '' if len ( tag_values ) > 1 : plural_value = 's' tag_text = ' with tag value%s %s' % ( plural_value , join_words ( tag_words ) ) self . iam . printer ( 'Querying AWS region %s for db instances%s.' % ( self . iam . region_name , tag_text ) ) instance_list = [ ] try : if tag_values : response = self . connection . describe_db_instances ( ** kw_args ) else : response = self . connection . describe_db_instances ( ) except : raise AWSConnectionError ( title ) response_list = response [ 'DBInstances' ] for instance in response_list : status_name = instance [ 'DBInstanceStatus' ] if status_name not in ( 'shutting-down' , 'terminated' , 'deleting' ) : instance_list . append ( instance [ 'DBInstanceIdentifier' ] ) if instance_list : print_out = 'Found db instance' if len ( instance_list ) > 1 : print_out += 's' from labpack . parsing . grammar import join_words print_out += ' %s.' % join_words ( instance_list ) self . iam . printer ( print_out ) else : self . iam . printer ( 'No db instances found.' ) return instance_list
a method to retrieve the list of instances on AWS RDS
a method to retrieve the list of instances on AWS RDS
'''
            a method to retrieve the list of instances on AWS RDS

        :param tag_values: [optional] dictionary of tag key-values pairs
        :return: list of strings with db instance AWS ids
        ''' # validate inputs # add tags to method arguments # request instance details from AWS # repeat request if any instances are currently pending # for instance in response_list: #     instance_info = instance['Instances'][0] #     if instance_info['State']['Name'] == 'pending': #         self.check_instance_state(instance_info['InstanceId']) #         try: #             if tag_values: #                 response = self.connection.describe_instances(**kw_args) #             else: #                 response = self.connection.describe_instances() #         except: #             raise AWSConnectionError(title) #         response_list = response['Reservations'] # populate list of instances with instance details # report results and return details
list of strings with db instance AWS ids
list of strings with db instance AWS ids
self
tag_values
[optional] dictionary of tag key-values pairs
[ optional ] dictionary of tag key - values pairs