def _clear_existing_sdn_controller_alarms(self, uuid): # Clear any existing OVSDB manager alarm, corresponding # to this SDN controller. We need to clear this alarm # for all hosts on which it is set, i.e. all unlocked # worker nodes. key = "sdn-controller=%s" % uuid obj = fm_api.FaultAPIs() alarms = obj.get_faults_by_id( fm_constants.FM_ALARM_ID_NETWORK_OVSDB_MANAGER) if alarms is not None: for alarm in alarms: if key in alarm.entity_instance_id: obj.clear_fault( fm_constants.FM_ALARM_ID_NETWORK_OVSDB_MANAGER, alarm.entity_instance_id) # Clear any existing Openflow Controller alarm, corresponding # to this SDN controller. We need need to clear this alarm # for all hosts on which it is set, i.e. all unlocked workers. sdn_controller = objects.sdn_controller.get_by_uuid( pecan.request.context, uuid) uri = "%s://%s" % (sdn_controller.transport, sdn_controller.ip_address) key = "openflow-controller=%s" % uri alarms = obj.get_faults_by_id( fm_constants.FM_ALARM_ID_NETWORK_OPENFLOW_CONTROLLER) if alarms is not None: for alarm in alarms: if key in alarm.entity_instance_id: obj.clear_fault( fm_constants.FM_ALARM_ID_NETWORK_OPENFLOW_CONTROLLER, alarm.entity_instance_id)
def _service_parameter_apply_semantic_check_http(): """Semantic checks for the HTTP Service Type """ # check if a patching operation in progress fm = fm_api.FaultAPIs() alarms = fm.get_faults_by_id( fm_constants.FM_ALARM_ID_PATCH_IN_PROGRESS) if alarms is not None: msg = _("Unable to apply %s service parameters. " "A patching operation is in progress." % constants.SERVICE_TYPE_HTTP) raise wsme.exc.ClientSideError(msg) # check if all hosts are unlocked/enabled hosts = pecan.request.dbapi.ihost_get_list() for host in hosts: if (host['administrative'] == constants.ADMIN_UNLOCKED and host['operational'] == constants.OPERATIONAL_ENABLED): continue else: # the host name might be None for a newly discovered host if not host['hostname']: host_id = host['uuid'] else: host_id = host['hostname'] raise wsme.exc.ClientSideError( _("Host %s must be unlocked and enabled." % host_id))
def __init__(self, *args, **kwargs): LOG.debug(_('SubcloudAuditManager initialization...')) super(SubcloudAuditManager, self).__init__(service_name="subcloud_audit_manager") self.context = context.get_admin_context() self.dcorch_rpc_client = dcorch_rpc_client.EngineClient() self.fm_api = fm_api.FaultAPIs() self.subcloud_manager = kwargs['subcloud_manager']
def __init__(self): # Daemon-specific init self.stdin_path = '/dev/null' self.stdout_path = '/dev/null' self.stderr_path = '/dev/null' self.pidfile_path = PID_FILE self.pidfile_timeout = 5 self.api_addr = "127.0.0.1:%d" % cfg.api_port self.fm_api = fm_api.FaultAPIs()
def __init__(self, conf): super(Service, self).__init__() self.conf = conf self.rpc_server = None self.sysinv_conductor = None self.ceph_api = None self.entity_instance_id = '' self.fm_api = fm_api.FaultAPIs() self.monitor = Monitor(self) self.config = None self.config_desired = None self.config_applied = None
def _raise_fm_fault(image_id, msg): """ Raise fault with message 'msg' using FM API """ entity_instance_id = str(image_id) fm_api.FaultAPIs().set_fault( fm_api.Fault(alarm_id=fm_const.FM_ALARM_ID_STORAGE_IMAGE, alarm_state=fm_const.FM_ALARM_STATE_MSG, entity_type_id=fm_const.FM_ENTITY_TYPE_SERVICE, entity_instance_id=entity_instance_id, severity=fm_const.FM_ALARM_SEVERITY_WARNING, reason_text=msg, alarm_type=fm_const.FM_ALARM_TYPE_4, probable_cause=fm_const.ALARM_PROBABLE_CAUSE_UNKNOWN, proposed_repair_action='Contact next level of support', service_affecting=False))
def _log_to_fm(msg, poposed_fix='', instance_id='', cause=None): """Save an error in the customer log""" # TODO(oponcea): Test and enable it or remove the code if not wanted alarm_id = fm_const.FM_ALARM_ID_STORAGE_IMAGE alarm_state = fm_const.FM_ALARM_STATE_MSG entity_type_id = fm_const.FM_ALARM_TYPE_SERVICE severity = fm_const.FM_ALARM_SEVERITY_WARNING alarm_type = fm_const.FM_ALARM_TYPE_3 probable_cause = cause or fm_const.ALARM_PROBABLE_CAUSE_UNKNOWN fix = poposed_fix fm_api.FaultAPIs().set_fault( fm_api.Fault(alarm_id=alarm_id, alarm_state=alarm_state, entity_type_id=entity_type_id, entity_instance_id=instance_id, severity=severity, reason_text=msg, alarm_type=alarm_type, probable_cause=probable_cause, proposed_repair_action=fix, service_affecting=True))
def update_alarm(alarm_state, alarm_id, reason_text=None): """ Update backup-in-progress alarm""" fmApi = fm_api.FaultAPIs() entity_instance_id = "%s=%s" % (fm_constants.FM_ENTITY_TYPE_HOST, sysinv_constants.CONTROLLER_HOSTNAME) if alarm_state == fm_constants.FM_ALARM_STATE_SET: fault = fm_api.Fault( alarm_id=alarm_id, alarm_state=alarm_state, entity_type_id=fm_constants.FM_ENTITY_TYPE_HOST, entity_instance_id=entity_instance_id, severity=fm_constants.FM_ALARM_SEVERITY_MINOR, reason_text=("System Backup in progress."), # operational alarm_type=fm_constants.FM_ALARM_TYPE_7, # congestion probable_cause=fm_constants.ALARM_PROBABLE_CAUSE_8, proposed_repair_action=("No action required."), service_affecting=False) fmApi.set_fault(fault) else: fmApi.clear_fault(alarm_id, entity_instance_id)
# Import list # UT imports import os import re import uuid import collectd from fm_api import constants as fm_constants from fm_api import fm_api import tsconfig.tsconfig as tsc # only load influxdb on the controller if tsc.nodetype == 'controller': from influxdb import InfluxDBClient api = fm_api.FaultAPIs() # Debug control debug = False debug_lists = False want_state_audit = False # number of notifier loops before the state is object dumped DEBUG_AUDIT = 2 # write a 'value' log on a the resource sample change of more than this amount LOG_STEP = 10 # Number of back to back database update misses MAX_NO_UPDATE_B4_ALARM = 5
def __init__(self): self._fm_api = fm_api.FaultAPIs()
def __init__(self): # Setup logging level_dict = { 'ERROR': logging.ERROR, 'WARN': logging.WARN, 'INFO': logging.INFO, 'DEBUG': logging.DEBUG } if CONF.cinder_congestion.log_level in level_dict.keys(): LOG.setLevel(level_dict[CONF.cinder_congestion.log_level]) else: LOG.setLevel(logging.INFO) LOG.info("Initializing %s..." % self.__class__.__name__) # DRBD file self.drbd_file = '/etc/drbd.d/drbd-cinder.res' # iostat parsing regex self.ts_regex = re.compile(r"(\d{2}/\d{2}/\d{2,4}) " "(\d{2}:\d{2}:\d{2})") self.device_regex = re.compile( r"(\w+-?\w+)\s+(\d+.\d+)\s+(\d+.\d+)\s+(\d+.\d+)\s+(\d+.\d+)" "\s+(\d+.\d+)\s+(\d+.\d+)\s+(\d+.\d+)\s+(\d+.\d+)\s+(\d+.\d+)\s+" "(\d+.\d+)\s+(\d+.\d+)\s+(\d+.\d+)\s+(\d+.\d+)") # window sizes self.s_window_sec = CONF.cinder_congestion.ssd_small_window_size self.m_window_sec = CONF.cinder_congestion.ssd_medium_window_size self.l_window_sec = CONF.cinder_congestion.ssd_large_window_size # state variables self.latest_time = None self.congestion_status = self.STATUS_NORMAL # init data collector self.device_dict = {} # devices self.phys_cinder_device = None self.base_cinder_devs = [] self.base_cinder_tracking_devs = [] self.non_cinder_dynamic_devs = [ 'drbd0', 'drbd1', 'drbd2', 'drbd3', 'drbd5' ] self.non_cinder_phys_devs = [] # set the default operational scenarios self.await_minimal_spike = CONF.cinder_congestion.ssd_thresh_max_await self.await_sustained_congestion = ( CONF.cinder_congestion.ssd_thresh_sustained_await) # FM self.fm_api = fm_api.FaultAPIs() self.fm_state_count = collections.Counter() # CSV handle self.csv = None # status logging self.status_skip_count = 0 # to compare with current g_count self.last_g_count = 0 message_rate = math.ceil(60 / (CONF.wait_time + 1)) self.status_skip_total = math.ceil( message_rate / (message_rate * CONF.cinder_congestion.status_log_rate_modifier)) LOG.info( "Display status message at %d per minute..." % (message_rate * CONF.cinder_congestion.status_log_rate_modifier)) # Clear any exiting alarms self._clear_fm()
# 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. import sys from fm_api import fm_api from fm_api import constants ser = fm_api.FaultAPIs() def print_alarm(alarm): alarm_str = "alarm_id: " + alarm.alarm_id + ", " alarm_str += "uuid: " + alarm.uuid + ", " alarm_str += "alarm_type: " + alarm.alarm_type + "\n" alarm_str += "state: " + alarm.alarm_state + ", " alarm_str += "severity: " + alarm.severity + ", " alarm_str += "entity_type_id: " + alarm.entity_type_id + ", " alarm_str += "timestamp: " + alarm.timestamp + "\n" alarm_str += "entity_instance_id: " + alarm.entity_instance_id + ", " alarm_str += "probable cause:" + alarm.probable_cause + "\n" print(alarm_str)
def update(self, req, id, body): """Updates an existing image with the registry. :param req: wsgi Request object :param body: Dictionary of information about the image :param id: The opaque internal identifier for the image :returns: Returns the updated image information as a mapping, """ image_data = body['image'] from_state = body.get('from_state') # Prohibit modification of 'owner' if not req.context.is_admin and 'owner' in image_data: del image_data['owner'] if 'location' in image_data: image_data['locations'] = [image_data.pop('location')] purge_props = req.headers.get("X-Glance-Registry-Purge-Props", "false") try: # These fields hold sensitive data, which should not be printed in # the logs. sensitive_fields = ['locations', 'location_data'] LOG.debug( "Updating image %(id)s with metadata: %(image_data)r", { 'id': id, 'image_data': { k: v for k, v in image_data.items() if k not in sensitive_fields } }) image_data = _normalize_image_location_for_db(image_data) if purge_props == "true": purge_props = True else: purge_props = False updated_image = self.db_api.image_update(req.context, id, image_data, purge_props=purge_props, from_state=from_state, v1_mode=True) if image_data.get('status') == 'killed': kill_reason = image_data.get('properties', {}) \ .get('kill_reason') if kill_reason: entity_instance_id = 'image=%(id)s' % {'id': id} try: image = make_image_dict( self.db_api.image_get(req.context, id)) instance_id = image.get('properties', {}) \ .get('instance_uuid') if instance_id: entity_instance_id += ', instance=%(id)s' % { 'id': instance_id } except Exception: pass fm_api.FaultAPIs().set_fault( fm_api.Fault( alarm_id=fm_const.FM_ALARM_ID_STORAGE_IMAGE, alarm_state=fm_const.FM_ALARM_STATE_MSG, entity_type_id=fm_const.FM_ENTITY_TYPE_SERVICE, entity_instance_id=entity_instance_id, severity=fm_const.FM_ALARM_SEVERITY_WARNING, reason_text=kill_reason, alarm_type=fm_const.FM_ALARM_TYPE_4, probable_cause=fm_const. ALARM_PROBABLE_CAUSE_UNKNOWN, proposed_repair_action= 'Contact next level of support', service_affecting=False)) LOG.info(_LI("Updating metadata for image %(id)s"), {'id': id}) return dict(image=make_image_dict(updated_image)) except exception.Invalid as e: msg = (_("Failed to update image metadata. " "Got error: %s") % encodeutils.exception_to_unicode(e)) LOG.error(msg) return exc.HTTPBadRequest(msg) except exception.ImageNotFound: LOG.info(_LI("Image %(id)s not found"), {'id': id}) raise exc.HTTPNotFound(body='Image not found', request=req, content_type='text/plain') except exception.ForbiddenPublicImage: LOG.info(_LI("Update denied for public image %(id)s"), {'id': id}) raise exc.HTTPForbidden() except exception.Forbidden: # If it's private and doesn't belong to them, don't let on # that it exists LOG.info( _LI("Access denied to image %(id)s but returning" " 'not found'"), {'id': id}) raise exc.HTTPNotFound(body='Image not found', request=req, content_type='text/plain') except exception.Conflict as e: LOG.info(encodeutils.exception_to_unicode(e)) raise exc.HTTPConflict(body='Image operation conflicts', request=req, content_type='text/plain') except Exception: LOG.exception(_LE("Unable to update image %s") % id) raise
def initialize(self, config_file): config.load(config_file) self._fm_api = fm_api.FaultAPIs()