Ejemplo n.º 1
0
def node_standby(argv, standby=True):
    if len(argv) == 0 and "--all" not in utils.pcs_options:
        if standby:
            usage.cluster(["standby"])
        else:
            usage.cluster(["unstandby"])
        sys.exit(1)

    nodes = utils.getNodesFromCorosyncConf()

    if "--all" not in utils.pcs_options:
        nodeFound = False
        for node in nodes:
            if node == argv[0]:
                nodeFound = True
                break

        if not nodeFound:
            utils.err("node '%s' does not appear to exist in configuration" %
                      argv[0])

        if standby:
            utils.run(["crm_standby", "-v", "on", "-N", node])
        else:
            utils.run(["crm_standby", "-D", "-N", node])
    else:
        for node in nodes:
            if standby:
                utils.run(["crm_standby", "-v", "on", "-N", node])
            else:
                utils.run(["crm_standby", "-D", "-N", node])
Ejemplo n.º 2
0
    def __getattr__(self, name):
        if not isinstance(name, str) or not hasattr(zookeeper, name):
            raise ZooKeeperError("Method %s() doesn't exist" % str(name))

        if name in ("ASSOCIATING_STATE","AUTH_FAILED_STATE",
                    "CONNECTED_STATE","CONNECTING_STATE",
                    "EXPIRED_SESSION_STATE","NOTWATCHING_EVENT",
                    "SESSION_EVENT","CREATED_EVENT",
                    "DELETED_EVENT","CHANGED_EVENT","CHILD_EVENT"):
            return getattr(zookeeper, name)

        def safe_get(*args, **kwargs):
            func, result = getattr(zookeeper, name), None
            def real_func():
                if name in ("get", "exists", "get_children"):
                    path, watcher = args[0], args[1] if len(args) > 1 else None
                    return func(self._handler, path, self._wrap_watcher(watcher))
                else:
                    return func(self._handler, *args, **kwargs)
            try:
                result = real_func()
            except zookeeper.SessionExpiredException, err:
                utils.err(utils.cur(), err, "session expired, retry %s(%s,%s)" % (name, args, kwargs))
                self.connect()
                result = real_func()
            except zookeeper.ConnectionLossException, err:
                utils.err(utils.cur(), err, "connection loss, retry %s(%s,%s)" % (name, args, kwargs))
                self.connect()
                result = real_func()
Ejemplo n.º 3
0
 def send_msg(self, msg):
     try:
         self.pika.send_msg(msg)
     except Exception, err:
         utils.err(utils.cur(), err)
         self.is_server_down = True
         self.try_reconnect()
Ejemplo n.º 4
0
 def error(self, message, line_index, col_index=None):
     if isinstance(line_index, tuple):
         line_index, col_index = line_index
     msg = self.filename + ', '
     if isinstance(line_index, slice):
         msg += 'lines {start} to {end}'.format(start=line_index.start+1, end=line_index.stop)
         err = '\n'.join(self.lines[line_index])
     else:
         msg += 'line {index}'.format(index=line_index+1)
         err = self.lines[line_index]
     if col_index is not None:
         msg += ', '
         if isinstance(col_index, slice):
             msg += 'columns {start} to {end}'.format(start=col_index.start+1, end=col_index.stop)
         else:
             msg += 'column {index}'.format(index=col_index+1)
     msg += '\n' + err + '\n'
     pointer = ''
     if isinstance(col_index, slice):
         pointer += ' ' * col_index.start + '^' * (col_index.stop - col_index.start)
     elif isinstance(col_index, int):
         pointer += ' ' * col_index + '^'
     if len(pointer) > 0:
         msg += pointer + ' '
     msg += message
     utils.err(msg)
Ejemplo n.º 5
0
    def post(self):
        """
        HTTP POST request
        :return: status code from the slack end point
        """

        post_data = get_post_data(request)
        current_app.logger.info('Received feedback: {0}'.format(post_data))

        if not post_data.get('g-recaptcha-response', False) or \
                not verify_recaptcha(request):
            current_app.logger.info('The captcha was not verified!')
            return err(ERROR_UNVERIFIED_CAPTCHA)
        else:
            current_app.logger.info('Skipped captcha!')

        try:
            current_app.logger.info('Prettifiying post data: {0}'
                                    .format(post_data))
            formatted_post_data = json.dumps(self.prettify_post(post_data))
            current_app.logger.info('Data prettified: {0}'
                                    .format(formatted_post_data))
        except BadRequestKeyError as error:
            current_app.logger.error('Missing keywords: {0}, {1}'
                                     .format(error, post_data))
            return err(ERROR_MISSING_KEYWORDS)

        slack_response = requests.post(
            url=current_app.config['FEEDBACK_SLACK_END_POINT'],
            data=formatted_post_data
        )

        return slack_response.json(), slack_response.status_code
Ejemplo n.º 6
0
def cluster_localnode(argv):
    if len(argv) != 2:
        usage.cluster()
        exit(1)
    elif argv[0] == "add":
        node = argv[1]
        if not utils.is_rhel6():
            success = utils.addNodeToCorosync(node)
        else:
            success = utils.addNodeToClusterConf(node)

        if success:
            print "%s: successfully added!" % node
        else:
            utils.err("unable to add %s" % node)
    elif argv[0] in ["remove","delete"]:
        node = argv[1]
        if not utils.is_rhel6():
            success = utils.removeNodeFromCorosync(node)
        else:
            success = utils.removeNodeFromClusterConf(node)

        if success:
            print "%s: successfully removed!" % node
        else:
            utils.err("unable to remove %s" % node)
    else:
        usage.cluster()
        exit(1)
