示例#1
0
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)
    credentials = SelectField(
        "Credentials",
        choices=(
            ("device", "Device Credentials"),
            ("user", "User Credentials"),
            ("custom", "Custom Credentials"),
        ),
    )
    custom_username = StringField("Custom Username", substitution=True)
    custom_password = PasswordField("Custom Password", substitution=True)

    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
示例#2
0
class DeviceForm(ObjectForm):
    template = "object"
    form_type = HiddenField(default="device")
    id = HiddenField()
    icon = SelectField(
        "Icon",
        choices=(
            ("antenna", "Antenna"),
            ("firewall", "Firewall"),
            ("host", "Host"),
            ("optical_switch", "Optical switch"),
            ("regenerator", "Regenerator"),
            ("router", "Router"),
            ("server", "Server"),
            ("switch", "Switch"),
        ),
    )
    ip_address = StringField("IP address")
    port = IntegerField("Port", default=22)
    operating_system = StringField("Operating System")
    os_version = StringField("OS Version")
    longitude = StringField("Longitude", default=0.0)
    latitude = StringField("Latitude", default=0.0)
    username = StringField("Username")
    password = PasswordField("Password")
    enable_password = PasswordField("'Enable' Password")
    napalm_driver = SelectField("NAPALM Driver",
                                choices=app.NAPALM_DRIVERS,
                                default="ios")
    netmiko_driver = SelectField("Netmiko Driver",
                                 choices=app.NETMIKO_DRIVERS,
                                 default="cisco_ios")
    scrapli_driver = SelectField("Scrapli Driver",
                                 choices=choices(app.SCRAPLI_DRIVERS),
                                 default="cisco_iosxe")
示例#3
0
class TaskForm(BaseForm):
    action = "eNMS.base.processData"
    form_type = HiddenField(default="task")
    id = HiddenField()
    name = StringField("Name", [InputRequired()])
    default_access = SelectField(choices=(
        ("creator", "Creator only"),
        ("public", "Public (all users)"),
        ("admin", "Admin Users only"),
    ))
    scheduling_mode = SelectField(
        "Scheduling Mode",
        choices=(("cron", "Crontab Scheduling"), ("standard",
                                                  "Standard Scheduling")),
    )
    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")

    @classmethod
    def form_init(cls):
        cls.configure_relationships("devices", "pools", "service")

    def validate(self):
        valid_form = super().validate()
        if self.name.data == "Bulk Edit":
            return valid_form
        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])
示例#4
0
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 (Put Direction only)")
    max_transfer_size = IntegerField(default=2**30)
    window_size = IntegerField(default=2**30)
示例#5
0
 class UserForm(RbacForm):
     form_type = HiddenField(default="user")
     is_admin = BooleanField(default=False)
     authentication = SelectField(
         "Authentication Method",
         choices=[(method, values["display_name"]) for method, values in
                  settings["authentication"]["methods"].items()],
     )
     theme = SelectField(
         "Theme",
         choices=[(theme, values["name"])
                  for theme, values in themes["themes"].items()],
     )
     password = PasswordField("Password")
示例#6
0
class SRPolicyForm(NapalmForm):
    form_type = HiddenField(default="sr_policy_service")
    headend = SelectField(choices=(
        ("pe01", "pe01"),
        ("pe02", "pe02"),
        ("pe03", "pe03"),
        ("pe04", "pe04"),
        ("p11", "p11"),
        ("p12", "p12"),
    ),
                          default="pe01")
    endpoint = SelectField(choices=(
        ("pe01", "pe01"),
        ("pe02", "pe02"),
        ("pe03", "pe03"),
        ("pe04", "pe04"),
        ("p11", "p11"),
        ("p12", "p12"),
    ),
                           default="pe04")
    endpoint_ipv4 = StringField(
        "end-point ipv4",
        [
            IPAddress(
                ipv4=True,
                message=
                "Please enter an end-point ipv4 address for the endpoint_ipv4 field",
            )
        ],
    )
    color = IntegerField(validators=[NumberRange(min=1, max=4294967295)])
    description = StringField()

    path_name = StringField(validators=[InputRequired()])
    segment_list = FieldList(FormField(SegmentForm), min_entries=5)

    groups = {
        "Policy Details": {
            "commands":
            ["headend", "endpoint", "endpoint_ipv4", "color", "description"],
            "default":
            "expanded"
        },
        "Policy Path": {
            "commands": ["path_name", "segment_list"],
            "default": "expanded",
        },
        **NapalmForm.groups,
    }
