Exemplo n.º 1
0
def DisableMultipath(naa):
    client = MultipathClient()
    with open(util.MULTIPATH_CONF, 'r') as fd:
        multipath_config_string = fd.read()

    _config = config.Configuration.from_multipathd_conf(
        multipath_config_string)

    # delete whitelist wwid
    white_list = _config.whitelist.wwid
    multipath_list = _config.multipaths

    # check naa
    if ('"%s"' % naa) not in white_list:
        raise store_exception.StoreInvalidException(naa)

    white_list.remove('"%s"' % naa)
    # delete multipath section if have
    for multipath in multipath_list:
        if naa == multipath.wwid.strip('"'):
            multipath_list.remove(multipath)
            break

    # reconfigure
    client.write_to_multipathd_conf(_config)
    util.StoreCmdRun("%s reconfigure" % util.MULTIPATHD)
    logging.info("Naa %s is disable multipath." % naa)
Exemplo n.º 2
0
def SetPolicy(naa, policy):
    client = MultipathClient()
    with open(util.MULTIPATH_CONF, 'r') as fd:
        multipath_config_string = fd.read()

    _config = config.Configuration.from_multipathd_conf(
        multipath_config_string)

    white_list = _config.whitelist.wwid
    multipath_list = _config.multipaths

    # check naa
    if ('"%s"' % naa) not in white_list:
        raise store_exception.StoreInvalidException(naa)

    # delete old multipath section
    for multipath in multipath_list:
        if naa == multipath.wwid.strip('"'):
            multipath_list.remove(multipath)
            break

    # new multipath section
    new_section = config.MultipathEntry()
    if policy == adp_pb2.DEFAULT:
        logging.info("Naa %s policy change to DEFAULT." % naa)

    if policy == adp_pb2.RECENTLY_USED:
        new_section.wwid = '"%s"' % naa
        new_section.path_grouping_policy = '"failover"'
        new_section.failback = '"manual"'
        multipath_list.append(new_section)
        logging.info("Naa %s policy change to RECENTLY_USED." % naa)

    if policy == adp_pb2.FIXED:
        new_section.wwid = '"%s"' % naa
        new_section.path_grouping_policy = '"failover"'
        new_section.failback = '"immediate"'
        multipath_list.append(new_section)
        logging.info("Naa %s policy change to FIXED." % naa)

    if policy == adp_pb2.LOOP:
        new_section.wwid = '"%s"' % naa
        new_section.path_grouping_policy = '"multibus"'
        multipath_list.append(new_section)
        logging.info("Naa %s policy change to LOOP." % naa)

    if policy == adp_pb2.OPTIMAL:
        new_section.wwid = '"%s"' % naa
        new_section.path_grouping_policy = '"group_by_prio"'
        new_section.prio = '"alua"'
        new_section.failback = '"immediate"'
        multipath_list.append(new_section)
        logging.info("Naa %s policy change to OPTIMAL." % naa)

    # reconfigure
    client.write_to_multipathd_conf(_config)
    util.StoreCmdRun("%s reconfigure" % util.MULTIPATHD)
Exemplo n.º 3
0
def SetDefaultConfig():
    # get default_multipath.conf
    client = MultipathClient()
    with open(DEFAULT_CONFIG, 'r') as fd:
        default_config_string = fd.read()
    logging.info("default_config_string is %s" % default_config_string)
    default_config = config.Configuration.from_multipathd_conf(
        default_config_string)

    # write to /etc/multipath.conf
    client.write_to_multipathd_conf(default_config)

    # reconfigure
    util.StoreCmdRun("%s reconfigure " % util.MULTIPATHD)
Exemplo n.º 4
0
def EnableMultipath(naa):
    client = MultipathClient()
    with open(util.MULTIPATH_CONF, 'r') as fd:
        multipath_config_string = fd.read()

    _config = config.Configuration.from_multipathd_conf(
        multipath_config_string)

    # check naa
    if ('"%s"' % naa) in _config.whitelist.wwid:
        logging.info('naa %s is already set multipath.' % naa)
    else:
        _config.whitelist.wwid.append('"%s"' % naa)
        client.write_to_multipathd_conf(_config)

    # reconfigure
    util.StoreCmdRun("%s reconfigure" % util.MULTIPATHD)
    logging.info("Naa %s is enable multipath." % naa)