mirror of
https://github.com/dkmstr/openuds.git
synced 2024-12-22 13:34:04 +03:00
Several minor actor fixed to manage some workarounds in a better way
This commit is contained in:
parent
e1bbbece43
commit
1fb46003fc
@ -104,13 +104,17 @@ class Api(object):
|
|||||||
def __init__(self, host, masterKey, ssl):
|
def __init__(self, host, masterKey, ssl):
|
||||||
self.host = host
|
self.host = host
|
||||||
self.masterKey = masterKey
|
self.masterKey = masterKey
|
||||||
self.useSSL = ssl
|
self.useSSL = True if ssl else False
|
||||||
self.uuid = None
|
self.uuid = None
|
||||||
self.mac = None
|
self.mac = None
|
||||||
self.url = "{}://{}/rest/actor/".format(('http', 'https')[ssl], self.host)
|
self.url = "{}://{}/rest/actor/".format(('http', 'https')[self.useSSL], self.host)
|
||||||
self.idle = None
|
self.idle = None
|
||||||
self.secretKey = six.text_type(uuid.uuid4())
|
self.secretKey = six.text_type(uuid.uuid4())
|
||||||
self.newerRequestLib = requests.__version__.split('.')[0] >= '1'
|
try:
|
||||||
|
self.newerRequestLib = requests.__version__.split('.')[0] >= '1'
|
||||||
|
except Exception:
|
||||||
|
self.newerRequestLib = False # I no version, guess this must be an old requests
|
||||||
|
|
||||||
# Disable logging requests messages except for errors, ...
|
# Disable logging requests messages except for errors, ...
|
||||||
logging.getLogger("requests").setLevel(logging.CRITICAL)
|
logging.getLogger("requests").setLevel(logging.CRITICAL)
|
||||||
# Tries to disable all warnings
|
# Tries to disable all warnings
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
'''
|
'''
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import traceback
|
||||||
import sys
|
import sys
|
||||||
import six
|
import six
|
||||||
|
|
||||||
@ -50,6 +51,10 @@ class Logger(object):
|
|||||||
self.remoteLogger = None
|
self.remoteLogger = None
|
||||||
|
|
||||||
def setLevel(self, level):
|
def setLevel(self, level):
|
||||||
|
'''
|
||||||
|
Sets log level filter (minimum level required for a log message to be processed)
|
||||||
|
:param level: Any message with a level below this will be filtered out
|
||||||
|
'''
|
||||||
self.logLevel = int(level) # Ensures level is an integer or fails
|
self.logLevel = int(level) # Ensures level is an integer or fails
|
||||||
|
|
||||||
def setRemoteLogger(self, remoteLogger):
|
def setRemoteLogger(self, remoteLogger):
|
||||||
@ -83,6 +88,14 @@ class Logger(object):
|
|||||||
def fatal(self, message):
|
def fatal(self, message):
|
||||||
self.log(FATAL, message)
|
self.log(FATAL, message)
|
||||||
|
|
||||||
|
def exception(self):
|
||||||
|
try:
|
||||||
|
tb = traceback.format_exc()
|
||||||
|
except Exception:
|
||||||
|
tb = '(could not get traceback!)'
|
||||||
|
|
||||||
|
self.log(DEBUG, tb)
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -126,7 +126,8 @@ class CommonService(object):
|
|||||||
logger.fatal('This host is not managed by UDS Broker (ids: {})'.format(ids))
|
logger.fatal('This host is not managed by UDS Broker (ids: {})'.format(ids))
|
||||||
return False # On unmanaged hosts, there is no reason right now to continue running
|
return False # On unmanaged hosts, there is no reason right now to continue running
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug('Exception caught: {}, retrying'.format(exceptionToMessage(e)))
|
logger.debug('Exception on network info: {}, retrying')
|
||||||
|
logger.exception()
|
||||||
# Any other error is expectable and recoverable, so let's wait a bit and retry again
|
# Any other error is expectable and recoverable, so let's wait a bit and retry again
|
||||||
# but, if too many errors, will log it (one every minute, for
|
# but, if too many errors, will log it (one every minute, for
|
||||||
# example)
|
# example)
|
||||||
|
@ -64,6 +64,7 @@ def getNetworkInfo():
|
|||||||
continue
|
continue
|
||||||
if ip == '' or ip is None:
|
if ip == '' or ip is None:
|
||||||
continue
|
continue
|
||||||
|
logger.debug('Net config found: {}=({}, {})'.format(obj.Caption, obj.MACAddress, ip))
|
||||||
yield utils.Bunch(name=obj.Caption, mac=obj.MACAddress, ip=ip)
|
yield utils.Bunch(name=obj.Caption, mac=obj.MACAddress, ip=ip)
|
||||||
except Exception:
|
except Exception:
|
||||||
return
|
return
|
||||||
@ -111,7 +112,7 @@ def loggoff():
|
|||||||
|
|
||||||
def renameComputer(newName):
|
def renameComputer(newName):
|
||||||
# Needs admin privileges to work
|
# Needs admin privileges to work
|
||||||
if ctypes.windll.kernel32.SetComputerNameExW(DWORD(win32con.ComputerNamePhysicalDnsHostname), LPCWSTR(newName)) == 0:
|
if ctypes.windll.kernel32.SetComputerNameExW(DWORD(win32con.ComputerNamePhysicalDnsHostname), LPCWSTR(newName)) == 0: # @UndefinedVariable
|
||||||
# win32api.FormatMessage -> returns error string
|
# win32api.FormatMessage -> returns error string
|
||||||
# win32api.GetLastError -> returns error code
|
# win32api.GetLastError -> returns error code
|
||||||
# (just put this comment here to remember to log this when logger is available)
|
# (just put this comment here to remember to log this when logger is available)
|
||||||
@ -131,6 +132,14 @@ NETSETUP_DEFER_SPN_SET = 0x1000000
|
|||||||
|
|
||||||
|
|
||||||
def joinDomain(domain, ou, account, password, executeInOneStep=False):
|
def joinDomain(domain, ou, account, password, executeInOneStep=False):
|
||||||
|
'''
|
||||||
|
Joins machine to a windows domain
|
||||||
|
:param domain: Domain to join to
|
||||||
|
:param ou: Ou that will hold machine
|
||||||
|
:param account: Account used to join domain
|
||||||
|
:param password: Password of account used to join domain
|
||||||
|
:param executeInOneStep: If true, means that this machine has been renamed and wants to add NETSETUP_JOIN_WITH_NEW_NAME to request so we can do rename/join in one step.
|
||||||
|
'''
|
||||||
# If account do not have domain, include it
|
# If account do not have domain, include it
|
||||||
if '@' not in account and '\\' not in account:
|
if '@' not in account and '\\' not in account:
|
||||||
if '.' in domain:
|
if '.' in domain:
|
||||||
@ -138,7 +147,6 @@ def joinDomain(domain, ou, account, password, executeInOneStep=False):
|
|||||||
else:
|
else:
|
||||||
account = domain + '\\' + account
|
account = domain + '\\' + account
|
||||||
|
|
||||||
|
|
||||||
# Do log
|
# Do log
|
||||||
flags = NETSETUP_ACCT_CREATE | NETSETUP_DOMAIN_JOIN_IF_JOINED | NETSETUP_JOIN_DOMAIN
|
flags = NETSETUP_ACCT_CREATE | NETSETUP_DOMAIN_JOIN_IF_JOINED | NETSETUP_JOIN_DOMAIN
|
||||||
|
|
||||||
@ -198,7 +206,7 @@ def getIdleDuration():
|
|||||||
lastInputInfo = LASTINPUTINFO()
|
lastInputInfo = LASTINPUTINFO()
|
||||||
lastInputInfo.cbSize = ctypes.sizeof(lastInputInfo)
|
lastInputInfo.cbSize = ctypes.sizeof(lastInputInfo)
|
||||||
ctypes.windll.user32.GetLastInputInfo(ctypes.byref(lastInputInfo))
|
ctypes.windll.user32.GetLastInputInfo(ctypes.byref(lastInputInfo))
|
||||||
millis = ctypes.windll.kernel32.GetTickCount() - lastInputInfo.dwTime
|
millis = ctypes.windll.kernel32.GetTickCount() - lastInputInfo.dwTime # @UndefinedVariable
|
||||||
return millis / 1000.0
|
return millis / 1000.0
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user