def __init__(self,parameters):
        Thread.__init__(self)

        if VOMSProxyManager.logger==None:
            VOMSProxyManager.logger = mainLogger.get_instance(classid='VOMSProxyManager')
#        if not hasattr(parameters, 'vo') or parameters.vo=='':
#            raise Exception, "Missing vo parameter"

        self.cert, self.key = getUserKeyAndCert()
        if self.cert==None:
            VOMSProxyManager.logger.debug("Using external proxy certificate")
            self.usingProxy = True
            self.proxyFile = getProxyFile()
            if int(self)==0:
                raise Exception, "Proxy %s is expired" % self.proxyFile
            return
        
        VOMSProxyManager.logger.debug("Enabled voms proxy management")
        self.usingProxy = False
        if checkEncryptedKey(self.key):
            self.password = getpass.getpass('Password for user key: ')
        else:
            self.password = ''
        
        self.proxyFile = '/tmp/x509up_u%d_%d' % (os.getuid(), os.getpid())
            
        if hasattr(parameters, 'valid') and parameters.valid<>'':
            tokens = string.split(parameters.valid, ':')
            self.interval = int(tokens[0])*3600 + int(tokens[1])*60
        else:
            self.interval = 600

        self.parameters = parameters
        self.running = True
        self.cond = Condition()
        self.pCond = Condition()
        self.wCheck = False
        self.rCheck = 0
        
        self.renewProxy()
        os.environ['X509_USER_PROXY'] = self.proxyFile
    def __init__(self, address, parameters, jobTable=None, proxyMan=None):
        HTTPServer.__init__(self, address, SOAPRequestHandler)
        
        if os.environ.has_key("X509_CONSUMER_CERT") and \
            os.environ.has_key("X509_CONSUMER_KEY"):
            self.consumerCert = os.environ["X509_CONSUMER_CERT"]
            if not os.path.isfile(self.consumerCert):
                raise Exception, "Cannot find: " + self.consumerCert
            self.consumerKey = os.environ["X509_CONSUMER_KEY"]
            if not os.path.isfile(self.consumerKey):
                raise Exception, "Cannot find: " + self.consumerKey
            
            if testsuite_utils.checkEncryptedKey(self.consumerKey):
                import getpass
                self.password = getpass.getpass('Password for consumer key: ')
            else:
                self.password = ''
#        elif proxyMan<>None and proxyMan.key<>None:
#                self.consumerCert = proxyMan.cert
#                self.consumerKey = proxyMan.key
#                self.password = proxyMan.password
        else:
            self.consumerCert = None
            self.consumerKey = None
            self.password = None
        
        if self.consumerKey<>None:
            ConsumerServer.logger.debug("Enabled secure channel for notifications")
            self.ssl_context = SSL.Context(SSL.SSLv23_METHOD)
            buffer = self.readPEMFile(self.consumerKey)
            if self.password<>'':
                privateKey = crypto.load_privatekey(crypto.FILETYPE_PEM, 
                                                    buffer, self.password)
            else:
                privateKey = crypto.load_privatekey(crypto.FILETYPE_PEM, buffer)
            self.ssl_context.use_privatekey(privateKey)
            self.ssl_context.use_certificate_file(self.consumerCert)
            caStore = self.ssl_context.get_cert_store()
            caList = glob.glob(testsuite_utils.getCACertDir() + "/*.0")
            for item in caList:
                buffer = self.readPEMFile(item)
                caCert = crypto.load_certificate(crypto.FILETYPE_PEM, buffer)
                caStore.add_cert(caCert)
            
            tmpsock = socket.socket(self.address_family,self.socket_type)
            self.socket = TSafeConnection(self.ssl_context, tmpsock)
            self.socket.settimeout(30)
            self.server_bind()
            self.server_activate()
        else:
            self.ssl_context = None
        
        self.jobTable = jobTable
        self.parameters = parameters
        self.running = False
        self.servicePrefix = 'https://' + parameters.resourceURI[:string.find(parameters.resourceURI,'/') + 1]
        self.cemonURL = self.servicePrefix + "ce-monitor/services/CEMonitor"
        
        self.proxyFile = testsuite_utils.getProxyFile()
        self.subscrId = job_utils.subscribeToCREAMJobs(self.cemonURL, \
                                                       self.parameters, self.proxyFile, self.ssl_context<>None)