当前位置: 首页>>代码示例>>Python>>正文


Python server_conf.ServerConf类代码示例

本文整理汇总了Python中cpc.util.conf.server_conf.ServerConf的典型用法代码示例。如果您正苦于以下问题:Python ServerConf类的具体用法?Python ServerConf怎么用?Python ServerConf使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ServerConf类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: establishOutboundConnection

def establishOutboundConnection(node):
    conf = ServerConf()

    for i in range(0, conf.getNumPersistentConnections()):
        try:
            #This will make a regular call, the connection pool will take
            # care of the rest
            message = PersistentServerMessage(node, conf)
            resp = message.persistOutgoingConnection()
            node.addOutboundConnection()

        except ServerConnectionError as e:
            #The node is not reachable at this moment,
            # no need to throw an exception since we are marking the node
            # as unreachable in ServerConnection
            log.log(cpc.util.log.TRACE, "Exception when establishing "
                                        "outgoing connections: %s " % e)
            break

    if node.isConnectedOutbound():
        log.log(cpc.util.log.TRACE,"Established outgoing "
                                   "connections to server "
                                   "%s"%node.toString())

    else:
        log.log(cpc.util.log.TRACE,"Could not establish outgoing "
                                   "connections to %s"%node.toString())
开发者ID:abhirathb,项目名称:copernicus,代码行数:27,代码来源:server_state.py

示例2: saveProject

    def saveProject(self,project):
        self.taskExecThreads.acquire()
        conf = ServerConf()
        try:
            self.taskExecThreads.pause()
            self._write()
            projectFolder = "%s/%s"%(conf.getRunDir(),project)
            if(os.path.isdir(projectFolder)):
                #tar the project folder but keep the old files also, this is
                # only a backup!!!
                #copy _state.xml to _state.bak.xml
                stateBackupFile = "%s/_state.bak.xml"%projectFolder
                shutil.copyfile("%s/_state.xml"%projectFolder,stateBackupFile)
                tff=tempfile.TemporaryFile()
                tf=tarfile.open(fileobj=tff, mode="w:gz")
                tf.add(projectFolder, arcname=".", recursive=True)
                tf.close()
                del(tf)
                tff.seek(0)
                os.remove(stateBackupFile)
                self.taskExecThreads.cont()
            else:
                self.taskExecThreads.cont()
                raise Exception("Project does not exist")
        finally:
            self.taskExecThreads.release()

        return tff
开发者ID:abhirathb,项目名称:copernicus,代码行数:28,代码来源:server_state.py

示例3: establishInboundConnection

def establishInboundConnection(node, serverState):
    conf=ServerConf()

    for i in range(0, conf.getNumPersistentConnections()):
        try:
            message = PersistentServerMessage(node, conf)
            socket = message.persistIncomingConnection()
            serverState.addReadableSocket(socket)
            node.addInboundConnection()


        except ServerConnectionError as e:
            #The node is not reachable at this moment,
            # no need to throw an exception since we are marking the node
            # as unreachable ins ServerConnectionHandler
            log.log(cpc.util.log.TRACE, "Exception when establishing "
                                        "inbound connections: %s " % e)
            break

    if node.isConnectedInbound():
        log.log(cpc.util.log.TRACE, "Established inbound "
                                "connections to server "
                                "%s" % node.toString())
    else:
        log.log(cpc.util.log.TRACE, "Could not establish inbound "
                                "connections to server "
                                "%s" % node.toString())
开发者ID:abhirathb,项目名称:copernicus,代码行数:27,代码来源:server_state.py

示例4: run

    def run(self, serverState, request, response):
        conf = ServerConf()
        host = request.getParam('host')

        client_secure_port = request.getParam('client_secure_port')
        result = dict()
        #do we have a server with this hostname or fqdn?
        connectedNodes = conf.getNodes()

        if (connectedNodes.hostnameOrFQDNExists(host) == False):
            serv = RawServerMessage(host, client_secure_port)
            resp = ProcessedResponse(serv.sendAddNodeRequest(host))

            if resp.isOK():
                result = resp.getData()
                nodeConnectRequest = NodeConnectRequest(result['serverId'],
                    int(client_secure_port),None,None,result['fqdn'],host)

                conf.addSentNodeConnectRequest(nodeConnectRequest)
                result['nodeConnectRequest']=nodeConnectRequest
                log.info("Added node %s" % host)
                response.add('', result)
            else:
                response.add("Remote server said: %s"%resp.getMessage(),
                            status="ERROR")

        else:
            errorMessage = "%s is already trusted" % host
            response.add(errorMessage, status="ERROR")
            log.info(errorMessage)
