Ejemplo n.º 1
0
def del_node(addr):
    '''
    Remove node from corosync
    '''
    f = open(conf()).read()
    p = Parser(f)
    nth = p.remove_section_where('nodelist.node', 'ring0_addr', addr)
    if nth == -1:
        return

    if p.count('nodelist.node') <= 2:
        p.set('quorum.two_node', '1')

    f = open(conf(), 'w')
    f.write(p.to_string())
    f.close()

    # check for running config
    try:
        nodes = utils.list_cluster_nodes()
    except Exception:
        nodes = []
    if nodes:
        utils.ext_cmd(["corosync-cmapctl", "-D", "nodelist.node.%s.nodeid" % (nth)],
                      shell=False)
        utils.ext_cmd(["corosync-cmapctl", "-D", "nodelist.node.%s.ring0_addr" % (nth)],
                      shell=False)
Ejemplo n.º 2
0
def _push_completer(args):
    try:
        n = utils.list_cluster_nodes()
        n.remove(utils.this_node())
        return n
    except:
        n = []
Ejemplo n.º 3
0
def del_node(addr):
    '''
    Remove node from corosync
    '''
    f = open(conf()).read()
    p = Parser(f)
    nth = p.remove_section_where('nodelist.node', 'ring0_addr', addr)
    if nth == -1:
        return

    if p.count('nodelist.node') <= 2:
        p.set('quorum.two_node', '1')

    f = open(conf(), 'w')
    f.write(p.to_string())
    f.close()

    # check for running config
    try:
        nodes = utils.list_cluster_nodes()
    except Exception:
        nodes = []
    if nodes:
        utils.ext_cmd(
            ["corosync-cmapctl", "-D",
             "nodelist.node.%s.nodeid" % (nth)],
            shell=False)
        utils.ext_cmd(
            ["corosync-cmapctl", "-D",
             "nodelist.node.%s.ring0_addr" % (nth)],
            shell=False)
Ejemplo n.º 4
0
def _push_completer(args):
    try:
        n = utils.list_cluster_nodes()
        n.remove(utils.this_node())
        return n
    except:
        n = []
Ejemplo n.º 5
0
 def do_push(self, context, *nodes):
     '''
     Push corosync configuration to other cluster nodes.
     If no nodes are provided, configuration is pushed to
     all other cluster nodes.
     '''
     if not nodes:
         nodes = utils.list_cluster_nodes()
         nodes.remove(utils.this_node())
     return corosync.push_configuration(nodes)
Ejemplo n.º 6
0
def _filter_nodes(nodes, user, port):
    'filter function for the nodes element'
    if nodes:
        nodes = nodes.replace(',', ' ').split()
    else:
        nodes = utils.list_cluster_nodes()
    if not nodes:
        raise ValueError("No hosts")
    nodes = [(node, port or None, user or None) for node in nodes]
    return nodes
Ejemplo n.º 7
0
def _filter_nodes(nodes, user, port):
    'filter function for the nodes element'
    if nodes:
        nodes = nodes.replace(',', ' ').split()
    else:
        nodes = utils.list_cluster_nodes()
    if not nodes:
        raise ValueError("No hosts")
    nodes = [(node, port or None, user or None) for node in nodes]
    return nodes
Ejemplo n.º 8
0
 def do_push(self, context, *nodes):
     '''
     Push corosync configuration to other cluster nodes.
     If no nodes are provided, configuration is pushed to
     all other cluster nodes.
     '''
     if not nodes:
         nodes = utils.list_cluster_nodes()
         nodes.remove(utils.this_node())
     return corosync.push_configuration(nodes)
Ejemplo n.º 9
0
 def do_diff(self, context, *nodes):
     '''
     Compare corosync configuration between nodes.
     '''
     checksum = False
     if nodes and nodes[0] == '--checksum':
         checksum = True
         nodes = nodes[1:]
     if not nodes:
         nodes = utils.list_cluster_nodes()
     return corosync.diff_configuration(nodes, checksum=checksum)
