Some small improvements and refactoring.
This commit is contained in:
parent
a4053a0db3
commit
7360ab1936
5 changed files with 11 additions and 36 deletions
45
linspector/services/vendor/avm/is_connected.py
vendored
Normal file
45
linspector/services/vendor/avm/is_connected.py
vendored
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
"""
|
||||
This file is part of Linspector (https://linspector.org/)
|
||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||
See LICENSE.txt (MIT license).
|
||||
"""
|
||||
from fritzconnection.lib.fritzstatus import FritzStatus
|
||||
|
||||
from linspector.core.service import Service
|
||||
|
||||
|
||||
def create(configuration, environment, log):
|
||||
return IsConnectedService(configuration, environment, log)
|
||||
|
||||
|
||||
class IsConnectedService(Service):
|
||||
def __init__(self, configuration, environment, log):
|
||||
super().__init__(configuration, environment, log)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__log = log
|
||||
|
||||
def execute(self, identifier, service, **kwargs):
|
||||
self.__log.debug('identifier=' + identifier +
|
||||
'service=' + service +
|
||||
' object=' + str(self) +
|
||||
' kwargs=' + str(kwargs))
|
||||
try:
|
||||
fc = FritzStatus(address=kwargs['host'],
|
||||
password=kwargs['password'])
|
||||
except Exception:
|
||||
self.__log.error('identifier=' + identifier +
|
||||
' host=' + str(kwargs['host']) +
|
||||
' service=' + service +
|
||||
' failed ')
|
||||
return False
|
||||
|
||||
self.__log.info('identifier=' + identifier +
|
||||
' host=' + str(kwargs['host']) +
|
||||
' service=' + service +
|
||||
' status=' + ('OK' if fc.is_connected else 'ERROR'))
|
||||
|
||||
if fc.is_connected:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
Loading…
Add table
Add a link
Reference in a new issue