本文整理汇总了Python中session.Session.doConnect方法的典型用法代码示例。如果您正苦于以下问题:Python Session.doConnect方法的具体用法?Python Session.doConnect怎么用?Python Session.doConnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类session.Session
的用法示例。
在下文中一共展示了Session.doConnect方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: stopProcess
# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import doConnect [as 别名]
def stopProcess(address, port, dbPassword):
s = Session(address, port=port, service="Monitor")
s.authorize("Cloud", dbPassword)
s.doConnect()
s.send("<Request Action=\"shutdown\"/>")
s.close()
示例2: doDatabaseAction
# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import doConnect [as 别名]
def doDatabaseAction(broker, user, password, db_name, action, child=None):
s = Session(broker, service="ChorusManagement")
s.authorize(user, password)
if child is not None:
child = [ child ]
s.doConnect(attributes={"Database" : db_name, "Action" : action}, children=child)
response = s.recv()
checkForError(response)
s.close()
return response
示例3: monitorEngine
# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import doConnect [as 别名]
def monitorEngine(address, port, dbPassword, listener=None):
if not listener:
listener = _StandardOutListener()
s = Session(address, port=port, service="Monitor")
s.authorize("Cloud", dbPassword)
monitor = SessionMonitor(s, listener=listener)
monitor.start()
s.doConnect()
return EngineMonitor(monitor, s)
示例4: monitorDomainStats
# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import doConnect [as 别名]
def monitorDomainStats(broker, user, password, listener=None):
if not listener:
listener = _StandardOutListener()
s = Session(broker, service="HostStats")
s.authorize(user, password)
s.doConnect()
checkForError(s.recv())
monitor = SessionMonitor(s, listener=listener)
monitor.start()
return monitor
示例5: getCloudEntry
# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import doConnect [as 别名]
def getCloudEntry(broker, db_name, attrs=None):
if not attrs:
attrs = dict()
attrs["Database"] = db_name
s = Session(broker, service="SQL2")
s.doConnect(attributes=attrs)
connectDetail = s.recv()
s.close()
checkForError(connectDetail)
root = ElementTree.fromstring(connectDetail)
if root.tag != "Cloud":
raise SessionException("Unexpecetd response type: " + root.tag)
return (root.get("Address"), int(root.get("Port")))
示例6: queryEngine
# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import doConnect [as 别名]
def queryEngine(address, port, target, dbPassword, msgBody=None):
s = Session(address, port=port, service="Query")
s.authorize("Cloud", dbPassword)
s.doConnect()
msg = "<Query Target=\"%s\"/>" % target
if msgBody is not None:
xml = ElementTree.fromstring(msg)
xml.append(msgBody)
msg = ElementTree.tostring(xml)
s.send(msg)
response = s.recv()
checkForError(response)
s.close()
return response
示例7: Domain
# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import doConnect [as 别名]
class Domain(BaseListener):
"""Represents the NuoDB domain.
The domain is the top level NuoDB management object. The domain object
provides access to the peers and databases that are contained within.
"""
def __init__(self, broker_addr, domain_user, domain_pwd, listener=None):
"""
@type broker_addr str
@type domain_user str
@type domain_pwd str
@type listener
"""
if not domain_pwd:
raise Exception("A password is required to join a domain")
self.__session = Session(broker_addr, service="Monitor")
self.__session.authorize(domain_user, domain_pwd)
self.__user = domain_user
self.__password = domain_pwd
self.__listener = listener
self.__peers = dict()
""" @type : dict[str, Peer] """
self.__databases = dict()
""" @type : dict[str, Database] """
self.__monitor = SessionMonitor(self.__session, self)
# These will be set in handle status after joining the domain
self.__domain_name = None
""" @type : str """
self.__entry_peer = None
""" @type : Peer """
try:
self.__session.doConnect()
self.__handle_status(self.__session.recv())
except Exception:
self.__monitor.close()
raise
self.__monitor.start()
def __str__(self):
return self.domain_name + " [Entered through: " + self.entry_peer.connect_str + "]"
def disconnect(self):
"""Disconnect from the domain."""
self.__monitor.close()
def _send_domain_message(self, service, attributes=None, text=None, children=None):
session = Session(self.__entry_peer.address, port=self.__entry_peer.port, service=service)
session.authorize(self.__user, self.__password)
return session.doRequest(attributes, text, children)
@property
def user(self):
"""Return the domain user."""
return self.__user
@property
def password(self):
"""Return the domain password."""
return self.__password
@property
def domain_name(self):
"""Return the domain name."""
return self.__domain_name
def find_peer(self, address):
"""
Find a peer by address
@type: address str
@rtype: Peer
"""
def get_peer(self, agent_id):
"""
Return a peer for a given agent_id.
@type agent_id str
@rtype: Peer
"""
return self.__peers.get(agent_id)
@property
def peers(self):
"""
Return a list of all peers in the domain.
@rtype: list[Peer]
"""
return self.__peers.values()
@property
def entry_peer(self):
"""
Return the peer that was used to enter the domain.
@rtype: Peer
#.........这里部分代码省略.........
示例8: Domain
# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import doConnect [as 别名]
class Domain(BaseListener):
def __init__(self, brokerAddr, domainUser, domainPwd, listener=None):
if not domainPwd:
raise Exception("A password is required to join a domain")
self.__session = Session(brokerAddr, service="Monitor")
self.__session.authorize(domainUser, domainPwd)
self.__user = domainUser
self.__password = domainPwd
self.__listener = listener
self.__peers = dict()
self.__databases = dict()
self.__monitor = SessionMonitor(self.__session, self)
try:
self.__session.doConnect()
self.__handleStatus(self.__session.recv())
except Exception:
self.__monitor.close()
raise
self.__monitor.start()
def __str__(self):
return self.getDomainName() + " [Entered through: " + self.getEntryPeer().getConnectStr() + "]"
def disconnect(self):
self.__monitor.close()
def getUser(self):
return self.__user
def getPassword(self):
return self.__password
def getDomainName(self):
return self.__domainName
def getPeer(self, agentId):
return self.__peers.get(agentId)
def getPeers(self):
return self.__peers.itervalues()
def getEntryPeer(self):
return self.__entryPeer
def getDatabase(self, name):
return self.__databases.get(name)
def getDatabases(self):
return self.__databases.itervalues()
def getDatabaseCount(self):
return len(self.__databases)
def shutdown(self, graceful=True):
for (dbName, db) in self.__databases.items():
db.shutdown(graceful)
def messageReceived(self, root):
if root.tag == "Event":
eventType = root.get("Type")
if eventType == "NewBroker":
self.__peerJoined(Peer.fromMessage(self, root.find("Broker")))
elif eventType == "BrokerExit":
self.__peerLeft(Peer.fromMessage(self, root.find("Broker")))
elif eventType == "StatusChanged":
status = root.get("Status")
processElement = root.find("Process")
db = self.__databases[processElement.get("Database")]
process = Process.fromMessage(db, processElement)
self.__processStatusChanged(process, status)
elif eventType == "ProcessFailed":
peer = Peer.fromMessage(self, root.find("Broker"))
peer = self.getPeer(peer.getId())
reason = root.get("Reason")
startId = root.get("StartId")
self.__processFailed(peer, startId, reason)
elif eventType == "NewProcess" or eventType == "ProcessExit":
processElement = root.find("Process")
dbName = processElement.get("Database")
if dbName not in self.__databases:
self.__databases[dbName] = Database(self, dbName)
if self.__listener:
try:
self.__listener.databaseJoined(self.__databases[dbName])
except:
pass
if eventType == "NewProcess":
startId = processElement.get("StartId")
self.__processJoined(Process.fromMessage(self.__databases[dbName], processElement), startId)
#.........这里部分代码省略.........