Beispiel #1
0
def get_slave_bricks_status(host, vol):
    po = Popen(['gluster', '--xml', '--remote-host=' + host,
                'volume', 'status', vol, "detail"],
               stdout=PIPE, stderr=PIPE)
    vix = po.stdout.read()
    po.wait()
    po.terminate_geterr(fail_on_err=False)
    if po.returncode != 0:
        logging.info("Volume status command failed, unable to get "
                     "list of up nodes of %s, returning empty list: %s" %
                     (vol, po.returncode))
        return []
    vi = XET.fromstring(vix)
    if vi.find('opRet').text != '0':
        logging.info("Unable to get list of up nodes of %s, "
                     "returning empty list: %s" %
                     (vol, vi.find('opErrstr').text))
        return []

    up_hosts = set()

    try:
        for el in vi.findall('volStatus/volumes/volume/node'):
            if el.find('status').text == '1':
                up_hosts.add(el.find('hostname').text)
    except (ParseError, AttributeError, ValueError) as e:
        logging.info("Parsing failed to get list of up nodes of %s, "
                     "returning empty list: %s" % (vol, e))

    return list(up_hosts)
Beispiel #2
0
def monitor(*resources):
    # Mount geo-rep management volume
    if gconf.meta_volume:
        mgmt_mnt = os.path.join(gconf.working_dir, gconf.meta_volume)
        if not os.path.exists(mgmt_mnt):
            try:
                os.makedirs(mgmt_mnt)
            except OSError:
                ex = sys.exc_info()[1]
                if ex.errno == EEXIST:
                    pass
                else:
                    raise

        if not os.path.ismount(mgmt_mnt):
            po = Popen(["mount", "-t", "glusterfs", "localhost:%s"
                        % gconf.meta_volume, mgmt_mnt], stdout=PIPE,
                       stderr=PIPE)
            po.wait()
            po.terminate_geterr()

    # Check if gsyncd restarted in pause state. If
    # yes, send SIGSTOP to negative of monitor pid
    # to go back to pause state.
    if gconf.pause_on_start:
        os.kill(-os.getpid(), signal.SIGSTOP)

    """oh yeah, actually Monitor is used as singleton, too"""
    return Monitor().multiplex(*distribute(*resources))
Beispiel #3
0
def subcmd_slave(args):
    from resource import GLUSTER, Popen

    Popen.init_errhandler()
    slavevol = args.slave.split("::")[-1]
    local = GLUSTER("localhost", slavevol)

    local.connect()
    local.service_loop()
Beispiel #4
0
def subcmd_slave(args):
    from resource import GLUSTER, Popen

    Popen.init_errhandler()
    slavevol = args.slave.split("::")[-1]
    local = GLUSTER("localhost", slavevol)

    local.connect()
    local.service_loop()
Beispiel #5
0
def subcmd_voluuidget(args):
    from subprocess import Popen, PIPE
    import xml.etree.ElementTree as XET

    ParseError = XET.ParseError if hasattr(XET, 'ParseError') else SyntaxError

    cmd = [
        'gluster', '--xml', '--remote-host=' + args.host, 'volume', 'info',
        args.volname
    ]

    if args.inet6:
        cmd.append("--inet6")

    po = Popen(cmd,
               bufsize=0,
               stdin=None,
               stdout=PIPE,
               stderr=PIPE,
               universal_newlines=True)

    vix, err = po.communicate()
    if po.returncode != 0:
        logging.info(
            lf(
                "Volume info failed, unable to get "
                "volume uuid of slavevol, "
                "returning empty string",
                slavevol=args.volname,
                slavehost=args.host,
                error=po.returncode))
        return ""
    vi = XET.fromstring(vix)
    if vi.find('opRet').text != '0':
        logging.info(
            lf(
                "Unable to get volume uuid of slavevol, "
                "returning empty string",
                slavevol=args.volname,
                slavehost=args.host,
                error=vi.find('opErrstr').text))
        return ""

    try:
        voluuid = vi.find("volInfo/volumes/volume/id").text
    except (ParseError, AttributeError, ValueError) as e:
        logging.info(
            lf(
                "Parsing failed to volume uuid of slavevol, "
                "returning empty string",
                slavevol=args.volname,
                slavehost=args.host,
                error=e))
        voluuid = ""

    print(voluuid)