开发者ID:abhirathb,项目名称:copernicus,代码行数:30,代码来源:network.py

示例5: __persistConnection

    def __persistConnection(self,direction,headers = dict()):
        headers['persistent-connection'] = direction
        #message body is actually irrellevant and is not read on the other
        # side.
        #we just need to conform to the http protocol
        fields = []
        fields.append(Input('cmd', "persist-connection"))

        #sending along the connection parameters for this server
        conf = ServerConf()
        connectionParams = dict()
        connectionParams['serverId'] = conf.getServerId()
        connectionParams['hostname'] = conf.getHostName()
        connectionParams['fqdn'] = conf.getFqdn()
        connectionParams['client_secure_port'] = conf\
        .getClientSecurePort()
        connectionParams['server_secure_port'] = conf\
        .getServerSecurePort()


        input2 = Input('connectionParams',
            json.dumps(connectionParams,default = json_serializer.toJson,
                indent=4))  # a json structure that needs to be dumped
        fields.append(input2)


        response= self.putRequest(ServerRequest.prepareRequest(fields, [],
            headers))

        return response
开发者ID:abhirathb,项目名称:copernicus,代码行数:30,代码来源:direct_message.py

示例6: readProjectState

    def readProjectState(self, projectName):
        prj = self.projects[projectName]

        conf = ServerConf()
        projectBaseDir = "%s/%s" % (conf.getRunDir(), projectName)

        # We have a couple of hardcoded paths that might not be valid anymore
        # Think of the case when we are moving projects to another server
        # here we replace those old paths with new valid paths

        stateBakXML = "%s/%s" % (projectBaseDir, "_state.bak.xml")
        # /get the state_bak.xml
        file = open(stateBakXML, "r")
        content = file.read()
        file.close()

        # find first occurence of <env ..... base_dir=<BASE_DIR>
        m = re.search('<env .* base_dir="(.*)".*>', content)
        if m != None:  # only if we have a project with active tasks
            oldBaseDir = m.group(1)

            new_content = re.sub(oldBaseDir, projectBaseDir, content)

            file = open(stateBakXML, "w")
            file.write(new_content)
            file.close()

        # reread project state
        prj.readState(stateFile="_state.bak.xml")
开发者ID:kassonlab,项目名称:copernicus,代码行数:29,代码来源:projectlist.py

示例7: test_createConf

 def test_createConf(self):
     self.createConfFolder(0)
     
     conf = ServerConf(None,self.serverConfs[0])
     
     test =conf.getServerKeyDir()
     
     self.assertTrue(os.path.isdir(conf.getServerKeyDir()))
开发者ID:abhirathb,项目名称:copernicus,代码行数:8,代码来源:test_network.py

示例8: establishOutBoundConnections

def establishOutBoundConnections():
    conf = ServerConf()

    log.log(cpc.util.log.TRACE,"Starting to establish outgoing connections")

    for node in conf.getNodes().nodes.itervalues():
        establishOutboundConnection(node)

    log.log(cpc.util.log.TRACE,"Finished establishing outgoing "
                               "connections")
开发者ID:abhirathb,项目名称:copernicus,代码行数:10,代码来源:server_state.py

示例9: testAddNodes

 def testAddNodes(self):
     conf = ServerConf(confdir=self.confDir)
     conf.addNode('localhost1')
     conf.addNode('localhost2')
     
     nodes = conf.getNodes()
     self.assertEquals(nodes.size(),2)
     
     self.assertTrue(nodes.exists("localhost1","13807"))
     self.assertTrue(nodes.exists("localhost2","13807") )
开发者ID:abhirathb,项目名称:copernicus,代码行数:10,代码来源:test_server_conf.py

示例10: establishInboundConnections

def establishInboundConnections(serverState):
    """
    for each node that is not connected
    try to establish an inbound connection
    """
    conf = ServerConf()
    log.log(cpc.util.log.TRACE,"Starting to establish incoming connections")
    for node in conf.getNodes().nodes.itervalues():
        establishInboundConnection(node, serverState)

    log.log(cpc.util.log.TRACE,"Finished establishing incoming "
                                   "connections")
开发者ID:abhirathb,项目名称:copernicus,代码行数:12,代码来源:server_state.py

示例11: initTracker

def initTracker():
    conf = ServerConf()
    dirs= Asset.getDirs()
    try:
        os.makedirs(conf.getLocalAssetsDir())
    except:
        pass
    for dir in dirs:
        try:
            os.makedirs(os.path.join(conf.getLocalAssetsDir(), dir))
        except:
            pass
