Пример #1
0
def stop(role=None, cli=False, force=False, **kwargs):
    try:
        if config['BLKTAP_ENABLED'] is False and vlmc_get_mapped():
            vlmc_showmapped()
            raise Error("Cannot stop archipelago. Mapped volumes exist")
    except VlmcTapdiskException:
        pass

    if role:
        try:
            p = peers[role]
        except KeyError:
            raise Error("Invalid peer %s" % role)
        return stop_peer(p, cli)

    #check devices
    if cli:
        print "===================="
        print "Stoping archipelago"
        print "===================="
        print ""

    if config["BLKTAP_ENABLED"] and loaded_module('blktap'):
        mapped = vlmc_get_mapped()
        if mapped and len(mapped) > 0:
            if not force:
                vlmc_showmapped()
                raise Error("Cannot stop archipelago. Mapped volumes exist")
            for m in mapped:
                if not VlmcTapdisk.is_paused(m.device):
                    VlmcTapdisk.pause(m.device)

    stop_peers(peers, cli)
    time.sleep(0.5)
    get_segment().destroy()
Пример #2
0
def start(role=None, cli=False, **kwargs):
    if role:
        try:
            p = peers[role]
        except KeyError:
            raise Error("Invalid peer %s" % role)
        return start_peer(p, cli)

    if status() > 0:
        raise Error("Cannot start. Try stopping first")

    if cli:
        print "===================="
        print "Starting archipelago"
        print "===================="
        print ""

    try:
        #get_segment().create()
        #time.sleep(0.5)
        create_posixfd_dirs()
        start_peers(peers, cli)
        if config["BLKTAP_ENABLED"]:
            load_module("blktap", None)
            mapped = vlmc_get_mapped()
            if mapped and len(mapped) > 0:
                for m in mapped:
                    if VlmcTapdisk.is_paused(m.device):
                        VlmcTapdisk.unpause(m.device)
    except Exception as e:
        if cli:
            print red(e)
        stop(role, cli, force=True)
Пример #3
0
def stop(role=None, cli=False, pause=False, unmap=False, **kwargs):
    if role:
        try:
            p = peers[role]
        except KeyError:
            raise Error("Invalid peer %s" % role)
        return stop_peer(p, cli)

    # check devices
    if cli:
        print "===================="
        print "Stoping archipelago"
        print "===================="
        print ""

    if config["BLKTAP_ENABLED"] and loaded_module('blktap'):
        mapped = vlmc_get_mapped()
        if mapped and len(mapped) > 0:
            if not pause:
                vlmc_showmapped()
                print ""
                if unmap:
                    print red("Mapped volumes exist, unmapping...")
                    try:
                        for m in mapped:
                            vlmc_unmap_volume(m.device)
                    except Error as e:
                        raise Error("Error while umapping volume, during "
                                    "shutdown: %s" % e)
                else:
                    raise Error("Found mapped volumes, cannot stop "
                                "Archipelago")
            else:
                for m in mapped:
                    if not VlmcTapdisk.is_paused(m.device):
                        VlmcTapdisk.pause(m.device)

        mapped = vlmc_get_mapped()
        if mapped and len(mapped) > 0:
            vlmc_showmapped()
            print ""
            if pause:
                import operator
                if not reduce(
                        operator.and_,
                    [VlmcTapdisk.is_paused(m.device) for m in mapped], True):
                    raise Error("Found unpaused volume, cannot stop "
                                "Archipelago")
            else:
                raise Error("Found more mapped volumes, cannot stop "
                            "Archipelago")

    stop_peers(peers, cli)
    time.sleep(0.5)
    get_segment().destroy()
Пример #4
0
def stop(role=None, cli=False, pause=False, unmap=False, **kwargs):
    if role:
        try:
            p = peers[role]
        except KeyError:
            raise Error("Invalid peer %s" % role)
        return stop_peer(p, cli)

    # check devices
    if cli:
        print "===================="
        print "Stoping archipelago"
        print "===================="
        print ""

    if config["BLKTAP_ENABLED"] and loaded_module('blktap'):
        mapped = vlmc_get_mapped()
        if mapped and len(mapped) > 0:
            if not pause:
                vlmc_showmapped()
                print ""
                if unmap:
                    print red("Mapped volumes exist, unmapping...")
                    try:
                        for m in mapped:
                            vlmc_unmap_volume(m.device)
                    except Error as e:
                        raise Error("Error while umapping volume, during "
                                    "shutdown: %s" % e)
                else:
                    raise Error("Found mapped volumes, cannot stop "
                                "Archipelago")
            else:
                for m in mapped:
                    if not VlmcTapdisk.is_paused(m.device):
                        VlmcTapdisk.pause(m.device)

        mapped = vlmc_get_mapped()
        if mapped and len(mapped) > 0:
            vlmc_showmapped()
            print ""
            if pause:
                import operator
                if not reduce(operator.and_, [VlmcTapdisk.is_paused(m.device)
                                              for m in mapped],
                              True):
                    raise Error("Found unpaused volume, cannot stop "
                                "Archipelago")
            else:
                raise Error("Found more mapped volumes, cannot stop "
                            "Archipelago")

    stop_peers(peers, cli)
    time.sleep(0.5)
    get_segment().destroy()
