def main():
    forti_api = API(api_info=system_reboot_api_args)
    if forti_api._update_config and forti_api._update_config[0].get('message'):
        _reboot_event_log_message = forti_api._update_config[0]['message']
    else:
        _reboot_event_log_message = 'Reboot by FortiOS API'
    log = {"event_log_message": _reboot_event_log_message}
    response = forti_api.perform_action_on_endpoint(
        changed=True, api_request_data=json.dumps(log))
    forti_api._module.exit_json(msg="System rebooted",
                                changed=True,
                                failed=False,
                                response=response)
def main():
    forti_api = API(api_info=system_firmware_upgrade_api_args)
    if forti_api._update_config and forti_api._update_config[0].get(
            'filename'):
        firmware_file = forti_api._update_config[0]['filename']
        if os.path.isfile(firmware_file):
            firmware = {
                "source":
                "upload",
                "file_content":
                b64encode(open(firmware_file, 'rb').read()).decode('utf-8')
            }
            try:
                response = forti_api.perform_action_on_endpoint(
                    changed=True,
                    api_request_data=json.dumps(firmware),
                    timeout=600)
                status = response['results']['status']
            except requests.exceptions.Timeout as error:
                forti_api._module.fail_json(msg="Firmware Upgrade Timeout: " +
                                            str(error),
                                            changed=False)
            if status == "success":
                # try:
                # message = "Firmware restored successfully"
                forti_api._module.exit_json(
                    msg="Firmware restored successfully",
                    changed=True,
                    failed=False,
                    response=response)
                # I encountered this issue occassionaly, the exit_json call might raise SystemExit exception for some reasons which I am not quite understand, below is part of the error message
                # fatal: [dyao501e02]: FAILED! => {"changed": false, "module_stderr": "Exception SystemExit: SystemExit(1,) in <bound method API.__del__ of <ansible.module_utils.fortios_api.API object at 0x7f3453de9ed0>> ignored\n", "module_stdout": "\n{\"msg\": \"Firmware restored successfully\", \"failed\": false, \"changed\": true, \"response\": {\"status\": \"success\", \"name\": \"firmware\", \"results\": {\"status\": \"success\"}, \"http_method\"
                # except SystemExit as error: # to bypass the SystemExit exception
                #     pass
            else:  # status == "error"
                message = "Firmware restore failed with error: " + response[
                    'results']['error']
                forti_api._module.fail_json(msg=message,
                                            changed=False,
                                            response=response)
        else:
            forti_api._module.fail_json(msg="Firmware file " + firmware_file +
                                        " is not found",
                                        changed=False)
    else:
        forti_api._module.fail_json(msg="Firmware filename is required",
                                    changed=False)
def main():
    forti_api = API(api_info=system_config_api_args)
    if forti_api._update_config and forti_api._update_config[0].get(
            'filename'):
        config_file = forti_api._update_config[0]['filename']
        if os.path.isfile(config_file):
            config = {
                "source":
                "upload",
                "scope":
                "global",
                "file_content":
                b64encode(open(config_file, 'rb').read()).decode('utf-8')
            }
            response = forti_api.perform_action_on_endpoint(
                changed=True, api_request_data=json.dumps(config))
            config_restored = response['results']['config_restored']
            if config_restored:
                message = "Config restored successfully"
                forti_api._module.exit_json(msg=message,
                                            changed=True,
                                            failed=False,
                                            response=response)
            else:
                message = "Config restore failed with error: " + response[
                    'results']['error']
                forti_api._module.fail_json(msg=message,
                                            changed=False,
                                            response=response)
        else:
            forti_api._module.fail_json(msg="Configuratin file " +
                                        config_file + " is not found",
                                        changed=False)
    else:
        forti_api._module.fail_json(msg="Configuratin filename is required",
                                    changed=False)
Exemple #4
0
def main():
    forti_api = API(system_global_api_args)
    forti_api.apply_configuration_to_endpoint()
Exemple #5
0
def main():
    forti_api = API(prefix_list_api_args)
    forti_api.apply_configuration_to_endpoint()
def main():
    forti_api = API(api_syslogd_setting_args)
    forti_api.apply_configuration_to_endpoint()
Exemple #7
0
def main():
    forti_api = API(module_args)
    forti_api.apply_configuration_to_endpoint()
Exemple #8
0
def main():
    forti_api = API(router_bgp_args)
    forti_api.apply_configuration_to_endpoint()
def main():
    forti_api = API(router_ospf_ospf_interface_args)
    forti_api.apply_configuration_to_endpoint()