Esempio n. 1
0
    def expand_keypair_globs( self, globs ):
        """
        Returns a list of EC2 key pair objects matching the specified globs. The order of the
        objects in the returned list will be consistent with the order of the globs and it will
        not contain any elements more than once. In other words, the returned list will start
        with all key pairs matching the first glob, followed by key pairs matching the second
        glob but not the first glob and so on.

        :rtype: list of KeyPair
        """

        def iam_lookup( glob ):
            if glob.startswith( '@@' ):
                return (_.user_name for _ in self.iam.get_group( 'developers' ).users)
            elif glob.startswith( '@' ):
                return (self.iam.get_user( glob[ 1: ] ).user_name,)
            else:
                return (glob,)

        globs = itertools.chain.from_iterable( map( iam_lookup, globs ) )

        result = [ ]
        keypairs = dict( (keypair.name, keypair) for keypair in self.ec2.get_all_key_pairs( ) )
        for glob in globs:
            i = len( result )
            for name, keypair in keypairs.iteritems( ):
                if fnmatch.fnmatch( name, glob ):
                    result.append( keypair )

            # since we can't modify the set during iteration
            for keypair in result[ i: ]:
                keypairs.pop( keypair.name )
        return result
Esempio n. 2
0
    def expand_keypair_globs(self, globs):
        """
        Returns a list of EC2 key pair objects matching the specified globs. The order of the
        objects in the returned list will be consistent with the order of the globs and it will
        not contain any elements more than once. In other words, the returned list will start
        with all key pairs matching the first glob, followed by key pairs matching the second
        glob but not the first glob and so on.

        :rtype: list of KeyPair
        """
        def iam_lookup(glob):
            if glob.startswith('@@'):
                return (_.user_name
                        for _ in self.iam.get_group('developers').users)
            elif glob.startswith('@'):
                return (self.iam.get_user(glob[1:]).user_name, )
            else:
                return (glob, )

        globs = itertools.chain.from_iterable(map(iam_lookup, globs))

        result = []
        keypairs = dict((keypair.name, keypair)
                        for keypair in self.ec2.get_all_key_pairs())
        for glob in globs:
            i = len(result)
            for name, keypair in keypairs.iteritems():
                if fnmatch.fnmatch(name, glob):
                    result.append(keypair)

            # since we can't modify the set during iteration
            for keypair in result[i:]:
                keypairs.pop(keypair.name)
        return result
Esempio n. 3
0
 def _list_roles(self, slave_glob):
     slaves = [
         slave
         for slave in check_output([cgcloud, 'list-roles']).split('\n')
         if fnmatch(slave, slave_glob)
     ]
     return slaves
Esempio n. 4
0
 def _list_roles( self, slave_glob ):
     slaves = [ slave
         for slave in check_output( [ cgcloud, 'list-roles' ] ).split( '\n' )
         if fnmatch( slave, slave_glob ) ]
     return slaves