Ejemplo n.º 10
0
 def do_diff(self, context, *nodes):
     '''
     Compare corosync configuration between nodes.
     '''
     checksum = False
     if nodes and nodes[0] == '--checksum':
         checksum = True
         nodes = nodes[1:]
     if not nodes:
         nodes = utils.list_cluster_nodes()
     return corosync.diff_configuration(nodes, checksum=checksum)
Ejemplo n.º 11
0
def add_node(name):
    '''
    Add node to corosync.conf
    '''
    coronodes = None
    nodes = None
    coronodes = utils.list_corosync_nodes()
    try:
        nodes = utils.list_cluster_nodes()
    except Exception:
        nodes = []
    ipaddr = get_ip(name)
    if name in coronodes or (ipaddr and ipaddr in coronodes):
        err_buf.warning("%s already in corosync.conf" % (name))
        return
    if name in nodes:
        err_buf.warning("%s already in configuration" % (name))
        return

    f = open(conf()).read()
    p = Parser(f)

    node_addr = name
    node_id = next_nodeid(p)

    p.add(
        'nodelist',
        make_section(
            'nodelist.node',
            make_value('nodelist.node.ring0_addr', node_addr) +
            make_value('nodelist.node.nodeid', str(node_id))))

    num_nodes = p.count('nodelist.node')
    if num_nodes > 2:
        p.remove('quorum.two_node')

    f = open(conf(), 'w')
    f.write(p.to_string())
    f.close()

    # update running config (if any)
    if nodes:
        utils.ext_cmd([
            "corosync-cmapctl", "-s",
            "nodelist.node.%s.nodeid" % (num_nodes - 1), "u32",
            str(node_id)
        ],
                      shell=False)
        utils.ext_cmd([
            "corosync-cmapctl", "-s",
            "nodelist.node.%s.ring0_addr" % (num_nodes - 1), "str", node_addr
        ],
                      shell=False)
Ejemplo n.º 12
0
def add_node(name):
    '''
    Add node to corosync.conf
    '''
    coronodes = None
    nodes = None
    coronodes = utils.list_corosync_nodes()
    try:
        nodes = utils.list_cluster_nodes()
    except Exception:
        nodes = []
    ipaddr = get_ip(name)
    if name in coronodes or (ipaddr and ipaddr in coronodes):
        err_buf.warning("%s already in corosync.conf" % (name))
        return
    if name in nodes:
        err_buf.warning("%s already in configuration" % (name))
        return

    f = open(conf()).read()
    p = Parser(f)

    node_addr = name
    node_id = next_nodeid(p)

    p.add('nodelist',
          make_section('nodelist.node',
                       make_value('nodelist.node.ring0_addr', node_addr) +
                       make_value('nodelist.node.nodeid', str(node_id))))

    num_nodes = p.count('nodelist.node')
    if num_nodes > 2:
        p.remove('quorum.two_node')

    f = open(conf(), 'w')
    f.write(p.to_string())
    f.close()

    # update running config (if any)
    if nodes:
        utils.ext_cmd(["corosync-cmapctl",
                       "-s", "nodelist.node.%s.nodeid" % (num_nodes - 1),
                       "u32", str(node_id)], shell=False)
        utils.ext_cmd(["corosync-cmapctl",
                       "-s", "nodelist.node.%s.ring0_addr" % (num_nodes - 1),
                       "str", node_addr], shell=False)
Ejemplo n.º 13
0
 def do_diff(self, context, filename, *nodes):
     "usage: diff <filename> [--checksum] [nodes...]. Diff file across cluster."
     this_node = utils.this_node()
     checksum = False
     if len(nodes) and nodes[0] == '--checksum':
         nodes = nodes[1:]
         checksum = True
     if not nodes:
         nodes = utils.list_cluster_nodes()
     if checksum:
         utils.remote_checksum(filename, nodes, this_node)
     elif len(nodes) == 1:
         utils.remote_diff_this(filename, nodes, this_node)
     elif this_node in nodes:
         nodes.remove(this_node)
         utils.remote_diff_this(filename, nodes, this_node)
     elif len(nodes):
         utils.remote_diff(filename, nodes)