Ejemplo n.º 7
0
def full_status():
    if "--full" in utils.pcs_options:
        (output, retval) = utils.run(["crm_mon", "-1", "-r", "-R", "-A", "-f"])
    else:
        (output, retval) = utils.run(["crm_mon", "-1", "-r"])

    if (retval != 0):
        utils.err("cluster is not currently running on this node")

    if not utils.usefile or "--corosync_conf" in utils.pcs_options:
        cluster_name = utils.getClusterName()
        print("Cluster name: %s" % cluster_name)

    if utils.stonithCheck():
        print("WARNING: no stonith devices and stonith-enabled is not false")

    if utils.corosyncPacemakerNodeCheck():
        print(
            "WARNING: corosync and pacemaker node names do not match (IPs used in setup?)"
        )

    print(output)

    if not utils.usefile:
        print_pcsd_daemon_status()
        print()
        utils.serviceStatus("  ")
Ejemplo n.º 8
0
def cluster_cib_revisions(argv):
    try:
        file_list = os.listdir(settings.cib_dir)
    except OSError as e:
        utils.err("unable to list CIB revisions: %s" % e)
    cib_list = []
    cib_name_re = re.compile("^cib-\d+\.raw$")
    for filename in file_list:
        if not cib_name_re.match(filename):
            continue
        file_path = os.path.join(settings.cib_dir, filename)
        try:
            if os.path.isfile(file_path):
                cib_list.append((int(os.path.getmtime(file_path)), filename))
        except OSError:
            pass
    cib_list.sort()
    if not cib_list:
        print "No CIB revisions available"
        return
    for cib_info in cib_list:
        print datetime.datetime.fromtimestamp(cib_info[0]), cib_info[1]
    print
    print(
        "You can inspect a CIB revision using the '-f' switch, e.g. "
        "'pcs -f %(path)s status' or 'pcs -f %(path)s constraint'"
        % {"path": os.path.join(settings.cib_dir, "<cib-revision>")}
    )
Ejemplo n.º 9
0
def list_property(argv):
    print_all = False
    if len(argv) == 0:
        print_all = True

    if "--all" in utils.pcs_options or "--defaults" in utils.pcs_options:
        if len(argv) != 0:
            utils.err("you cannot specify a property when using --all or --defaults")
        properties = get_default_properties()
    else:
        properties = {}

    if "--defaults" not in utils.pcs_options:
        (output, retVal) = utils.run(["cibadmin", "-Q", "--scope", "crm_config"])
        if retVal != 0:
            utils.err("unable to get crm_config\n" + output)
        dom = parseString(output)
        de = dom.documentElement
        crm_config_properties = de.getElementsByTagName("nvpair")
        for prop in crm_config_properties:
            if print_all == True or (argv[0] == prop.getAttribute("name")):
                properties[prop.getAttribute("name")] = prop.getAttribute("value")

    print "Cluster Properties:"
    for prop, val in sorted(properties.iteritems()):
        print " " + prop + ": " + val

    node_attributes = utils.get_node_attributes()
    if node_attributes:
        print "Node Attributes:"
        for node in sorted(node_attributes):
            print " " + node + ":",
            for attr in node_attributes[node]:
                print attr,
            print
Ejemplo n.º 10
0
Archivo: config.py Proyecto: WeiRG/pcs
def config_restore(argv):
    if len(argv) > 1:
        usage.config(["restore"])
        sys.exit(1)

    infile_name = infile_obj = None
    if argv:
        infile_name = argv[0]
    if not infile_name:
        infile_obj = cStringIO.StringIO(sys.stdin.read())

    if os.getuid() == 0:
        if "--local" in utils.pcs_options:
            config_restore_local(infile_name, infile_obj)
        else:
            config_restore_remote(infile_name, infile_obj)
    else:
        new_argv = ['config', 'restore']
        new_stdin = None
        if '--local' in utils.pcs_options:
            new_argv.append('--local')
        if infile_name:
            new_argv.append(os.path.abspath(infile_name))
        else:
            new_stdin = infile_obj.read()
        err_msgs, exitcode, std_out, std_err = utils.call_local_pcsd(
            new_argv, True, new_stdin
        )
        if err_msgs:
            for msg in err_msgs:
                utils.err(msg, False)
            sys.exit(1)
        print std_out
        sys.stderr.write(std_err)
        sys.exit(exitcode)
Ejemplo n.º 11
0
def order_rm(argv):
    if len(argv) == 0:
        usage.constraint()
        sys.exit(1)

    elementFound = False
    (dom,constraintsElement) = getCurrentConstraints()

    for resource in argv:
        for ord_loc in constraintsElement.getElementsByTagName('rsc_order')[:]:
            if ord_loc.getAttribute("first") == resource or ord_loc.getAttribute("then") == resource:
                constraintsElement.removeChild(ord_loc)
                elementFound = True

        resource_refs_to_remove = []
        for ord_set in constraintsElement.getElementsByTagName('resource_ref'):
            if ord_set.getAttribute("id") == resource:
                resource_refs_to_remove.append(ord_set)
                elementFound = True

        for res_ref in resource_refs_to_remove:
            res_set = res_ref.parentNode
            res_order = res_set.parentNode

            res_ref.parentNode.removeChild(res_ref)
            if len(res_set.getElementsByTagName('resource_ref')) <= 0:
                res_set.parentNode.removeChild(res_set)
                if len(res_order.getElementsByTagName('resource_set')) <= 0:
                    res_order.parentNode.removeChild(res_order)

    if elementFound == True:
        utils.replace_cib_configuration(dom)
    else:
        utils.err("No matching resources found in ordering list")
