コード例 #1
0
ファイル: api.py プロジェクト: chenxu1990/marker
    def __init__(self,
                 config_file=None,
                 config_args=None,
                 plugin_paths=None,
                 skip_db_check=False):
        """Initialize Marker API instance

        :param config_file: Path to marker configuration file. If None, default
                            path will be selected
        :type config_file: str
        :param config_args: Arguments for initialization current configuration
        :type config_args: list
        :param plugin_paths: Additional custom plugin locations
        :type plugin_paths: list
        :param skip_db_check: Allows to skip db revision check
        :type skip_db_check: bool
        """

        try:
            from marker.probes.network import Network
            tasks = []
            for p in BaseProbes.get_all():
                tasks.append(p.get_name())
            for task in tasks:
                opt_group = cfg.OptGroup(name=task)
                OPTS = [
                    cfg.IntOpt("step",
                               default=5,
                               help="specifies the base interval in seconds"
                               " with which data will fed into the rrd.")
                ]
                CONF.register_group(opt_group)
                CONF.register_opts(OPTS, opt_group)
                if task == "network":
                    OPTS = [
                        cfg.ListOpt("qperf_port",
                                    default=[10000, 10100],
                                    help="specifies the port range of qperf.")
                    ]
                    CONF.register_opts(OPTS, opt_group)
            HOST_OPTS = [
                cfg.StrOpt("host",
                           default="localhost",
                           help="specifies host of marker service.")
            ]
            PORT_OPTS = [
                cfg.IntOpt("port",
                           default=9999,
                           help="specifies port of marker service.")
            ]
            DATA_OPTS = [
                cfg.StrOpt("data_dir",
                           default="/opt/marker/",
                           help="dir where paste rrd files and marker.json.")
            ]
            CONF.register_opts(HOST_OPTS)
            CONF.register_opts(PORT_OPTS)
            CONF.register_opts(DATA_OPTS)
            config_files = ([config_file]
                            if config_file else self._default_config_file())
            CONF(config_args or [],
                 project="marker",
                 version="1.0",
                 default_config_files=config_files)

            logging.setup("marker")
            if not CONF.get("log_config_append"):
                LOG.debug(
                    "INFO logs from urllib3 and requests module are hide.")
                requests_log = logging.getLogger("requests").logger
                requests_log.setLevel(logging.WARNING)
                urllib3_log = logging.getLogger("urllib3").logger
                urllib3_log.setLevel(logging.WARNING)

                LOG.debug("urllib3 insecure warnings are hidden.")
                for warning in ("InsecurePlatformWarning", "SNIMissingWarning",
                                "InsecureRequestWarning"):
                    warning_cls = getattr(urllib3.exceptions, warning, None)
                    if warning_cls is not None:
                        urllib3.disable_warnings(warning_cls)

            # NOTE(wtakase): This is for suppressing boto error logging.
            LOG.debug("ERROR log from boto module is hide.")
            boto_log = logging.getLogger("boto").logger
            boto_log.setLevel(logging.CRITICAL)

            # Set alembic log level to ERROR
            alembic_log = logging.getLogger("alembic").logger
            alembic_log.setLevel(logging.ERROR)

        except cfg.ConfigFilesNotFoundError as e:
            cfg_files = e.config_files
            raise Exception("Failed to read configuration file(s): %s" %
                            cfg_files)

        self._target = _Target(self)
        self._task = _Task(self)
        self._service = _Service(self, config_files)
コード例 #2
0
ファイル: api.py プロジェクト: chenxu1990/marker
import copy
import os
import sys

from oslo_config import cfg
from marker.common import logging
from marker.common import objects
from marker.common import validate
from marker.probes.base_probes import BaseProbes
from marker.server.tcp_server import ServiceEngine
from marker.server import utils
from requests.packages import urllib3
from random import randint

CONF = cfg.CONF
LOG = logging.getLogger(__name__)


class APIGroup(object):
    def __init__(self, api):
        """Initialize API group

        """

        self.api = api

    def _update_task_obj(self, action, targets=None, task=None):
        task_obj = objects.Task()
        task_dict = task_obj.list()
        if not targets:
            targets = [k for k in task_dict]