コード例 #1
0
ファイル: add.py プロジェクト: parr0tr1ver/crmsh
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
ファイル: add.py プロジェクト: aomoriringo/crmsh
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
ファイル: add.py プロジェクト: parr0tr1ver/crmsh
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
ファイル: add.py プロジェクト: aomoriringo/crmsh
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
ファイル: add.py プロジェクト: parr0tr1ver/crmsh
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
ファイル: add.py プロジェクト: aomoriringo/crmsh
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
ファイル: add.py プロジェクト: parr0tr1ver/crmsh
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
ファイル: remove.py プロジェクト: RedFlames/crmsh
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
ファイル: add.py プロジェクト: aomoriringo/crmsh
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
ファイル: add.py プロジェクト: parr0tr1ver/crmsh
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
ファイル: remove.py プロジェクト: parr0tr1ver/crmsh
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
ファイル: remove.py プロジェクト: RedFlames/crmsh
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
ファイル: remove.py プロジェクト: parr0tr1ver/crmsh
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
ファイル: configure.py プロジェクト: aspiers/crmsh
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
ファイル: configure.py プロジェクト: aspiers/crmsh
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
ファイル: add.py プロジェクト: aomoriringo/crmsh
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
ファイル: verify.py プロジェクト: ingted/crmsh
    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
ファイル: collect.py プロジェクト: parr0tr1ver/crmsh
#!/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
ファイル: remove.py プロジェクト: RedFlames/crmsh
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
ファイル: hahealth.py プロジェクト: ClusterLabs/crmsh
#!/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
ファイル: init.py プロジェクト: dmuhamedagic/crmsh
#!/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
ファイル: add.py プロジェクト: aomoriringo/crmsh
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
ファイル: remove.py プロジェクト: parr0tr1ver/crmsh
def run_collect():
    crm_script.exit_ok(host)
コード例 #31
0
ファイル: add.py プロジェクト: parr0tr1ver/crmsh
def run_firewall():
    if host not in add_nodes:
        crm_script.exit_ok(host)
    crm_init.configure_firewall()
    crm_script.exit_ok(host)