Ejemplo n.º 12
0
    def export(self, pos):
        elements = []
        delta_pos = self.gen_pos_delta(pos)
        for tile in self.view.tiles:
            tile_html = TileHtmlElement()
            tile_html.pos = list(
                map(lambda x: x[0] + x[1], zip(tile.pos, delta_pos)))
            tile_html.size = tile.size
            for facet in tile.facets:
                f = FacetHtmlElement(facet.pic, facet.title)
                if facet.typecode not in api_module.api_mapping:
                    err("ViewExport::export() no typecode found in api mapping "
                        "structure: %s" % facet.typecode)
                    exit(0)
                if facet.typecode not in api_module.module_mapping:
                    errtrace("Facet::self_verify() no api module defined for "
                             "typecode %s" % facet.typecode.encode())
                    exit(0)
                cl = api_module.module_mapping[facet.typecode]
                m = cl(facet.id, facet.title)
                f.url = m.export_html(settings.POSTER_HOME, settings.override)
                om_output("Facet %s export html %s" % (facet.title, f.url))
                if f.url is False:
                    f.url = "#"

                tile_html.facets.append(f)
            elements.append(tile_html)

        s = ""
        for e in elements:
            s += e.export() + "\n"
        return s
Ejemplo n.º 13
0
def cluster_remote_node(argv):
    if len(argv) < 1:
        usage.cluster(["remote-node"])
        sys.exit(1)

    command = argv.pop(0)
    if command == "add":
        if len(argv) < 2:
            usage.cluster(["remote-node"])
            sys.exit(1)
        hostname = argv.pop(0)
        rsc = argv.pop(0)
        if not utils.is_resource(rsc):
            utils.err("unable to find resource '%s'", rsc)
        resource.resource_update(rsc, ["meta", "remote-node="+hostname] + argv)

    elif command in ["remove","delete"]:
        if len(argv) < 1:
            usage.cluster(["remote-node"])
            sys.exit(1)
        hostname = argv.pop(0)
        dom = utils.get_cib_dom()
        nvpairs = dom.getElementsByTagName("nvpair")
        nvpairs_to_remove = []
        for nvpair in nvpairs:
            if nvpair.getAttribute("name") == "remote-node" and nvpair.getAttribute("value") == hostname:
                for np in nvpair.parentNode.getElementsByTagName("nvpair"):
                    if np.getAttribute("name").startswith("remote-"):
                        nvpairs_to_remove.append(np)
        for nvpair in nvpairs_to_remove[:]:
            nvpair.parentNode.removeChild(nvpair)
        utils.replace_cib_configuration(dom)
    else:
        usage.cluster(["remote-node"])
        sys.exit(1)
Ejemplo n.º 14
0
Archivo: config.py Proyecto: tradej/pcs
def config_checkpoint_list():
    try:
        file_list = os.listdir(settings.cib_dir)
    except OSError as e:
        utils.err("unable to list checkpoints: %s" % e)
    cib_list = []
    cib_name_re = re.compile("^cib-(\d+)\.raw$")
    for filename in file_list:
        match = cib_name_re.match(filename)
        if not match:
            continue
        file_path = os.path.join(settings.cib_dir, filename)
        try:
            if os.path.isfile(file_path):
                cib_list.append(
                    (float(os.path.getmtime(file_path)), match.group(1)))
        except OSError:
            pass
    cib_list.sort()
    if not cib_list:
        print("No checkpoints available")
        return
    for cib_info in cib_list:
        print(
            "checkpoint %s: date %s" %
            (cib_info[1], datetime.datetime.fromtimestamp(round(cib_info[0]))))
Ejemplo n.º 15
0
def list_property(argv):
    print_all = False
    if len(argv) == 0:
        print_all = True

    if "--all" in utils.pcs_options or "--defaults" in utils.pcs_options:
        if len(argv) != 0:
            utils.err("you cannot specify a property when using --all or --defaults")
        properties = get_default_properties()
    else:
        properties = {}
        
    if "--defaults" not in utils.pcs_options:
        (output, retVal) = utils.run(["cibadmin","-Q","--scope", "crm_config"])
        if retVal != 0:
            utils.err("unable to get crm_config\n"+output)
        dom = parseString(output)
        de = dom.documentElement
        crm_config_properties = de.getElementsByTagName("nvpair")
        for prop in crm_config_properties:
            if print_all == True or (argv[0] == prop.getAttribute("name")):
                properties[prop.getAttribute("name")] = prop.getAttribute("value")

    print "Cluster Properties:"
    for prop,val in sorted(properties.iteritems()):
        print " " + prop + ": " + val

    node_attributes = utils.get_node_attributes()
    if node_attributes:
        print "Node Attributes:"
        for node in sorted(node_attributes):
            print " " + node + ":",
            for attr in node_attributes[node]:
                print attr,
            print
Ejemplo n.º 16
0
def node_standby(argv,standby=True):
    if len(argv) == 0 and "--all" not in utils.pcs_options:
        if standby:
            usage.cluster(["standby"])
        else:
            usage.cluster(["unstandby"])
        sys.exit(1)

    nodes = utils.getNodesFromPacemaker()

    if "--all" not in utils.pcs_options:
        nodeFound = False
        for node in nodes:
            if node == argv[0]:
                nodeFound = True
                break

        if not nodeFound:
            utils.err("node '%s' does not appear to exist in configuration" % argv[0])

        if standby:
            utils.run(["crm_standby", "-v", "on", "-N", node])
        else:
            utils.run(["crm_standby", "-D", "-N", node])
    else:
        for node in nodes:
            if standby:
                utils.run(["crm_standby", "-v", "on", "-N", node])
            else:
                utils.run(["crm_standby", "-D", "-N", node])
