connectors/PYRO/__init__.py
changeset 2478 733d77bf0aa7
parent 2468 046303391dea
child 2492 7dd551ac2fa0
equal deleted inserted replaced
2477:4866c01e7428 2478:733d77bf0aa7
    37 from Pyro.errors import PyroError
    37 from Pyro.errors import PyroError
    38 
    38 
    39 import PSKManagement as PSK
    39 import PSKManagement as PSK
    40 from runtime import PlcStatus
    40 from runtime import PlcStatus
    41 
    41 
    42 zeroconf_service_type = '_PYRO._tcp.local.'
       
    43 # this module attribute contains a list of DNS-SD (Zeroconf) service types
    42 # this module attribute contains a list of DNS-SD (Zeroconf) service types
    44 # supported by this connector confnode.
    43 # supported by this connector confnode.
    45 #
    44 #
    46 # for connectors that do not support DNS-SD, this attribute can be omitted
    45 # for connectors that do not support DNS-SD, this attribute can be omitted
    47 # or set to an empty list.
    46 # or set to an empty list.
    68         Pyro.config.PYROPSK = (secret, ID)
    67         Pyro.config.PYROPSK = (secret, ID)
    69         # strip ID from URL, so that pyro can understand it.
    68         # strip ID from URL, so that pyro can understand it.
    70         location = url
    69         location = url
    71     else:
    70     else:
    72         schemename = "PYROLOC"
    71         schemename = "PYROLOC"
    73 
       
    74     if location.find(zeroconf_service_type) != -1:
       
    75         try:
       
    76             from zeroconf import Zeroconf
       
    77             r = Zeroconf()
       
    78             i = r.get_service_info(zeroconf_service_type, location)
       
    79             if i is None:
       
    80                 raise Exception("'%s' not found" % location)
       
    81             ip = str(socket.inet_ntoa(i.address))
       
    82             port = str(i.port)
       
    83             newlocation = ip + ':' + port
       
    84             confnodesroot.logger.write(_("'{a1}' is located at {a2}\n").format(a1=location, a2=newlocation))
       
    85             location = newlocation
       
    86             r.close()
       
    87         except Exception:
       
    88             confnodesroot.logger.write_error(_("MDNS resolution failure for '%s'\n") % location)
       
    89             confnodesroot.logger.write_error(traceback.format_exc())
       
    90             return None
       
    91 
    72 
    92     # Try to get the proxy object
    73     # Try to get the proxy object
    93     try:
    74     try:
    94         RemotePLCObjectProxy = Pyro.core.getAttrProxyForURI(schemename + "://" + location + "/PLCObject")
    75         RemotePLCObjectProxy = Pyro.core.getAttrProxyForURI(schemename + "://" + location + "/PLCObject")
    95     except Exception:
    76     except Exception: