Beispiel #1
0
def option_list(platform, args):

    e_host = platform._active_export_host
    configurations = platform.get_configurations([e_host], Role.EXPORTD)
    config = configurations[e_host][Role.EXPORTD]

    export_l = {}
    errors_l = {}

    # Check exception
    if isinstance(config, Exception):
        # Get error msg
        err_str = type(config).__name__ + ' (' + str(config) + ')'
        # Update standard output dict
        export_l.update({e_host: err_str})
        # Update errors dict
        errors_l.update({e_host: err_str})
    else:
        options_l = []
        options_l.append({'nbcores': config.nbcores})
        export_l.update({e_host: {'OPTIONS': options_l}})

    ordered_puts(export_l)

    if errors_l:
        raise MultipleError(errors_l)
Beispiel #2
0
def option_get(platform, args):

    # Check given option
    valid_opts = [NBCORES]
    if args.option not in valid_opts:
        raise Exception('invalid option: \'%s\' (valid value: %s).' %
                        (args.option, ', '.join(valid_opts)))

    e_host = platform._active_export_host
    configurations = platform.get_configurations([e_host], Role.EXPORTD)
    config = configurations[e_host][Role.EXPORTD]

    export_l = {}
    errors_l = {}

    # Check exception
    if isinstance(config, Exception):
        # Get error msg
        err_str = type(config).__name__ + ' (' + str(config) + ')'
        # Update standard output dict
        export_l.update({e_host: err_str})
        # Update errors dict
        errors_l.update({e_host: err_str})
    else:
        options_l = []
        if args.option == NBCORES:
            options_l.append({'nbcores': config.nbcores})
        export_l.update({e_host: {'OPTIONS': options_l}})

    ordered_puts(export_l)

    if errors_l:
        raise MultipleError(errors_l)
Beispiel #3
0
def option_set(platform, args):

    e_host = platform._active_export_host

    if args.nodes is not None:
        for host in args.nodes:
            if host not in platform.list_nodes(Role.STORAGED):
                raise Exception('%s: invalid storaged server.' % host)

    if args.option not in [SELF_HEALING]:
        raise Exception('%s: invalid option.' % args.option)

    sid_l = {}
    errors_l = {}

    for host, configuration in platform.get_configurations(
            args.nodes, Role.STORAGED).items():

        # Node without storaged role
        if not configuration:
            continue

        sid_l[host] = []
        config = configuration[Role.STORAGED]

        # Check exception
        if isinstance(config, Exception):
            # Get error msg
            err_str = type(config).__name__ + ' (' + str(config) + ')'
            # Update standard output dict
            sid_l.update({host: err_str})
            # Update errors dict
            errors_l.update({host: err_str})
            continue

        if args.option == SELF_HEALING:
            if int(args.value) < 1:
                raise Exception(
                    'invalid value: \'%s\' (The lowest possible value is 1).' %
                    args.value)
            config.self_healing = args.value

        # TO DO: not send value option if it's not necessary
        configuration[Role.STORAGED] = config
        try:
            platform._get_nodes(e_host)[host].set_configurations(configuration)
        except Exception as e:
            err = type(e).__name__ + ' (' + str(e) + ')'
            sid_l.update({host: err})
            continue

        sid_l[host].append({args.option: args.value})

    ordered_puts(sid_l)

    if errors_l:
        raise MultipleError(errors_l)
Beispiel #4
0
def option_list(platform, args):

    if args.nodes is not None:
        for host in args.nodes:
            if not host in platform.list_nodes(Role.STORAGED):
                raise Exception('%s: invalid storaged server.' % host)

    sid_l = {}
    errors_l = {}

    for host, configuration in platform.get_configurations(
            args.nodes, Role.STORAGED).items():

        # Node without storaged role
        if not configuration:
            continue

        sid_l[host] = []

        config = configuration[Role.STORAGED]

        # Check exception
        if isinstance(config, Exception):
            # Get error msg
            err_str = type(config).__name__ + ' (' + str(config) + ')'
            # Update standard output dict
            sid_l.update({host: err_str})
            # Update errors dict
            errors_l.update({host: err_str})
            continue

        options_l = []
        if config.nbcores is not None:
            options_l.append({'nbcores': config.nbcores})
        if config.threads is not None:
            options_l.append({'threads': config.threads})
        if config.storio is not None:
            options_l.append({'storio': config.storio})
        if config.self_healing is not None:
            options_l.append({'self-healing': config.self_healing})
        if config.export_hosts is not None:
            options_l.append({'export-hosts': config.export_hosts})

        options_l.append({'crc32c_check': bool(config.crc32c_check)})
        options_l.append({'crc32c_generate': bool(config.crc32c_generate)})
        options_l.append({'crc32c_hw_forced': bool(config.crc32c_hw_forced)})

        sid_l[host].append({'OPTIONS': options_l})

    ordered_puts(sid_l)

    if errors_l:
        raise MultipleError(errors_l)