Beispiel #6
0
def subcmd_monitor(args):
    import monitor
    from resource import GLUSTER, SSH, Popen
    go_daemon = False if args.debug else True

    monitor.startup(go_daemon)
    Popen.init_errhandler()
    local = GLUSTER("localhost", args.master)
    slavehost, slavevol = args.slave.split("::")
    remote = SSH(slavehost, slavevol)
    return monitor.monitor(local, remote)
Beispiel #7
0
def subcmd_monitor(args):
    import monitor
    from resource import GLUSTER, SSH, Popen
    go_daemon = False if args.debug else True

    monitor.startup(go_daemon)
    Popen.init_errhandler()
    local = GLUSTER("localhost", args.master)
    slavehost, slavevol = args.slave.split("::")
    remote = SSH(slavehost, slavevol)
    return monitor.monitor(local, remote)
Beispiel #8
0
def subcmd_worker(args):
    import os
    import fcntl

    from resource import GLUSTER, SSH, Popen

    Popen.init_errhandler()
    fcntl.fcntl(args.feedback_fd, fcntl.F_SETFD, fcntl.FD_CLOEXEC)
    local = GLUSTER("localhost", args.master)
    slavehost, slavevol = args.slave.split("::")
    remote = SSH(slavehost, slavevol)
    remote.connect_remote()
    local.connect()
    logging.info("Worker spawn successful. Acknowledging back to monitor")
    os.close(args.feedback_fd)
    local.service_loop(remote)
Beispiel #9
0
def subcmd_worker(args):
    import os
    import fcntl

    from resource import GLUSTER, SSH, Popen

    Popen.init_errhandler()
    fcntl.fcntl(args.feedback_fd, fcntl.F_SETFD, fcntl.FD_CLOEXEC)
    local = GLUSTER("localhost", args.master)
    slavehost, slavevol = args.slave.split("::")
    remote = SSH(slavehost, slavevol)
    remote.connect_remote()
    local.connect()
    logging.info("Worker spawn successful. Acknowledging back to monitor")
    os.close(args.feedback_fd)
    local.service_loop(remote)
Beispiel #10
0
 def __init__(self, vol, host='localhost', prelude=[]):
     po = Popen(prelude + ['gluster', '--xml', '--remote-host=' + host, 'volume', 'info', vol],
                stdout=PIPE, stderr=PIPE)
     vix = po.stdout.read()
     po.wait()
     po.terminate_geterr()
     vi = XET.fromstring(vix)
     if vi.find('opRet').text != '0':
         if prelude:
             via = '(via %s) ' % prelude.join(' ')
         else:
             via = ' '
         raise GsyncdError('getting volume info of %s%s failed with errorcode %s',
                           (vol, via, vi.find('opErrno').text))
     self.tree = vi
     self.volume = vol
     self.host = host
Beispiel #11
0
def subcmd_voluuidget(args):
    from subprocess import Popen, PIPE
    import xml.etree.ElementTree as XET

    ParseError = XET.ParseError if hasattr(XET, 'ParseError') else SyntaxError

    cmd = ['gluster', '--xml', '--remote-host=' + args.host,
           'volume', 'info', args.volname]

    if args.inet6:
        cmd.append("--inet6")

    po = Popen(cmd, bufsize=0,
               stdin=None, stdout=PIPE, stderr=PIPE,
               universal_newlines=True)

    vix, err = po.communicate()
    if po.returncode != 0:
        logging.info(lf("Volume info failed, unable to get "
                        "volume uuid of slavevol, "
                        "returning empty string",
                        slavevol=args.volname,
                        slavehost=args.host,
                        error=po.returncode))
        return ""
    vi = XET.fromstring(vix)
    if vi.find('opRet').text != '0':
        logging.info(lf("Unable to get volume uuid of slavevol, "
                        "returning empty string",
                        slavevol=args.volname,
                        slavehost=args.host,
                        error=vi.find('opErrstr').text))
        return ""

    try:
        voluuid = vi.find("volInfo/volumes/volume/id").text
    except (ParseError, AttributeError, ValueError) as e:
        logging.info(lf("Parsing failed to volume uuid of slavevol, "
                        "returning empty string",
                        slavevol=args.volname,
                        slavehost=args.host,
                        error=e))
        voluuid = ""

    print(voluuid)