示例#7
0
class NetmikoFileTransferForm(NetmikoForm):
    form_type = HiddenField(default="netmiko_file_transfer_service")
    source_file = StringField(validators=[InputRequired()], substitution=True)
    destination_file = StringField(validators=[InputRequired()],
                                   substitution=True)
    file_system = StringField()
    direction = SelectField(choices=(("put", "Upload"), ("get", "Download")))
    disable_md5 = BooleanField()
    inline_transfer = BooleanField()
    overwrite_file = BooleanField()
    groups = {
        "Main Parameters": {
            "commands": [
                "source_file",
                "destination_file",
                "file_system",
                "direction",
                "disable_md5",
                "inline_transfer",
                "overwrite_file",
            ],
            "default":
            "expanded",
        },
        **NetmikoForm.groups,
    }
示例#8
0
class ConnectionForm(ServiceForm):
    form_type = HiddenField(default="connection")
    abstract_service = True
    credentials = SelectField(
        "Credentials",
        choices=(
            ("device", "Device Credentials"),
            ("user", "User Credentials"),
            ("custom", "Custom Credentials"),
        ),
    )
    custom_username = StringField("Custom Username", substitution=True)
    custom_password = PasswordField("Custom Password", substitution=True)
    use_host_keys = BooleanField("Use Host Keys - Requires: 'Custom Credentials' with 'Custom Username'")
    start_new_connection = BooleanField("Start New Connection")
    close_connection = BooleanField("Close Connection")
    groups = {
        "Connection Parameters": {
            "commands": [
                "credentials",
                "custom_username",
                "custom_password",
                "use_host_keys",
                "start_new_connection",
                "close_connection",
            ],
            "default": "expanded",
        }
    }
示例#9
0
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)
示例#10
0
def filtering_form_generator():
    for form_type in models:
        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,
                **{
                    f"{relation}_filter": SelectField(choices=(
                        ("any", "Any"),
                        ("all", "All"),
                        ("not_any", "Unrelated"),
                        ("none", "None"),
                    ))
                    for relation in 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)
示例#11
0
class DeviceDataForm(BaseForm):
    template = "device_data"
    form_type = HiddenField(default="device_data")
    data_type = SelectField(
        "Display",
        choices=(("configuration", "Configuration"), ("data",
                                                      "Operational Data")),
    )
示例#12
0
class PingForm(ServiceForm):
    form_type = HiddenField(default="ping_service")
    protocol = SelectField(choices=(("ICMP", "ICMP Ping"), ("TCP", "TCP Ping")))
    ports = StringField()
    count = IntegerField(default=5)
    timeout = IntegerField(default=2)
    ttl = IntegerField(default=60)
    packet_size = IntegerField(default=56)
示例#13
0
class SegmentForm(FlaskForm):
    segment_type = SelectField("Next Node Type",
                               choices=(
                                   ("address ipv4", "Specify hop address"),
                                   ("mpls label", "MPLS configuration"),
                               ),
                               default="address")
    value = StringField()
示例#14
0
class WorkflowLabelForm(BaseForm):
    form_type = HiddenField(default="workflow_label")
    action = "eNMS.workflow.createLabel"
    text = StringField(widget=TextArea(), render_kw={"rows": 15})
    alignment = SelectField(
        "Text Alignment",
        choices=(("left", "Left"), ("center", "Center"), ("right", "Right")),
    )
