Example #1
0
def make_bindnetaddr():
    host = crm_script.host()
    hostinfo = crm_script.output(2)[host]
    ba = crm_script.param('bindnetaddr')
    if ba:
        return ba

    # if not, try to figure it out based
    # on preferred interface
    iface = crm_script.param('iface')
    if isinstance(iface, dict):
        iface = iface[host]
    interfaces = hostinfo['net']['interfaces']
    if not iface:
        for info in interfaces:
            if info.get('Destination') == '0.0.0.0':
                iface = info.get('Iface')
                break
    try:
        for info in interfaces:
            if info.get('Iface') != iface:
                continue
            dst = info.get('Destination')
            if dst != '0.0.0.0':
                return info.get('Destination')
    except:
        pass
    crm_script.fail_exit("Could not discover appropriate bindnetaddr")
Example #2
0
def run_corosync():
    # create corosync.conf

    nodelist = crm_script.output(2).keys()
    nodelist_txt = ""
    for i, node in enumerate(nodelist):
        nodelist_txt += """
    node {
        ring0_addr: %s
        nodeid: %s
    }
""" % (node, i + 1)

    quorum_txt = ""
    if len(nodelist) == 1:
        quorum_txt = ''
    if len(nodelist) == 2:
        quorum_txt = """    two_node: 1
"""
    else:
        quorum_txt = """    provider: corosync_votequorum
    expected_votes: %s
""" % ((len(nodelist) / 2) + 1)

    try:
        crm_script.save_template('./corosync.conf.template',
                                 '/etc/corosync/corosync.conf',
                                 bindnetaddr=make_bindnetaddr(),
                                 mcastaddr=crm_script.param('mcastaddr'),
                                 mcastport=crm_script.param('mcastport'),
                                 transport=crm_script.param('transport'),
                                 nodelist=nodelist_txt,
                                 quorum=quorum_txt)
    except Exception, e:
        crm_script.exit_fail(str(e))
Example #3
0
def make_bindnetaddr():
    host = crm_script.host()
    hostinfo = crm_script.output(1)[host]
    ba = crm_script.param('bindnetaddr')
    if ba:
        return ba

    # if not, try to figure it out based
    # on preferred interface
    iface = crm_script.param('iface')
    if isinstance(iface, dict):
        iface = iface[host]
    interfaces = hostinfo['net']['interfaces']
    if not iface:
        for info in interfaces:
            if info.get('Destination') == '0.0.0.0':
                iface = info.get('Iface')
                break
    try:
        for info in interfaces:
            if info.get('Iface') != iface:
                continue
            dst = info.get('Destination')
            if dst != '0.0.0.0':
                return info.get('Destination')
    except:
        pass
    crm_script.fail_exit("Could not discover appropriate bindnetaddr")
Example #4
0
def run_corosync():
    # create corosync.conf

    nodelist = crm_script.output(1).keys()
    nodelist_txt = ""
    for i, node in enumerate(nodelist):
        nodelist_txt += """
    node {
        ring0_addr: %s
        nodeid: %s
    }
""" % (node, i + 1)

    quorum_txt = ""
    if len(nodelist) == 1:
        quorum_txt = ''
    if len(nodelist) == 2:
        quorum_txt = """    two_node: 1
"""
    else:
        quorum_txt = """    provider: corosync_votequorum
    expected_votes: %s
""" % ((len(nodelist) / 2) + 1)

    try:
        crm_script.save_template('./corosync.conf.template',
                                 '/etc/corosync/corosync.conf',
                                 bindnetaddr=make_bindnetaddr(),
                                 mcastaddr=crm_script.param('mcastaddr'),
                                 mcastport=crm_script.param('mcastport'),
                                 transport=crm_script.param('transport'),
                                 nodelist=nodelist_txt,
                                 quorum=quorum_txt)
    except Exception, e:
        crm_script.exit_fail(str(e))
Example #5
0
def run_validate():
    data = crm_script.output(1)
    for node in remove_nodes:
        if data.get(node) != node:
            crm_script.exit_fail("%s not found or not responding: %s" % (node, data.get(node)))
        if host == node:
            crm_script.exit_fail("Call from another node: %s = %s" % (node, host))
    crm_script.exit_ok(host)