Beispiel #5
0
def option_get(platform, args):

    if args.nodes is not None:
        for host in args.nodes:
            if host not in platform.list_nodes(Role.STORAGED):
                raise Exception('%s: invalid storaged server.' % host)

    # Check given option
    valid_opts = [SELF_HEALING, EXPORT_HOSTS]
    if args.option not in valid_opts:
        raise Exception('invalid option: \'%s\' (valid values: %s).' %
                        (args.option, ', '.join(valid_opts)))

    sid_l = {}
    errors_l = {}

    for host, configuration in platform.get_configurations(
            args.nodes, Role.STORAGED).items():

        # Node without storaged role
        if not configuration:
            continue

        sid_l[host] = []
        config = configuration[Role.STORAGED]

        # Check exception
        if isinstance(config, Exception):
            # Get error msg
            err_str = type(config).__name__ + ' (' + str(config) + ')'
            # Update standard output dict
            sid_l.update({host: err_str})
            # Update errors dict
            errors_l.update({host: err_str})
            continue

        if args.option == SELF_HEALING:
            sid_l[host].append({SELF_HEALING: config.self_healing})

        if args.option == EXPORT_HOSTS:
            sid_l[host].append({EXPORT_HOSTS: config.export_hosts})

    ordered_puts(sid_l)

    if errors_l:
        raise MultipleError(errors_l)
Beispiel #6
0
def status(platform, args):

    statuses = platform.get_statuses(args.nodes, __args_to_roles(args))
    status_l = {}
    errors_l = {}

    for h, s in statuses.items():
        role_l = []
        role_err_l = []

        for role, status in s.items():

            # Check exception
            if isinstance(status, Exception):
                # Update standard output dict
                err_str = type(status).__name__ + ' (' + str(status) + ')'
                role_l.append({ROLES_STR[role]: err_str})
                # Update errors dict
                role_err_l.append({ROLES_STR[role]: err_str})
                errors_l.update({'NODE: ' + str(h): role_err_l})
                continue
            if (role & Role.ROZOFSMOUNT == Role.ROZOFSMOUNT):
                mount_l = []
                if not status:
                    role_l.append(
                        {ROLES_STR[role]: 'no mountpoint configured'})
                else:
                    for m, s in status.items():
                        mount_l.append({m: 'mounted' if s else 'unmounted'})
                    role_l.append({ROLES_STR[role]: mount_l})
            else:
                if status:
                    role_l.append({ROLES_STR[role]: 'running'})
                else:
                    role_l.append({ROLES_STR[role]: 'not running'})

        if role_l:
            status_l.update({h: role_l})

    # Display output
    ordered_puts(status_l)

    # Check errors
    if errors_l:
        raise MultipleError(errors_l)
Beispiel #7
0
def start(platform, args):

    changes = platform.start(args.nodes, __args_to_roles(args))

    status_l = {}
    errors_l = {}

    for h, s in changes.items():
        role_l = []
        role_err_l = []

        for role, change in s.items():

            # Check exception
            if isinstance(change, Exception):
                # Update standard output dict
                err_str = type(change).__name__ + ' (' + str(change)  + ')'
                role_l.append({ROLES_STR[role]: 'failed, ' + err_str})
                # Update errors dict
                role_err_l.append({ROLES_STR[role]: err_str})
                errors_l.update({'NODE: ' + str(h) : role_err_l})
                continue

            if (role & Role.ROZOFSMOUNT == Role.ROZOFSMOUNT):
                mount_l = []
                for m, s in change.items():
                    mount_l.append({m : 'mounted' if s else 'already mounted'})
                role_l.append({ROLES_STR[role]: mount_l})
            else:
                if change:
                    role_l.append({ROLES_STR[role]: 'started'})
                else:
                    role_l.append({ROLES_STR[role]: 'already started'})

        if role_l:
            status_l.update({h:role_l})

    # Display output
    ordered_puts(status_l)

    # Check errors
    if errors_l:
     raise MultipleError(errors_l)
