Convert to cfg.CONF pattern
This commit is contained in:
parent
e937282626
commit
064395fea8
@ -67,8 +67,6 @@ class DrydockConfig(object):
|
||||
cfg.StrOpt('node_driver',
|
||||
default='drydock_provisioner.drivers.node.maasdriver.driver.MaasNodeDriver',
|
||||
help='Module path string of the Node driver to enable'),
|
||||
cfg.StrOpt('network_driver',
|
||||
default=None, help='Module path string of the Network driver to enable'),
|
||||
]
|
||||
|
||||
# Timeouts for various tasks specified in minutes
|
||||
@ -82,7 +80,7 @@ class DrydockConfig(object):
|
||||
]
|
||||
|
||||
def __init__(self):
|
||||
self.conf = cfg.ConfigOpts()
|
||||
self.conf = cfg.CONF
|
||||
|
||||
def register_options(self):
|
||||
self.conf.register_opts(DrydockConfig.logging_options, group='logging')
|
||||
@ -90,9 +88,6 @@ class DrydockConfig(object):
|
||||
self.conf.register_opts(DrydockConfig.plugin_options, group='plugins')
|
||||
self.conf.register_opts(DrydockConfig.timeout_options, group='timeouts')
|
||||
|
||||
config_mgr = DrydockConfig()
|
||||
conf = config_mgr.conf
|
||||
|
||||
IGNORED_MODULES = ('drydock', 'config')
|
||||
|
||||
def list_opts():
|
||||
|
@ -16,7 +16,7 @@ import falcon
|
||||
import logging
|
||||
import uuid
|
||||
|
||||
import drydock_provisioner.config as config
|
||||
from oslo_config import cfg
|
||||
|
||||
class AuthMiddleware(object):
|
||||
|
||||
@ -66,7 +66,7 @@ class ContextMiddleware(object):
|
||||
|
||||
requested_logging = req.get_header('X-Log-Level')
|
||||
|
||||
if (config.conf.logging.log_level == 'DEBUG' or
|
||||
if (cfg.CONF.logging.log_level == 'DEBUG' or
|
||||
(requested_logging == 'DEBUG' and 'admin' in ctx.roles)):
|
||||
ctx.set_log_level('DEBUG')
|
||||
elif requested_logging == 'INFO':
|
||||
@ -78,7 +78,7 @@ class ContextMiddleware(object):
|
||||
class LoggingMiddleware(object):
|
||||
|
||||
def __init__(self):
|
||||
self.logger = logging.getLogger(config.conf.logging.control_logger_name)
|
||||
self.logger = logging.getLogger(cfg.CONF.logging.control_logger_name)
|
||||
|
||||
def process_response(self, req, resp, resource, req_succeeded):
|
||||
ctx = req.context
|
||||
|
@ -44,7 +44,6 @@ class MaasRequestFactory(object):
|
||||
self.base_url = base_url
|
||||
self.apikey = apikey
|
||||
|
||||
print("Creating MaaS API client for URL %s with key %s" % (base_url, apikey))
|
||||
self.signer = MaasOauth(apikey)
|
||||
self.http_session = requests.Session()
|
||||
|
||||
@ -143,7 +142,7 @@ class MaasRequestFactory(object):
|
||||
resp = self.http_session.send(prepared_req, timeout=timeout)
|
||||
|
||||
if resp.status_code >= 400:
|
||||
print("FAILED API CALL:\nURL: %s %s\nBODY:\n%s\nRESPONSE: %s\nBODY:\n%s" %
|
||||
self.logger.debug("FAILED API CALL:\nURL: %s %s\nBODY:\n%s\nRESPONSE: %s\nBODY:\n%s" %
|
||||
(prepared_req.method, prepared_req.url, str(prepared_req.body).replace('\\r\\n','\n'),
|
||||
resp.status_code, resp.text))
|
||||
return resp
|
||||
return resp
|
||||
|
@ -18,7 +18,6 @@ import sys
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
import drydock_provisioner.config as config
|
||||
import drydock_provisioner.error as errors
|
||||
import drydock_provisioner.drivers as drivers
|
||||
import drydock_provisioner.objects.fields as hd_fields
|
||||
@ -46,10 +45,9 @@ class MaasNodeDriver(NodeDriver):
|
||||
def __init__(self, **kwargs):
|
||||
super(MaasNodeDriver, self).__init__(**kwargs)
|
||||
|
||||
config.conf.register_opts(MaasNodeDriver.maasdriver_options, group=MaasNodeDriver.driver_key)
|
||||
cfg.CONF.register_opts(MaasNodeDriver.maasdriver_options, group=MaasNodeDriver.driver_key)
|
||||
|
||||
self.logger = logging.getLogger("%s.%s" %
|
||||
(config.conf.logging.nodedriver_logger_name, self.driver_key))
|
||||
self.logger = logging.getLogger(cfg.CONF.logging.nodedriver_logger_name)
|
||||
|
||||
def execute_task(self, task_id):
|
||||
task = self.state_manager.get_task(task_id)
|
||||
@ -64,7 +62,7 @@ class MaasNodeDriver(NodeDriver):
|
||||
if task.action == hd_fields.OrchestratorAction.ValidateNodeServices:
|
||||
self.orchestrator.task_field_update(task.get_id(),
|
||||
status=hd_fields.TaskStatus.Running)
|
||||
maas_client = MaasRequestFactory(config.conf.maasdriver.maas_api_url, config.conf.maasdriver.maas_api_key)
|
||||
maas_client = MaasRequestFactory(cfg.CONF.maasdriver.maas_api_url, cfg.CONF.maasdriver.maas_api_key)
|
||||
|
||||
try:
|
||||
if maas_client.test_connectivity():
|
||||
@ -136,7 +134,7 @@ class MaasNodeDriver(NodeDriver):
|
||||
|
||||
runner.start()
|
||||
|
||||
runner.join(timeout=config.conf.timeouts.create_network_template * 60)
|
||||
runner.join(timeout=cfg.CONF.timeouts.create_network_template * 60)
|
||||
|
||||
if runner.is_alive():
|
||||
result = {
|
||||
@ -190,7 +188,7 @@ class MaasNodeDriver(NodeDriver):
|
||||
attempts = 0
|
||||
worked = failed = False
|
||||
|
||||
while running_subtasks > 0 and attempts < config.conf.timeouts.identify_node:
|
||||
while running_subtasks > 0 and attempts < cfg.CONF.timeouts.identify_node:
|
||||
for t in subtasks:
|
||||
subtask = self.state_manager.get_task(t)
|
||||
|
||||
@ -260,7 +258,7 @@ class MaasNodeDriver(NodeDriver):
|
||||
worked = failed = False
|
||||
|
||||
#TODO Add timeout to config
|
||||
while running_subtasks > 0 and attempts < config.conf.timeouts.configure_hardware:
|
||||
while running_subtasks > 0 and attempts < cfg.CONF.timeouts.configure_hardware:
|
||||
for t in subtasks:
|
||||
subtask = self.state_manager.get_task(t)
|
||||
|
||||
@ -329,7 +327,7 @@ class MaasNodeDriver(NodeDriver):
|
||||
attempts = 0
|
||||
worked = failed = False
|
||||
|
||||
while running_subtasks > 0 and attempts < config.conf.timeouts.apply_node_networking:
|
||||
while running_subtasks > 0 and attempts < cfg.CONF.timeouts.apply_node_networking:
|
||||
for t in subtasks:
|
||||
subtask = self.state_manager.get_task(t)
|
||||
|
||||
@ -467,7 +465,7 @@ class MaasNodeDriver(NodeDriver):
|
||||
attempts = 0
|
||||
worked = failed = False
|
||||
|
||||
while running_subtasks > 0 and attempts < config.conf.timeouts.deploy_node:
|
||||
while running_subtasks > 0 and attempts < cfg.CONF.timeouts.deploy_node:
|
||||
for t in subtasks:
|
||||
subtask = self.state_manager.get_task(t)
|
||||
|
||||
@ -519,8 +517,8 @@ class MaasTaskRunner(drivers.DriverTaskRunner):
|
||||
status=hd_fields.TaskStatus.Running,
|
||||
result=hd_fields.ActionResult.Incomplete)
|
||||
|
||||
self.maas_client = MaasRequestFactory(config.conf.maasdriver.maas_api_url,
|
||||
config.conf.maasdriver.maas_api_key)
|
||||
self.maas_client = MaasRequestFactory(cfg.CONF.maasdriver.maas_api_url,
|
||||
cfg.CONF.maasdriver.maas_api_key)
|
||||
|
||||
site_design = self.orchestrator.get_effective_site(self.task.design_id)
|
||||
|
||||
@ -809,7 +807,7 @@ class MaasTaskRunner(drivers.DriverTaskRunner):
|
||||
# Poll machine status
|
||||
attempts = 0
|
||||
|
||||
while attempts < config.conf.timeouts.configure_hardware and machine.status_name != 'Ready':
|
||||
while attempts < cfg.CONF.timeouts.configure_hardware and machine.status_name != 'Ready':
|
||||
attempts = attempts + 1
|
||||
time.sleep(1 * 60)
|
||||
try:
|
||||
@ -1149,7 +1147,7 @@ class MaasTaskRunner(drivers.DriverTaskRunner):
|
||||
continue
|
||||
|
||||
attempts = 0
|
||||
while attempts < config.conf.timeouts.deploy_node and not machine.status_name.startswith('Deployed'):
|
||||
while attempts < cfg.CONF.timeouts.deploy_node and not machine.status_name.startswith('Deployed'):
|
||||
attempts = attempts + 1
|
||||
time.sleep(1 * 60)
|
||||
try:
|
||||
|
@ -14,9 +14,9 @@
|
||||
import time
|
||||
import logging
|
||||
|
||||
import drydock_provisioner.config as config
|
||||
import drydock_provisioner.error as errors
|
||||
from oslo_config import cfg
|
||||
|
||||
import drydock_provisioner.error as errors
|
||||
|
||||
import drydock_provisioner.objects.fields as hd_fields
|
||||
import drydock_provisioner.objects.task as task_model
|
||||
@ -36,8 +36,7 @@ class ManualDriver(oob.OobDriver):
|
||||
self.driver_key = "manual_driver"
|
||||
self.driver_desc = "Manual (Noop) OOB Driver"
|
||||
|
||||
self.logger = logging.getLogger("%s.%s" %
|
||||
(config.conf.logging.oobdriver_logger_name, self.driver_key))
|
||||
self.logger = logging.getLogger(cfg.CONF.logging.oobdriver_logger_name)
|
||||
|
||||
def execute_task(self, task_id):
|
||||
task = self.state_manager.get_task(task_id)
|
||||
|
@ -14,9 +14,9 @@
|
||||
import time
|
||||
import logging
|
||||
|
||||
from oslo_config import cfg
|
||||
from pyghmi.ipmi.command import Command
|
||||
|
||||
import drydock_provisioner.config as config
|
||||
import drydock_provisioner.error as errors
|
||||
|
||||
import drydock_provisioner.objects.fields as hd_fields
|
||||
@ -37,8 +37,7 @@ class PyghmiDriver(oob.OobDriver):
|
||||
self.driver_key = "pyghmi_driver"
|
||||
self.driver_desc = "Pyghmi OOB Driver"
|
||||
|
||||
self.logger = logging.getLogger("%s.%s" %
|
||||
(config.conf.logging.oobdriver_logger_name, self.driver_key))
|
||||
self.logger = logging.getLogger(cfg.CONF.logging.oobdriver_logger_name)
|
||||
|
||||
def execute_task(self, task_id):
|
||||
task = self.state_manager.get_task(task_id)
|
||||
@ -101,7 +100,7 @@ class PyghmiDriver(oob.OobDriver):
|
||||
|
||||
attempts = 0
|
||||
while (len(incomplete_subtasks) > 0 and
|
||||
attempts <= getattr(config.conf.timeouts, task.action, config.conf.timeouts.drydock_timeout)):
|
||||
attempts <= getattr(cfg.CONF.timeouts, task.action, cfg.CONF.timeouts.drydock_timeout)):
|
||||
for n in incomplete_subtasks:
|
||||
t = self.state_manager.get_task(n)
|
||||
if t.get_status() in [hd_fields.TaskStatus.Terminated,
|
||||
@ -298,4 +297,4 @@ class PyghmiTaskRunner(drivers.DriverTaskRunner):
|
||||
result=hd_fields.ActionResult.Success,
|
||||
status=hd_fields.TaskStatus.Complete,
|
||||
result_detail=mci_id)
|
||||
return
|
||||
return
|
||||
|
@ -30,24 +30,24 @@ def start_drydock():
|
||||
cfg.BoolOpt('debug', short='d', default=False, help='Enable debug logging'),
|
||||
]
|
||||
|
||||
config.conf.register_cli_opts(cli_options)
|
||||
cfg.CONF.register_cli_opts(cli_options)
|
||||
config.config_mgr.register_options()
|
||||
config.conf(sys.argv[1:])
|
||||
cfg.CONF(sys.argv[1:])
|
||||
|
||||
if config.conf.debug:
|
||||
config.conf.logging.log_level = 'DEBUG'
|
||||
if cfg.CONF.debug:
|
||||
cfg.CONF.logging.log_level = 'DEBUG'
|
||||
|
||||
# Setup root logger
|
||||
logger = logging.getLogger(config.conf.logging.global_logger_name)
|
||||
logger = logging.getLogger(cfg.CONF.logging.global_logger_name)
|
||||
|
||||
logger.setLevel(config.conf.logging.log_level)
|
||||
logger.setLevel(cfg.CONF.logging.log_level)
|
||||
ch = logging.StreamHandler()
|
||||
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(filename)s:%(funcName)s - %(message)s')
|
||||
ch.setFormatter(formatter)
|
||||
logger.addHandler(ch)
|
||||
|
||||
# Specalized format for API logging
|
||||
logger = logging.getLogger(config.conf.logging.control_logger_name)
|
||||
logger = logging.getLogger(cfg.CONF.logging.control_logger_name)
|
||||
logger.propagate = False
|
||||
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(user)s - %(req_id)s - %(external_ctx)s - %(message)s')
|
||||
|
||||
@ -55,16 +55,14 @@ def start_drydock():
|
||||
ch.setFormatter(formatter)
|
||||
logger.addHandler(ch)
|
||||
|
||||
|
||||
state = statemgmt.DesignState()
|
||||
|
||||
orchestrator = orch.Orchestrator(config.conf.plugins,
|
||||
state_manager=state)
|
||||
orchestrator = orch.Orchestrator(cfg.CONF.plugins, state_manager=state)
|
||||
input_ingester = ingester.Ingester()
|
||||
input_ingester.enable_plugins(config.conf.plugins.ingester)
|
||||
input_ingester.enable_plugins(cfg.CONF.plugins.ingester)
|
||||
|
||||
# Now that loggers are configured, log the effective config
|
||||
config.conf.log_opt_values(logging.getLogger(config.conf.logging.global_logger_name), logging.DEBUG)
|
||||
cfg.CONF.log_opt_values(logging.getLogger(cfg.CONF.logging.global_logger_name), logging.DEBUG)
|
||||
|
||||
# Now that loggers are configured, log the effective config
|
||||
drydock_provisioner.conf.log_opt_values(logging.getLogger(drydock_provisioner.conf.logging.global_logger_name), logging.DEBUG)
|
||||
|
@ -41,10 +41,9 @@ class Orchestrator(object):
|
||||
|
||||
# This is because oslo_config changes the option value
|
||||
# for multiopt depending on if multiple values are actually defined
|
||||
print("%s" % (oob_drivers))
|
||||
|
||||
for d in oob_drivers:
|
||||
print("Enabling OOB driver %s" % d)
|
||||
self.logger.info("Enabling OOB driver %s" % d)
|
||||
if d is not None:
|
||||
m, c = d.rsplit('.', 1)
|
||||
oob_driver_class = \
|
||||
|
Loading…
x
Reference in New Issue
Block a user