class ChangeMACForm(Form): password = PasswordField( validators=[Required(gettext(u"Passwort nicht angegeben!"))]) mac = TextField(validators=[ Required(u"MAC-Adresse nicht angegeben!"), MacAddress(u"MAC ist nicht in gültigem Format!") ])
class DeviceForm(FlaskForm): '''manage.DeviceForm(FlaskForm)''' alias = StringField('设备名', validators=[InputRequired()]) serial = StringField('序列号', validators=[InputRequired()]) device_type = SelectField('设备类型', coerce=str, validators=[InputRequired()]) room = SelectField('所属场地', coerce=str, validators=[InputRequired()]) mac_address = StringField('MAC地址', validators=[Optional(), MacAddress()]) lesson_types = SelectMultipleField('授权课程类型', coerce=str) development_machine = BooleanField('开发用机器') submit = SubmitField('提交') def __init__(self, is_developer, *args, **kwargs): super(DeviceForm, self).__init__(*args, **kwargs) if is_developer: self.device_type.choices = [('', '选择设备类型')] + \ [(str(device_type.id), device_type.name) \ for device_type in DeviceType.query.order_by(DeviceType.id.asc()).all()] else: self.device_type.choices = [('', '选择设备类型')] + \ [(str(device_type.id), device_type.name) for device_type in DeviceType.query\ .filter(DeviceType.name != 'Server')\ .order_by(DeviceType.id.asc())\ .all()] self.room.choices = [('', '选择所属场地')] + [('0', '无')] + \ [(str(room.id), room.name) for room in Room.query.order_by(Room.id.asc()).all()] self.lesson_types.choices = [('', '选择授权课程类型')] + \ [(str(lesson_type.id), lesson_type.name) for lesson_type in LessonType.query.all()]
class ChangeMACForm(FlaskForm): password = PasswordField( label=lazy_gettext("Passwort"), validators=[DataRequired(lazy_gettext("Passwort nicht angegeben!"))]) mac = StrippedStringField( label=lazy_gettext("Neue MAC"), validators=[DataRequired("MAC-Adresse nicht angegeben!"), MacAddress("MAC ist nicht in gültigem Format!"), require_unicast_mac])
class NewAlertForm(Form): title = StringField('Title', validators=[DataRequired()]) atype = StringField('Type', validators=[DataRequired()]) ip = StringField('IP Address', validators=[Optional(), IPAddress("Bad IP Address")]) mac = StringField('MAC Address', validators=[Optional(), MacAddress("Bad Mac Address")]) comments = TextAreaField('Comments')
class UpdateAlertForm(Form): status = SelectField('Status', choices=app.config['ASTATUS_CHOICES']) atype = StringField('Type') ip = StringField('IP Address', validators=[Optional(), IPAddress("Bad IP Address")]) mac = StringField('MAC Address', validators=[Optional(), MacAddress("Bad Mac Address")]) comments = TextAreaField('Comments')
class InterfaceForm(Form): identifier = StringField("Interface identifier", [Optional()]) mac = StringField("MAC", [ InputRequired(), MacAddress(message='Must provide a valid MAC address') ]) dhcpv4 = BooleanField("DHCP v4", false_values=('false', '', '0'), default=True) reserved_ipv4 = NullableStringField( "Reserved IPv4", [Optional(), IPAddress(ipv4=True)])
class EqptCreateForm(FlaskForm): model_id = SelectField(u'Модель', coerce=int) name = StringField('Имя узла', default='Узел 1', validators=[ Length(min=2, max=50), ]) ipv4 = StringField( 'IP адрес узла', default='0.0.0.0', validators=[ IPAddress(ipv4=True, ipv6=False, message='Неверный IP адрес'), ], ) def validate_ipv4(form, field): if field.data == "0.0.0.0": raise ValidationError('Неверный IP адрес') serial = StringField('Серийный номер', default='1234', validators=[ Length(min=5, max=50), ]) mac = StringField( 'MAC адресс', default='00:00:00:00:00:00', validators=[ MacAddress(message='Неверный MAC адрес'), ], ) def validate_mac(form, field): if field.data == "00:00:00:00:00:00": raise ValidationError('Неверный MAC адрес') network_id = SelectField(u'IP сеть', coerce=int) cvlan = IntegerField(u'Клиентский vlan', default=1, validators=[ NumberRange( min=1, max=3999, message=u'Vlan в не диапазона (1-4000)') ]) submit = SubmitField('Сохранить')
class RegistrationForm(Form): firstname = StringField('firstname', validators=[DataRequired()]) lastname = StringField('lastname', validators=[DataRequired()]) nickname = StringField('nickname', validators=[DataRequired()]) robot_mac = StringField('robot_mac', validators=[DataRequired(), MacAddress()]) robot_name = StringField('robot_name', validators=[DataRequired()]) password = PasswordField('new_password', validators=[ DataRequired(), EqualTo('confirm', message='Password must match') ]) confirm = PasswordField('repeat_password') def __init__(self, *args, **kwargs): Form.__init__(self, *args, **kwargs) def validate(self): if not Form.validate(self): return False errorcheck = False onepass = False while not onepass and not errorcheck: user = User.query.filter_by(nickname=self.nickname.data).first() if user != None: self.nickname.errors.append( 'This nickname is already in use. Please choose another one.' ) errorcheck = True robot = Robot.query.filter_by(alias=self.robot_name.data).first() if robot != None: self.robot_name.errors.append( 'This robot name is already in use. Please choose another one.' ) errorcheck = True mac = Robot.query.filter_by(macid=self.robot_mac.data).first() if mac != None: self.robot_mac.errors.append( 'This robot already has an owner.') errorcheck = True onepass = True if errorcheck: return False return True
class GenericFormTemplate(GatewayForm): # When updating the form, remember to make the corresponding changes to the workflow pages workflow_name = 'register_mac_address' workflow_permission = 'register_mac_address_page' text = get_resource_text() require_message = text['require_message'] mac_address = CustomStringField( label=text['label_mac_address'], default='FF:FF:FF:FF:FF:FF', is_disabled_on_start=False, validators=[DataRequired(message=require_message), MacAddress()]) device_group = CustomSelectField(label=text['label_device_group'], coerce=int, is_disabled_on_start=False, validators=[]) asset_code = CustomStringField( label=text['label_asset_code'], is_disabled_on_start=False, validators=[DataRequired(message=require_message)]) employee_code = CustomStringField( label=text['label_employee_code'], is_disabled_on_start=False, validators=[DataRequired(message=require_message)]) location = CustomSelectField(label=text['label_location'], coerce=int, is_disabled_on_start=False) submit_date = DateTimeField(label=text['label_submit_date'], default=datetime.datetime.now(), format='%Y/%m/%d') expiry_date = DateTimeField(label=text['label_expiry_date'], default=datetime.datetime.now() + datetime.timedelta(days=365), format='%Y/%m/%d') submit = CustomSubmitField(label=text['label_submit'], is_disabled_on_start=False)
class ClientForm(Form): def hostname_validation(form, field): if "." in field.data or len(field.data) > 63: raise ValidationError( 'Hostname must be under 63 chars long and can not contain a dot.' ) def pi_validation(form, field): if not field.data.lower().startswith("b8:27:eb"): raise ValidationError( 'Invalid client MAC address. All Raspberry Pi MAC addresses start with B8:27:EB' ) mac_address = StringField( "MAC Address", validators=[DataRequired(), MacAddress(), pi_validation]) hostname = StringField("Machine hostname", validators=[DataRequired()]) location = StringField("Machine location", validators=[DataRequired()])
class CreateMachineForm(Form): name = StringField("Name", [InputRequired(), Length(min=3, max=256)]) macs = FieldList(StringField("MAC address", [Optional(), MacAddress(message='Must provide a valid MAC address')]), min_entries=0, max_entries=64) bmc_id = SelectField("BMC", coerce=opt_int, validators=[Optional()]) bmc_info = StringField("BMC info", [Optional()]) pdu = StringField("PDU", [Length(max=256)]) pdu_port = OptionalIntegerField("PDU port", [Optional(), NumberRange(max=256)]) serial = StringField("Serial Console", [Length(max=256)]) serial_port = OptionalIntegerField("Serial port", [Optional(), NumberRange(max=256)]) @staticmethod def populate_choices(form, g): bmcs = BMC.query.all() if g.user.admin else [] form.bmc_id.choices = [("", "(None)")] + \ [(bmc.id, "%s - %s - %s" % (bmc.name, bmc.ip, bmc.bmc_type)) for bmc in bmcs]
class DeviceForm(BaseForm): template_id = SelectField(l_('Template'), validators=[InputRequired()], choices=[]) ip = StringField(l_('IP'), validators=[IPAddress()]) mac = StringField(l_('MAC'), validators=[MacAddress()]) model = StringField(l_('Model')) plugin = SelectField(l_('Plugin'), validators=[InputRequired()], choices=[]) vendor = StringField(l_('Vendor')) version = StringField(l_('Version')) status = SelectField(l_('Status'), choices=[ ('autoprov', l_('Autoprov')), ('configured', l_('Configured')), ('not_configured', l_('Not configured')), ]) options = FormField(DeviceOptionsForm) description = StringField(l_('Description')) submit = SubmitField()
class GenericFormTemplate(GatewayForm): workflow_name = 'lease_history_mac' workflow_permission = 'lease_history_mac_page' text = get_resource_text() mac_address = CustomStringField( label=text['label_mac_address'], default='FF:FF:FF:FF:FF:FF', validators=[DataRequired(message=text['require_message']), MacAddress()], required=True, is_disabled_on_start=False ) query_history = CustomSearchButtonField( workflow_name=workflow_name, permissions=workflow_permission, label=text['label_query'], default='Search Objects', inputs={'mac_address': 'mac_address'}, server_side_method=query_history_by_mac_endpoint, display_message=True, on_complete=['call_output_table'], is_disabled_on_start=False ) output_table = TableField( workflow_name=workflow_name, permissions=workflow_permission, label='', data_function=raw_table_data, table_features={ 'searching': False, 'ordering': False, 'info': False, 'lengthChange': False }, is_disabled_on_start=False )
class GenericFormTemplate(GatewayForm): """ Generic form Template Note: When updating the form, remember to make the corresponding changes to the workflow pages """ workflow_name = 'add_mac_address' workflow_permission = 'add_mac_address_page' configuration = Configuration( workflow_name=workflow_name, permissions=workflow_permission, label='Configuration', required=True, coerce=int, is_disabled_on_start=False, ) mac_address = CustomStringField(label='MAC Address', is_disabled_on_start=False, validators=[MacAddress()], required=True) mac_address_name = CustomStringField(label='MAC Address Name', is_disabled_on_start=False, required=True) mac_pool_boolean = CustomBooleanField(label='Add to MAC Pool', is_disabled_on_start=False) mac_pool = MACPool(workflow_name=workflow_name, permissions=workflow_permission, label='MAC Pool', is_disabled_on_start=False) submit = CustomSubmitField(label='Submit', is_disabled_on_start=False)
class ChangeMachineForm(Form): name = StringField("Name", [Optional(), Length(min=3, max=256)]) mac = StringField( "MAC address", [Optional(), MacAddress(message='Must provide a valid MAC address')]) bmc_id = OptionalIntegerField("BMC", [Optional()]) bmc_info = StringField("BMC info", [Optional()]) pdu = StringField("PDU", [Length(max=256)]) pdu_port = OptionalIntegerField( "PDU port", [Optional(), NumberRange(max=256)]) serial = StringField("Serial Console", [Length(max=256)]) serial_port = OptionalIntegerField( "Serial port", [Optional(), NumberRange(max=256)]) kernel_id = OptionalIntegerField( "Kernel", [Optional(), ValidImage(image_type="Kernel")]) kernel_opts = StringField("Kernel opts", [Length(max=256)]) initrd_id = OptionalIntegerField( "Initrd", [Optional(), ValidImage(image_type="Initrd")]) preseed_id = OptionalIntegerField("Preseed", [Optional()]) netboot_enabled = BooleanField("Is netboot enabled?", [InputRequired()], false_values=('false', '', '0')) reason = StringField("Reason for Assignment", [Length(max=256)]) assignee = OptionalIntegerField("Assignee", [Optional()])
class GenericFormTemplate(GatewayForm): """ Generic form Template Note: When updating the form, remember to make the corresponding changes to the workflow pages """ workflow_name = 'unit_tests_example' workflow_permission = 'unit_tests_example_page' configuration = Configuration( workflow_name=workflow_name, permissions=workflow_permission, label='Configuration', required=True, coerce=int, validators=[], is_disabled_on_start=False, on_complete=[], enable_on_complete=['email', 'password', 'ip_address'], clear_below_on_change=False) email = CustomStringField(label='Email', default='*****@*****.**', validators=[DataRequired(), Email()]) password = PasswordField(label='Password', default='abc', validators=[DataRequired()]) ip_address = IP4Address(workflow_name=workflow_name, permissions=workflow_permission, label='IP Address', required=True, inputs={ 'configuration': 'configuration', 'address': 'ip_address' }, result_decorator=None, enable_on_complete=[ 'mac_address', 'url', 'file', 'boolean_checked', 'boolean_unchecked', 'date_time', 'submit' ]) mac_address = CustomStringField(label='MAC Address', default='11:11:11:11:11:11', validators=[MacAddress()]) url = StringField(label='URL', default='http://www.example.com', validators=[URL()]) file = FileField(label='File') boolean_checked = BooleanField(label='Use for true or false things', default='checked') boolean_unchecked = BooleanField(label='default for field is unchecked') date_time = DateTimeField(label='Date and Time:', default=datetime.datetime.now(), format='%Y-%m-%d %H:%M:%S') submit = SubmitField(label='Submit')
class PhoneForm(FlaskForm): name = StringField("Name", validators=[DataRequired()]) mac_address = StringField("MAC Address", validators=[DataRequired(), MacAddress()]) note = StringField("Note") submit = SubmitField("Submit")
class makeNewMachine(FlaskForm): MachineName = StringField('Name', description="test", validators=[DataRequired(), Length(min=2,max=100)]) MachineMacAddress = StringField('Mac Address', validators=[DataRequired("This field is reqired and must be a valid MAC Address"), MacAddress()]) academicAmount = DecimalField('Academic Rate', validators=[DataRequired("This field is reqired and must be a number"), NumberRange(min=0, max=10000000)]) industrialAmount = DecimalField('Industrial Rate', validators=[DataRequired("This field is reqired and must be a number"), NumberRange(min=0, max=10000000)]) submit = SubmitField("Submit")
class AddDeviceForm(Form): name = TextField('Name', validators=[Required()]) mac = TextField('MAC', validators=[Required(), MacAddress()]) ip = TextField('IP', validators=[Required(), IPAddress()]) submit_button = SubmitField('Add')
class ExampleForm(ServiceForm): # Each service model must have an corresponding form. # The purpose of a form is twofold: # - Define how the service is displayed in the UI # - Check for each field that the user input is valid. # A service cannot be created/updated until all fields are validated. # The following line is mandatory: the default value must point # to the service. form_type = HiddenField(default="ExampleService") # string1 is defined as a "SelectField": it will be displayed as a # drop-down list in the UI. string1 = SelectField(choices=[("cisco", "Cisco"), ("juniper", "Juniper"), ("arista", "Arista")]) # String2 is a StringField, which is displayed as a standard textbox. # The "InputRequired" validator is used: this field is mandatory. string2 = StringField("String 2 (required)", [InputRequired()]) # The main address field uses two validators: # - The input length must be comprised between 7 and 25 characters # - The input syntax must match that of an email address. mail_address = StringField( "Mail address", [Length(min=7, max=25), Email()]) # This IP address validator will ensure the user input is a valid IPv4 address. # If it isn't, you can set the error message to be displayed in the GUI. ip_address = StringField( "IP address", [ IPAddress( ipv4=True, message="Please enter an IPv4 address for the IP address field", ) ], ) # MAC address validator mac_address = StringField("MAC address", [MacAddress()]) # The NumberRange validator will ensure the user input is an integer # between 3 and 8. number_in_range = IntegerField("Number in range", [NumberRange(min=3, max=8)]) # The Regexp field will ensure the user input matches the regular expression. regex = StringField("Regular expression", [Regexp(r".*")]) # URL validation, with or without TLD. url = StringField( "URL", [ URL( require_tld=True, message="An URL with TLD is required for the url field", ) ], ) # The NoneOf validator lets you define forbidden value for a field. exclusion_field = StringField( "Exclusion field", [ NoneOf( ("a", "b", "c"), message=("'a', 'b', and 'c' are not valid " "inputs for the exclusion field"), ) ], ) an_integer = IntegerField() a_float = FloatField() # If validator the user input is more complex, you can create a python function # to implement the validation mechanism. # Here, the custom_integer field will be validated by the "validate_custom_integer" # function below. # That function will check that the custom integer value is superior to the product # of "an_integer" and "a_float". # You must raise a "ValidationError" when the validation fails. custom_integer = IntegerField("Custom Integer") # A SelectMultipleField will be displayed as a drop-down list that allows # multiple selection. a_list = SelectMultipleField( choices=[("value1", "Value 1"), ("value2", "Value 2"), ("value3", "Value 3")]) a_dict = DictField() # A BooleanField is displayed as a check box. boolean1 = BooleanField() boolean2 = BooleanField("Boolean N°1") def validate_custom_integer(self, field: IntegerField) -> None: product = self.an_integer.data * self.a_float.data if field.data > product: raise ValidationError("Custom integer must be less than the " "product of 'An integer' and 'A float'")
class SearchByMacForm(Form): server_mac = StringField( u'Server MAC address', validators=[MacAddress(message="Must use a valid MAC address.")]) submit = SubmitField(u'Get iPXE script')
class GenericFormTemplate(GatewayForm): """ Generic form Template Note: When updating the form, remember to make the corresponding changes to the workflow pages """ workflow_name = 'create_server_vro' workflow_permission = 'create_server_vro_page' configuration = Configuration( workflow_name=workflow_name, permissions=workflow_permission, label='Configuration', required=True, coerce=int, clear_below_on_change=False, is_disabled_on_start=False, on_complete=['call_view'], enable_dependencies={'on_complete': ['view']}, disable_dependencies={'on_change': ['view']}, clear_dependencies={'on_change': ['view']} ) view = View( workflow_name=workflow_name, permissions=workflow_permission, label='View', required=True, one_off=True, on_complete=['call_zone'], clear_below_on_change=False, enable_dependencies={'on_complete': ['zone']}, disable_dependencies={'on_change': ['zone']}, clear_dependencies={'on_change': ['zone']}, should_cascade_disable_on_change=True, should_cascade_clear_on_change=True ) zone = Zone( workflow_name=workflow_name, permissions=workflow_permission, label='Zone', required=True, clear_below_on_change=False, enable_dependencies={'on_complete': ['ip4_network']}, disable_dependencies={'on_change': ['ip4_network']}, clear_dependencies={'on_change': ['ip4_network']}, should_cascade_disable_on_change=True, should_cascade_clear_on_change=True ) ip4_network = IP4Network( workflow_name=workflow_name, permissions=workflow_permission, label='Network', required=True, one_off=False, enable_dependencies={'on_complete': ['mac_address', 'hostname', 'submit']}, disable_dependencies={'on_change': ['mac_address', 'hostname', 'submit']}, clear_dependencies={'on_change': ['mac_address', 'hostname', 'submit']}, is_disabled_on_start=False ) mac_address = CustomStringField( label='MAC Address', required=True, validators=[MacAddress()] ) hostname = CustomStringField( label='Hostname', required=True ) submit = SubmitField(label='Submit')
class MacAdressValidationForm(Form): addr = StringField(validators=[DataRequired(), MacAddress()])