Beispiel #8
0
def listen_get(platform, args):

    if args.nodes is not None:
        for host in args.nodes:
            if host not in platform.list_nodes(Role.STORAGED):
                raise Exception('%s: invalid storaged server.' % host)

    errors_l = {}
    sid_l = {}
    for host, configuration in platform.get_configurations(
            args.nodes, Role.STORAGED).items():

        # Node without storaged role
        if not configuration:
            continue

        sid_l[host] = []
        lid_l = {}

        config = configuration[Role.STORAGED]

        if isinstance(config, Exception):
            # Get error msg
            err_str = type(config).__name__ + ' (' + str(config) + ')'
            # Update standard output dict
            sid_l.update({host: err_str})
            # Update errors dict
            errors_l.update({host: err_str})
            continue

        for lconfig in configuration[Role.STORAGED].listens:
            lid_l = OrderedDict([('addr', lconfig.addr),
                                 ('port', lconfig.port)])
            sid_l[host].append(lid_l)

    ordered_puts(sid_l)

    if errors_l:
        raise MultipleError(errors_l)
Beispiel #9
0
def config(platform, args):
    if not args.roles:
        args.roles = [EXPORTD_MANAGER, STORAGED_MANAGER, ROZOFSMOUNT_MANAGER]

    configurations = platform.get_configurations(args.nodes, __args_to_roles(args))

    errors_l = {}
    host_l = {}

    for h, c in configurations.items():

        # Is-it necessary ?
        if c is None:
            host_l.update({'NODE: ' + str(h) : "not reachable"})
            continue

        role_l=[]
        role_err_l = []

        for role, config in c.items():
            # Check exception
            if isinstance(config, Exception):
                # Get error msg
                err_str = type(config).__name__ + ' (' + str(config) + ')'
                # Update standard output dict
                role_l.append({ROLES_STR[role]: err_str})
                host_l.update({'NODE: ' + str(h) : role_l})
                # Update errors dict
                role_err_l.append({ROLES_STR[role]: err_str})
                errors_l.update({'NODE: ' + str(h) : role_err_l})
                continue

            if (role & Role.EXPORTD == Role.EXPORTD):
                exportd_l = []
                volume_l = []
                for v in config.volumes.values():
                    cluster_l = []
                    for cluster in v.clusters.values():
                        s_l = []
                        for s, hhh in cluster.storages.items():
                            s_l.append({'sid ' + str(s): hhh})
                        cluster_l.append({'cluster ' + str(cluster.cid): s_l})
                    volume_l.append({'volume ' + str(v.vid): cluster_l})
                exportd_l.append({'VOLUME':volume_l})
                if len(config.exports) != 0:
                    for e in config.exports.values():
                        export_l = OrderedDict([
                            ('vid', e.vid),
                            ('root', e.root),
                            ('md5', e.md5),
                            ('squota', e.squota),
                            ('hquota', e.hquota)])
                        exportd_l.append({'EXPORT':export_l})
                role_l.append({'EXPORTD':exportd_l})

            if (role & Role.STORAGED == Role.STORAGED):
                options_l = []
                interface_l = []
                storage_l = []

                if config.nbcores is not None:
                    options_l.append({'nbcores' : config.nbcores})
                if config.threads is not None:
                    options_l.append({'threads' : config.threads})
                if config.storio is not None:
                    options_l.append({'storio' : config.storio})
                if config.self_healing is not None:
                    options_l.append({'self-healing' : config.self_healing})
                if config.export_hosts is not None:
                    options_l.append({'export-hosts' : config.export_hosts})

                options_l.append({'crc32c_check' : bool(config.crc32c_check)})
                options_l.append({'crc32c_generate' : bool(config.crc32c_generate)})
                options_l.append({'crc32c_hw_forced' : bool(config.crc32c_hw_forced)})
                storage_l.append({'OPTIONS':options_l})

                for lconfig in config.listens:
                    interface_l.append({lconfig.addr : lconfig.port})
                storage_l.append({'INTERFACE':interface_l})

                keylist = config.storages.keys()
                keylist.sort()
                st_l = []
                for key in keylist:
                    st = config.storages[key]

                    stor_l = OrderedDict([
                    ('root', st.root),
                    ('device-total', st.device_t),
                    ('device-mapper', st.device_m),
                    ('device-redundancy', st.device_r)])

                    st_l.append({'cid ' + str(st.cid) + ', sid '+
                        str(st.sid) : stor_l})

                storage_l.append({'STORAGE': st_l})

                role_l.append({'STORAGED': storage_l})

            if (role & Role.ROZOFSMOUNT == Role.ROZOFSMOUNT):
                exp_l = []
                if config:
                    for c in config:
                        mountdict = {}
                        mountdict["mountpoint"] = c.mountpoint
                        mountdict["export host"] = c.export_host
                        mountdict["export path"] = c.export_path
                        exp_l.append(mountdict)
                    role_l.append({'ROZOFSMOUNT': exp_l})

            host_l.update({'NODE: ' + str(h) : role_l})

    ordered_puts(host_l)

    if errors_l:
        raise MultipleError(errors_l)
