Esempio n. 1
0
def get_conf_params(obj):
    from chroma_core.models import ManagedOst, ManagedMdt, ManagedFilesystem

    if hasattr(obj, "content_type"):
        obj = obj.downcast()

    if isinstance(obj, ManagedOst):
        conf_params_query = obj.ostconfparam_set.all()
    elif isinstance(obj, ManagedMdt):
        conf_params_query = obj.mdtconfparam_set.all()
    elif isinstance(obj, ManagedFilesystem):
        import itertools

        conf_params_query = itertools.chain(
            obj.filesystemclientconfparam_set.all(),
            obj.filesystemglobalconfparam_set.all())
    else:
        raise NotImplementedError()

    # First get explicitly set conf params
    set_conf_params = ConfParam.get_latest_params(conf_params_query)
    result = dict([(conf_param.key, conf_param.value)
                   for conf_param in set_conf_params])
    # Then populate None for unset conf params
    for unset_conf_param in set(
            get_possible_conf_params(obj.__class__).keys()) ^ set(
                result.keys()):
        result[unset_conf_param] = None

    return result
Esempio n. 2
0
def set_conf_params(obj, params, new=True):
    from chroma_core.models import ManagedFilesystem, ManagedMdt, ManagedOst, FilesystemMember

    if isinstance(obj, ManagedFilesystem):
        mgs = obj.mgs.downcast()
    elif isinstance(obj, FilesystemMember):
        mgs = obj.filesystem.mgs.downcast()
    else:
        raise NotImplementedError

    if isinstance(obj, ManagedFilesystem):
        kwargs = {"filesystem": obj}
    elif isinstance(obj, ManagedMdt):
        kwargs = {"mdt": obj}
    elif isinstance(obj, ManagedOst):
        kwargs = {"ost": obj}
    else:
        raise NotImplementedError

    # TODO: check if the value is unchanged and return if so

    if not len(params):
        return

    param_records = []
    for key, value in params.items():
        model_klass, param_value_obj, help_text = all_params[key]
        existing_params = ConfParam.get_latest_params(
            model_klass.objects.filter(key=key, **kwargs))
        # Store if the new value is
        if (len(existing_params) > 0 and existing_params[0].value != value
            ) or (len(existing_params) == 0 and value is not None):
            p = model_klass(key=key, value=value, **kwargs)
            param_records.append(p)
        else:
            from chroma_api import api_log

            api_log.info("Ignoring %s %s=%s, already set" % (obj, key, value))

    if param_records:
        mgs.set_conf_params(param_records, new)
        return mgs.id
    else:
        return None