Ejemplo n.º 17
0
def bash(cmd,
         interpreter='/bin/bash',
         strict=set_options(True),
         cwd=os.getcwd(),
         **kwargs):
    """
    Interface to run a process or bash command. Using subprocess.call_check()
    due to portability across most python versions. It was introduced in python 2.5
    and it is also interoperabie across all python 3 versions. 
    @param cmd <str>:
        Shell command to run
    @param interpreter <str>:
        Interpreter for command to run [default: bash]
    @pararm strict <bool>:
        Prefixes any command with 'set -euo pipefail' to ensure process fail with
        the expected exit-code  
    @params kwargs <check_call()>:
        Keyword arguments to modify subprocess.check_call() behavior
    @return exitcode <int>:
        Returns the exit code of the run command, failures return non-zero exit codes
    """
    try:
        exitcode = subprocess.check_call(strict + cmd,
                                         shell=True,
                                         executable=interpreter,
                                         cwd=cwd,
                                         **kwargs)
    except CalledProcessError as e:
        exitcode = e.returncode
        err("""WARNING: Failed to run '{}' command!
        └── Command returned a non-zero exitcode of '{}'.""".format(
            strict + cmd, exitcode))

    return exitcode
Ejemplo n.º 18
0
    def export(self, pos):
        elements = []
        delta_pos = self.gen_pos_delta(pos)
        for tile in self.view.tiles:
            tile_html = TileHtmlElement()
            tile_html.pos = list(map(lambda x: x[0]+x[1],
                                     zip(tile.pos, delta_pos)))
            tile_html.size = tile.size
            for facet in tile.facets:
                f = FacetHtmlElement(facet.pic, facet.title)
                if facet.typecode not in api_module.api_mapping:
                    err("ViewExport::export() no typecode found in api mapping "
                        "structure: %s"%facet.typecode)
                    exit(0)
                if facet.typecode not in api_module.module_mapping:
                    errtrace("Facet::self_verify() no api module defined for "
                             "typecode %s"%facet.typecode.encode())
                    exit(0)
                cl = api_module.module_mapping[facet.typecode]
                m = cl(facet.id, facet.title)
                f.url = m.export_html(settings.POSTER_HOME, settings.override)
                om_output("Facet %s export html %s"%(facet.title, f.url))
                if f.url is False:
                    f.url = "#"

                tile_html.facets.append(f)
            elements.append(tile_html)

        s = ""
        for e in elements:
            s += e.export() + "\n"
        return s
Ejemplo n.º 19
0
def cluster_remote_node(argv):
    if len(argv) < 1:
        usage.cluster(["remote-node"])
        sys.exit(1)

    command = argv.pop(0)
    if command == "add":
        if len(argv) < 2:
            usage.cluster(["remote-node"])
            sys.exit(1)
        hostname = argv.pop(0)
        rsc = argv.pop(0)
        if not utils.is_resource(rsc):
            utils.err("unable to find resource '%s'", rsc)
        resource.resource_update(rsc, ["meta", "remote-node="+hostname] + argv)

    elif command == "remove":
        if len(argv) < 1:
            usage.cluster(["remote-node"])
            sys.exit(1)
        hostname = argv.pop(0)
        dom = utils.get_cib_dom()
        nvpairs = dom.getElementsByTagName("nvpair")
        nvpairs_to_remove = []
        for nvpair in nvpairs:
            if nvpair.getAttribute("name") == "remote-node" and nvpair.getAttribute("value") == hostname:
                for np in nvpair.parentNode.getElementsByTagName("nvpair"):
                    if np.getAttribute("name").startswith("remote-"):
                        nvpairs_to_remove.append(np)
        for nvpair in nvpairs_to_remove[:]:
            nvpair.parentNode.removeChild(nvpair)
        utils.replace_cib_configuration(dom)
    else:
        usage.cluster(["remote-node"])
        sys.exit(1)
Ejemplo n.º 20
0
def location_rule(argv):
    if len(argv) < 3:
        usage.constraint("location rule")
        sys.exit(1)
    
    res_name = argv.pop(0)
    resource_valid, resource_error = utils.validate_constraint_resource(
        utils.get_cib_dom(), res_name
    )
    if not resource_valid:
        utils.err(resource_error)

    argv.pop(0)

    cib = utils.get_cib_dom()
    constraints = cib.getElementsByTagName("constraints")[0]
    lc = cib.createElement("rsc_location")
    constraints.appendChild(lc)
    lc_id = utils.find_unique_id(cib, "location-" + res_name)
    lc.setAttribute("id", lc_id)
    lc.setAttribute("rsc", res_name)

    rule_utils.dom_rule_add(lc, argv)

    utils.replace_cib_configuration(cib)
Ejemplo n.º 21
0
def location_prefer(argv):
    rsc = argv.pop(0)
    prefer_option = argv.pop(0)

    if prefer_option == "prefers":
        prefer = True
    elif prefer_option == "avoids":
        prefer = False
    else:
        usage.constraint()
        sys.exit(1)


    for nodeconf in argv:
        nodeconf_a = nodeconf.split("=",1)
        if len(nodeconf_a) == 1:
            node = nodeconf_a[0]
            if prefer:
                score = "INFINITY"
            else:
                score = "-INFINITY"
        else:
            score = nodeconf_a[1]
            if not utils.is_score(score):
                utils.err("invalid score '%s', use integer or INFINITY or -INFINITY" % score)
            if not prefer:
                if score[0] == "-":
                    score = score[1:]
                else:
                    score = "-" + score
            node = nodeconf_a[0]
        location_add(["location-" +rsc+"-"+node+"-"+score,rsc,node,score])