Beispiel #10
0
def listen_remove(platform, args):
    e_host = platform._active_export_host

    for host in args.nodes:
        if host not in platform.list_nodes(Role.STORAGED):
            raise Exception('%s: invalid storaged server.' % host)

    for host in args.nodes:
        configurations = platform._get_nodes(e_host)[host].get_configurations(
            Role.STORAGED)
        config = configurations[Role.STORAGED]
        check = True

        sid_l = {}
        sid_l[host] = []
        lid_l = {}
        errors_l = {}

        # Check exception
        if isinstance(config, Exception):
            # Get error msg
            err_str = type(config).__name__ + ' (' + str(config) + ')'
            # Update standard output dict
            sid_l.update({host: err_str})
            ordered_puts(sid_l)
            # Update errors dict
            errors_l.update({host: err_str})
            continue

        for listener in config.listens:
            if args.interface == listener.addr:
                if args.port == listener.port:
                    # listen entry is found
                    check = False
                    # Check if it's the last listen entry
                    # Replaced by default address
                    if len(config.listens) == 1:
                        listener.addr = "*"
                        listener.port = 41001
                    else:
                        config.listens.remove(listener)
        if check:
            raise Exception('entry %s:%s does not exist.' %
                            (args.interface, args.port))

        configurations[Role.STORAGED] = config

        try:
            platform._get_nodes(e_host)[host].set_configurations(
                configurations)
        except Exception as e:
            err = type(e).__name__ + ' (' + str(e) + ')'
            sid_l.update({host: err})
            ordered_puts(sid_l)
            continue

        for lconfig in config.listens:
            lid_l = OrderedDict([('addr', lconfig.addr),
                                 ('port', lconfig.port)])
            sid_l[host].append(lid_l)

        ordered_puts(sid_l)

    if errors_l:
        raise MultipleError(errors_l)