Example #6
0
def run_validate():
    data = crm_script.output(1)
    for node in remove_nodes:
        if data.get(node) != node:
            crm_script.exit_fail("%s not found or not responding: %s" %
                                 (node, data.get(node)))
        if host == node:
            crm_script.exit_fail("Call from another node: %s = %s" %
                                 (node, host))
    crm_script.exit_ok(host)
Example #7
0
#!/usr/bin/env python
import crm_script
import os
import stat

host = crm_script.host()
others = crm_script.output(1).keys()
others.remove(host)

COROSYNC_AUTH = '/etc/corosync/authkey'
COROSYNC_CONF = '/etc/corosync/corosync.conf'


def make_opts():
    from psshlib import api as pssh
    opts = pssh.Options()
    opts.timeout = 60
    opts.recursive = True
    opts.user = '******'
    opts.ssh_options += [
        'PasswordAuthentication=no', 'StrictHostKeyChecking=no',
        'ControlPersist=no'
    ]
    return opts


def check_results(pssh, results):
    failures = []
    for host, result in results.items():
        if isinstance(result, pssh.Error):
            failures.add("%s: %s" % (host, str(result)))
Example #8
0
#!/usr/bin/python3
import crm_script
show_all = crm_script.is_true(crm_script.param('show_all'))
uptimes = list(crm_script.output(1).items())
max_uptime = '', 0.0
for host, uptime in uptimes:
    if float(uptime) > max_uptime[1]:
        max_uptime = host, float(uptime)
if show_all:
    print("Uptimes: %s" % (', '.join("%s: %s" % v for v in uptimes)))
print("Longest uptime is %s seconds on host %s" %
      (max_uptime[1], max_uptime[0]))
Example #9
0
def compare_files(systems):
    keys = set()
    for host, files in systems:
        keys.update(list(files.keys()))
    for filename in keys:
        vals = set([files.get(filename) for host, files in systems])
        if len(vals) > 1:
            info = ', '.join('%s: %s' % (h, files.get(filename)) for h, files in systems)
            warn("%s: %s" % ("Files differ", info))


compare_system((h, info['system']) for h, info in health_report.items())
compare_files((h, info['files']) for h, info in health_report.items())

if crm_script.output(2):
    report = crm_script.output(2)
    status = report.get('status')
    analysis = report.get('analysis')
    if status and not analysis:
        warn("Cluster report: %s" % (status))
    elif analysis:
        print("INFO: Cluster report:")
        print(analysis)
    else:
        warn("No cluster report generated")

if errors:
    for e in errors:
        print("ERROR:", e)
if warnings:
Example #10
0
#!/usr/bin/env python
import crm_script
import os
import stat

host = crm_script.host()
others = crm_script.output(2).keys()
others.remove(host)

COROSYNC_AUTH = '/etc/corosync/authkey'
COROSYNC_CONF = '/etc/corosync/corosync.conf'


def make_opts():
    import parallax
    opts = parallax.Options()
    opts.timeout = 60
    opts.recursive = True
    opts.user = '******'
    opts.ssh_options += ['PasswordAuthentication=no',
                         'StrictHostKeyChecking=no',
                         'ControlPersist=no']
    return opts


def check_results(parallax, results):
    failures = []
    for host, result in results.items():
        if isinstance(result, parallax.Error):
            failures.add("%s: %s" % (host, str(result)))
    if failures:
Example #11
0
    for host, iface in selections.iteritems():
        if not iface or invalid(host, iface):
            crm_script.exit_fail("No usable network interface on %s: %s" % (host, iface))

    return user_iface


def make_mcastaddr():
    import random

    random.seed()
    b, c, d = random.randint(1, 254), random.randint(1, 254), random.randint(1, 254)
    return "%d.%d.%d.%d" % (239, b, c, d)


try:
    data = crm_script.output(2)

    crm_init.verify(data)

    ret = {}
    ret["iface"] = select_interfaces(crm_script.param("iface"), data)

    if not crm_script.param("mcastaddr"):
        ret["mcastaddr"] = make_mcastaddr()

    crm_script.exit_ok(ret)

