Пример #1
0
def run_copy():
    try:
        import parallax
    except ImportError:
        crm_script.exit_fail("Command node needs parallax installed")
    opts = make_opts()
    has_auth = os.path.isfile(COROSYNC_AUTH)
    if has_auth:
        results = parallax.copy(add_nodes, COROSYNC_AUTH, COROSYNC_AUTH, opts)
        check_results(parallax, results)
        results = parallax.call(
            add_nodes,
            "chown root:root %s;chmod 400 %s" % (COROSYNC_AUTH, COROSYNC_AUTH),
            opts)
        check_results(parallax, results)

    # Add new nodes to corosync.conf before copying
    for node in add_nodes:
        rc, _, err = crm_script.call(['crm', 'corosync', 'add-node', node])
        if rc != 0:
            crm_script.exit_fail('Failed to add %s to corosync.conf: %s' %
                                 (node, err))

    results = parallax.copy(add_nodes, COROSYNC_CONF, COROSYNC_CONF, opts)
    check_results(parallax, results)

    # reload corosync config here?
    rc, _, err = crm_script.call(['crm', 'corosync', 'reload'])
    if rc != 0:
        crm_script.exit_fail('Failed to reload corosync configuration: %s' %
                             (err))

    crm_script.exit_ok(host)
Пример #2
0
def run_ssh():
    try:
        crm_script.service('sshd', 'start')
        rc, _, _ = crm_script.sudo_call(
            ["mkdir", "-m", "700", "-p", "/root/.ssh"])
        if rc != 0:
            crm_script.exit_fail("Failed to create /root/.ssh directory")
        keypath = None
        for key in ('id_rsa', 'id_dsa', 'id_ecdsa'):
            if os.path.exists(os.path.join('/root/.ssh', key)):
                keypath = os.path.join('/root/.ssh', key)
                break
        if not keypath:
            keypath = os.path.join('/root/.ssh', 'id_rsa')
            keygen = [
                'ssh-keygen', '-q', '-f', keypath, '-C', 'Cluster Internal',
                '-N', ''
            ]
            rc, out, err = crm_script.sudo_call(keygen)
            if rc != 0:
                crm_script.exit_fail("Failed to generate SSH key")
        _authorize_key(keypath)
        crm_script.exit_ok(True)
    except IOError, e:
        crm_script.exit_fail(str(e))
Пример #3
0
def run_copy():
    try:
        from psshlib import api as pssh
    except ImportError:
        crm_script.exit_fail("Command node needs pssh installed")
    opts = make_opts()
    has_auth = os.path.isfile(COROSYNC_AUTH)
    if has_auth:
        results = pssh.copy(add_nodes, COROSYNC_AUTH, COROSYNC_AUTH, opts)
        check_results(pssh, results)
        results = pssh.call(add_nodes,
                            "chown root:root %s;chmod 400 %s" % (COROSYNC_AUTH, COROSYNC_AUTH),
                            opts)
        check_results(pssh, results)

    # Add new nodes to corosync.conf before copying
    for node in add_nodes:
        rc, _, err = crm_script.call(['crm', 'corosync', 'add-node', node])
        if rc != 0:
            crm_script.exit_fail('Failed to add %s to corosync.conf: %s' % (node, err))

    results = pssh.copy(add_nodes, COROSYNC_CONF, COROSYNC_CONF, opts)
    check_results(pssh, results)

    # reload corosync config here?
    rc, _, err = crm_script.call(['crm', 'corosync', 'reload'])
    if rc != 0:
        crm_script.exit_fail('Failed to reload corosync configuration: %s' % (err))

    crm_script.exit_ok(host)
Пример #4
0
def run_install():
    packages = [
        'cluster-glue', 'corosync', 'crmsh', 'pacemaker', 'resource-agents'
    ]
    crm_init.install_packages(packages)
    crm_init.configure_firewall()
    crm_script.exit_ok(True)
Пример #5
0
def start_new_node():
    if host not in add_nodes:
        crm_script.exit_ok(host)
    rc, _, err = crm_script.call(['crm', 'cluster', 'start'])
    if rc == 0:
        crm_script.exit_ok(host)
    crm_script.exit_fail(err)
Пример #6
0
def start_new_node():
    if host not in add_nodes:
        crm_script.exit_ok(host)
    rc, _, err = crm_script.call(['crm', 'cluster', 'start'])
    if rc == 0:
        crm_script.exit_ok(host)
    crm_script.exit_fail(err)
