예제 #1
0
def delete_export_by_id(content, export_id):
    export_block = build_export_block(export_id)
    block = BLOCK(export_block)

    try:
        new = block.del_keys(content, [])
    except ArgError as e:
        sys.exit(e.error)
    modify_file(CONF_PATH, new)
예제 #2
0
def delete_client_by_host(content, export_id, host):
    if host is None:
        dmsg("error : must specify host value ")
        sys.exit(-1)
    export_block = build_export_block(export_id, host)
    block = BLOCK(export_block)

    try:
        new = block.del_keys(content, [])
    except ArgError as e:
        sys.exit(e.error)
    modify_file(CONF_PATH, new)
예제 #3
0
    (names, pairs) = get_blocks(sys.argv[2:])
    if not names:
        sys.exit("no block names")
    if len(pairs) % 2 != 0:
        sys.exit("odd number for key value pairs")

    for key in pairs[::2]:
        if not key.startswith("--"):
            sys.exit("some keys are not with -- prefix")

    # remove "--" prefix of keys
    keys = [key[2:] for key in pairs[::2]]
    values = [value for value in pairs[1::2]]

    opairs = zip(keys, values)
    block = BLOCK(names)

elif opcode == "del":
    (names, keys) = get_blocks(sys.argv[2:])
    if not names:
        sys.exit("no block names")
    for key in keys:
        if not key.startswith("--"):
            sys.exit("some key not with -- prefix")

    # remove "--" prefix of keys
    keys = [key[2:] for key in keys]
    if not keys:
        keys = []

    block = BLOCK(names)
예제 #4
0
def set_conf(abs_conf_path, params_list):
    is_new = False
    client_pairs = []
    export_block = []
    fsal_block = []
    client_block = []
    l_keys = []
    l_values = []
    for export in params_list:
        with open(abs_conf_path, 'r') as fp:
            content = fp.read()
        keys = export.values()[0].keys()[1]
        values = export.values()[0].values()[1]
        if cmp(values.strip(' '), "read-write") == 0:
            l_values.append("RW")
        else:
            l_values.append("RO")
        l_keys.append(keys)
        host = export.values()[0].values()[0].strip(' ')
        client_pairs = zip(l_keys, l_values)
        export_path = export.keys()[0].strip(' ')
        export_id = get_export_id_by_path(content, export_path)
        if export_id == '0':
            is_new = True
            export_id = get_max_export_id(content)

        logging.debug("export_id : %s", export_id)
        #无论是否是新export记录,首先需要设置默认参数
        common_block = build_export_block(export_id)
        logging.debug("common_block : %s ", common_block)
        c_block = BLOCK(common_block)
        common_pairs = build_common_param(export_path)
        logging.debug("common_pairs : %s ", common_pairs)
        try:
            common = c_block.set_keys(content, common_pairs)
        except ArgError as e:
            sys.exit(e.error)
        modify_file(abs_conf_path, common)

        #构建fsal block
        fsal_block = build_fsal_block(export_id)
        logging.debug("fsal_block : %s", fsal_block)
        fs_block = BLOCK(fsal_block)
        fsal_pairs = build_fsal_param()
        with open(abs_conf_path, 'r') as fp:
            content = fp.read()
        logging.debug("fsal_pairs : %s", fsal_pairs)
        try:
            fsal = fs_block.set_keys(content, fsal_pairs)
        except ArgError as e:
            sys.exit(e.error)
        modify_file(abs_conf_path, fsal)

        #构建client block
        client_block = build_export_block(export_id, host)
        logging.debug("client_block : %s", client_block)
        cl_block = BLOCK(client_block)
        with open(abs_conf_path, 'r') as fp:
            update_content = fp.read()
        try:
            logging.debug("client_pairs : ", client_pairs)
            client = cl_block.set_keys(update_content, client_pairs)
        except ArgError as e:
            sys.exit(e.error)
        modify_file(abs_conf_path, client)

        common_pairs = []
        fsal_pairs = []
        client_pairs = []
        l_keys = []
        l_values = []

        common_block = []
        fsal_block = []
        client_block = []
        is_new = False
        host = ""
예제 #5
0
    (names, pairs) = get_blocks(sys.argv[2:])
    if not names:
        sys.exit("no block names")
    if len(pairs) % 2 != 0:
        sys.exit("odd number for key value pairs")

    for key in pairs[::2]:
        if not key.startswith("--"):
            sys.exit("some keys are not with -- prefix")

    # remove "--" prefix of keys
    keys = [key[2:] for key in pairs[::2]]
    values = [value for value in pairs[1::2]]

    opairs = zip(keys, values)
    block = BLOCK(names)

elif opcode == "del":
    (names, keys) = get_blocks(sys.argv[2:])
    if not names:
        sys.exit("no block names")
    for key in keys:
        if not key.startswith("--"):
            sys.exit("some key not with -- prefix")

    # remove "--" prefix of keys
    keys = [key[2:] for key in keys]
    if not keys:
        keys = []

    block = BLOCK(names)