except Exception, e:
    crm_script.exit_fail("Verification failed: %s" % (e))
Example #12
0
#!/usr/bin/python3
import crm_script
show_all = crm_script.is_true(crm_script.param('show_all'))
uptimes = list(crm_script.output(1).items())
max_uptime = '', 0.0
for host, uptime in uptimes:
    if float(uptime) > max_uptime[1]:
        max_uptime = host, float(uptime)
if show_all:
    print("Uptimes: %s" % (', '.join("%s: %s" % v for v in uptimes)))
print("Longest uptime is %s seconds on host %s" % (max_uptime[1], max_uptime[0]))
Example #13
0
    #check('version', 'Kernel version differs')

def compare_files(systems):
    keys = set()
    for host, files in systems:
        keys.update(files.keys())
    for filename in keys:
        vals = set([files.get(filename) for host, files in systems])
        if len(vals) > 1:
            info = ', '.join('%s: %s' % (h, files.get(filename)) for h, files in systems)
            warn("%s: %s" % ("Files differ", info))

compare_system((h, info['system']) for h, info in health_report.iteritems())
compare_files((h, info['files']) for h, info in health_report.iteritems())

if crm_script.output(2):
    report = crm_script.output(2)
    status = report.get('status')
    analysis = report.get('analysis')
    if status and not analysis:
        warn("Cluster report: %s" % (status))
    elif analysis:
        print "INFO: Cluster report:"
        print analysis
    else:
        warn("No cluster report generated")

if errors:
    for e in errors:
        print "ERROR:", e
if warnings:
Example #14
0
#!/usr/bin/env python
import crm_script
show_all = crm_script.is_true(crm_script.param('show_all'))
uptimes = crm_script.output(1).items()
max_uptime = '', 0
for host, uptime in uptimes:
    if uptime > max_uptime[1]:
        max_uptime = host, uptime
if show_all:
    print "Uptimes: %s" % (', '.join("%s: %s" % v for v in uptimes))
print "Longest uptime is %s seconds on host %s" % (max_uptime[1], max_uptime[0])
Example #15
0
rc, _, err = crm_script.call(['crm', 'cluster', 'wait_for_startup', '30'])
if rc != 0:
    crm_script.exit_fail("Cluster not responding")

def check_for_primitives():
    rc, out, err = crm_script.call("crm configure show type:primitive | grep primitive", shell=True)
    if rc == 0 and out:
        return True
    return False

if check_for_primitives():
    crm_script.debug("Joined existing cluster - will not reconfigure")
    crm_script.exit_ok(True)

try:
    nodelist = crm_script.output(1).keys()
    if len(nodelist) < 3:
        policy = 'ignore'
    else:
        policy = 'stop'
    crm_script.save_template('./basic.cib.template',
                             './basic.cib',
                             no_quorum_policy=policy)
except IOError, e:
    crm_script.exit_fail("IO error: %s" % (str(e)))
except ValueError, e:
    crm_script.exit_fail("Value error: %s" % (str(e)))

rc, _, err = crm_script.call(['crm', 'configure', 'load', 'replace', './basic.cib'])
if rc != 0:
    crm_script.exit_fail("Failed to load CIB configuration: %s" % (err))
Example #16
0
            crm_script.exit_fail("No usable network interface on %s: %s" %
                                 (host, iface))

    return user_iface


def make_mcastaddr():
    import random
    random.seed()
    b, c, d = random.randint(1,
                             254), random.randint(1,
                                                  254), random.randint(1, 254)
    return "%d.%d.%d.%d" % (239, b, c, d)


try:
    data = crm_script.output(1)

    crm_init.verify(data)

    ret = {}
    ret['iface'] = select_interfaces(crm_script.param('iface'), data)

    if not crm_script.param('mcastaddr'):
        ret['mcastaddr'] = make_mcastaddr()

    crm_script.exit_ok(ret)

except Exception, e:
    crm_script.exit_fail("Verification failed: %s" % (e))