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"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<?eclipse-pydev version="1.0"?>
|
<?eclipse-pydev version="1.0"?><pydev_project>
|
||||||
|
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
|
||||||
<pydev_project>
|
|
||||||
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">python2.6</pydev_property>
|
|
||||||
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.6</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">
|
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
|
||||||
<path>/linuxActor/src</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
|
udsactor (1.0) stable; urgency=low
|
||||||
* Initial version
|
* 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/
|
@see: http://code.activestate.com/recipes/439094-get-the-ip-address-associated-with-a-network-inter/
|
||||||
'''
|
'''
|
||||||
import fcntl, socket, struct, array, platform
|
import fcntl, socket, struct, array, platform
|
||||||
|
|
||||||
|
import logging
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def getMacAddr(ifname):
|
def getMacAddr(ifname):
|
||||||
if isinstance(ifname, list):
|
if isinstance(ifname, list):
|
||||||
return dict([ (name, getMacAddr(name)) for name in ifname ])
|
return dict([ (name, getMacAddr(name)) for name in ifname ])
|
||||||
try:
|
try:
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
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]
|
return ''.join(['%02x:' % ord(char) for char in info[18:24]])[:-1]
|
||||||
except Exception:
|
except Exception:
|
||||||
return None
|
return None
|
||||||
@ -35,8 +39,8 @@ def getInterfaces():
|
|||||||
elif platform.architecture()[0] == '64bit':
|
elif platform.architecture()[0] == '64bit':
|
||||||
offset, length = 16, 40
|
offset, length = 16, 40
|
||||||
else:
|
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)
|
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
names = array.array('B', '\0' * space)
|
names = array.array('B', '\0' * space)
|
||||||
outbytes = struct.unpack('iL', fcntl.ioctl(
|
outbytes = struct.unpack('iL', fcntl.ioctl(
|
||||||
@ -45,16 +49,17 @@ def getInterfaces():
|
|||||||
struct.pack('iL', space, names.buffer_info()[0])
|
struct.pack('iL', space, names.buffer_info()[0])
|
||||||
))[0]
|
))[0]
|
||||||
namestr = names.tostring()
|
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):
|
def getIpAndMac(ifname):
|
||||||
ip, mac = getIpAddr(ifname), getMacAddr(ifname)
|
ip, mac = getIpAddr(ifname), getMacAddr(ifname)
|
||||||
if isinstance(ifname, list):
|
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)
|
return (ip, mac)
|
||||||
|
|
||||||
def getExternalIpAndMacs():
|
def getExternalIpAndMacs():
|
||||||
res = getIpAndMac(getInterfaces())
|
res = getIpAndMac(getInterfaces())
|
||||||
|
logger.debug('Res: {0}'.format(res))
|
||||||
for key in res.keys():
|
for key in res.keys():
|
||||||
if res[key]['mac'] == '00:00:00:00:00:00':
|
if res[key]['mac'] == '00:00:00:00:00:00':
|
||||||
del res[key]
|
del res[key]
|
||||||
|
@ -17,20 +17,20 @@ INFO_MSG = 'info'
|
|||||||
IP_MSG = 'ip'
|
IP_MSG = 'ip'
|
||||||
|
|
||||||
class Rpc(object):
|
class Rpc(object):
|
||||||
|
|
||||||
_manager = None
|
_manager = None
|
||||||
|
|
||||||
def __init__(self, broker, ssl, timeout=10):
|
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))
|
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
|
self._id = None
|
||||||
socket.setdefaulttimeout(timeout)
|
socket.setdefaulttimeout(timeout)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def initialize():
|
def initialize():
|
||||||
Rpc._manager = Rpc(config['server'], config['ssl'], config['timeout'])
|
Rpc._manager = Rpc(config['server'], config['ssl'], config['timeout'])
|
||||||
|
|
||||||
def test(self):
|
def test(self):
|
||||||
try:
|
try:
|
||||||
self._server.test()
|
self._server.test()
|
||||||
@ -39,51 +39,52 @@ class Rpc(object):
|
|||||||
except Exception:
|
except Exception:
|
||||||
logger.error('Test unsuccessful')
|
logger.error('Test unsuccessful')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def message(self, msg, data):
|
def message(self, msg, data):
|
||||||
try:
|
try:
|
||||||
if self._id is None:
|
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))
|
logger.debug('Sending message to broker: {0} -> {1}, {2}'.format(self._id, msg, data))
|
||||||
return self._server.message(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 None
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def login(username):
|
def login(username):
|
||||||
if Rpc._manager is None: # Not managed
|
if Rpc._manager is None: # Not managed
|
||||||
return
|
return
|
||||||
return Rpc._manager.message(LOGIN_MSG, username)
|
return Rpc._manager.message(LOGIN_MSG, username)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def logout(username):
|
def logout(username):
|
||||||
if Rpc._manager is None: # Not managed
|
if Rpc._manager is None: # Not managed
|
||||||
return
|
return
|
||||||
return Rpc._manager.message(LOGOUT_MSG, username)
|
return Rpc._manager.message(LOGOUT_MSG, username)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def getInfo():
|
def getInfo():
|
||||||
if Rpc._manager is None: # Not managed
|
if Rpc._manager is None: # Not managed
|
||||||
return
|
return
|
||||||
return Rpc._manager.message(INFO_MSG, '')
|
return Rpc._manager.message(INFO_MSG, '')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def setReady():
|
def setReady():
|
||||||
if Rpc._manager is None: # Not managed
|
if Rpc._manager is None: # Not managed
|
||||||
return
|
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)
|
return Rpc._manager.message(READY_MSG, interfaces)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def notifyIpChange():
|
def notifyIpChange():
|
||||||
if Rpc._manager is None: # Not managed
|
if Rpc._manager is None: # Not managed
|
||||||
return
|
return None
|
||||||
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(IP_MSG, interfaces)
|
return Rpc._manager.message(IP_MSG, interfaces)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def resetId():
|
def resetId():
|
||||||
logger.debug('Reseting rpc id')
|
logger.debug('Reseting rpc id')
|
||||||
Rpc._manager._id = None
|
Rpc._manager._id = None
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user