def setLogLevel(level, module_name): level = level.upper() if level not in logging._levelNames: LOG.error(_(' Invalid log level %s ') % level) l = logging.getLevelName(level.upper()) if module_name == 'healthnmon': logging.getLogger().setLevel(l) log.getLogger().logger.setLevel(l) else: log.getLogger(module_name).logger.setLevel(l) LOG.audit(_(module_name + ' log level set to %s ') % level)
def test_set_log_level_AUDIT(self): self.log = log.getLogger('healthnmon.example') self.assertEqual(logging.INFO, self.log.logger.getEffectiveLevel()) helper.setLogLevel('AUDIT', 'healthnmon.example') self.assertEqual(log.logging.AUDIT, self.log.logger.getEffectiveLevel())
def test_set_log_level_AUDIT(self): self.log = log.getLogger('healthnmon.example') self.assertEqual(logging.INFO, self.log.logger.getEffectiveLevel()) helper.setLogLevel('AUDIT', 'healthnmon.example') self.assertEqual( log.logging.AUDIT, self.log.logger.getEffectiveLevel())
def test_set_log_level_healthnmon_invalid_loglevel(self): self.log = log.getLogger('healthnmon.example') self.assertEqual(logging.INFO, self.log.logger.getEffectiveLevel()) helper.setLogLevel('test', 'healthnmon') self.assertNotEqual(logging.DEBUG, self.log.logger.getEffectiveLevel()) self.assertNotEqual(logging.DEBUG, logging.getLogger().getEffectiveLevel())
def test_set_log_level_healthnmon_invalid_loglevel(self): self.log = log.getLogger('healthnmon.example') self.assertEqual(logging.INFO, self.log.logger.getEffectiveLevel()) helper.setLogLevel('test', 'healthnmon') self.assertNotEqual(logging.DEBUG, self.log.logger.getEffectiveLevel()) self.assertNotEqual( logging.DEBUG, logging.getLogger().getEffectiveLevel())
def notify(context, message): """Notifies the recipient of the desired event given the model. Log notifications using nova's default logging system""" priority = message.get('priority', CONF.healthnmon_default_notification_level) priority = priority.lower() logger = logging.getLogger('healthnmon.notification.%s' % message['event_type']) getattr(logger, priority)(json.dumps(message))
def setUp(self): super(HealthnmonAuditFormatterTestCase, self).setUp() self.log = log.getLogger() self.stream = cStringIO.StringIO() self.handler = logging.StreamHandler(self.stream) self.log.logger.addHandler(self.handler) self.formatter = log.HealthnmonFormatter() self.handler.setFormatter(self.formatter) self.log.logger.addHandler(self.handler) self.level = self.log.logger.getEffectiveLevel() self.log.logger.setLevel(logging.DEBUG)
def profile_cputime(*args, **kwarg): if not modules: getmodules() module = get_module_name(name) status = get_state(module) if status: st = time.time() rt = fn(*args, **kwarg) logger = logging.getLogger(module) logger.debug(_(' %(fn_name)s | %(time)f | ms'), {'fn_name': name, 'time': (time.time() - st) * 1000}) return rt else: return fn(*args, **kwarg)
def profile_cputime(*args, **kwarg): if not modules: getmodules() module = get_module_name(name) status = get_state(module) if status: st = time.time() rt = fn(*args, **kwarg) logger = logging.getLogger(module) logger.debug(_(' %(fn_name)s | %(time)f | ms'), { 'fn_name': name, 'time': (time.time() - st) * 1000 }) return rt else: return fn(*args, **kwarg)
def setUp(self): super(HealthnmonFormatterTestCase, self).setUp() self.flags(logging_greenthread_format_string="GTHREAD ID | " "%(gthread_id)d | " "%(message)s", logging_thread_format_string="THREAD ID | " "%(message)s") self.log = log.getLogger() self.stream = cStringIO.StringIO() self.handler = logging.StreamHandler(self.stream) self.log.logger.addHandler(self.handler) self.formatter = log.HealthnmonFormatter() self.handler.setFormatter(self.formatter) self.log.logger.addHandler(self.handler) self.level = self.log.logger.getEffectiveLevel() self.log.logger.setLevel(logging.DEBUG)
def setUp(self): super(HealthnmonLoggerTestCase, self).setUp() self.flags(logging_greenthread_format_string="GTHREAD ID | " "%(levelname)s | " "%(gthread_id)d | " "%(message)s", logging_thread_format_string="THREAD ID | " "%(thread)d | " "%(message)s", healthnmon_log_config=self.log_config_file_path, healthnmon_manage_log_config=self.manage_log_config_file_path) logdir = 'healthnmon' if not os.path.exists(logdir): os.makedirs(logdir) log.setup() self.log = log.getLogger()
def setUp(self): super(HealthnmonLoggerTestCase, self).setUp() self.flags( logging_greenthread_format_string="GTHREAD ID | " "%(levelname)s | " "%(gthread_id)d | " "%(message)s", logging_thread_format_string="THREAD ID | " "%(thread)d | " "%(message)s", healthnmon_log_config=self.log_config_file_path, healthnmon_manage_log_config=self.manage_log_config_file_path) logdir = 'healthnmon' if not os.path.exists(logdir): os.makedirs(logdir) log.setup() self.log = log.getLogger()
#!/usr/bin/python # -*- coding: utf-8 -*- # Copyright 2012 Hewlett-Packard Development Company, L.P. # Module: Database schema for all ISC models # Author: Raj N Marndi, Litty Preeth, Renuka Prasad from sqlalchemy import Column, Integer, String, MetaData, ForeignKey, \ Boolean, Numeric, Enum, BigInteger from sqlalchemy.schema import Table from healthnmon import log as logging LOG = logging.getLogger('healthnmon.db.models') meta = MetaData() def __common_columns(): """ List of common column definitions for entity sub classes. """ return (Column('createEpoch', BigInteger), Column('lastModifiedEpoch', BigInteger), Column('deletedEpoch', BigInteger), Column('deleted', Boolean, default=False)) Cost = Table('healthnmon_cost', meta, Column('id', Integer, primary_key=True, autoincrement=True), Column('value', Numeric(16, 2)), Column('units', String(255)))
import sys import os import pwd import warnings with warnings.catch_warnings(): warnings.simplefilter("ignore") import paramiko import subprocess import time import socket import libvirt from healthnmon import log from nova import crypto LOG = log.getLogger('healthnmon.common.sshConfiguration') """ Find's nova Home path """ def get_nova_home(): """ retrieve home path of nova . By default it is /var/lib/nova """ nova_home = pwd.getpwnam('nova').pw_dir LOG.debug(_('Nova Home Directory' + nova_home)) return nova_home
# 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. import sys import pyclbr import inspect import logging import traceback from nova.openstack.common import importutils from healthnmon import log from healthnmon.profiler import profile_cpu, profile_mem LOG = log.getLogger('healthnmon.utils') def profile_cputime(module, decorator_name, status): try: if status: profile_cpu.add_module(module) else: profile_cpu.delete_module(module) # import decorator function decorator = importutils.import_class(decorator_name) __import__(module) # Retrieve module information using pyclbr module_data = pyclbr.readmodule_ex(module) for key in module_data.keys():
""" Healthnmon notifier api Implements the healthnmon notifier API """ import uuid from nova.openstack.common import cfg from nova.openstack.common import timeutils, jsonutils, importutils from healthnmon import log as logging from nova.openstack.common import cfg from nova import exception import time from healthnmon.constants import Constants LOG = logging.getLogger('healthnmon.notifier.api') CONF = cfg.CONF WARN = 'WARN' INFO = 'INFO' ERROR = 'ERROR' CRITICAL = 'CRITICAL' DEBUG = 'DEBUG' priorities = (DEBUG, WARN, INFO, ERROR, CRITICAL) drivers = None class BadPriorityException(Exception):
# 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. """ A fake (in-memory) hypervisor+api. Allows nova testing w/o a hypervisor. This module also documents the semantics of real hypervisor connections. """ from healthnmon.virt import driver from healthnmon import log as logging LOG = logging.getLogger('healthnmon.virt.fake') def get_connection(_=None): # The read_only parameter is ignored. return FakeConnection.instance() class FakeConnection(driver.ComputeInventoryDriver): """Fake hypervisor driver""" def __init__(self): self.instances = {} self.host_status = { 'host_name-description': 'Fake Host',
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. """ Defines decorator for profiling heathnmon Service Uses heapy- for memory profiling """ from healthnmon import log as logging from nova.openstack.common import cfg import traceback import functools import os LOG = logging.getLogger('healthnmon.profiler') CONF = cfg.CONF h = None mem_profile_path = None hpy = None modules_profiling_status = {} setref = None def profile_memory_decorator(method, fn): """ decorator for logging which is used from utils.monkey_patch() :param name: name of the function :param function: - object of the function :returns: function -- decorated function
from healthnmon.resourcemodel.healthnmonResourceModel import ResourceUtilization from healthnmon.utils import XMLUtils from healthnmon.inventory_cache_manager import InventoryCacheManager from healthnmon.events import api as event_api from healthnmon.events import event_metadata from healthnmon.constants import Constants from healthnmon.perfmon.perf_stats import Stats from healthnmon import log from nova.openstack.common import cfg import time import datetime import paramiko CONF = cfg.CONF LOG = log.getLogger('healthnmon.libvirt_perfdata') class LibvirtPerfMonitor: perfDataCache = {} @staticmethod def get_perfdata_fromCache(uuid, stats_type): LOG.debug(_(' Entering into get_perfdata_fromCache for uuid ' + uuid)) if uuid in LibvirtPerfMonitor.perfDataCache: return LibvirtPerfMonitor.perfDataCache[uuid][stats_type] @staticmethod def update_perfdata_InCache(uuid, old_stats, new_stats): LOG.debug(_(' Entering into update_perfdata_InCache for uuid ' + uuid))
""" heathnmon Service - Manage communication with compute nodes and collects inventory and monitoring info """ from nova import manager, utils from healthnmon.profiler import helper from nova.openstack.common import importutils from nova.openstack.common import cfg from healthnmon.constants import Constants from healthnmon import driver from healthnmon import log as logging from nova import exception import sys LOG = logging.getLogger("healthnmon.manager") manager_opts = [ cfg.StrOpt( "healthnmon_driver", default="healthnmon.driver.Healthnmon", help="Default driver to use for the healthnmon service", ) ] perfmon_opts = [cfg.IntOpt("perfmon_refresh_interval", default=300, help="performance data refresh period.")] topic_opts = [cfg.StrOpt("healthnmon_topic", default="healthnmon", help="the topic healthnmon service listen on")] CONF = cfg.CONF
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import time from lxml import etree from healthnmon.resourcemodel import resourcemodel_diff from nova import utils from nova.openstack.common import cfg from nova.openstack.common import timeutils from healthnmon import log # including instances_path defined in nova.compute.manager in order to create nova-storage-pool CONF = cfg.CONF CONF.import_opt('instances_path', 'nova.compute.manager') LOG = log.getLogger(__name__) def get_current_epoch_ms(): return long(time.time() * 1000) def getFlagByKey(key): """ Returns the value of the flag queried based on key""" CONF = cfg.CONF return CONF.get(key) def is_service_alive(updated_at, created_at): delta = timeutils.utcnow() - (updated_at or created_at) return abs(utils.total_seconds(delta)) <= CONF.service_down_time
# 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. """ Defines decorator for profiling heathnmon Service Uses heapy- for memory profiling """ from healthnmon import log as logging from nova.openstack.common import cfg import traceback import functools import os LOG = logging.getLogger('healthnmon.profiler') CONF = cfg.CONF h = None mem_profile_path = None hpy = None modules_profiling_status = {} setref = None def profile_memory_decorator(method, fn): """ decorator for logging which is used from utils.monkey_patch() :param name: name of the function :param function: - object of the function :returns: function -- decorated function
# # 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. """ ResourceModelDiff - Handles comparing two resource model objects and provides dictionary of add, update and delete attributes """ from healthnmon import log as logging logging = logging.getLogger('healthnmon.resourcemodeldiff') class ResourceModelDiff(object): """ ResourceModelDIff - Handles comparing two resource model objects and provides dictionary of add, update and delete attributes """ def __init__(self, old_resource_model=None, new_resource_model=None): self.old_modelobj = old_resource_model self.new_modelobj = new_resource_model def _collate_results(self, result): """Method to collate the results""" out_result = {}
# under the License. import time from lxml import etree from healthnmon.resourcemodel import resourcemodel_diff from nova import utils from nova.openstack.common import cfg from nova.openstack.common import timeutils from healthnmon import log # including instances_path defined in nova.compute.manager # in order to create nova-storage-pool CONF = cfg.CONF CONF.import_opt("instances_path", "nova.compute.manager") CONF.import_opt("service_down_time", "nova.service") LOG = log.getLogger(__name__) def get_current_epoch_ms(): return long(time.time() * 1000) def getFlagByKey(key): """ Returns the value of the flag queried based on key""" CONF = cfg.CONF return CONF.get(key) def is_service_alive(updated_at, created_at): delta = timeutils.utcnow() - (updated_at or created_at) return abs(utils.total_seconds(delta)) <= CONF.service_down_time
""" heathnmon Service - Manage communication with compute nodes and collects inventory and monitoring info """ from nova import manager, utils from healthnmon.profiler import helper from nova.openstack.common import importutils from nova.openstack.common import cfg from healthnmon.constants import Constants from healthnmon import driver from healthnmon import log as logging from nova import exception import sys LOG = logging.getLogger('healthnmon.manager') manager_opts = [ cfg.StrOpt('healthnmon_driver', default='healthnmon.driver.Healthnmon', help='Default driver to use for the healthnmon service') ] perfmon_opts = [ cfg.IntOpt("perfmon_refresh_interval", default=300, help="performance data refresh period.") ] topic_opts = [ cfg.StrOpt('healthnmon_topic',
# 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. """ Handles all requests relating to inventory. """ from healthnmon import log as logging from nova.openstack.common import cfg from nova.db.sqlalchemy import api as context_api from healthnmon.db import api from nova.openstack.common import rpc from nova.openstack.common import cfg LOG = logging.getLogger('healthnmon.healthnmon_api') api_opts = [ cfg.StrOpt('healthnmon_topic', default='healthnmon', help='the topic healthnmon service listen on') ] CONF = cfg.CONF try: CONF.healthnmon_topic except cfg.NoSuchOptError: CONF.register_opts(api_opts) '''def vm_host_get_all(context): """ This API will make a call to db layer to fetch the list of all
# 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 sqlalchemy import Column, Integer, String, MetaData, ForeignKey, Boolean, Numeric, Enum, BigInteger from sqlalchemy.schema import Table from healthnmon import log as logging LOG = logging.getLogger("healthnmon.db.models") meta = MetaData() def __common_columns(): """ List of common column definitions for entity sub classes. """ return ( Column("createEpoch", BigInteger), Column("lastModifiedEpoch", BigInteger), Column("deletedEpoch", BigInteger), Column("deleted", Boolean, default=False), )
# 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. """ heathnmon Service default driver - Manage communication with compute nodes and collects inventory and monitoring info """ from nova.openstack.common import cfg from nova.openstack.common import importutils from healthnmon import log as logging LOG = logging.getLogger('healthnmon.driver') driver_opts = [ cfg.StrOpt('healthnmon_inventory_manager', default='healthnmon.inventory_manager.InventoryManager', help='The healthnmon inventory manager class to use'), ] CONF = cfg.CONF CONF.register_opts(driver_opts) class Healthnmon(object): """The base class that all healthnmon classes should inherit from.""" def __init__(self):
# 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. """ Handles all requests relating to inventory. """ from healthnmon import log as logging from nova.openstack.common import cfg from nova.db.sqlalchemy import api as context_api from healthnmon.db import api from nova.openstack.common import rpc from nova.openstack.common import cfg LOG = logging.getLogger('healthnmon.healthnmon_api') api_opts = [ cfg.StrOpt('healthnmon_topic', default='healthnmon', help='the topic healthnmon service listen on') ] CONF = cfg.CONF try: CONF.healthnmon_topic except cfg.NoSuchOptError: CONF.register_opts(api_opts)
# # 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. """Common utility methods for events module """ from healthnmon.resourcemodel.healthnmonResourceModel import Vm, \ PortGroup from healthnmon import log LOG = log.getLogger('healthnmon.events.util') # Properties of different resource model types for which updated event is ignored ignoredProperties = { Vm: [ 'connectionState', 'powerState', 'cpuResourceAllocation', 'memoryResourceAllocation', 'processorSpeedMhz', 'processorSpeedTotalMhz', 'memoryConsumed', 'processorLoadPercent', 'utilization', 'limits',
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. """ A fake (in-memory) hypervisor+api. Allows nova testing w/o a hypervisor. This module also documents the semantics of real hypervisor connections. """ from healthnmon.virt import driver from healthnmon import log as logging LOG = logging.getLogger('healthnmon.virt.fake') def get_connection(_=None): # The read_only parameter is ignored. return FakeConnection.instance() class FakeConnection(driver.ComputeInventoryDriver): """Fake hypervisor driver""" def __init__(self): self.instances = {}
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. """Event generator module Generates events by by calling healthnmon notifier """ from healthnmon.inventory_cache_manager import InventoryCacheManager from healthnmon.events import event_metadata, payload_generator from healthnmon.constants import Constants from healthnmon.notifier import api as notifier_api from nova import context from nova.db import api as nova_db from healthnmon import log LOG = log.getLogger('healthnmon.events.api') def notify(event_type, obj, **kwargs): """Generate event for a event type id This API is used by the different healthnmon modules which need to generate event. Parameters: event_type - One of the event types declared in healthnmon.events.event_meta_data obj - Vm, VmHost or StorageVolume object for which this event is to be generated """ eventmetadata_obj = event_metadata.get_EventMetaData(event_type) payload = payload_generator.generate_payload(eventmetadata_obj, obj, **kwargs)
import traceback invman_opts = [ cfg.IntOpt("compute_db_check_interval", default=60, help="Interval for refresh of inventory from DB"), cfg.IntOpt( "compute_failures_to_offline", default=3, help="Number of consecutive errors \ before marking compute_node offline ", ), cfg.StrOpt("_compute_inventory_driver", default="healthnmon.virt.connection", help="connection "), ] CONF = cfg.CONF CONF.register_opts(invman_opts) LOG = logging.getLogger("healthnmon.inventory_manager") class ComputeInventory(object): """Holds the compute node inventory for a particular compute node that is being managed in the zone.""" def __init__(self, compute_rmcontext): self.is_active = True self.attempt = 0 self.last_seen = datetime.datetime.min self.last_exception = None self.last_exception_time = None self.compute_rmcontext = compute_rmcontext self.compute_info = {}
# 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. """Common utility methods for events module """ from healthnmon.resourcemodel.healthnmonResourceModel import Vm, \ PortGroup from healthnmon import log LOG = log.getLogger('healthnmon.events.util') # Properties of different resource model types for which updated event is ignored ignoredProperties = {Vm: [ 'connectionState', 'powerState', 'cpuResourceAllocation', 'memoryResourceAllocation', 'processorSpeedMhz', 'processorSpeedTotalMhz', 'memoryConsumed', 'processorLoadPercent', 'utilization', 'limits', 'createEpoch',
# 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. """ ResourceModelDiff - Handles comparing two resource model objects and provides dictionary of add, update and delete attributes """ from healthnmon import log as logging logging = logging.getLogger("healthnmon.resourcemodeldiff") class ResourceModelDiff(object): """ ResourceModelDIff - Handles comparing two resource model objects and provides dictionary of add, update and delete attributes """ def __init__(self, old_resource_model=None, new_resource_model=None): self.old_modelobj = old_resource_model self.new_modelobj = new_resource_model def _collate_results(self, result): """Method to collate the results"""
# # 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. """ heathnmon Service default driver - Manage communication with compute nodes and collects inventory and monitoring info """ from nova.openstack.common import cfg from nova.openstack.common import importutils from nova.openstack.common import cfg from healthnmon import log as logging LOG = logging.getLogger('healthnmon.driver') driver_opts = [ cfg.StrOpt('healthnmon_inventory_manager', default='healthnmon.inventory_manager.InventoryManager', help='The healthnmon inventory manager class to use'), ] CONF = cfg.CONF CONF.register_opts(driver_opts) class Healthnmon(object): """The base class that all healthnmon classes should inherit from.""" def __init__(self): self.inventory_manager = \ importutils.import_object(CONF.healthnmon_inventory_manager)
from healthnmon.resourcemodel.healthnmonResourceModel import ResourceUtilization from healthnmon.utils import XMLUtils from healthnmon.inventory_cache_manager import InventoryCacheManager from healthnmon.events import api as event_api from healthnmon.events import event_metadata from healthnmon.constants import Constants from healthnmon.perfmon.perf_stats import Stats from healthnmon import log from nova.openstack.common import cfg import time import datetime import paramiko CONF = cfg.CONF LOG = log.getLogger('healthnmon.libvirt_perfdata') class LibvirtPerfMonitor: perfDataCache = {} @staticmethod def get_perfdata_fromCache(uuid, stats_type): LOG.debug(_(' Entering into get_perfdata_fromCache for uuid ' + uuid)) if uuid in LibvirtPerfMonitor.perfDataCache: return LibvirtPerfMonitor.perfDataCache[uuid][stats_type] @staticmethod def update_perfdata_InCache(uuid, old_stats, new_stats):
# 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 sqlalchemy import Column, Integer, String, MetaData, ForeignKey, \ Boolean, Numeric, Enum, BigInteger from sqlalchemy.schema import Table from healthnmon import log as logging LOG = logging.getLogger('healthnmon.db.models') meta = MetaData() def __common_columns(): """ List of common column definitions for entity sub classes. """ return (Column('createEpoch', BigInteger), Column('lastModifiedEpoch', BigInteger), Column('deletedEpoch', BigInteger), Column('deleted', Boolean, default=False)) Cost = Table('healthnmon_cost', meta, Column('id', Integer, primary_key=True, autoincrement=True),
# License for the specific language governing permissions and limitations # under the License. """Event generator module Generates events by by calling healthnmon notifier """ from healthnmon.inventory_cache_manager import InventoryCacheManager from healthnmon.events import event_metadata, payload_generator from healthnmon.constants import Constants from healthnmon.notifier import api as notifier_api from nova import context from nova.db import api as nova_db from healthnmon import log LOG = log.getLogger('healthnmon.events.api') def notify(event_type, obj, **kwargs): """Generate event for a event type id This API is used by the different healthnmon modules which need to generate event. Parameters: event_type - One of the event types declared in healthnmon.events.event_meta_data obj - Vm, VmHost or StorageVolume object for which this event is to be generated """ eventmetadata_obj = event_metadata.get_EventMetaData(event_type)
:libvirt_type: Libvirt domain type. Can be kvm, qemu, uml, xen (default: kvm). :libvirt_uri: Override for the default libvirt URI (depends on libvirt_type). """ from healthnmon import libvirt_inventorymonitor from healthnmon.perfmon import libvirt_perfdata from healthnmon.virt import driver from healthnmon import log as logging from nova.openstack.common import cfg import traceback libvirt = None LOG = logging.getLogger('healthnmon.virt.libvirt.connection') conn_opts = [ cfg.StrOpt('libvirt_type', default='kvm', help='Libvirt domain type (valid options are: ' 'kvm, lxc, qemu, uml, xen)'), cfg.StrOpt('libvirt_uri', default='', help='Override the default libvirt URI (which is dependent' ' on libvirt_type)') ] CONF = cfg.CONF CONF.register_opts(conn_opts)
invman_opts = [ cfg.IntOpt('compute_db_check_interval', default=60, help='Interval for refresh of inventory from DB'), cfg.IntOpt('compute_failures_to_offline', default=3, help='Number of consecutive errors \ before marking compute_node offline '), cfg.StrOpt('_compute_inventory_driver', default='healthnmon.virt.connection', help='connection ') ] CONF = cfg.CONF CONF.register_opts(invman_opts) LOG = logging.getLogger('healthnmon.inventory_manager') class ComputeInventory(object): """Holds the compute node inventory for a particular compute node that is being managed in the zone.""" def __init__(self, compute_rmcontext): self.is_active = True self.attempt = 0 self.last_seen = datetime.datetime.min self.last_exception = None self.last_exception_time = None self.compute_rmcontext = compute_rmcontext self.compute_info = {}