Beispiel #11
0
def listen_add(platform, args):
    e_host = platform._active_export_host

    for host in args.nodes:
        if host not in platform.list_nodes(Role.STORAGED):
            raise Exception('%s: invalid storaged server.' % host)

    for host in args.nodes:

        configurations = platform._get_nodes(e_host)[host].get_configurations(
            Role.STORAGED)
        config = configurations[Role.STORAGED]

        errors_l = {}
        sid_l = {}
        sid_l[host] = []
        lid_l = {}

        # Check exception
        if isinstance(config, Exception):
            # Get error msg
            err_str = type(config).__name__ + ' (' + str(config) + ')'
            # Update standard output dict
            sid_l.update({host: err_str})
            ordered_puts(sid_l)
            # Update errors dict
            errors_l.update({host: err_str})
            continue

        for listener in config.listens:
            # if given interface is '*', remove existing interfaces
            if args.interface == "*":
                config.listens = []
                continue
            elif args.interface == listener.addr:
                if args.port == listener.port:
                    raise Exception('entry %s:%s already exists.' %
                                    (args.interface, args.port))
            if listener.addr == '*':
                config.listens = []

        lconfig = ListenConfig(args.interface, args.port)
        config.listens.append(lconfig)
        configurations[Role.STORAGED] = config

        try:
            platform._get_nodes(e_host)[host].set_configurations(
                configurations)
        except Exception as e:
            err = type(e).__name__ + ' (' + str(e) + ')'
            sid_l.update({host: err})
            ordered_puts(sid_l)
            continue

        for lconfig in config.listens:
            lid_l = OrderedDict([('addr', lconfig.addr),
                                 ('port', lconfig.port)])
            sid_l[host].append(lid_l)

        ordered_puts(sid_l)

    if errors_l:
        raise MultipleError(errors_l)
Beispiel #12
0
def create(platform, args):
    if not args.eids:
        args.eids = None

    statuses = platform.mount_export(args.eids, args.exports, args.nodes,
                                     args.mountpoints, args.options)
    host_statuses_l = {}
    host_errors_l = {}

    for h, s in statuses.items():

        # Check exception
        if isinstance(s, Exception):
            # Update standard output dict
            err_str = type(s).__name__ + ' (' + str(s) + ')'
            host_statuses_l.update({str(h): err_str})
            host_errors_l.update({str(h): err_str})
            continue

        mount_statuses_l = []
        mount_errors_l = []

        for mountpoint, status in s.items():

            mountpoint_status = {}
            mountpoint_error = {}

            # Check config status
            if status['config'] is True:
                mountpoint_status.update({'configuration': 'added'})
            elif status['config'] is None:
                mountpoint_status.update({'configuration': 'already present'})
            else:
                # Check exception
                if isinstance(status['config'], Exception):
                    # Update standard output dict
                    err_str = type(status['config']).__name__ + ' (' + str(
                        status['config']) + ')'
                    mountpoint_status.update(
                        {'configuration': 'failed, ' + err_str})
                    # Update errors dict
                    mountpoint_error.update(
                        {'configuration': 'failed, ' + err_str})

            # Check service status
            if status['service'] is True:
                mountpoint_status.update({'status': 'mounted'})
            elif status['service'] is False:
                mountpoint_status.update({'status': 'unmounted'})
            elif status['service'] is None:
                mountpoint_status.update({'status': 'already mounted'})
            else:
                # Check exception
                if isinstance(status['service'], Exception):
                    # Update standard output dict
                    err_str = type(status['service']).__name__ + ' (' + str(
                        status['service']) + ')'
                    mountpoint_status.update({'status': 'failed, ' + err_str})
                    # Update errors dict
                    mountpoint_error.update({'status': 'failed, ' + err_str})

            # Update list of mountpoint statuses
            export_name = os.path.basename(status['export_root'])
            mnt_config = {
                "export " + export_name + ' (eid=' + str(status['eid']) + ') on ' + mountpoint:
                mountpoint_status
            }
            mount_statuses_l.append(mnt_config)
            if mountpoint_error:
                mnt_config_err = {
                    "export " + export_name + ' (eid=' + str(status['eid']) + ') on ' + mountpoint:
                    mountpoint_error
                }
                mount_errors_l.append(mnt_config_err)

        # Update host
        host_statuses_l.update({str(h): mount_statuses_l})
        if mount_errors_l:
            host_errors_l.update({str(h): mount_errors_l})

    # Display output
    ordered_puts(host_statuses_l)

    # Check errors
    if host_errors_l:
        raise MultipleError(host_errors_l)
