Dedicated server settings

This commit is contained in:
tomkat83 2017-08-02 17:22:53 +02:00
parent 0628b40b8f
commit 3310e0ad25

View file

@ -299,7 +299,7 @@ class ConnectionManager(object):
try: try:
publicInfo = self._tryConnect(address, options=options) publicInfo = self._tryConnect(address, options=options)
except Exception: except requests.RequestException:
return _onFail() return _onFail()
else: else:
server = { server = {
@ -308,7 +308,7 @@ class ConnectionManager(object):
'options': options 'options': options
} }
self._updateServerInfo(server, publicInfo) self._updateServerInfo(server, publicInfo)
server = self.connectToServer(server, options) server = self.connectToServer(server)
if server is False: if server is False:
return _onFail() return _onFail()
else: else:
@ -518,73 +518,68 @@ class ConnectionManager(object):
return 0 return 0
def connectToServer(self, server, options=None): def connectToServer(self, server, settings=None):
# First test manual connections, then local, then remote
tests = [ tests = [
CONNECTIONMODE['Manual'], CONNECTIONMODE['Manual'],
CONNECTIONMODE['Local'], CONNECTIONMODE['Local'],
CONNECTIONMODE['Remote'] CONNECTIONMODE['Remote']
] ]
return self._testNextCONNECTIONMODE(tests, 0, server, options) return self._testNextCONNECTIONMODE(tests, 0, server, settings)
def _stringEqualsIgnoreCase(self, str1, str2): def _stringEqualsIgnoreCase(self, str1, str2):
return (str1 or "").lower() == (str2 or "").lower() return (str1 or "").lower() == (str2 or "").lower()
def _testNextCONNECTIONMODE(self, tests, index, server, options): def _testNextCONNECTIONMODE(self, tests, index, server, settings):
if index >= len(tests): if index >= len(tests):
log.info("Tested all connection modes. Failing server connection.") log.info("Tested all connection modes. Failing server connection.")
return self._resolveFailure() return self._resolveFailure()
mode = tests[index] mode = tests[index]
log.debug('Testing connection %s with options %s' % (mode, options))
address = getServerAddress(server, mode) address = getServerAddress(server, mode)
enableRetry = False
skipTest = False skipTest = False
timeout = self.default_timeout
if mode == CONNECTIONMODE['Local']: if mode == CONNECTIONMODE['Local']:
enableRetry = True if self._stringEqualsIgnoreCase(address,
timeout = 8 server.get('ManualAddress')):
# skipping LocalAddress test because it is the same as
if self._stringEqualsIgnoreCase(address, server.get('ManualAddress')): # ManualAddress
log.info("skipping LocalAddress test because it is the same as ManualAddress")
skipTest = True skipTest = True
elif mode == CONNECTIONMODE['Manual']:
if self._stringEqualsIgnoreCase(address, server.get('LocalAddress')):
enableRetry = True
timeout = 8
if skipTest or not address: if skipTest or not address:
log.info("skipping test at index: %s" % index) log.debug("skipping test for %s" % mode)
return self._testNextCONNECTIONMODE(tests, index+1, server, options) return self._testNextCONNECTIONMODE(tests,
index+1,
server,
settings)
log.info("testing connection mode %s with server %s" % (mode, server.get('Name'))) log.debug("testing connection %s with settings %s for server %s"
% (address, settings, server.get('Name')))
try: try:
result = self._tryConnect(address, timeout, options) result = self._tryConnect(address, options=server.get('options'))
except requests.RequestException:
except Exception: log.info("Connection test failed for %s with server %s"
log.error("test failed for connection mode %s with server %s" % (mode, server.get('Name'))) % (address, server.get('Name')))
return self._testNextCONNECTIONMODE(tests,
if enableRetry: index+1,
# TODO: wake on lan and retry server,
return self._testNextCONNECTIONMODE(tests, index+1, server, options) settings)
else: else:
return self._testNextCONNECTIONMODE(tests, index+1, server, options)
else:
if self._compareVersions(self._getMinServerVersion(), if self._compareVersions(self._getMinServerVersion(),
result.attrib['version']) == 1: result.attrib['version']) == 1:
log.warn("minServerVersion requirement not met. Server version: %s" % result.attrib['version']) log.warn("Minimal PMS version requirement not met. PMS version"
" is: %s" % result.attrib['version'])
return { return {
'State': CONNECTIONSTATE['ServerUpdateNeeded'], 'State': CONNECTIONSTATE['ServerUpdateNeeded'],
'Servers': [server] 'Servers': [server]
} }
else: else:
log.info("calling onSuccessfulConnection with connection mode %s with server %s" log.debug("calling onSuccessfulConnection with mode %s, "
% (mode, server.get('Name'))) "address %s, settings %s with server %s"
return self._onSuccessfulConnection(server, result, mode, options) % (mode, address, settings, server.get('Name')))
return self._onSuccessfulConnection(server,
result,
mode,
settings)
def _onSuccessfulConnection(self, server, systemInfo, CONNECTIONMODE, options): def _onSuccessfulConnection(self, server, systemInfo, CONNECTIONMODE, options):
@ -772,19 +767,19 @@ class ConnectionManager(object):
except Exception: except Exception:
return False return False
def connect(self, options=None): def connect(self, settings=None):
log.info("Begin connect") log.info("Begin connect")
servers = self.getAvailableServers() servers = self.getAvailableServers()
return self._connectToServers(servers, options) return self._connectToServers(servers, settings)
def _connectToServers(self, servers, options): def _connectToServers(self, servers, settings):
log.info("Begin connectToServers, with %s servers" % len(servers)) log.info("Begin connectToServers, with %s servers" % len(servers))
if len(servers) == 1: if len(servers) == 1:
result = self.connectToServer(servers[0], options) result = self.connectToServer(servers[0], settings)
if result and result.get('State') == CONNECTIONSTATE['Unavailable']: if result and result.get('State') == CONNECTIONSTATE['Unavailable']:
result['State'] = CONNECTIONSTATE['ConnectSignIn'] if result['ConnectUser'] == None else CONNECTIONSTATE['ServerSelection'] result['State'] = CONNECTIONSTATE['ConnectSignIn'] if result['ConnectUser'] == None else CONNECTIONSTATE['ServerSelection']
@ -795,7 +790,7 @@ class ConnectionManager(object):
# See if we have any saved credentials and can auto sign in # See if we have any saved credentials and can auto sign in
if firstServer: if firstServer:
result = self.connectToServer(firstServer, options) result = self.connectToServer(firstServer, settings)
if result and result.get('State') == CONNECTIONSTATE['SignedIn']: if result and result.get('State') == CONNECTIONSTATE['SignedIn']:
return result return result