Пример #7
0
def run_collect():
    if host not in add_nodes:
        crm_script.exit_ok(host)

    rc, out, err = crm_script.service('pacemaker', 'is-active')
    if rc == 0 and out.strip() == 'active':
        crm_script.exit_fail("Pacemaker already running on %s" % (host))
    crm_script.exit_ok(crm_init.info())
Пример #8
0
def run_collect():
    if host not in add_nodes:
        crm_script.exit_ok(host)

    rc, out, err = crm_script.service('pacemaker', 'is-active')
    if rc == 0 and out.strip() == 'active':
        crm_script.exit_fail("Pacemaker already running on %s" % (host))
    crm_script.exit_ok(crm_init.info())
Пример #9
0
def run_install():
    if host not in add_nodes:
        crm_script.exit_ok(host)
    packages = [
        'cluster-glue', 'corosync', 'crmsh', 'pacemaker', 'resource-agents'
    ]
    crm_init.install_packages(packages)
    crm_script.exit_ok(host)
Пример #10
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)
Пример #11
0
def run_validate():
    try:
        from psshlib import api
    except ImportError:
        crm_script.exit_fail("Command node needs pssh installed")

    if host in add_nodes:
        crm_script.exit_fail("Run script from node in cluster")

    crm_script.exit_ok(host)
Пример #12
0
def run_validate():
    try:
        import parallax
    except ImportError:
        crm_script.exit_fail("Command node needs parallax installed")

    if host in add_nodes:
        crm_script.exit_fail("Run script from node in cluster")

    crm_script.exit_ok(host)
Пример #13
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)
Пример #14
0
def run_apply():
    for node in remove_nodes:
        rc, out, err = crm_script.call(['ssh',
                                        '-o', 'PasswordAuthentication=no',
                                        'root@%s' % (node),
                                        'systemctl stop corosync.service'])
        if rc != 0:
            crm_script.exit_fail("Failed to stop corosync on %s: %s" % (node, err))

        rc, out, err = crm_script.call(['crm', 'node', 'delete', node])
        if rc != 0:
            crm_script.exit_fail("Failed to remove %s from CIB: %s" % (node, err))

    crm_script.exit_ok({"removed": remove_nodes})
Пример #15
0
def run_apply():
    for node in remove_nodes:
        rc, out, err = crm_script.call([
            'ssh', '-o', 'PasswordAuthentication=no',
            'root@%s' % (node), 'systemctl stop corosync.service'
        ])
        if rc != 0:
            crm_script.exit_fail("Failed to stop corosync on %s: %s" %
                                 (node, err))

        rc, out, err = crm_script.call(['crm', 'node', 'delete', node])
        if rc != 0:
            crm_script.exit_fail("Failed to remove %s from CIB: %s" %
                                 (node, err))

    crm_script.exit_ok({"removed": remove_nodes})
Пример #16
0
def run_ssh():
    try:
        crm_script.service('sshd', 'start')
        rc, _, _ = crm_script.sudo_call(["mkdir", "-m", "700", "-p", "/root/.ssh"])
        if rc != 0:
            crm_script.exit_fail("Failed to create /root/.ssh directory")
        keypath = None
        for key in ('id_rsa', 'id_dsa', 'id_ecdsa'):
            if os.path.exists(os.path.join('/root/.ssh', key)):
                keypath = os.path.join('/root/.ssh', key)
                break
        if not keypath:
            keypath = os.path.join('/root/.ssh', 'id_rsa')
            keygen = ['ssh-keygen', '-q', '-f', keypath,
                      '-C', 'Cluster Internal', '-N', '']
            rc, out, err = crm_script.sudo_call(keygen)
            if rc != 0:
                crm_script.exit_fail("Failed to generate SSH key")
        _authorize_key(keypath)
        crm_script.exit_ok(True)
    except IOError, e:
        crm_script.exit_fail(str(e))
Пример #17
0
    '/etc/sysconfig/sbd',
    '/etc/sysconfig/SuSEfirewall2',
    '/etc/sysconfig/SuSEfirewall2.d/services/cluster'
    ]


def files_info():
    ret = {}
    for f in FILES:
        if os.path.isfile(f):
            try:
                ret[f] = hashlib.sha1(open(f).read()).hexdigest()
            except IOError, e:
                ret[f] = "error: %s" % (e)
        else:
            ret[f] = ""
    return ret


