本文整理汇总了Python中cloud.aws.CloudHost.instance_local_ip方法的典型用法代码示例。如果您正苦于以下问题:Python CloudHost.instance_local_ip方法的具体用法?Python CloudHost.instance_local_ip怎么用?Python CloudHost.instance_local_ip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cloud.aws.CloudHost
的用法示例。
在下文中一共展示了CloudHost.instance_local_ip方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sendrecv
# 需要导入模块: from cloud.aws import CloudHost [as 别名]
# 或者: from cloud.aws.CloudHost import instance_local_ip [as 别名]
def sendrecv(self, cmd, data, dest=None, port=None):
if (dest is None) or (dest == 'localhost'):
dest = '127.0.0.1'
else:
dest = CloudHost.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.aws import CloudHost [as 别名]
# 或者: from cloud.aws.CloudHost import 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 = CloudHost.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.bind(ppbindaddr)
else:
self._push_pull_sock.connect(ppconnaddr)
self._poller.register(self._push_pull_sock, zmq.POLLIN)
self._req_rep_sock = self._ctx.socket(rrmode)
self._req_rep_sock.bind(rraddr)