class CustomForm(BaseForm): form_type = HiddenField(default="custom") address = SelectField(choices=[("ipv4", "IPv4"), ("ipv6", "IPv6")]) connected_links = MultipleInstanceField("Links", model="link") hostname = StringField("Username", default="admin") ip_address = StringField("IP address") neighbors = MultipleInstanceField("Devices", model="device") password = PasswordField("Password") router_id = IntegerField("Router ID") carry_customer_traffic = BooleanField("Carry Customer Traffic", default=False)
class DeviceConnectionForm(BaseForm): template = "device_connection" form_type = HiddenField(default="device_connection") address_choices = [("ip_address", "IP address"), ("name", "Name")] + [ (property, values["pretty_name"]) for property, values in app.properties["custom"]["device"].items() if values.get("is_address", False) ] address = SelectField(choices=address_choices) username = StringField("Username") password = PasswordField("Password")
class AddServiceForm(BaseForm): form_type = HiddenField(default="add_services_to_workflow") template = "add_services_to_workflow" mode = SelectField( "Mode", choices=( ("deep", "Deep Copy (creates a duplicate from the service)"), ("shallow", "Shallow Copy (creates a reference to the service)"), ), ) search = StringField()
class TaskForm(BaseForm): template = "object" form_type = HiddenField(default="task") id = HiddenField() scheduling_mode = SelectField( "Scheduling Mode", choices=(("cron", "Crontab Scheduling"), ("standard", "Standard Scheduling")), ) name = StringField("Name", [InputRequired()]) description = StringField("Description") start_date = StringField("Start Date", type="date") end_date = StringField("End Date", type="date") frequency = IntegerField("Frequency", default=0) frequency_unit = SelectField( "Frequency Unit", choices=( ("seconds", "Seconds"), ("minutes", "Minutes"), ("hours", "Hours"), ("days", "Days"), ), ) crontab_expression = StringField("Crontab Expression") initial_payload = DictField("Payload") def validate(self): valid_form = super().validate() no_date = self.scheduling_mode.data == "standard" and not self.start_date.data if no_date: self.start_date.errors.append("A start date must be set.") no_cron_expression = (self.scheduling_mode.data == "cron" and not self.crontab_expression.data) if no_cron_expression: self.crontab_expression.errors.append( "A crontab expression must be set.") no_service = not self.service.data if no_service: self.service.errors.append("No service set.") return valid_form and not any( [no_date, no_cron_expression, no_service])
class DebugForm(BaseForm): template = "debug" form_type = HiddenField(default="debug") snippets = SelectField(choices=(), validation=False) code = StringField( "Python Code", type="code", python=True, widget=TextArea(), render_kw={"rows": 15}, ) output = StringField("Output", widget=TextArea(), render_kw={"rows": 16})
class NapalmConfigurationForm(NapalmForm): form_type = HiddenField(default="napalm_configuration_service") action = SelectField( choices=( ("load_merge_candidate", "Load merge"), ("load_replace_candidate", "Load replace"), ) ) content = StringField(widget=TextArea(), render_kw={"rows": 5}, substitution=True) groups = { "Main Parameters": {"commands": ["action", "content"], "default": "expanded"}, **NapalmForm.groups, }
class CredentialForm(BaseForm): action = "eNMS.base.processData" form_type = HiddenField(default="credential") id = HiddenField() name = StringField("Name", [InputRequired()]) description = StringField(widget=TextArea(), render_kw={"rows": 13}) role = SelectField( "Role", choices=( ("read-write", "Read Write"), ("read-only", "Read Only"), ), ) subtype = SelectField("Type", choices=(("password", "Username / Password"), ("key", "SSH Key"))) device_pools = MultipleInstanceField("Devices", model="pool") user_pools = MultipleInstanceField("Users", model="pool") priority = IntegerField("Priority", default=1) username = StringField("Username") enable_password = PasswordField("'Enable' Password") password = PasswordField("Password") private_key = StringField(widget=TextArea(), render_kw={"rows": 10})
class NapalmForm(ConnectionForm): form_type = HiddenField(default="napalm") abstract_service = True driver = SelectField(choices=app.NAPALM_DRIVERS) use_device_driver = BooleanField(default=True) timeout = IntegerField(default=10) optional_args = DictField() groups = { "Napalm Parameters": { "commands": ["driver", "use_device_driver", "timeout", "optional_args"], "default": "expanded", }, **ConnectionForm.groups, }
class AnsiblePlaybookForm(ServiceForm): form_type = HiddenField(default="ansible_playbook_service") playbook_path = SelectField("Playbook Path", choices=(), validation=False) arguments = StringField( "Arguments (Ansible command line options)", substitution=True, help="ansible/arguments", ) pass_device_properties = BooleanField( "Pass Device Inventory Properties (to be used " "in the playbook as {{name}} or {{ip_address}})") credentials = SelectField( "Credentials", choices=( ("device", "Device Credentials"), ("user", "User Credentials"), ), ) options = DictField( "Options (passed to ansible as -e extra args)", substitution=True, help="ansible/options", )
class ChangelogForm(BaseForm): template = "object" form_type = HiddenField(default="changelog") id = HiddenField() severity = SelectField( "Severity", choices=( ("debug", "Debug"), ("info", "Info"), ("warning", "Warning"), ("error", "Error"), ("critical", "Critical"), ), ) content = StringField(widget=TextArea(), render_kw={"rows": 10})
class GenericFileTransferForm(ServiceForm): form_type = HiddenField(default="generic_file_transfer_service") direction = SelectField(choices=(("get", "Get"), ("put", "Put"))) protocol = SelectField(choices=(("scp", "SCP"), ("sftp", "SFTP"))) source_file = StringField(validators=[InputRequired()], substitution=True) destination_file = StringField(validators=[InputRequired()], substitution=True) missing_host_key_policy = BooleanField() load_known_host_keys = BooleanField() look_for_keys = BooleanField() source_file_includes_globbing = BooleanField( "Source file includes glob pattern") max_transfer_size = IntegerField(default=2**30) window_size = IntegerField(default=2**30) timeout = FloatField(default=10.0) def validate(self): valid_form = super().validate() invalid_direction = (self.source_file_includes_globbing.data and self.direction.data == "get") if invalid_direction: self.direction.errors.append( "Globbing only works with the 'PUT' direction") return valid_form and not invalid_direction
class PoolForm(BaseForm): template = "pool" form_type = HiddenField(default="pool") id = HiddenField() name = StringField("Name", [InputRequired()]) description = StringField("Description") longitude = StringField("Longitude", default=0.0) latitude = StringField("Latitude", default=0.0) operator = SelectField( "Type of match", choices=( ("all", "Match if all properties match"), ("any", "Match if any property matches"), ), ) manually_defined = BooleanField( "Manually defined (won't be automatically updated)")
class RestCallForm(ServiceForm): form_type = HiddenField(default="rest_call_service") call_type = SelectField(choices=( ("GET", "GET"), ("POST", "POST"), ("PUT", "PUT"), ("DELETE", "DELETE"), ("PATCH", "PATCH"), )) rest_url = StringField(substitution=True) payload = DictField(json_only=True, substitution=True) params = DictField(substitution=True) headers = DictField(substitution=True) verify_ssl_certificate = BooleanField("Verify SSL Certificate") timeout = IntegerField(default=15) username = StringField() password = PasswordField()
class UnixShellScriptForm(NetmikoForm): form_type = HiddenField(default="unix_shell_script_service") enable_mode = BooleanField("Run as root using sudo") config_mode = BooleanField("Config mode") source_code = StringField( widget=TextArea(), render_kw={"rows": 15}, default=("#!/bin/bash\n" "# The following example shell script returns" " 0 for success; non-zero for failure\n" "directory_contents=`ls -al /root` # Needs privileged mode\n" "return_code=$?\n" "if [ $return_code -ne 0 ]; then\n" " exit $return_code # Indicating Failure\n" "else\n" ' echo -e "$directory_contents"\n' " exit 0 # Indicating Success\n" "fi\n"), ) driver = SelectField(choices=app.NETMIKO_DRIVERS, default="linux") use_device_driver = BooleanField(default=True) fast_cli = BooleanField() timeout = IntegerField(default=10) delay_factor = FloatField(default=1.0) global_delay_factor = FloatField(default=1.0) expect_string = StringField(substitution=True) auto_find_prompt = BooleanField(default=True) strip_prompt = BooleanField(default=True) strip_command = BooleanField(default=True) groups = { "Main Parameters": { "commands": ["source_code"], "default": "expanded" }, "Advanced Netmiko Parameters": { "commands": [ "expect_string", "auto_find_prompt", "strip_prompt", "strip_command", ], "default": "hidden", }, **NetmikoForm.groups, }
class WorkflowForm(ServiceForm): form_type = HiddenField(default="workflow") close_connection = BooleanField(default=False) run_method = SelectField( "Run Method", choices=( ("per_device", "Run the workflow device by device"), ( "per_service_with_workflow_targets", "Run the workflow service by service using workflow targets", ), ( "per_service_with_service_targets", "Run the workflow service by service using service targets", ), ), ) superworkflow = InstanceField("Superworkflow")
class NapalmBackupForm(NapalmForm): form_type = HiddenField(default="napalm_backup_service") property = SelectField( "Configuration Property to Update", choices=list(app.configuration_properties.items()), ) getters = SelectMultipleField(choices=app.NAPALM_GETTERS) replacements = FieldList(FormField(ReplacementForm), min_entries=3) groups = { "Target Property and Getters": { "commands": ["property", "getters"], "default": "expanded", }, "Search Response & Replace": { "commands": ["replacements"], "default": "expanded", }, **NapalmForm.groups, }
def form_init(cls): cls.models = ("device", "link", "service", "user") for model in cls.models: setattr(cls, f"{model}_properties", app.properties["filtering"][model]) for property in app.properties["filtering"][model]: setattr(cls, f"{model}_{property}", StringField(property)) setattr(cls, f"{model}_{property}_invert", BooleanField(property)) form_properties["pool"][f"{model}_{property}_invert"] = {"type": "bool"} setattr( cls, f"{model}_{property}_match", SelectField( choices=( ("inclusion", "Inclusion"), ("equality", "Equality"), ("regex", "Regular Expression"), ) ), )
def configure_pool_form(cls): cls.device_properties = app.properties["filtering"]["device"] cls.link_properties = app.properties["filtering"]["link"] for cls_name, properties in ( ("device", app.properties["filtering"]["device"]), ("link", app.properties["filtering"]["link"]), ): for property in properties: match_field = f"{cls_name}_{property}_match" setattr(cls, f"{cls_name}_{property}", StringField(property)) setattr( cls, match_field, SelectField(choices=( ("inclusion", "Inclusion"), ("equality", "Equality"), ("regex", "Regular Expression"), )), ) return cls
class DataBackupForm(NetmikoForm): form_type = HiddenField(default="netmiko_backup_service") property = SelectField( "Configuration Property to Update", choices=list(app.configuration_properties.items()), ) commands = FieldList(FormField(CommandsForm), min_entries=12) replacements = FieldList(FormField(ReplacementForm), min_entries=12) add_header = BooleanField("Add header for each ommand", default=True) groups = { "Target property and commands": { "commands": ["property", "add_header", "commands"], "default": "expanded", }, "Search Response & Replace": { "commands": ["replacements"], "default": "expanded", }, **NetmikoForm.groups, }
class PayloadExtractionForm(ServiceForm): form_type = HiddenField(default="payload_extraction_service") variable1 = StringField("Variable Name") query1 = StringField("Python Extraction Query", python=True) match_type1 = SelectField("Post Processing", choices=match_choices) match1 = StringField( "Regular Expression / TextFSM Template Text", widget=TextArea(), render_kw={"rows": 5}, ) operation1 = SelectField("Operation", choices=operation_choices) variable2 = StringField("Variable Name") query2 = StringField("Python Extraction Query", python=True) match_type2 = SelectField("Post Processing", choices=match_choices) match2 = StringField( "Regular Expression / TextFSM Template Text", widget=TextArea(), render_kw={"rows": 5}, ) operation2 = SelectField("Operation", choices=operation_choices) variable3 = StringField("Variable Name") query3 = StringField("Python Extraction Query", python=True) match_type3 = SelectField("Post Processing", choices=match_choices) match3 = StringField( "Regular Expression / TextFSM Template Text", widget=TextArea(), render_kw={"rows": 5}, ) operation3 = SelectField("Operation", choices=operation_choices) groups = { "Extraction 1": { "commands": ["variable1", "query1", "match_type1", "match1", "operation1"], "default": "expanded", }, "Extraction 2": { "commands": ["variable2", "query2", "match_type2", "match2", "operation2"], "default": "expanded", }, "Extraction 3": { "commands": ["variable3", "query3", "match_type3", "match3", "operation3"], "default": "expanded", }, }
class Ipv4Form(FlaskForm): ipv4_address = StringField( "IPv4 address", [ Optional(), IPAddress( ipv4=True, message="Please enter an IPv4 address for the IPv4 address field", ) ], ) mask = SelectField( choices=( ("255.0.0.0", "8"), ("255.128.0.0", "9"), ("255.192.0.0", "10"), ("255.224.0.0", "11"), ("255.240.0.0", "12"), ("255.248.0.0", "13"), ("255.252.0.0", "14"), ("255.254.0.0", "15"), ("255.255.0.0", "16"), ("255.255.128.0", "17"), ("255.255.192.0", "18"), ("255.255.224.0", "19"), ("255.255.240.0", "20"), ("255.255.248.0", "21"), ("255.255.252.0", "22"), ("255.255.254.0", "23"), ("255.255.255.0", "24"), ("255.255.255.128", "25"), ("255.255.255.192", "26"), ("255.255.255.224", "27"), ("255.255.255.240", "28"), ("255.255.255.248", "29"), ("255.255.255.252", "30"), ("255.255.255.254", "31"), ), default="255.255.255.0" )
class PoolForm(BaseForm): template = "pool" form_type = HiddenField(default="pool") id = HiddenField() name = StringField("Name", [InputRequired()]) admin_only = BooleanField("Pool visible to admin users only") access_groups = StringField("Groups") description = StringField("Description") operator = SelectField( "Type of match", choices=( ("all", "Match if all properties match"), ("any", "Match if any property matches"), ), ) manually_defined = BooleanField( "Manually defined (won't be automatically updated)") @classmethod def form_init(cls): cls.models = ("device", "link", "service", "user") for model in cls.models: setattr(cls, f"{model}_properties", app.properties["filtering"][model]) for property in app.properties["filtering"][model]: setattr(cls, f"{model}_{property}", StringField(property)) setattr(cls, f"{model}_{property}_invert", BooleanField(property)) form_properties["pool"][f"{model}_{property}_invert"] = { "type": "bool" } setattr( cls, f"{model}_{property}_match", SelectField(choices=( ("inclusion", "Inclusion"), ("equality", "Equality"), ("regex", "Regular Expression"), )), )
class TopologyImportForm(ServiceForm): form_type = HiddenField(default="topology_import_service") import_type = SelectField(choices=( ("librenms", "LibreNMS"), ("netbox", "Netbox"), ("opennms", "OpenNMS"), )) netbox_address = StringField(default="http://0.0.0.0:8000") netbox_token = PasswordField() opennms_address = StringField() opennms_devices = StringField() opennms_login = StringField() opennms_password = PasswordField() librenms_address = StringField(default="http://librenms.example.com") librenms_token = PasswordField() groups = { "Type of Import": { "commands": ["import_type"], "default": "expanded" }, "Netbox": { "commands": ["netbox_address", "netbox_token"], "default": "expanded", }, "OpenNMS": { "commands": [ "opennms_address", "opennms_devices", "opennms_login", "opennms_password", ], "default": "expanded", }, "LibreNMS": { "commands": ["librenms_address", "librenms_token"], "default": "expanded", }, }
def filtering_form_generator(): for form_type in ("device", "link", "pool", "run", "service", "task", "user"): properties, relations = app.properties["filtering"].get(form_type, []), {} for model, relation in relationships[form_type].items(): if model in ("edges", "results"): continue relations[model] = MultipleInstanceField(model) relationships[f"{form_type}_filtering"][model] = relation relationships[f"{form_type}_relation_filtering"][model] = relation relation_form = { "template": "filtering", "properties": sorted(relations), "object_type": form_type, "form_type": HiddenField(default=f"{form_type}_relation_filtering"), **relations, } type(f"{form_type}RelationshipFilteringForm", (BaseForm, ), relation_form) form = deepcopy(relation_form) form.update({ "form_type": HiddenField(default=f"{form_type}_filtering"), "properties": sorted(properties) + sorted(relations), **{property: StringField() for property in properties}, **{ f"{property}_filter": SelectField(choices=( ("inclusion", "Inclusion"), ("equality", "Equality"), ("regex", "Regular Expression"), )) for property in properties }, }) type(f"{form_type}FilteringForm", (BaseForm, ), form)
class NetconfForm(ConnectionForm): form_type = HiddenField(default="netconf_service") nc_type = SelectField( choices=( ("get_config", "Get Full Config"), ("get_filtered_config", "Get"), ("push_config", "Edit Config"), ("copy_config", "Copy Config"), ("rpc", "Dispatch"), ), label="NETCONF Operation", ) xml_filter = StringField(label="XML Filter", widget=TextArea(), render_kw={"rows": 5}, substitution=True) target = SelectField( choices=( ("running", "Running"), ("candidate", "Candidate"), ("startup", "Startup"), ), label="Target Config", ) default_operation = SelectField( choices=( ("merge", "Merge"), ("replace", "Replace"), ("None", "None"), ), label="Default config operation", validate_choice=False, ) test_option = SelectField( choices=( ("test-then-set", "Test, then set"), ("set", "Set"), ("None", "None"), ), label="Config test option", validate_choice=False, ) error_option = SelectField( choices=( ("stop-on-error", "Stop on error"), ("continue-on-error", "Continue on error"), ("rollback-on-error", "Rollback on error"), ("None", "None"), ), label="Error option", validate_choice=False, ) lock = BooleanField(label="Lock target") unlock = BooleanField(label="Unlock target") copy_source = SelectField( choices=( ("running", "Running"), ("candidate", "Candidate"), ("startup", "Startup"), ("source_url", "Source URL"), ), label="Copy Source", validate_choice=False, ) source_url = StringField( label="Copy source URL", widget=TextArea(), render_kw={"rows": 1}, substitution=True, ) copy_destination = SelectField( choices=( ("running", "Running"), ("candidate", "Candidate"), ("startup", "Startup"), ("destination_url", "Destination URL"), ), label="Copy Destination", validate_choice=False, ) destination_url = StringField( label="Copy destination URL", widget=TextArea(), render_kw={"rows": 1}, substitution=True, ) commit_conf = BooleanField(label="Commit") timeout = IntegerField(default=15) xml_conversion = BooleanField(label="Convert XML result to dictionary", default=True) @classmethod def form_init(cls): parameters = { "get_config": ["target", "xml_conversion"], "get_filtered_config": [ "target", "xml_filter", "xml_conversion", ], "push_config": [ "target", "xml_filter", "default_operation", "test_option", "error_option", "lock", "unlock", "commit_conf", "xml_conversion", ], "copy_config": [ "copy_source", "source_url", "copy_destination", "destination_url", "commit_conf", "xml_conversion", ], "rpc": ["xml_filter", "xml_conversion"], } list_parameters = list(set(sum(parameters.values(), []))) cls.groups = { "NETCONF Parameters": { "commands": ["nc_type"] + list_parameters, "default": "expanded", }, **ConnectionForm.groups, } cls.input_data = HiddenField( "", default=dumps({ "fields": list_parameters, "netconf_type": parameters }), )
class DeviceDataForm(BaseForm): template = "device_data" form_type = HiddenField(default="device_data") data_type = SelectField("Display", choices=app.configuration_properties)
class RestartWorkflowForm(BaseForm): action = "eNMS.workflow.restartWorkflow" form_type = HiddenField(default="restart_workflow") start_services = MultipleInstanceField("Services", model="service") restart_runtime = SelectField("Restart Runtime", choices=(), validation=False)
class NetmikoForm(ConnectionForm): form_type = HiddenField(default="netmiko") abstract_service = True driver = SelectField(choices=app.NETMIKO_DRIVERS) use_device_driver = BooleanField(default=True) enable_mode = BooleanField( "Enable mode (run in enable mode or as root)", default=True ) config_mode = BooleanField("Config mode", default=False) fast_cli = BooleanField() timeout = FloatField(default=10.0) delay_factor = FloatField( ( "Delay Factor (Changing from default of 1" " will nullify Netmiko Timeout setting)" ), default=1.0, ) global_delay_factor = FloatField( ( "Global Delay Factor (Changing from default of 1" " will nullify Netmiko Timeout setting)" ), default=1.0, ) jump_on_connect = BooleanField( "Jump to remote device on connect", default=False, render_kw={"help": "netmiko/jump_on_connect"}, ) jump_command = StringField( label="Command that jumps to device", default="ssh jump_server_IP", substitution=True, render_kw={"help": "netmiko/jump_command"}, ) jump_username = StringField( label="Device username", substitution=True, render_kw={"help": "netmiko/jump_username"}, ) jump_password = PasswordField( label="Device password", substitution=True, render_kw={"help": "netmiko/jump_password"}, ) exit_command = StringField( label="Command to exit device back to original device", default="exit", substitution=True, render_kw={"help": "netmiko/exit_command"}, ) expect_username_prompt = StringField( "Expected username prompt", default="username:"******"help": "netmiko/expect_username_prompt"}, ) expect_password_prompt = StringField( "Expected password prompt", default="password", substitution=True, render_kw={"help": "netmiko/expect_password_prompt"}, ) expect_prompt = StringField( "Expected prompt after login", default="admin.*$", substitution=True, render_kw={"help": "netmiko/expect_prompt"}, ) groups = { "Netmiko Parameters": { "commands": [ "driver", "use_device_driver", "enable_mode", "config_mode", "fast_cli", "timeout", "delay_factor", "global_delay_factor", ], "default": "expanded", }, **ConnectionForm.groups, "Jump on connect Parameters": { "commands": [ "jump_on_connect", "jump_command", "expect_username_prompt", "jump_username", "expect_password_prompt", "jump_password", "expect_prompt", "exit_command", ], "default": "hidden", }, }
class ServiceForm(BaseForm): template = "service" form_type = HiddenField(default="service") id = HiddenField() name = StringField("Name") type = StringField("Service Type") shared = BooleanField("Shared Service") scoped_name = StringField("Scoped Name", [InputRequired()]) description = StringField("Description") device_query = StringField( "Device Query", python=True, widget=TextArea(), render_kw={"rows": 2} ) device_query_property = SelectField( "Query Property Type", choices=(("name", "Name"), ("ip_address", "IP address")) ) devices = MultipleInstanceField("Devices") disable_result_creation = BooleanField("Disable Result Creation") pools = MultipleInstanceField("Pools") update_pools = BooleanField("Update pools before running") workflows = MultipleInstanceField("Workflows") waiting_time = IntegerField( "Time to Wait before next service is started (in seconds)", default=0 ) send_notification = BooleanField("Send a notification") send_notification_method = SelectField( "Notification Method", choices=(("mail", "Mail"), ("slack", "Slack"), ("mattermost", "Mattermost")), ) notification_header = StringField(widget=TextArea(), render_kw={"rows": 5}) include_device_results = BooleanField("Include Device Results") include_link_in_summary = BooleanField("Include Result Link in Summary") display_only_failed_nodes = BooleanField("Display only Failed Devices") mail_recipient = StringField("Mail Recipients (separated by comma)") reply_to = StringField("Reply-to Email Address") number_of_retries = IntegerField("Number of retries", default=0) time_between_retries = IntegerField("Time between retries (in seconds)", default=10) max_number_of_retries = IntegerField("Maximum number of retries", default=100) maximum_runs = IntegerField("Maximum number of runs", default=1) skip = BooleanField("Skip") skip_query = StringField( "Skip Query (Python)", python=True, widget=TextArea(), render_kw={"rows": 2} ) skip_value = SelectField( "Skip Value", choices=(("True", "True"), ("False", "False")), ) vendor = StringField("Vendor") operating_system = StringField("Operating System") iteration_values = StringField("Iteration Values", python=True) initial_payload = DictField() iteration_variable_name = StringField( "Iteration Variable Name", default="iteration_value" ) iteration_devices = StringField("Iteration Devices", python=True) iteration_devices_property = SelectField( "Iteration Devices Property", choices=(("name", "Name"), ("ip_address", "IP address")), ) preprocessing = StringField(type="code", python=True, widget=TextArea()) postprocessing = StringField(type="code", python=True, widget=TextArea()) postprocessing_mode = SelectField( choices=( ("always", "Always run"), ("success", "Run on success only"), ("failure", "Run on failure only"), ) ) public = BooleanField("Public") log_level = SelectField( "Logging", choices=((0, "Disable logging"), *enumerate(app.log_levels, 1)), default=1, validation=False, ) multiprocessing = BooleanField("Multiprocessing") max_processes = IntegerField("Maximum number of processes", default=15) validation_condition = SelectField( choices=( ("success", "Run on success only"), ("failure", "Run on failure only"), ("always", "Always run"), ) ) conversion_method = SelectField( choices=( ("none", "No conversion"), ("text", "Text"), ("json", "Json dictionary"), ("xml", "XML dictionary"), ) ) validation_method = SelectField( "Validation Method", choices=( ("none", "No validation"), ("text", "Validation by text match"), ("dict_included", "Validation by dictionary inclusion"), ("dict_equal", "Validation by dictionary equality"), ), ) content_match = StringField( "Content Match", widget=TextArea(), render_kw={"rows": 8}, substitution=True ) content_match_regex = BooleanField("Match content with Regular Expression") dict_match = DictField("Dictionary to Match Against", substitution=True) negative_logic = BooleanField("Negative logic") delete_spaces_before_matching = BooleanField("Delete Spaces before Matching") run_method = SelectField( "Run Method", choices=( ("per_device", "Run the service once per device"), ("once", "Run the service once"), ), ) def validate(self): valid_form = super().validate() no_recipient_error = ( self.send_notification.data and self.send_notification_method.data == "mail" and not self.mail_recipient.data ) if no_recipient_error: self.mail_recipient.errors.append( "Please add at least one recipient for the mail notification." ) forbidden_name_error = self.scoped_name.data in ("Start", "End", "Placeholder") if forbidden_name_error: self.name.errors.append("This name is not allowed.") conversion_validation_mismatch = ( self.conversion_method.data == "text" and "dict" in self.validation_method.data or self.conversion_method.data in ("xml", "json") and "dict" not in self.validation_method.data ) if conversion_validation_mismatch: self.conversion_method.errors.append( f"The conversion method is set to '{self.conversion_method.data}'" f" and the validation method to '{self.validation_method.data}' :" " these do not match." ) return ( valid_form and not no_recipient_error and not conversion_validation_mismatch and not forbidden_name_error )
class ImportService(BaseForm): action = "eNMS.administration.importService" form_type = HiddenField(default="import_service") import_services = SelectField("Service", choices=())