Ejemplo n.º 14
0
 def do_add(self, context, *args):
     '''
     Add the given node(s) to the cluster.
     Installs packages, sets up corosync and pacemaker, etc.
     Must be executed from a node in the existing cluster.
     '''
     params = self._args_implicit(context, args, 'node')
     paramdict = utils.nvpairs2dict(params)
     node = paramdict.get('node')
     if node:
         node = node.replace(',', ' ').split()
     else:
         node = []
     nodes = paramdict.get('nodes')
     if not nodes:
         nodes = utils.list_cluster_nodes()
     nodes += node
     params += ['nodes=%s' % (','.join(nodes))]
     return scripts.run('add', params)
Ejemplo n.º 15
0
 def do_add(self, context, *args):
     '''
     Add the given node(s) to the cluster.
     Installs packages, sets up corosync and pacemaker, etc.
     Must be executed from a node in the existing cluster.
     '''
     params = self._args_implicit(context, args, 'node')
     paramdict = utils.nvpairs2dict(params)
     node = paramdict.get('node')
     if node:
         node = node.replace(',', ' ').split()
     else:
         node = []
     nodes = paramdict.get('nodes')
     if not nodes:
         nodes = utils.list_cluster_nodes()
     nodes += node
     params += ['nodes=%s' % (','.join(nodes))]
     return scripts.run('add', params)
Ejemplo n.º 16
0
    def do_run(self, context, cmd):
        '''
        Execute the given command on all nodes, report outcome
        '''
        try:
            from psshlib import api as pssh
            _has_pssh = True
        except ImportError:
            _has_pssh = False

        if not _has_pssh:
            context.fatal_error("PSSH not found")

        hosts = utils.list_cluster_nodes()
        opts = pssh.Options()
        for host, result in pssh.call(hosts, cmd, opts).iteritems():
            if isinstance(result, pssh.Error):
                err_buf.error("[%s]: %s" % (host, result))
            else:
                if result[0] != 0:
                    err_buf.error("[%s]: rc=%s\n%s\n%s" % (host, result[0], result[1], result[2]))
                else:
                    err_buf.ok("[%s]\n%s" % (host, result[1]))
Ejemplo n.º 17
0
    def do_run(self, context, cmd):
        '''
        Execute the given command on all nodes, report outcome
        '''
        try:
            from psshlib import api as pssh
            _has_pssh = True
        except ImportError:
            _has_pssh = False

        if not _has_pssh:
            context.fatal_error("PSSH not found")

        hosts = utils.list_cluster_nodes()
        opts = pssh.Options()
        for host, result in pssh.call(hosts, cmd, opts).iteritems():
            if isinstance(result, pssh.Error):
                err_buf.error("[%s]: %s" % (host, result))
            else:
                if result[0] != 0:
                    err_buf.error("[%s]: rc=%s\n%s\n%s" %
                                  (host, result[0], result[1], result[2]))
                else:
                    err_buf.ok("[%s]\n%s" % (host, result[1]))
Ejemplo n.º 18
0
 def _node_in_cluster(self, node):
     return node in utils.list_cluster_nodes()
Ejemplo n.º 19
0
 def _node_in_cluster(self, node):
     return node in utils.list_cluster_nodes()
Ejemplo n.º 20
0
def _all_nodes(args):
    try:
        return utils.list_cluster_nodes()
    except:
        return []
Ejemplo n.º 21
0
def _remove_completer(args):
    try:
        n = utils.list_cluster_nodes()
    except:
        n = []
    return scripts.param_completion_list('remove') + n
Ejemplo n.º 22
0
def _remove_completer(args):
    try:
        n = utils.list_cluster_nodes()
    except:
        n = []
    return scripts.param_completion_list('remove') + n
Ejemplo n.º 23
0
def _all_nodes(args):
    try:
        return utils.list_cluster_nodes()
    except:
        return []