Beispiel #13
0
def option_set(platform, args):

    e_host = platform._active_export_host

    if args.nodes is not None:
        for host in args.nodes:
            if not host in platform.list_nodes(Role.STORAGED):
                raise Exception('%s: invalid storaged server.' % host)

    if args.option not in [
            THREADS, NBCORES, STORIO, CRC32C_CHECK, CRC32C_GENERATE,
            CRC32C_HW_FORCED, SELF_HEALING
    ]:
        raise Exception('%s: invalid option.' % args.option)

    sid_l = {}
    errors_l = {}

    for host, configuration in platform.get_configurations(
            args.nodes, Role.STORAGED).items():

        # Node without storaged role
        if not configuration:
            continue

        sid_l[host] = []
        config = configuration[Role.STORAGED]

        # Check exception
        if isinstance(config, Exception):
            # Get error msg
            err_str = type(config).__name__ + ' (' + str(config) + ')'
            # Update standard output dict
            sid_l.update({host: err_str})
            # Update errors dict
            errors_l.update({host: err_str})
            continue

        if args.option == THREADS:
            config.threads = args.value

        if args.option == NBCORES:
            config.nbcores = args.value

        if args.option == STORIO:
            if args.value not in STORIO_VALID_VALUES:
                raise Exception('invalid value: \'%s\' (valid values: %s).' %
                                (args.value, ', '.join(STORIO_VALID_VALUES)))
            config.storio = args.value

        if args.option == SELF_HEALING:
            if int(args.value) < 1:
                raise Exception(
                    'invalid value: \'%s\' (The lowest possible value is 1).' %
                    args.value)
            config.self_healing = args.value

        if args.option == CRC32C_CHECK:
            value = __check_bool_value(args.value)
            config.crc32c_check = value

        if args.option == CRC32C_GENERATE:
            value = __check_bool_value(args.value)
            config.crc32c_generate = value

        if args.option == CRC32C_HW_FORCED:
            value = __check_bool_value(args.value)
            config.crc32c_hw_forced = value

        # TO DO: not send value option if it's not necessary
        configuration[Role.STORAGED] = config
        try:
            platform._get_nodes(e_host)[host].set_configurations(configuration)
        except Exception as e:
            err = type(e).__name__ + ' (' + str(e) + ')'
            sid_l.update({host: err})
            continue

        sid_l[host].append({args.option: args.value})

    ordered_puts(sid_l)

    if errors_l:
        raise MultipleError(errors_l)
Beispiel #14
0
def option_get(platform, args):

    if args.nodes is not None:
        for host in args.nodes:
            if not host in platform.list_nodes(Role.STORAGED):
                raise Exception('%s: invalid storaged server.' % host)

    # Check given option
    valid_opts = [
        THREADS, NBCORES, STORIO, CRC32C_CHECK, CRC32C_GENERATE,
        CRC32C_HW_FORCED, SELF_HEALING, EXPORT_HOSTS
    ]
    if args.option not in valid_opts:
        raise Exception('invalid option: \'%s\' (valid values: %s).' %
                        (args.option, ', '.join(valid_opts)))

    sid_l = {}
    errors_l = {}

    for host, configuration in platform.get_configurations(
            args.nodes, Role.STORAGED).items():

        # Node without storaged role
        if not configuration:
            continue

        sid_l[host] = []
        config = configuration[Role.STORAGED]

        # Check exception
        if isinstance(config, Exception):
            # Get error msg
            err_str = type(config).__name__ + ' (' + str(config) + ')'
            # Update standard output dict
            sid_l.update({host: err_str})
            # Update errors dict
            errors_l.update({host: err_str})
            continue

        if args.option == THREADS:
            sid_l[host].append({THREADS: config.threads})

        if args.option == NBCORES:
            sid_l[host].append({NBCORES: config.nbcores})

        if args.option == STORIO:
            sid_l[host].append({STORIO: config.storio})

        if args.option == SELF_HEALING:
            sid_l[host].append({SELF_HEALING: config.self_healing})

        if args.option == EXPORT_HOSTS:
            sid_l[host].append({EXPORT_HOSTS: config.export_hosts})

        if args.option == CRC32C_CHECK:
            sid_l[host].append({CRC32C_CHECK: bool(config.crc32c_check)})

        if args.option == CRC32C_GENERATE:
            sid_l[host].append({CRC32C_GENERATE: bool(config.crc32c_generate)})

        if args.option == CRC32C_HW_FORCED:
            sid_l[host].append(
                {CRC32C_HW_FORCED: bool(config.crc32c_hw_forced)})

    ordered_puts(sid_l)

    if errors_l:
        raise MultipleError(errors_l)