try:
    data = {
        'rpm': rpm_info(),
        'logrotate': logrotate_info(),
        'system': sys_info(),
        'disk': disk_info(),
        'files': files_info()
    }
    crm_script.exit_ok(data)
except Exception, e:
    crm_script.exit_fail(str(e))
Пример #18
0
def run_install():
    packages = ['cluster-glue', 'corosync', 'crmsh', 'pacemaker', 'resource-agents']
    crm_init.install_packages(packages)
    crm_init.configure_firewall()
    crm_script.exit_ok(True)
Пример #19
0
#!/usr/bin/python3
import crm_script
try:
    uptime = open('/proc/uptime').read().split()[0]
    crm_script.exit_ok(uptime)
except Exception as e:
    crm_script.exit_fail("Couldn't open /proc/uptime: %s" % (e))
Пример #20
0
def run_install():
    if host not in add_nodes:
        crm_script.exit_ok(host)
    packages = ['cluster-glue', 'corosync', 'crmsh', 'pacemaker', 'resource-agents']
    crm_init.install_packages(packages)
    crm_script.exit_ok(host)
Пример #21
0
#!/usr/bin/python3
import os
import crm_script as crm

if not os.path.isfile('/usr/sbin/crm') and not os.path.isfile('/usr/bin/crm'):
    # crm not installed
    crm.exit_ok({'status': 'crm not installed'})


def get_from_date():
    rc, out, err = crm.call("date '+%F %H:%M' --date='1 day ago'", shell=True)
    return out.strip()


def create_report():
    cmd = ['crm', 'report', '-f', get_from_date(), '-D', '-Z', 'health-report']
    rc, out, err = crm.call(cmd, shell=False)
    return rc == 0


if not create_report():
    crm.exit_ok({'status': 'Failed to create report'})


def extract_report():
    rc, out, err = crm.call(['tar', 'xjf', 'health-report.tar.bz2'],
                            shell=False)
    return rc == 0


if not extract_report():
Пример #22
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))
Пример #23
0
#!/usr/bin/env python
import crm_script
import crm_init
try:
    crm_script.exit_ok(crm_init.info())
except Exception, e:
    crm_script.exit_fail(str(e))
Пример #24
0
def run_collect():
    crm_script.exit_ok(host)
Пример #25
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))
Пример #26
0
#!/usr/bin/python3
import os
import crm_script as crm


if not os.path.isfile('/usr/sbin/crm') and not os.path.isfile('/usr/bin/crm'):
    # crm not installed
    crm.exit_ok({'status': 'crm not installed'})


def get_from_date():
    rc, out, err = crm.call("date '+%F %H:%M' --date='1 day ago'", shell=True)
    return out.strip()


def create_report():
    cmd = ['crm', 'report',
           '-f', get_from_date(),
           '-D', '-Z', 'health-report']
    rc, out, err = crm.call(cmd, shell=False)
    return rc == 0


if not create_report():
    crm.exit_ok({'status': 'Failed to create report'})


def extract_report():
    rc, out, err = crm.call(['tar', 'xjf', 'health-report.tar.bz2'], shell=False)
    return rc == 0
Пример #27
0
#!/usr/bin/env python
import crm_script

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.param('nodes')
    crm_script.save_template('./basic.cib.template',
                             './basic.cib')
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))

crm_script.exit_ok(True)
Пример #28
0
def run_firewall():
    if host not in add_nodes:
        crm_script.exit_ok(host)
    crm_init.configure_firewall()
    crm_script.exit_ok(host)
Пример #29
0
    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))

    # start cluster
    rc, out, err = crm_script.call(['crm', 'cluster', 'start'])
    if rc != 0:
        crm_script.exit_fail("Failed to start cluster: %s" % (err))

    crm_script.exit_ok(True)


if __name__ == "__main__":
    if len(sys.argv) < 2:
        crm_script.exit_fail("Missing argument to configure.py")
    elif sys.argv[1] == 'install':
        run_install()
    elif sys.argv[1] == 'corosync':
        run_corosync()
    else:
        crm_script.exit_fail("Bad argument to configure.py: %s" %
                             (sys.argv[1]))
Пример #30
0
def run_collect():
    crm_script.exit_ok(host)
Пример #31
0
def run_firewall():
    if host not in add_nodes:
        crm_script.exit_ok(host)
    crm_init.configure_firewall()
    crm_script.exit_ok(host)