Ejemplo n.º 1
0
def handle_alias_create(session, defined, name, members, apply_to_fos):
    print("Create Alias -", name, "with", members)
    status = find_in_db(defined, pyfos_zone.ALIAS, name, members, False)
    if status == EXIST_SAME:
        print("\talready exist")
        return 0
    elif status == EXIST_DIFF_SUBSET:
        print("\talready exist and members are already a subset", members)
        return 0
    elif status == EXIST_DIFF_NON_SUBSET:
        print("\texist but members are different. adding", members)
        if apply_to_fos:
            aliases = [{
                "alias-name": name,
                "member-entry": {
                    "alias-entry-name": members
                }
            }]
            result = aliascreate.aliascreate(session, aliases)
            if 'success-code' in result and result['success-code'] == 201:
                print(CHANGED, "\tadd succeeded", END)
            else:
                print(result)
        else:
            print(CHANGED, "\tneed change", END)

        return 1
    else:
        aliases = [{
            "alias-name": name,
            "member-entry": {
                "alias-entry-name": members
            }
        }]
        if apply_to_fos:
            result = aliascreate.aliascreate(session, aliases)
            if 'success-code' in result and result['success-code'] == 201:
                print(CHANGED, "\tcreate succeeded", END)
            else:
                print(result)
        else:
            print(CHANGED, "\tneed change", END)

        return 1
Ejemplo n.º 2
0
def process_txt(session, filename):
    current_effective = pyfos_zone.effective_configuration.get(session)

    file = open(filename, "r")
    for line in file:
        if len(line) > 0:
            # pylint: disable=W1401
            command_line = re.split('\s|\,', line)
            if command_line[0] == "alicreate":
                aliases = parse_alicreate(command_line)
                result = aliascreate.aliascreate(session, aliases)
                if 'success-code' in result and result['success-code'] == 201:
                    print("\tcreate succeeded")
                else:
                    print(result)
            elif command_line[0] == "zonecreate":
                zones = parse_zonecreate(command_line)
                result = zonecreate.zonecreate(session, zones)
                if 'success-code' in result and result['success-code'] == 201:
                    print("\tcreate succeeded")
                else:
                    print(result)
            elif command_line[0] == "cfgadd":
                cfgs = parse_cfgadd_or_create(command_line)
                result = cfgcreate.cfgcreate(session, cfgs)
                if 'success-code' in result and result['success-code'] == 201:
                    print("\tadd succeeded")
                else:
                    print(result)
            elif command_line[0] == "cfgcreate":
                cfgs = parse_cfgadd_or_create(command_line)
                result = cfgcreate.cfgcreate(session, cfgs)
                if 'success-code' in result and result['success-code'] == 201:
                    print("\tcreate succeeded")
                else:
                    print(result)
            elif command_line[0] == "cfgenable":
                command_line[1] = command_line[1].replace("\"", "")
                print("cfgenable with", command_line[1])
                result = cfgenable.cfgenable(session, command_line[1],
                                             current_effective.peek_checksum())
                if 'success-code' in result and result['success-code'] == 204:
                    print("\tenable succeeded")
                else:
                    print(result)