本文整理汇总了Python中cloud.Compute.get_instance_local_ip方法的典型用法代码示例。如果您正苦于以下问题:Python Compute.get_instance_local_ip方法的具体用法?Python Compute.get_instance_local_ip怎么用?Python Compute.get_instance_local_ip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cloud.Compute
的用法示例。
在下文中一共展示了Compute.get_instance_local_ip方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sendrecv
# 需要导入模块: from cloud import Compute [as 别名]
# 或者: from cloud.Compute import get_instance_local_ip [as 别名]
def sendrecv(self, cmd, data, dest=None, port=None):
if (dest is None) or (dest == 'localhost'):
dest = Compute.get_instance_local_ip()
else:
dest = Compute.get_instance_local_ip(dest)
if port is None:
port = self._rrport
rraddr = 'tcp://%s:%d' % (dest, port)
JBoxAsyncJob.log_debug("sendrecv to %s. connecting...", rraddr)
sock = self._ctx.socket(zmq.REQ)
sock.setsockopt(zmq.LINGER, 5*1000)
sock.connect(rraddr)
poller = zmq.Poller()
poller.register(sock, zmq.POLLOUT)
if poller.poll(10*1000):
sock.send_json(self._make_msg(cmd, data))
else:
sock.close()
raise IOError("could not connect to %s", rraddr)
poller.modify(sock, zmq.POLLIN)
if poller.poll(10*1000):
msg = sock.recv_json()
else:
sock.close()
raise IOError("did not receive anything from %s", rraddr)
JBoxAsyncJob.log_debug("sendrecv to %s. received.", rraddr)
sock.close()
return msg
示例2: __init__
# 需要导入模块: from cloud import Compute [as 别名]
# 或者: from cloud.Compute import get_instance_local_ip [as 别名]
def __init__(self, ports, mode):
self._mode = mode
self._ctx = zmq.Context()
ppmode = zmq.PUSH if (mode == JBoxAsyncJob.MODE_PUB) else zmq.PULL
self._push_pull_sock = self._ctx.socket(ppmode)
rrmode = zmq.REQ if (mode == JBoxAsyncJob.MODE_PUB) else zmq.REP
local_ip = Compute.get_instance_local_ip()
JBoxAsyncJob.log_debug("local hostname [%s]", local_ip)
ppbindaddr = 'tcp://%s:%d' % (local_ip, ports[0],)
ppconnaddr = 'tcp://%s:%d' % (local_ip, ports[0],)
rraddr = 'tcp://%s:%d' % (local_ip, ports[1],)
self._rrport = ports[1]
self._poller = zmq.Poller()
if mode == JBoxAsyncJob.MODE_PUB:
self._push_pull_sock.connect(ppconnaddr)
else:
self._push_pull_sock.bind(ppbindaddr)
self._poller.register(self._push_pull_sock, zmq.POLLIN)
self._req_rep_sock = self._ctx.socket(rrmode)
self._req_rep_sock.bind(rraddr)