def _stop_talker_thread(): global talker_thread if talker_thread is not None: console_log.debug("Stopping talker thread") talker_thread.stop() talker_thread = None ServiceControl.unregister_listener('corosync', _corosync_listener)
def _start_talker_thread(interface): global talker_thread if talker_thread is None: console_log.debug("Starting talker thread") talker_thread = TalkerThread(interface, console_log) talker_thread.start() ServiceControl.register_listener('corosync', _corosync_listener)
def _get_md(self): try: matches = re.finditer("^(md\d+) : active", open('/proc/mdstat').read().strip(), flags=re.MULTILINE) dev_md_nodes = self.block_devices.find_block_devs( BlockDevices.MDRAIDPATH) devs = [] for match in matches: # e.g. md0 device_name = match.group(1) device_path = "/dev/%s" % device_name device_major_minor = self.block_devices.path_to_major_minor( device_path) # Defensive, but perhaps the md device doesn't show up as disk/by-id in which case we can't use it try: device_path = dev_md_nodes[device_major_minor] except KeyError: continue try: detail = AgentShell.try_run([ 'mdadm', '--brief', '--detail', '--verbose', device_path ]) device_uuid = re.search("UUID=(.*)[ \\n]", detail.strip(), flags=re.MULTILINE).group(1) device_list_csv = re.search("^\s+devices=(.*)$", detail.strip(), flags=re.MULTILINE).group(1) device_list = device_list_csv.split(",") devs.append({ "uuid": device_uuid, "path": device_path, "mm": device_major_minor, "device_paths": device_list }) except OSError as os_error: # mdadm doesn't exist, threw an error etc. console_log.debug("mdadm threw an exception '%s' " % os_error.strerror) return devs except IOError: return []
def update_session(self): messages = DevicePluginMessageCollection([], priority=PRIO_LOW) total_lines = 0 while True: lines = self.poll() if lines: messages.append({'log_lines': lines}) else: break console_log.debug("SyslogDevicePlugin: %lines in %s messages" % (total_lines, len(messages))) if messages: return messages else: return None
def discover_existing_mcastport(ring1, timeout = 10): console_log.debug("Sniffing for packets to %s on %s (%s)" % (ring1.mcastaddr, ring1.name, ring1.ipv4_address)) console_log.debug("Sniffing for packets to %s on %s" % (ring1.mcastaddr, ring1.name)) networking.subscribe_multicast(ring1) cap = networking.start_cap(ring1, timeout / 10, "ip multicast and dst host %s and not src host %s" % (ring1.mcastaddr, ring1.ipv4_address)) # Stop the talker thread if it is running. _stop_talker_thread() ring1_original_mcast_port = ring1.mcastport def recv_packets(header, data): ring1.mcastport = networking.get_dport_from_packet(data) console_log.debug("Sniffed multicast traffic on %d" % ring1.mcastport) try: packet_count = 0 start_time = time.time() while packet_count < 1 and time.time() < start_time + timeout: try: packet_count += cap.dispatch(1, recv_packets) except Exception, e: raise RuntimeError("Error reading from the network: %s" % str(e)) # If we haven't seen anything yet, make sure we are blathering... if packet_count < 1: _start_talker_thread(ring1) console_log.debug("Finished after %d seconds, sniffed: %d" % (time.time() - start_time, packet_count))
def discover_existing_mcastport(ring1, timeout=10): console_log.info( "Sniffing for packets on {}({})".format(ring1.name, ring1.mcastaddr) ) # Stop the talker thread if it is running. _stop_talker_thread() # Start the talker thread _start_talker_thread(ring1) ring1_original_mcast_port = ring1.mcastport try: dports = sniff( lfilter=lambda x: x.haslayer(UDP) and isinstance(x[UDP].dport, (int, long)) and x[IP].dst == ring1.mcastaddr and x[IP].src != ring1.ipv4_address, iface=ring1.name, count=1, timeout=timeout, ) dports = map(lambda x: x[UDP].dport, dports) console_log.debug( "Finished after %d seconds, sniffed: %d" % (timeout, len(dports)) ) if len(dports): ring1.mcastport = dports.pop() console_log.debug("Sniffed multicast traffic on %d" % ring1.mcastport) finally: # If we heard someone else talking (ring1_original_mcast_post != ring1.mcast_post) # then stop the talker thread, otherwise we should continue to fill the dead air until we start corosync. if ring1_original_mcast_port != ring1.mcastport: _stop_talker_thread()
def recv_packets(header, data): ring1.mcastport = networking.get_dport_from_packet(data) console_log.debug("Sniffed multicast traffic on %d" % ring1.mcastport)
def _corosync_listener(service, action): if service == 'corosync' and action == ServiceControl.ServiceState.SERVICESTARTED: console_log.debug("Corosync has been started by this node") _stop_talker_thread()
def _get_emcpower(self): try: devs = [] # We are looking in /dev for all emcpowerX devices but not /dev/emcpower. The *? means we get /dev/emcpowerX # and /dev/emcpowerXX in case they have more than 26 devices for device_path in glob.glob("/dev/emcpower?*"): try: device_major_minor = self.block_devices.path_to_major_minor( device_path) name = os.path.basename(device_path) out = AgentShell.try_run( ['powermt', 'display', 'dev=%s' % name]) # The command above returns something like below, so use the === lines as keys to search for different things. # above search for the logical device ID and below search for the devices used by the emcpower device. # VNX ID=APM00122204204 [NGS1]\n" # Logical device ID=600601603BC12D00C4CECB092F1FE311 [LUN 11]\n" # state=alive; policy=CLAROpt; queued-IOs=0 # Owner: default=SP A, current=SP A Array failover mode: 4 # ============================================================================== # --------------- Host --------------- - Stor - -- I/O Path -- -- Stats --- # ### HW Path I/O Paths Interf. Mode State Q-IOs Errors # ============================================================================== # 13 qla2xxx sdb SP A0 active alive 0 0" # 12 qla2xxx sde SP B0 active alive 0 0 pwr_lines = [i for i in out.split("\n") if len(i) > 0] device_list = [] # Compose a lookup of names of multipath devices, for use parsing other lines headerlinesremaining = 2 # pass 2 ========= type lines. for line in pwr_lines: if (headerlinesremaining > 0): if line.startswith("================="): headerlinesremaining -= 1 match = re.search("Logical device ID=([0-9A-Z]+)", line) if match: device_uuid = match.group(1) else: tokens = re.findall(r"[\w]+", line) device_list.append("/dev/%s" % tokens[2]) devs.append({ "uuid": device_uuid[0:8] + ":" + device_uuid[8:16] + ":" + device_uuid[16:24] + ":" + device_uuid[24:32], "path": device_path, "mm": device_major_minor, "device_paths": device_list }) except OSError as os_error: # powermt doesn't exist, threw an error etc. console_log.debug("powermt threw an exception '%s' " % os_error.strerror) return devs except IOError: return []
def stop(self): console_log.debug("SystemdJournalListener.stop") self.should_run = False
def teardown(self): console_log.debug("SystemdJournalDevicePlugin.teardown") self._listener.stop() self._listener.join()
def stop(self): console_log.debug("SyslogListener.stop") if self.server: console_log.debug("SyslogListener.stop: closing socket") self.server.shutdown() self.server.server_close()