labpack/platforms/aws/ec2.py
def list_subnets(self, tag_values=None):

        '''
            a method to discover the list of subnets on AWS EC2

        :param tag_values: [optional] list of tag values
        :return: list of strings with subnet ids
        '''

        title = '%s.list_subnets' % 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 subnets%s.' % (self.iam.region_name, tag_text))
        subnet_list = []
        try:
            if kw_args:
                response = self.connection.describe_subnets(**kw_args)
            else:
                response = self.connection.describe_subnets()
        except:
            raise AWSConnectionError(title)
        response_list = []
        if 'Subnets' in response:
            response_list = response['Subnets']

    # construct list of subnets from response
        for sub_dict in response_list:
            subnet_list.append(sub_dict['SubnetId'])

    # report results and return list
        if subnet_list:
            print_out = 'Found subnet'
            if len(subnet_list) > 1:
                print_out += 's'
            from labpack.parsing.grammar import join_words
            print_out += ' %s.' % join_words(subnet_list)
            self.iam.printer(print_out)
        else:
            self.iam.printer('No subnets found.')

        return subnet_list

            a method to discover the list of subnets on AWS EC2

        :param tag_values: [optional] list of tag values
        :return: list of strings with subnet ids
        
a method to discover the list of subnets on AWS EC2
a method to discover the list of subnets on AWS EC2
def list_subnets(self, tag_values=None):
        title = '%s.list_subnets' % 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 subnets%s.' % (self.iam.region_name, tag_text))
        subnet_list = []
        try:
            if kw_args:
                response = self.connection.describe_subnets(**kw_args)
            else:
                response = self.connection.describe_subnets()
        except:
            raise AWSConnectionError(title)
        response_list = []
        if 'Subnets' in response:
            response_list = response['Subnets']
        for sub_dict in response_list:
            subnet_list.append(sub_dict['SubnetId'])
        if subnet_list:
            print_out = 'Found subnet'
            if len(subnet_list) > 1:
                print_out += 's'
            from labpack.parsing.grammar import join_words
            print_out += ' %s.' % join_words(subnet_list)
            self.iam.printer(print_out)
        else:
            self.iam.printer('No subnets found.')
        return subnet_list
def list_subnets ( self , tag_values = None ) : title = '%s.list_subnets' % 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 subnets%s.' % ( self . iam . region_name , tag_text ) ) subnet_list = [ ] try : if kw_args : response = self . connection . describe_subnets ( ** kw_args ) else : response = self . connection . describe_subnets ( ) except : raise AWSConnectionError ( title ) response_list = [ ] if 'Subnets' in response : response_list = response [ 'Subnets' ] for sub_dict in response_list : subnet_list . append ( sub_dict [ 'SubnetId' ] ) if subnet_list : print_out = 'Found subnet' if len ( subnet_list ) > 1 : print_out += 's' from labpack . parsing . grammar import join_words print_out += ' %s.' % join_words ( subnet_list ) self . iam . printer ( print_out ) else : self . iam . printer ( 'No subnets found.' ) return subnet_list
a method to discover the list of subnets on AWS EC2
a method to discover the list of subnets on AWS EC2
'''
            a method to discover the list of subnets on AWS EC2

        :param tag_values: [optional] list of tag values
        :return: list of strings with subnet ids
        ''' # validate inputs # add tags to method arguments # request instance details from AWS # construct list of subnets from response # report results and return list
list of strings with subnet ids
list of strings with subnet ids
self
tag_values
[optional] list of tag values
[ optional ] list of tag values