Esempio n. 1
0
def _list_live_group_attrs(rts_obj):
    '''
    Returns a list of all group attributes for the rts_obj rtslib object
    currently running on the live system, in LIO configuration file format.
    '''
    attrs = []
    for attribute in rts_obj.list_attributes(writable=True):
        value = rts_obj.get_attribute(attribute)
        attrs.append("attribute %s %s" % (attribute, dump_value(value)))
    for parameter in rts_obj.list_parameters(writable=True):
        value = rts_obj.get_parameter(parameter)
        attrs.append("parameter %s %s" % (parameter, dump_value(value)))
    for auth_attr in rts_obj.list_auth_attrs(writable=True):
        value = rts_obj.get_auth_attr(auth_attr)
        attrs.append("auth %s %s" % (auth_attr, dump_value(value)))
    return attrs
Esempio n. 2
0
def _list_live_group_attrs(rts_obj):
    '''
    Returns a list of all group attributes for the rts_obj rtslib object
    currently running on the live system, in LIO configuration file format.
    '''
    attrs = []
    for attribute in rts_obj.list_attributes(writable=True):
        value = rts_obj.get_attribute(attribute)
        attrs.append("attribute %s %s" % (attribute, dump_value(value)))
    for parameter in rts_obj.list_parameters(writable=True):
        value = rts_obj.get_parameter(parameter)
        attrs.append("parameter %s %s" % (parameter, dump_value(value)))
    for auth_attr in rts_obj.list_auth_attrs(writable=True):
        value = rts_obj.get_auth_attr(auth_attr)
        attrs.append("auth %s %s" % (auth_attr, dump_value(value)))
    return attrs
Esempio n. 3
0
def dump_live_fabric():
    '''
    Returns a text dump of the fabric objects and attributes currently
    running on the live system, in LIO configuration file format.
    '''
    dump = []
    for fm in sorted(get_root().fabric_modules, key=lambda fm: fm.name):
        if fm.has_feature('discovery_auth'):
            dump.append("fabric %s {" % fm.name)
            dump.append("%sdiscovery_auth enable %s" %
                        (_indent, dump_value(fm.discovery_enable_auth)))
            dump.append("%sdiscovery_auth userid %s" %
                        (_indent, dump_value(fm.discovery_userid)))
            dump.append("%sdiscovery_auth password %s" %
                        (_indent, dump_value(fm.discovery_password)))
            dump.append("%sdiscovery_auth mutual_userid %s" %
                        (_indent, dump_value(fm.discovery_mutual_userid)))
            dump.append("%sdiscovery_auth mutual_password %s" %
                        (_indent, dump_value(fm.discovery_mutual_password)))
            dump.append("}")

        for tg in fm.targets:
            tpgs = []
            if not list(tg.tpgs):
                dump.append("fabric %s target %s" % (fm.name, tg.wwn))
            for tpg in tg.tpgs:
                if tpg.has_feature("tpgts"):
                    head = ("fabric %s target %s tpgt %s" %
                            (fm.name, tg.wwn, tpg.tag))
                else:
                    head = ("fabric %s target %s" % (fm.name, tg.wwn))

                if tpg.has_enable():
                    enable = int(tpg.enable)
                else:
                    enable = None

                section = []
                if tpg.has_feature("nexus"):
                    section.append("%snexus_wwn %s" % (_indent, tpg.nexus_wwn))

                attrs = [
                    "%s%s" % (_indent, attr)
                    for attr in _list_live_group_attrs(tpg)
                ]
                if attrs:
                    section.append("\n".join(attrs))

                for lun in sorted(tpg.luns, key=lambda l: l.lun):
                    attrs = [
                        "%s%s" % (_indent, attr)
                        for attr in _list_live_group_attrs(lun)
                    ]
                    if attrs:
                        fmt = "%slun %s %s %s {"
                    else:
                        fmt = "%slun %s backend %s:%s"
                    section.append(
                        fmt %
                        (_indent, lun.lun, lun.storage_object.backstore.plugin,
                         lun.storage_object.name))
                    if attrs:
                        section.append("\n".join(attrs))
                        section.append("%s}" % _indent)

                if tpg.has_feature("acls"):
                    for acl in tpg.node_acls:
                        section.append("%sacl %s {" % (_indent, acl.node_wwn))
                        attrs = [
                            "%s%s" % (2 * _indent, attr)
                            for attr in _list_live_group_attrs(acl)
                        ]
                        if attrs:
                            section.append("\n".join(attrs))
                        for mlun in acl.mapped_luns:
                            section.append("%smapped_lun %s {" %
                                           (2 * _indent, mlun.mapped_lun))
                            section.append("%s target_lun %s" %
                                           (3 * _indent, mlun.tpg_lun.lun))
                            section.append(
                                "%s write_protect %s" %
                                (3 * _indent, int(mlun.write_protect)))
                            section.append("%s}" % (2 * _indent))
                        section.append("%s}" % (_indent))

                if tpg.has_feature("nps"):
                    for np in tpg.network_portals:
                        section.append("%sportal %s:%s" %
                                       (_indent, np.ip_address, np.port))
                if section:
                    if enable is not None:
                        section.append("%senable %s" % (_indent, enable))
                    dump.append("%s {" % head)
                    dump.append("\n".join(section))
                    dump.append("}")
                else:
                    if enable is not None:
                        dump.append("%s enable %s" % (head, enable))
                    else:
                        dump.append(head)

    return "\n".join(dump)