Ejemplo n.º 22
0
Archivo: config.py Proyecto: tradej/pcs
def config_restore(argv):
    if len(argv) > 1:
        usage.config(["restore"])
        sys.exit(1)

    infile_name = infile_obj = None
    if argv:
        infile_name = argv[0]
    if not infile_name:
        infile_obj = cStringIO.StringIO(sys.stdin.read())

    if os.getuid() == 0:
        if "--local" in utils.pcs_options:
            config_restore_local(infile_name, infile_obj)
        else:
            config_restore_remote(infile_name, infile_obj)
    else:
        new_argv = ['config', 'restore']
        new_stdin = None
        if '--local' in utils.pcs_options:
            new_argv.append('--local')
        if infile_name:
            new_argv.append(os.path.abspath(infile_name))
        else:
            new_stdin = infile_obj.read()
        err_msgs, exitcode, std_out, std_err = utils.call_local_pcsd(
            new_argv, True, new_stdin)
        if err_msgs:
            for msg in err_msgs:
                utils.err(msg, False)
            sys.exit(1)
        print(std_out)
        sys.stderr.write(std_err)
        sys.exit(exitcode)
Ejemplo n.º 23
0
Archivo: acl.py Proyecto: MichalCab/pcs
def acl_permission(argv):
    if len(argv) < 1:
        usage.acl("permission")
        sys.exit(1)

    dom = utils.get_cib_dom()
    dom, acls = get_acls(dom)

    command = argv.pop(0)
    if command == "add":
        if len(argv) < 4:
            usage.acl("permission add")
            sys.exit(1)
        role_id = argv.pop(0)
        found = False
        for role in dom.getElementsByTagName("acl_role"):
            if role.getAttribute("id") == role_id:
                found = True
                break
        if found == False:
            acl_role(["create", role_id] + argv) 
            return

        while len(argv) >= 3:
            kind = argv.pop(0)
            se = dom.createElement("acl_permission")
            se.setAttribute("id", utils.find_unique_id(dom, role_id + "-" + kind))
            se.setAttribute("kind", kind)
            xp_id = argv.pop(0)
            if xp_id == "xpath":
                xpath_query = argv.pop(0)
                se.setAttribute("xpath",xpath_query)
            elif xp_id == "id":
                acl_ref = argv.pop(0)
                se.setAttribute("reference",acl_ref)
            else:
                usage.acl("permission add")
            role.appendChild(se)

        utils.replace_cib_configuration(dom)

    elif command == "delete":
        if len(argv) < 1:
            usage.acl("permission delete")
            sys.exit(1)

        perm_id = argv.pop(0)
        found = False
        for elem in dom.getElementsByTagName("acl_permission"):
            if elem.getAttribute("id") == perm_id:
                elem.parentNode.removeChild(elem)
                found = True
        if not found:
            utils.err("Unable to find permission with id: %s" % perm_id)

        utils.replace_cib_configuration(dom)

    else:
        usage.acl("permission")
        sys.exit(1)
Ejemplo n.º 24
0
 def send_msg(self, msg):
     try:
         self.pika.send_msg(msg)
     except Exception, err:
         utils.err(utils.cur(), err)
         self.is_server_down = True
         self.try_reconnect()
Ejemplo n.º 25
0
def constraint_rule(argv):
    if len(argv) < 2:
        usage.constraint("rule")
        sys.exit(1)

    found = False
    command = argv.pop(0)


    constraint_id = None
    rule_id = None

    if command == "add":
        constraint_id = argv.pop(0)
        cib = utils.get_cib_dom()
        constraint = utils.dom_get_element_with_id(
            cib.getElementsByTagName("constraints")[0],
            "rsc_location",
            constraint_id
        )
        if not constraint:
            utils.err("Unable to find constraint: " + constraint_id)
        options, rule_argv = rule_utils.parse_argv(argv)
        rule_utils.dom_rule_add(constraint, options, rule_argv)
        location_rule_check_duplicates(cib, constraint)
        utils.replace_cib_configuration(cib)

    elif command in ["remove","delete"]:
        cib = utils.get_cib_etree()
        temp_id = argv.pop(0)
        constraints = cib.find('.//constraints')
        loc_cons = cib.findall(str('.//rsc_location'))

        rules = cib.findall(str('.//rule'))
        for loc_con in loc_cons:
            for rule in loc_con:
                if rule.get("id") == temp_id:
                    if len(loc_con) > 1:
                        print("Removing Rule: {0}".format(rule.get("id")))
                        loc_con.remove(rule)
                        found = True
                        break
                    else:
                        print(
                            "Removing Constraint: {0}".format(loc_con.get("id"))
                        )
                        constraints.remove(loc_con)
                        found = True
                        break

            if found == True:
                break

        if found:
            utils.replace_cib_configuration(cib)
        else:
            utils.err("unable to find rule with id: %s" % temp_id)
    else:
        usage.constraint("rule")
        sys.exit(1)
Ejemplo n.º 26
0
def node_standby(argv,standby=True):
    # If we didn't specify any arguments, use the current node name
    if len(argv) == 0 and "--all" not in utils.pcs_options:
        p = subprocess.Popen(["uname","-n"], stdout=subprocess.PIPE)
        cur_node = p.stdout.readline().rstrip()
        argv = [cur_node]

    nodes = utils.getNodesFromPacemaker()

    if "--all" not in utils.pcs_options:
        nodeFound = False
        for node in nodes:
            if node == argv[0]:
                nodeFound = True
                break

        if not nodeFound:
            utils.err("node '%s' does not appear to exist in configuration" % argv[0])

        if standby:
            utils.run(["crm_standby", "-v", "on", "-N", node])
        else:
            utils.run(["crm_standby", "-D", "-N", node])
    else:
        for node in nodes:
            if standby:
                utils.run(["crm_standby", "-v", "on", "-N", node])
            else:
                utils.run(["crm_standby", "-D", "-N", node])