开发者ID:abhirathb,项目名称:copernicus,代码行数:12,代码来源:tracker.py

示例12: DBHandler

class DBHandler(object):
    """
    Provides access to the server database. Can be used from several threads.
    example usage is
        handler = DBHandler()
        with handler.getCursor() as c:
            c.execute("query")
            c.execute("query")
    This provides a transactional cursor which will rollback any changes if an
    exception is throw at any time during the 'with' clause. The changes are
    committed once the with-clause goes out of scope.
    Note that transaction only cover DML statements and will implicitly commit
    before any non-dml, such as a CREATE TABLE
    """
    def __init__(self):
        from cpc.util.conf.server_conf import ServerConf
        self.conf = ServerConf()
        self.dbpath = os.path.join(self.conf.getConfDir(),'users.db')

    def getCursor(self):
        return DBCursor(self.dbpath)

    def allocateDatabase(self):
        if os.path.isfile(self.dbpath):
            raise DataBaseError("Database already exist at %s"%self.dbpath)
        sqlite3.connect(self.dbpath)
开发者ID:abhirathb,项目名称:copernicus,代码行数:26,代码来源:database.py

示例13: testInit

 def testInit(self):
     #init the server conf
     conf = ServerConf(confdir=self.confDir)
     
     self.assertEquals(conf.get('conf_dir'),self.confDir)
     self.assertEquals(self.confFile,conf.get('conf_file'))
     
     
     conf.getServerKeyDir()    #just to make sure it has been initiated the proper way
     conf.setServerHost("testhost")
     
     conf2 = ServerConf(confdir = self.confDir)  #creating a new  instance reinitiates the config and reads parameters from config file  
     self.assertEquals('testhost',conf2.get('server_host'))
开发者ID:abhirathb,项目名称:copernicus,代码行数:13,代码来源:test_server_conf.py

示例14: testStart2Servers

    def testStart2Servers(self):            

        numServers = 2

        self.createConfFolders(numServers)

        hostname = gethostname()
        
        node0HttpsPort = 13807
        node1HttpsPort = 13808
        node0HttpPort = 14807
        node1HttpPort = 14808

        for i in range(numServers):
            args = ['../../../../cpc-server','-c',self.serverConfs[i],'start']  #doing cpc.server.server.forkAndRun(cf, debug ) directly here will will for some strange reason mess up things when shutting down, the process wont shutdown 
            subprocess.call(args)
        
        time.sleep(2)
        
        #connect node 0 to node 1
        args = ['../../../../cpc-server','-c',self.serverConfs[0],'connnect-server',hostname,str(node1HttpPort)]  #doing cpc.server.server.forkAndRun(cf, debug ) directly here will will for some strange reason mess up things when shutting down, the process wont shutdown
        subprocess.call(args)

        args = ['../../../../cpc-server','-c',self.serverConfs[1],'trust',hostname,str(node0HttpsPort)]  #doing cpc.server.server.forkAndRun(cf, debug ) directly here will will for some strange reason mess up things when shutting down, the process wont shutdown
        subprocess.call(args)


        #verify existense of of nodes in each conf file
        conf1 = ServerConf(confdir=self.serverConfs[0], reload=True)
        node0Nodes = conf1.getNodes()
        self.assertTrue(node0Nodes.exists(hostname,node1HttpsPort))

        conf2 = ServerConf(confdir=self.serverConfs[1],reload=True)
        node1Nodes = conf2.getNodes()
        self.assertTrue(node1Nodes.exists(hostname,node0HttpsPort))
                
        
        #do a network topology call        
        conf = ConnectionBundle(confdir=self.serverConfs[0],reload=True)
        client = ClientMessage()        
        topology =ProcessedResponse(client.networkTopology()).getData()
         
        self.assertEquals(topology.size() ,2)
开发者ID:abhirathb,项目名称:copernicus,代码行数:43,代码来源:test_network.py

示例15: __init__

    def __init__(self,host=None,port=None):
        self.conf = ServerConf()
        self.host = host
        self.port = port
        if self.host == None:
            self.host = self.conf.getServerHost()
        if self.port == None:
            self.port = self.conf.getServerSecurePort()

        self.privateKey = self.conf.getPrivateKey()
        self.keychain = self.conf.getCaChainFile()
开发者ID:abhirathb,项目名称:copernicus,代码行数:11,代码来源:untrusted_server_message.py


注:本文中的cpc.util.conf.server_conf.ServerConf类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。