當前位置: 首頁>>代碼示例>>Python>>正文


Python Compute.get_instance_local_ip方法代碼示例

本文整理匯總了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
開發者ID:NHDaly,項目名稱:JuliaBox,代碼行數:35,代碼來源:jbox_tasks.py

示例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)
開發者ID:NHDaly,項目名稱:JuliaBox,代碼行數:27,代碼來源:jbox_tasks.py


注:本文中的cloud.Compute.get_instance_local_ip方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。