Ejemplo n.º 27
0
def config_checkpoint_list():
    try:
        file_list = os.listdir(settings.cib_dir)
    except OSError as e:
        utils.err("unable to list checkpoints: %s" % e)
    cib_list = []
    cib_name_re = re.compile("^cib-(\d+)\.raw$")
    for filename in file_list:
        match = cib_name_re.match(filename)
        if not match:
            continue
        file_path = os.path.join(settings.cib_dir, filename)
        try:
            if os.path.isfile(file_path):
                cib_list.append(
                    (float(os.path.getmtime(file_path)), match.group(1))
                )
        except OSError:
            pass
    cib_list.sort()
    if not cib_list:
        print "No checkpoints available"
        return
    for cib_info in cib_list:
        print(
            "checkpoint %s: date %s"
            % (cib_info[1], datetime.datetime.fromtimestamp(round(cib_info[0])))
        )
Ejemplo n.º 28
0
def navigate():
    global current_label
    while(True):
        inp = raw_input("Enter your choice: ")
        inp = inp.strip()
        if inp.lower() == "q":
            exit(0)
        if inp == "":
            show_current_menu()
            continue
        if inp.lower() == "u":
            current_label = up_label(current_label)
            show_current_menu()
            continue
        succ, msg = validate_label(inp)
        if succ is False:
            err(msg)
            continue
        print "your choice is %s"%inp
        label = go_to_label(inp)
        if label not in menu_items:
            err("label is out of range")
            continue
        item = menu_items[label]
        if item.__class__.__name__ == "CommandItem":
            item.execute()
            show_current_menu()
        else:
            current_label = label
            show_current_menu()
        continue
Ejemplo n.º 29
0
def main(args):
    utils.drop_privileges()
    if json is None:
        utils.err("This collector requires the `json' Python module.")
        return 13  # Ask tcollector not to respawn us
    name_node_service = HadoopNameNode()
    name_node_service.emit()
Ejemplo n.º 30
0
def auth_nodes(nodes):
    if "-u" in utils.pcs_options:
        username = utils.pcs_options["-u"]
    else:
        username = None

    if "-p" in utils.pcs_options:
        password = utils.pcs_options["-p"]
    else:
        password = None

    for node in nodes:
        status = utils.checkAuthorization(node)
        if status[0] == 3 or "--force" in utils.pcs_options:
            if username == None:
                sys.stdout.write('Username: ')
                sys.stdout.flush()
                username = raw_input("")
            if password == None:
                if sys.stdout.isatty():
                    password = getpass.getpass("Password: "******"")
            utils.updateToken(node,nodes,username,password)
            print "%s: Authorized" % (node)
        elif status[0] == 0:
            print node + ": Already authorized"
        else:
            utils.err("Unable to communicate with %s" % (node))
Ejemplo n.º 31
0
def full_status():
    if "--full" in utils.pcs_options:
        (output, retval) = utils.run(["crm_mon", "-1", "-r", "-R", "-A", "-f"])
    else:
        (output, retval) = utils.run(["crm_mon", "-1", "-r"])

    if (retval != 0):
        utils.err("cluster is not currently running on this node")

    if not utils.usefile or "--corosync_conf" in utils.pcs_options:
        cluster_name = utils.getClusterName()
        print "Cluster name: %s" % cluster_name

    if utils.stonithCheck():
        print("WARNING: no stonith devices and stonith-enabled is not false")

    if utils.corosyncPacemakerNodeCheck():
        print("WARNING: corosync and pacemaker node names do not match (IPs used in setup?)")

    print output

    if not utils.usefile:
        if not utils.is_rhel6():
            print "PCSD Status:"
            cluster.cluster_gui_status([],True)
            print ""
        utils.serviceStatus("  ")
Ejemplo n.º 32
0
def set_add_resource_sets(elem, sets, cib):
    allowed_options = {
        "sequential": ("true", "false"),
        "require-all": ("true", "false"),
        "action" : ("start", "promote", "demote", "stop"),
        "role" : ("Stopped", "Started", "Master", "Slave"),
    }

    for o_set in sets:
        set_id = "pcs_rsc_set"
        res_set = ET.SubElement(elem,"resource_set")
        for opts in o_set:
            if opts.find("=") != -1:
                key,val = opts.split("=")
                if key not in allowed_options:
                    utils.err(
                        "invalid option '%s', allowed options are: %s"
                        % (key, ", ".join(allowed_options.keys()))
                    )
                if val not in allowed_options[key]:
                    utils.err(
                        "invalid value '%s' of option '%s', allowed values are: %s"
                        % (val, key, ", ".join(allowed_options[key]))
                    )
                res_set.set(key,val)
            else:
                se = ET.SubElement(res_set,"resource_ref")
                se.set("id",opts)
                set_id = set_id + "_" + opts
        res_set.set("id", utils.find_unique_id(cib,set_id))
Ejemplo n.º 33
0
Archivo: prop.py Proyecto: tradej/pcs
def list_property(argv):
    print_all = False
    if len(argv) == 0:
        print_all = True

    if "--all" in utils.pcs_options or "--defaults" in utils.pcs_options:
        if len(argv) != 0:
            utils.err("you cannot specify a property when using --all or --defaults")
        properties = get_default_properties()
    else:
        properties = {}
        
    if "--defaults" not in utils.pcs_options:
        properties = get_set_properties(
            None if print_all else argv[0],
            properties
        )

    print("Cluster Properties:")
    for prop,val in sorted(properties.items()):
        print(" " + prop + ": " + val)

    node_attributes = utils.get_node_attributes()
    if node_attributes:
        print("Node Attributes:")
        for node in sorted(node_attributes):
            print(" " + node + ":", end=' ')
            for attr in node_attributes[node]:
                print(attr, end=' ')
            print()
