def _pacemaker_host_check(): parser = argparse.ArgumentParser( description='Check amqp connection of an OpenStack service.') parser.add_argument('-r', dest='pacemaker_resource', help='pacemaker resource', required=True) parser.add_argument('-s', dest='script', required=False, help='Script') parser.add_argument('--crm', dest='crm', required=False, help='Use "crm_mon -1" instead of "pcs status"', action='store_true', default=False) options = parser.parse_args() if options.script and (not os.path.isfile(options.script) or not os.access(options.script, os.X_OK)): utils.critical('the script %s could not be read' % options.script) local_hostname = subprocess.check_output(['hostname', '-s']).strip() try: if options.crm: output = subprocess.check_output(['crm_mon', '-1']) else: output = subprocess.check_output(['pcs', 'status']) except subprocess.CalledProcessError as e: utils.critical('pcs status with status %s: %s' % e.returncode, e.output) except OSError: utils.critical('pcs not found') for line in re.sub("\n +", " ", output).splitlines(): line = " ".join(line.strip().split()) # Sanitize separator if not line: continue resource, remaining = line.split(None, 1) if resource == options.pacemaker_resource: agent, __, remaining = remaining.partition(' ') if ' ' in remaining: status, __, current_hostname = remaining.partition(' ') else: status, current_hostname = remaining, '' if status != "Started": utils.critical("pacemaker resource %s is not started (%s)" % (resource, status)) if current_hostname != local_hostname: utils.ok("pacemaker resource %s doesn't run on this node " "(but on %s)" % (resource, current_hostname)) _ok_run_script(options) elif resource == 'Clone': _check_resource_in_host(remaining, 'Started:', options, local_hostname) elif resource == 'Master/Slave': _check_resource_in_host(remaining, 'Masters:', options, local_hostname) else: utils.critical('pacemaker resource %s not found' % options.pacemaker_resource)
def excepthook(self, ex_type, value, tb): """ Custom exception hook so that we can handle errors in a nicer way """ where = ''.join(traceback.format_tb(tb)) msg = '{}'.format(value) utils.critical(msg) def showError(): html = """ <html> <body bgcolor="#FFEDED"> <p><b>{}</b></p> <p align="left"><small>{}</small></p> </body> </html> """.format(msg, where) self.errorreport.updateHTML(html) self.widget = self.iface.messageBar().createMessage("oops", "Looks like an error occurred", QIcon(":/icons/sad")) button = QPushButton(self.widget) button.setCheckable(True) button.setChecked(self.errorreport.isVisible()) button.setText("Show error") button.toggled.connect(showError) button.toggled.connect(functools.partial(self.errorreport.setVisible)) self.widget.destroyed.connect(self.hideReports) self.widget.layout().addWidget(button) self.messageBar.pushWidget(self.widget, QgsMessageBar.CRITICAL)
def excepthook(self, ex_type, value, tb): """ Custom exception hook so that we can handle errors in a nicer way """ where = ''.join(traceback.format_tb(tb)) msg = '{}'.format(value) utils.critical(msg) def showError(): html = """ <html> <body bgcolor="#FFEDED"> <p><b>{}</b></p> <p align="left"><small>{}</small></p> </body> </html> """.format(msg, where) self.errorreport.updateHTML(html) self.widget = self.messageBar.createMessage("oops", "Looks like an error occurred", QIcon(":/icons/sad")) button = QPushButton(self.widget) button.setCheckable(True) button.setChecked(self.errorreport.isVisible()) button.setText("Show error") button.toggled.connect(showError) button.toggled.connect(functools.partial(self.errorreport.setVisible)) self.widget.destroyed.connect(self.hideReports) self.widget.layout().addWidget(button) self.messageBar.pushWidget(self.widget, QgsMessageBar.CRITICAL)
def _pacemaker_host_check(): parser = argparse.ArgumentParser( description='Check amqp connection of an OpenStack service.') parser.add_argument('-r', dest='pacemaker_resource', help='pacemaker resource', required=True) parser.add_argument('-s', dest='script', required=False, help='Script') parser.add_argument('--crm', dest='crm', required=False, help='Use "crm_mon -1" instead of "pcs status"', action='store_true', default=False) options = parser.parse_args() if options.script and (not os.path.isfile(options.script) or not os.access(options.script, os.X_OK)): utils.critical('the script %s could not be read' % options.script) local_hostname = subprocess.check_output(['hostname', '-s']).strip() try: if options.crm : output = subprocess.check_output(['crm_mon', '-1']) else: output = subprocess.check_output(['pcs', 'status']) except subprocess.CalledProcessError as e: utils.critical('pcs status with status %s: %s' % e.returncode, e.output) except OSError: utils.critical('pcs not found') for line in re.sub("\n +", " ", output).splitlines(): line = " ".join(line.strip().split()) # Sanitize separator if not line: continue resource, remaining = line.split(None, 1) if resource == options.pacemaker_resource: agent, __, remaining = remaining.partition(' ') if ' ' in remaining: status, __, current_hostname = remaining.partition(' ') else: status, current_hostname = remaining, '' if status != "Started": utils.critical("pacemaker resource %s is not started (%s)" % (resource, status)) if current_hostname != local_hostname: utils.ok("pacemaker resource %s doesn't run on this node " "(but on %s)" % (resource, current_hostname)) _ok_run_script(options) elif resource == 'Clone' : _check_resource_in_host(remaining, 'Started:', options, local_hostname) elif resource == 'Master/Slave': _check_resource_in_host(remaining, 'Masters:', options, local_hostname) else: utils.critical('pacemaker resource %s not found' % options.pacemaker_resource)
def _pacemaker_host_check(): parser = argparse.ArgumentParser(description="Check amqp connection of an OpenStack service.") parser.add_argument("-r", dest="pacemaker_resource", help="pacemaker resource", required=True) parser.add_argument("-s", dest="script", required=True, help="Script") options = parser.parse_args() local_hostname = subprocess.check_output(["hostname", "-s"]).strip() try: output = subprocess.check_output(["pcs", "status"]) except subprocess.CalledProcessError as e: utils.critical("pcs status with status %s: %s" % e.returncode, e.output) except OSError: utils.critical("pcs not found") for line in output.splitlines(): line = " ".join(line.strip().split()) # Sanitize separator if not line: continue resource, remaining = line.split(None, 1) if resource == options.pacemaker_resource: agent, __, remaining = remaining.partition(" ") if " " in remaining: status, __, current_hostname = remaining.partition(" ") else: status, current_hostname = remaining, "" if status != "Started": utils.critical("pacemaker resource %s is not started (%s)" % (resource, status)) if current_hostname != local_hostname: utils.ok("pacemaker resource %s doesn't on this node " "(but on %s)" % (resource, current_hostname)) script = shlex.split(options.script) os.execvp(script[0], script) else: utils.critical("pacemaker resource %s not found" % options.pacemaker_resource)