mirror of
https://github.com/dkmstr/openuds.git
synced 2024-12-22 13:34:04 +03:00
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
|
||||
-- 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
|
||||
|
@ -1,15 +1,19 @@
|
||||
'''
|
||||
@author: Ben Mackey (getHwAddr) and paul cannon (getIpAddr)
|
||||
@author: Ben Mackey (getHwAddr) and paul cannon (getIpAddr)
|
||||
@see: http://code.activestate.com/recipes/439094-get-the-ip-address-associated-with-a-network-inter/
|
||||
'''
|
||||
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 ])
|
||||
try:
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', ifname[:15]))
|
||||
info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', ifname[:15]))
|
||||
return ''.join(['%02x:' % ord(char) for char in info[18:24]])[:-1]
|
||||
except Exception:
|
||||
return None
|
||||
@ -35,8 +39,8 @@ 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)
|
||||
outbytes = struct.unpack('iL', fcntl.ioctl(
|
||||
@ -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]
|
||||
|
@ -17,20 +17,20 @@ INFO_MSG = 'info'
|
||||
IP_MSG = 'ip'
|
||||
|
||||
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)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def initialize():
|
||||
Rpc._manager = Rpc(config['server'], config['ssl'], config['timeout'])
|
||||
|
||||
|
||||
def test(self):
|
||||
try:
|
||||
self._server.test()
|
||||
@ -39,51 +39,52 @@ class Rpc(object):
|
||||
except Exception:
|
||||
logger.error('Test unsuccessful')
|
||||
return False
|
||||
|
||||
|
||||
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 ''
|
||||
|
||||
|
||||
@staticmethod
|
||||
def login(username):
|
||||
if Rpc._manager is None: # Not managed
|
||||
if Rpc._manager is None: # Not managed
|
||||
return
|
||||
return Rpc._manager.message(LOGIN_MSG, username)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def logout(username):
|
||||
if Rpc._manager is None: # Not managed
|
||||
if Rpc._manager is None: # Not managed
|
||||
return
|
||||
return Rpc._manager.message(LOGOUT_MSG, username)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def getInfo():
|
||||
if Rpc._manager is None: # Not managed
|
||||
if Rpc._manager is None: # Not managed
|
||||
return
|
||||
return Rpc._manager.message(INFO_MSG, '')
|
||||
|
||||
|
||||
@staticmethod
|
||||
def setReady():
|
||||
if Rpc._manager is None: # Not managed
|
||||
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() ] )
|
||||
if Rpc._manager is None: # Not managed
|
||||
return None
|
||||
interfaces = ','.join([ v['mac'] + '=' + v['ip'] for v in net.getExternalIpAndMacs().values() ])
|
||||
return Rpc._manager.message(IP_MSG, interfaces)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def resetId():
|
||||
logger.debug('Reseting rpc id')
|
||||
Rpc._manager._id = None
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user