Ejemplo n.º 34
0
def stonith_list_options(stonith_agent):
    metadata = utils.get_stonith_metadata(utils.fence_bin + stonith_agent)
    if not metadata:
        utils.err("unable to get metadata for %s" % stonith_agent)
    try:
        dom = parseString(metadata)
    except xml.parsers.expat.ExpatError as e:
        utils.err("Unable to parse xml for '%s': %s" % (stonith_agent, e))

    title = dom.documentElement.getAttribute("name") or stonith_agent
    short_desc = dom.documentElement.getAttribute("shortdesc")
    if not short_desc:
        for sd in dom.documentElement.getElementsByTagName("shortdesc"):
            if sd.parentNode.tagName == "resource-agent" and sd.firstChild:
                short_desc = sd.firstChild.data.strip()
                break
    long_desc = ""
    for ld in dom.documentElement.getElementsByTagName("longdesc"):
        if ld.parentNode.tagName == "resource-agent" and ld.firstChild:
            long_desc = ld.firstChild.data.strip()
            break

    if short_desc:
        title += " - " + resource.format_desc(len(title + " - "), short_desc)
    print(title)
    print()
    if long_desc:
        print(long_desc)
        print()
    print("Stonith options:")

    params = dom.documentElement.getElementsByTagName("parameter")
    for param in params:
        name = param.getAttribute("name")
        if param.getAttribute("required") == "1":
            name += " (required)"
        desc = ""
        shortdesc_els = param.getElementsByTagName("shortdesc")
        if shortdesc_els and shortdesc_els[0].firstChild:
            desc = shortdesc_els[0].firstChild.nodeValue.strip().replace(
                "\n", " ")
        if not desc:
            desc = "No description available"
        indent = name.__len__() + 4
        desc = resource.format_desc(indent, desc)
        print("  " + name + ": " + desc)

    default_stonith_options = utils.get_default_stonith_options()
    for do in default_stonith_options:
        name = do.attrib["name"]
        desc = ""
        if len(do.findall("shortdesc")) > 0:
            if do.findall("shortdesc")[0].text:
                desc = do.findall("shortdesc")[0].text.strip()
        if not desc:
            desc = "No description available"
        indent = len(name) + 4
        desc = resource.format_desc(indent, desc)
        print("  " + name + ": " + desc)
Ejemplo n.º 35
0
    def get(self, uid):
        """
        HTTP GET request that finds the libraries within ADS 2.0 for that user.

        :param uid: user ID for the API
        :type uid: int

        Return data (on success)
        ------------------------
        libraries: <list<dict>> a list of dictionaries, that contains the
        following for each library entry:
            name: <string> name of the library
            description: <string> description of the library
            documents: <list<string>> list of documents

        HTTP Responses:
        --------------
        Succeed getting libraries: 200
        User does not have a classic/ADS 2.0 account: 400
        User does not have any libraries in their ADS 2.0 account: 400
        Unknown error: 500

        Any other responses will be default Flask errors
        """
        with current_app.session_scope() as session:
            if not current_app.config['ADS_TWO_POINT_OH_LOADED_USERS']:
                current_app.logger.error(
                    'Users from MongoDB have not been loaded into the app')
                return err(TWOPOINTOH_AWS_PROBLEM)

            try:
                user = session.query(Users).filter(
                    Users.absolute_uid == uid).one()

                # Have they got an email for ADS 2.0?
                if not user.twopointoh_email:
                    raise NoResultFound

            except NoResultFound:
                current_app.logger.warning(
                    'User does not have an associated ADS 2.0 account')
                return err(NO_TWOPOINTOH_ACCOUNT)

            library_file_name = current_app.config[
                'ADS_TWO_POINT_OH_USERS'].get(user.twopointoh_email, None)

            if not library_file_name:
                current_app.logger.warning(
                    'User does not have any libraries in ADS 2.0')
                return err(NO_TWOPOINTOH_LIBRARIES)

            try:
                library = TwoPointOhLibraries.get_s3_library(library_file_name)
            except Exception as error:
                current_app.logger.error(
                    'Unknown error with AWS: {}'.format(error))
                return err(TWOPOINTOH_AWS_PROBLEM)

            return {'libraries': library}, 200
Ejemplo n.º 36
0
def find_sock_file(conf_file):
    """Returns the unix socket file of haproxy."""
    try:
        fd = open(conf_file)
    except IOError, e:
        utils.err("Error: %s. Config file path is relative: %s" %
                  (e, conf_file))
        return None
Ejemplo n.º 37
0
 def try_reconnect(self):
     while self.running and self.is_server_down:
         try:
             self.pika.try_connect()
             self.is_server_down = False
         except Exception, err:
             utils.err(utils.cur(), time.time(), err)
             time.sleep(MQConf.RECONNECTION_TIME)
Ejemplo n.º 38
0
def find_conf_file(pid):
    """Returns the conf file of haproxy."""
    try:
        output = subprocess.check_output(
            ["ps", "--no-headers", "-o", "cmd", pid])
    except subprocess.CalledProcessError, e:
        utils.err("HAProxy (pid %s) went away? %s" % (pid, e))
        return None
Ejemplo n.º 39
0
 def try_reconnect(self):
     while self.running and self.is_server_down:
         try:
             self.pika.try_connect()
             self.is_server_down = False
         except Exception, err:
             utils.err(utils.cur(), time.time(), err)
             time.sleep(MQConf.RECONNECTION_TIME)
