Ejemplo n.º 1
0
def zone_name_members_func(session, inputs, usage, func):
    # comment zone helper to execute & commit
    # name, and member based operations
    if "name" not in inputs:
        print("*** missing input: name")
        pyfos_auth.logout(session)
        brcd_util.full_usage(usage)
        sys.exit()
    name = inputs["name"]

    if "members" not in inputs:
        print("*** missing input: members")
        pyfos_auth.logout(session)
        brcd_util.full_usage(usage)
        sys.exit()
    members = inputs["members"]

    current_effective = pyfos_zone.effective_configuration.get(session)

    print("executing", func.__name__)
    result = func(session, name, members)
    if pyfos_util.is_failed_resp(result):
        pyfos_util.response_print(result)
        print(func.__name__, "failed. Aborting transaction.")
        result = cfgabort.cfgabort(session)
        pyfos_util.response_print(result)
    else:
        pyfos_util.response_print(result)
        print(func.__name__, "succeeded. Saving transaction.")
        result = cfgsave.cfgsave(session, current_effective.peek_checksum())
        if pyfos_util.is_failed_resp(result):
            pyfos_util.response_print(result)
            print(func.__name__, "failed. Aborting transaction.")
            result = cfgabort.cfgabort(session)
            pyfos_util.response_print(result)
Ejemplo n.º 2
0
def main(argv):
    filters = ["zone_object"]
    inputs = brcd_util.parse(argv, zone_operation_parameters, filters,
                             validate)
    session = brcd_util.getsession(inputs)

    # Store the checksum before editing the zoneDB to use for the
    #  cfgsave at the end
    current_effective = pyfos_zone.effective_configuration.get(session)

    result = do_zone_object_expunge(session, inputs['utilobject'])
    pyfos_util.response_print(result)

    # If the expunge operation succeeds, perform an implicit cfgsave
    # If the expunge operation fails, it should get automatically aborted
    # in the FOS Zone module, so no need to abort the transaction.
    if pyfos_util.is_success_resp(result):
        result = cfgsave.cfgsave(session, current_effective.peek_checksum())

        # If the save operation fails, check to see if there is an open
        #  transaction. If there is, then abort the transaction
        if pyfos_util.is_failed_resp(result):
            print("Expunge succeeded, but the cfgSave failed.")
            current_effective = pyfos_zone.effective_configuration.get(session)
            if current_effective.peek_transaction_token() != 0:
                pyfos_util.response_print(result)
                print("\nAborting the transaction.")
                result = cfgabort.cfgabort(session)
                pyfos_util.response_print(result)

    pyfos_auth.logout(session)
Ejemplo n.º 3
0
def main(argv):
    valid_options = ["allaccess"]
    inputs = brcd_util.generic_input(argv, usage, valid_options)

    session = pyfos_auth.login(inputs["login"],
                               inputs["password"],
                               inputs["ipaddr"],
                               inputs["secured"],
                               verbose=inputs["verbose"])
    if pyfos_auth.is_failed_login(session):
        print(
            "login failed because",
            session.get(pyfos_auth.CREDENTIAL_KEY)[pyfos_auth.LOGIN_ERROR_KEY])
        brcd_util.full_usage(usage)
        sys.exit()

    brcd_util.exit_register(session)

    vfid = None
    if 'vfid' in inputs:
        vfid = inputs['vfid']

    if vfid is not None:
        pyfos_auth.vfid_set(session, vfid)

    if "allaccess" not in inputs:
        pyfos_auth.logout(session)
        usage()
        sys.exit()
    allaccess = inputs["allaccess"]

    current_effective = pyfos_zone.effective_configuration.get(session)

    result = defzone(session, allaccess)

    if pyfos_util.is_failed_resp(result):
        pyfos_util.response_print(result)
    else:
        pyfos_util.response_print(result)
        result = cfgsave.cfgsave(session, current_effective.peek_checksum())
        pyfos_util.response_print(result)
        if pyfos_util.is_failed_resp(result):
            print("failed. Aborting transaction.")
            result = cfgabort.cfgabort(session)
            pyfos_util.response_print(result)

    pyfos_auth.logout(session)