示例#15
0
 class UserForm(RbacForm):
     form_type = HiddenField(default="user")
     manual_rbac = BooleanField("Manually defined RBAC")
     theme = SelectField(
         "Theme",
         choices=[(theme, values["name"])
                  for theme, values in themes["themes"].items()],
     )
     password = PasswordField("Password")
示例#16
0
class UserForm(BaseForm):
    template = "object"
    form_type = HiddenField(default="user")
    id = HiddenField()
    name = StringField("Name", [InputRequired()])
    password = PasswordField("Password")
    email = StringField("Email")
    group = SelectField("Permissions",
                        choices=[(g, g) for g in app.rbac["groups"]])
示例#17
0
class VlanConfigurationForm(NapalmForm):
    form_type = HiddenField(default="vlan_configuration_service")
    action = SelectField(
        choices=(
            ("load_merge_candidate", "Load merge"),
            ("load_replace_candidate", "Load replace"),
        )
    )
    interface_name = StringField(validators=[InputRequired()])
    vlan_id = IntegerField(validators=[NumberRange(min=10, max=4000)])
    description = StringField()
    vrf = StringField()
    qos = StringField()
    ipv4s = FieldList(FormField(Ipv4Form), min_entries=5)
    ipv6s = FieldList(FormField(Ipv6Form), min_entries=5)
    shutdown = SelectField(
        choices=(
            ("yes", "yes"),
            ("no", "no"),
        ),
        default="no"
    )
    groups = {
        "Main Parameters": {
            "commands": [
                "action",
                "interface_name",
                "vlan_id",
                "description",
                "vrf",
                "qos",
                "shutdown"
            ], "default": "expanded"
        },
        "IPv4 address Parameters": {
            "commands": ["ipv4s"],
            "default": "expanded",
        },
        "IPv6 address Parameters": {
            "commands": ["ipv6s"],
            "default": "expanded",
        },
        **NapalmForm.groups,
    }
示例#18
0
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)
    pass_device_properties = BooleanField(
        "Pass Device Inventory Properties (to be used "
        "in the playbook as {{name}} or {{ip_address}})")
    options = DictField("Options (passed to ansible as -e extra args)",
                        substitution=True)
示例#19
0
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")
示例#20
0
class AddServiceForm(BaseForm):
    form_type = HiddenField(default="add_services")
    template = "add_services"
    mode = SelectField(
        "Mode",
        choices=(
            ("deep", "Deep Copy (creates a duplicate from the service)"),
            ("shallow", "Shallow Copy (creates a reference to the service)"),
        ),
    )
    search = StringField()
示例#21
0
class Form(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")
    neighbor = InstanceField("Devices", model="device")
    ports = MultipleInstanceField("Port", model="port")
    password = PasswordField("Password")
    carry_customer_traffic = BooleanField("Carry Customer Traffic",
                                          default=False)
示例#22
0
class ScrapliForm(ConnectionForm):
    form_type = HiddenField(default="scrapli_service")
    commands = StringField(substitution=True, widget=TextArea(), render_kw={"rows": 5})
    is_configuration = BooleanField()
    driver = SelectField(choices=choices(app.SCRAPLI_DRIVERS))
    transport = SelectField(choices=choices(("system", "paramiko", "ssh2")))
    use_device_driver = BooleanField(default=True)
    groups = {
        "Main Parameters": {
            "commands": [
                "commands",
                "is_configuration",
                "driver",
                "transport",
                "use_device_driver",
            ],
            "default": "expanded",
        },
        **ConnectionForm.groups,
    }
示例#23
0
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])
示例#24
0
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})
示例#25
0
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,
    }
示例#26
0
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,
    }
示例#27
0
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})
示例#28
0
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})
示例#29
0
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()
示例#30
0
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,
    }