Ejemplo n.º 40
0
Archivo: stonith.py Proyecto: krig/pcs
def stonith_list_options(stonith_agent):
    metadata = utils.get_stonith_metadata(utils.fence_bin + stonith_agent)
    if not metadata:
        utils.err("unable to get metadata for %s" % stonith_agent)
    try:
        dom = parseString(metadata)
    except xml.parsers.expat.ExpatError as e:
        utils.err("Unable to parse xml for '%s': %s" % (stonith_agent, e))

    title = dom.documentElement.getAttribute("name") or stonith_agent
    short_desc = dom.documentElement.getAttribute("shortdesc")
    if not short_desc:
        for sd in dom.documentElement.getElementsByTagName("shortdesc"):
            if sd.parentNode.tagName == "resource-agent" and sd.firstChild:
                short_desc = sd.firstChild.data.strip()
                break
    long_desc = ""
    for ld in dom.documentElement.getElementsByTagName("longdesc"):
        if ld.parentNode.tagName == "resource-agent" and ld.firstChild:
            long_desc = ld.firstChild.data.strip()
            break

    if short_desc:
        title += " - " + resource.format_desc(len(title + " - "), short_desc)
    print title
    print
    if long_desc:
        print long_desc
        print
    print "Stonith options:"

    params = dom.documentElement.getElementsByTagName("parameter")
    for param in params:
        name = param.getAttribute("name")
        if param.getAttribute("required") == "1":
            name += " (required)"
        desc = ""
        shortdesc_els = param.getElementsByTagName("shortdesc")
        if shortdesc_els and shortdesc_els[0].firstChild:
            desc = shortdesc_els[0].firstChild.nodeValue.strip().replace("\n", " ")
        if not desc:
            desc = "No description available"
        indent = name.__len__() + 4
        desc = resource.format_desc(indent, desc)
        print "  " + name + ": " + desc

    default_stonith_options = utils.get_default_stonith_options()
    for do in default_stonith_options:
        name = do.attrib["name"]
        desc = ""
        if len(do.findall("shortdesc")) > 0:
            if do.findall("shortdesc")[0].text:
                desc = do.findall("shortdesc")[0].text.strip()
        if not desc:
            desc = "No description available"
        indent = len(name) + 4
        desc = resource.format_desc(indent, desc)
        print "  " + name + ": " + desc
Ejemplo n.º 41
0
def constraint_rule(argv):
    if len(argv) < 2:
        usage.constraint("rule")
        sys.exit(1)

    found = False
    command = argv.pop(0)


    constraint_id = None
    rule_id = None
    cib = utils.get_cib_etree()

    if command == "add":
        constraint_id = argv.pop(0)
        constraint = None

        for a in cib.findall(".//configuration//*"):
            if a.get("id") == constraint_id and a.tag == "rsc_location":
                found = True
                constraint = a

        if not found:
            utils.err("Unable to find constraint: " + constraint_id)

        utils.rule_add(constraint, argv) 
        utils.replace_cib_configuration(cib)

    elif command in ["remove","delete"]:
        temp_id = argv.pop(0)
        constraints = cib.find('.//constraints')
        loc_cons = cib.findall('.//rsc_location')

        rules = cib.findall('.//rule')
        for loc_con in loc_cons:
            for rule in loc_con:
                if rule.get("id") == temp_id:
                    if len(loc_con) > 1:
                        print "Removing Rule:",rule.get("id")
                        loc_con.remove(rule)
                        found = True
                        break
                    else:
                        print "Removing Constraint:",loc_con.get("id") 
                        constraints.remove(loc_con)
                        found = True
                        break

            if found == True:
                break

        if found:
            utils.replace_cib_configuration(cib)
        else:
            utils.err("unable to find rule with id: %s" % temp_id)
    else:
        usage.constraint("rule")
        sys.exit(1)
Ejemplo n.º 42
0
	def _createVirtual( cls, **kwargs ) :
		# print '-----------', 'createVirtual'
		pynodetype = cls.get_pynodetype()
		if( pynodetype ) : 
			node = pynodetype( **kwargs )
			return node.name()
		else : 
			utils.err( 'No PyNode found in bases of %s' % ( cls.__name__ ) )
			return False
Ejemplo n.º 43
0
 def timed(*args, **kw):
     # Start time
     ts = time.time()
     # Run target function
     result = func(*args, **kw)
     # End time
     te = time.time()
     err('{}\t{} ms'.format(func.__name__, (te - ts) * 1000))
     return result
Ejemplo n.º 44
0
def open_page(url=None, max_tries=10):
    url = gen_url("/") if url is None else url
    for idx in range(max_tries):
        try:
            br.get(url)
            return True
        except WebDriverException:
            err(f"could not open: {url}, try: {idx+1}")
    return False
Ejemplo n.º 45
0
	def zero_group( self ) :
		parent = self.getParent().getParent()
		d = settings.name_string_delimeter
		n = utils.get_tag( 'zero' )
		if( parent.name().rsplit( d, 1 )[-1] == n ) :
			return parent
		else :
			utils.err( 'Cannot find %s group for %s' % ( n, self ) )
			return False
Ejemplo n.º 46
0
def get_local_network():
    args = ["/sbin/ip", "route"]
    p = subprocess.Popen(args, stdout=subprocess.PIPE)
    iproute_out = p.stdout.read()
    network_addr = re.search(r"^([0-9\.]+)", iproute_out)
    if network_addr:
        return network_addr.group(1)
    else:
        utils.err("unable to determine network address, is interface up?")
Ejemplo n.º 47
0
def cluster_reload(argv):
    if len(argv) != 1 or argv[0] != "corosync":
        usage.cluster(["reload"])
        exit(1)

    output, retval = utils.reloadCorosync()
    if retval != 0 or "invalid option" in output:
        utils.err(output.rstrip())
    print "Corosync reloaded"
Ejemplo n.º 48
0
def print_node_utilization(node):
    cib = utils.get_cib_dom()
    node_el = utils.dom_get_node(cib, node)
    if node_el is None:
        utils.err("Unable to find a node: {0}".format(node))
    utilization = utils.get_utilization_str(node_el)

    print("Node Utilization:")
    print(" {0}: {1}".format(node, utilization))