Пример #5
0
def unmap_volume(name, **kwargs):
    if not loaded_module("blktap"):
        raise Error("blktap module not loaded")
    device = name
    try:
        if is_device_mapped(device) is not None:
            busy = VlmcTapdisk.busy_pid(device)
            mounted = VlmcTapdisk.is_mounted(device)
            if not busy and not mounted:
                VlmcTapdisk.destroy(device)
            else:
                if busy:
                    raise Error("Device is busy (PID: %s)." % busy)
                elif mounted:
                    raise Error("Device is mounted. Cannot unmap device.")
            return
        raise Error("Device doesn't exist")
    except Exception, reason:
        raise Error(device + ': ' + str(reason))
Пример #6
0
def get_mapped():
    # If tap-ctl exists return mapped volumes even if blktap module is
    # disabled. There is always the possibility we are facing a mixed
    # situation where the blktap module is disabled but we have remaining
    # archipelago volumes.
    if find_executable(VlmcTapdisk.TAP_CTL):
        return VlmcTapdisk.list()
    else:
        # If the executable does not exist and the blktap module is disabled
        # we can assume that we can safely return an empty list.
        if not config['BLKTAP_ENABLED']:
            return []
        else:
            # Assume that blktap-archipelago-utils package is not
            # installed and that tap-ctl executable is missing.
            # That way we provide a hint where to find tap-ctl file.
            raise Error("%s\n%s" % ("Cannot execute tap-ctl command.",
                                    "Maybe blktap-archipelago-utils package "
                                    "is missing or you don't have sufficient "
                                    "privileges"))
Пример #7
0
def status(cli=False, **kwargs):
    r = 0
    if config["BLKTAP_ENABLED"]:
        if not loaded_module("blktap"):
            for role, _ in reversed(config['roles']):
                p = peers[role]
                if peer_running(p, cli):
                    r += 1
            if cli:
                pretty_print("blktap", red('Not loaded'))
            return r

        if cli:
            if vlmc_showmapped() > 0:
                r += 1
        else:
            mapped = vlmc_get_mapped()
            if mapped and len(mapped) > 0:
                for m in mapped:
                    if not VlmcTapdisk.is_paused(m.device):
                        r += 1
        if loaded_module("blktap"):
            if cli:
                pretty_print("blktap", green('Loaded'))
            #r += 1
        else:
            if cli:
                pretty_print("blktap", red('Not loaded'))

    for role, _ in reversed(config['roles']):
        p = peers[role]
        if peer_running(p, cli):
            r += 1
    try:
        if config['BLKTAP_ENABLED'] is False and vlmc_get_mapped():
            print red("Mapped volumes exist while blktap module is disabled.")
            vlmc_showmapped()
            r += 1
    except VlmcTapdiskException:
        pass
    return r
Пример #8
0
def map_volume(name, assume_v0=False, v0_size=-1, readonly=False, **kwargs):
    if not loaded_module("blktap"):
        raise Error("blktap module not loaded")

    if not is_valid_name(name):
        raise Error("Invalid volume name")

    device = is_mapped(name)
    if device is not None:
        raise Error("Volume %s already mapped on device %s%s" % (name,
                    '/dev/xen/blktap-2/tapdev', device))

    try:
        device = VlmcTapdisk.create(name, vport=peers['vlmcd'].portno_start,
                                    mport=peers['mapperd'].portno_start,
                                    assume_v0=assume_v0, v0_size=v0_size,
                                    readonly=readonly)
        if device:
            sys.stderr.write(device + '\n')
            return device.split(DEVICE_PREFIX)[1]
        raise Error("Cannot map volume '%s'.\n" % name)
    except Exception, reason:
        raise Error(name + ': ' + str(reason))