Dynamic imports of drivers classes.
Change-Id: I10274bf9bada30f0fbd4ed27f367454c09dad5c2
This commit is contained in:
parent
ff8d249fc5
commit
2cad4fc204
|
@ -1,18 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Author: François Rossigneux <francois.rossigneux@inria.fr>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from wattsup import Wattsup
|
||||
from dummy import Dummy
|
|
@ -17,7 +17,6 @@
|
|||
"""Loads and checks driver threads."""
|
||||
|
||||
import ast
|
||||
import sys
|
||||
import signal
|
||||
import thread
|
||||
from threading import Timer
|
||||
|
@ -61,17 +60,19 @@ def load_all_drivers():
|
|||
def load_driver(class_name, probe_ids, kwargs):
|
||||
"""Starts a probe thread."""
|
||||
try:
|
||||
probeClass = getattr(sys.modules['kwapi.drivers'], class_name)
|
||||
except AttributeError:
|
||||
module = __import__('kwapi.drivers.' + class_name.lower(),
|
||||
fromlist=class_name)
|
||||
probe_class = getattr(module, class_name)
|
||||
except ImportError:
|
||||
raise NameError("%s doesn't exist." % class_name)
|
||||
try:
|
||||
probeObject = probeClass(probe_ids, **kwargs)
|
||||
probe_object = probe_class(probe_ids, **kwargs)
|
||||
except Exception as exception:
|
||||
LOG.error('Exception occurred while initializing %s(%s, %s): %s'
|
||||
% (class_name, probe_ids, kwargs, exception))
|
||||
else:
|
||||
probeObject.start()
|
||||
return probeObject
|
||||
probe_object.start()
|
||||
return probe_object
|
||||
|
||||
|
||||
def check_drivers_alive():
|
||||
|
|
Loading…
Reference in New Issue