Beispiel #12
0
 def __init__(self, vol, host="localhost", prelude=[]):
     po = Popen(
         prelude + ["gluster", "--xml", "--remote-host=" + host, "volume", "info", vol], stdout=PIPE, stderr=PIPE
     )
     vix = po.stdout.read()
     po.wait()
     po.terminate_geterr()
     vi = XET.fromstring(vix)
     if vi.find("opRet").text != "0":
         if prelude:
             via = "(via %s) " % prelude.join(" ")
         else:
             via = " "
         raise GsyncdError(
             "getting volume info of %s%s " "failed with errorcode %s", (vol, via, vi.find("opErrno").text)
         )
     self.tree = vi
     self.volume = vol
     self.host = host
Beispiel #13
0
def get_slave_bricks_status(host, vol):
    po = Popen(['gluster', '--xml', '--remote-host=' + host,
                'volume', 'status', vol, "detail"],
               stdout=PIPE, stderr=PIPE)
    vix = po.stdout.read()
    po.wait()
    po.terminate_geterr(fail_on_err=False)
    if po.returncode != 0:
        logging.info("Volume status command failed, unable to get "
                     "list of up nodes of %s, returning empty list: %s" %
                     (vol, po.returncode))
        return []
    vi = XET.fromstring(vix)
    if vi.find('opRet').text != '0':
        logging.info("Unable to get list of up nodes of %s, "
                     "returning empty list: %s" %
                     (vol, vi.find('opErrstr').text))
        return []

    up_hosts = set()

    try:
        for el in vi.findall('volStatus/volumes/volume/node'):
            if el.find('status').text == '1':
                up_hosts.add(el.find('hostname').text)
    except (ParseError, AttributeError, ValueError) as e:
        logging.info("Parsing failed to get list of up nodes of %s, "
                     "returning empty list: %s" % (vol, e))

    return list(up_hosts)
Beispiel #14
0
def monitor(*resources):
    # Mount geo-rep management volume
    if gconf.meta_volume:
        mgmt_mnt = os.path.join(gconf.working_dir, gconf.meta_volume)
        if not os.path.exists(mgmt_mnt):
            try:
                os.makedirs(mgmt_mnt)
            except OSError:
                ex = sys.exc_info()[1]
                if ex.errno == EEXIST:
                    pass
                else:
                    raise

        if not os.path.ismount(mgmt_mnt):
            po = Popen([
                "mount", "-t", "glusterfs",
                "localhost:%s" % gconf.meta_volume, mgmt_mnt
            ],
                       stdout=PIPE,
                       stderr=PIPE)
            po.wait()
            po.terminate_geterr()

    # Check if gsyncd restarted in pause state. If
    # yes, send SIGSTOP to negative of monitor pid
    # to go back to pause state.
    if gconf.pause_on_start:
        os.kill(-os.getpid(), signal.SIGSTOP)
    """oh yeah, actually Monitor is used as singleton, too"""
    return Monitor().multiplex(*distribute(*resources))
Beispiel #15
0
 def __init__(self, vol, host='localhost', prelude=[]):
     po = Popen(prelude + ['gluster', '--xml', '--remote-host=' + host,
                           'volume', 'info', vol],
                stdout=PIPE, stderr=PIPE)
     vix = po.stdout.read()
     po.wait()
     po.terminate_geterr()
     vi = XET.fromstring(vix)
     if vi.find('opRet').text != '0':
         if prelude:
             via = '(via %s) ' % prelude.join(' ')
         else:
             via = ' '
         raise GsyncdError('getting volume info of %s%s '
                           'failed with errorcode %s' %
                           (vol, via, vi.find('opErrno').text))
     self.tree = vi
     self.volume = vol
     self.host = host