Esempio n. 4
0
def dump_live_fabric():
    '''
    Returns a text dump of the fabric objects and attributes currently
    running on the live system, in LIO configuration file format.
    '''
    dump = []
    for fm in sorted(get_root().fabric_modules, key=lambda fm: fm.name):
        if fm.has_feature('discovery_auth'):
            dump.append("fabric %s {" % fm.name)
            dump.append("%sdiscovery_auth enable %s"
                        % (_indent, dump_value(fm.discovery_enable_auth)))
            dump.append("%sdiscovery_auth userid %s"
                        % (_indent, dump_value(fm.discovery_userid)))
            dump.append("%sdiscovery_auth password %s"
                        % (_indent, dump_value(fm.discovery_password)))
            dump.append("%sdiscovery_auth mutual_userid %s"
                        % (_indent, dump_value(fm.discovery_mutual_userid)))
            dump.append("%sdiscovery_auth mutual_password %s"
                        % (_indent, dump_value(fm.discovery_mutual_password)))
            dump.append("}")

        for tg in fm.targets:
            tpgs = []
            if not list(tg.tpgs):
                dump.append("fabric %s target %s" % (fm.name, tg.wwn))
            for tpg in tg.tpgs:
                if tpg.has_feature("tpgts"):
                    head = ("fabric %s target %s tpgt %s"
                            % (fm.name, tg.wwn, tpg.tag))
                else:
                    head = ("fabric %s target %s"
                            % (fm.name, tg.wwn))

                if tpg.has_enable():
                    enable = int(tpg.enable)
                else:
                    enable = None

                section = []
                attrs = ["%s%s" % (_indent, attr)
                         for attr in _list_live_group_attrs(tpg)]
                if attrs:
                    section.append("\n".join(attrs))

                for lun in sorted(tpg.luns, key=lambda l: l.lun):
                    attrs = ["%s%s" % (_indent, attr)
                             for attr in _list_live_group_attrs(lun)]
                    if attrs:
                        fmt = "%slun %s %s %s {"
                    else:
                        fmt = "%slun %s backend %s:%s"
                    section.append(fmt % (_indent, lun.lun,
                                       lun.storage_object.backstore.plugin,
                                       lun.storage_object.name))
                    if attrs:
                        section.append("\n".join(attrs))
                        section.append("%s}" % _indent)

                if tpg.has_feature("acls"):
                    for acl in tpg.node_acls:
                        section.append("%sacl %s {" % (_indent, acl.node_wwn))
                        attrs = ["%s%s" % (2*_indent, attr)
                                 for attr in _list_live_group_attrs(acl)]
                        if attrs:
                            section.append("\n".join(attrs))
                        for mlun in acl.mapped_luns:
                            section.append("%smapped_lun %s {"
                                        % (2*_indent, mlun.mapped_lun))
                            section.append("%s target_lun %s"
                                           % (3*_indent, mlun.tpg_lun.lun))
                            section.append("%s write_protect %s"
                                           % (3*_indent,
                                              int(mlun.write_protect)))
                            section.append("%s}" % (2*_indent))
                        section.append("%s}" % (_indent))

                if tpg.has_feature("nps"):
                    for np in tpg.network_portals:
                        section.append("%sportal %s:%s"
                                    % (_indent, np.ip_address, np.port))
                if section:
                    if enable is not None:
                        section.append("%senable %s"
                                       % (_indent, enable))
                    dump.append("%s {" % head)
                    dump.append("\n".join(section))
                    dump.append("}")
                else:
                    if enable is not None:
                        dump.append("%s enable %s" % (head, enable))
                    else:
                        dump.append(head)

    return "\n".join(dump)