forked from shaba/openuds
Updating linux actor
This commit is contained in:
parent
af2de4881f
commit
9bdfb4a7eb
@ -1,8 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<?eclipse-pydev version="1.0"?>
|
||||
|
||||
<pydev_project>
|
||||
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">python2.6</pydev_property>
|
||||
<?eclipse-pydev version="1.0"?><pydev_project>
|
||||
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
|
||||
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.6</pydev_property>
|
||||
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
|
||||
<path>/linuxActor/src</path>
|
||||
|
@ -1,3 +1,9 @@
|
||||
udsactor (1.1) stable; urgency=medium
|
||||
|
||||
* Fixing IP notification issues
|
||||
|
||||
-- Adolfo Gómez García <dkmaster@dkmon.com> Fri, 23 May 2014 13:00:32 +0200
|
||||
|
||||
udsactor (1.0) stable; urgency=low
|
||||
* Initial version
|
||||
-- Adolfo Gómez García <agomez@virtualcable.es> Fri, 18 Nov 2011 05:35:11 +0100
|
@ -1 +1 @@
|
||||
udsactor_1.0_all.deb contrib/net extra
|
||||
udsactor_1.1_all.deb contrib/net extra
|
||||
|
@ -4,6 +4,10 @@
|
||||
'''
|
||||
import fcntl, socket, struct, array, platform
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def getMacAddr(ifname):
|
||||
if isinstance(ifname, list):
|
||||
return dict([ (name, getMacAddr(name)) for name in ifname ])
|
||||
@ -35,7 +39,7 @@ def getInterfaces():
|
||||
elif platform.architecture()[0] == '64bit':
|
||||
offset, length = 16, 40
|
||||
else:
|
||||
raise OSError('Unknown arquitecture {0}'.format( platform.architecture()[0]))
|
||||
raise OSError('Unknown arquitecture {0}'.format(platform.architecture()[0]))
|
||||
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
names = array.array('B', '\0' * space)
|
||||
@ -45,16 +49,17 @@ def getInterfaces():
|
||||
struct.pack('iL', space, names.buffer_info()[0])
|
||||
))[0]
|
||||
namestr = names.tostring()
|
||||
return [namestr[i:i+offset].split('\0', 1)[0] for i in range(0, outbytes, length)]
|
||||
return [namestr[i:i + offset].split('\0', 1)[0] for i in range(0, outbytes, length)]
|
||||
|
||||
def getIpAndMac(ifname):
|
||||
ip, mac = getIpAddr(ifname), getMacAddr(ifname)
|
||||
if isinstance(ifname, list):
|
||||
return dict( [ (key, { 'ip': ip[key], 'mac': mac[key] }) for key in ip.keys() ] )
|
||||
return dict([ (key, { 'ip': ip[key], 'mac': mac[key] }) for key in ip.keys() ])
|
||||
return (ip, mac)
|
||||
|
||||
def getExternalIpAndMacs():
|
||||
res = getIpAndMac(getInterfaces())
|
||||
logger.debug('Res: {0}'.format(res))
|
||||
for key in res.keys():
|
||||
if res[key]['mac'] == '00:00:00:00:00:00':
|
||||
del res[key]
|
||||
|
@ -21,9 +21,9 @@ class Rpc(object):
|
||||
_manager = None
|
||||
|
||||
def __init__(self, broker, ssl, timeout=10):
|
||||
url = ( ssl and 'https' or 'http' ) + '://' + broker + '/xmlrpc'
|
||||
url = (ssl and 'https' or 'http') + '://' + broker + '/xmlrpc'
|
||||
logger.debug('Remote address: {0}'.format(url))
|
||||
self._server = xmlrpclib.ServerProxy(uri = url, verbose=False)
|
||||
self._server = xmlrpclib.ServerProxy(uri=url, verbose=False)
|
||||
self._id = None
|
||||
socket.setdefaulttimeout(timeout)
|
||||
|
||||
@ -43,10 +43,11 @@ class Rpc(object):
|
||||
def message(self, msg, data):
|
||||
try:
|
||||
if self._id is None:
|
||||
self._id = ','.join( [ v['mac'] for v in net.getExternalIpAndMacs().values() ] )
|
||||
self._id = ','.join([ v['mac'] for v in net.getExternalIpAndMacs().values() ])
|
||||
logger.debug('Sending message to broker: {0} -> {1}, {2}'.format(self._id, msg, data))
|
||||
return self._server.message(self._id, msg, data)
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
logger.exception('Error notifyinh message')
|
||||
return None
|
||||
return ''
|
||||
|
||||
@ -72,14 +73,14 @@ class Rpc(object):
|
||||
def setReady():
|
||||
if Rpc._manager is None: # Not managed
|
||||
return
|
||||
interfaces = ','.join( [ v['mac'] + '=' + v['ip'] for v in net.getExternalIpAndMacs().values() ] )
|
||||
interfaces = ','.join([ v['mac'] + '=' + v['ip'] for v in net.getExternalIpAndMacs().values() ])
|
||||
return Rpc._manager.message(READY_MSG, interfaces)
|
||||
|
||||
@staticmethod
|
||||
def notifyIpChange():
|
||||
if Rpc._manager is None: # Not managed
|
||||
return
|
||||
interfaces = ','.join( [ v['mac'] + '=' + v['ip'] for v in net.getExternalIpAndMacs().values() ] )
|
||||
return None
|
||||
interfaces = ','.join([ v['mac'] + '=' + v['ip'] for v in net.getExternalIpAndMacs().values() ])
|
||||
return Rpc._manager.message(IP_MSG, interfaces)
|
||||
|
||||
@staticmethod
|
||||
|
Loading…
Reference in New Issue
Block a user