diff --git a/app/defaults.py b/app/defaults.py index b140097add5b1995c9ac64b72f31344faf16464d..d4ebf2b8f7637dd9423c62e4e518fb5fb332d451 100644 --- a/app/defaults.py +++ b/app/defaults.py @@ -23,7 +23,10 @@ defaults = [ models.DeviceType(name="PhysicalMachine"), models.DeviceType(name="VirtualMachine"), models.DeviceType(name="Network"), - models.DeviceType(name="MicroTCA"), + models.DeviceType(name="MTCA-AMC"), + models.DeviceType(name="MTCA-IOxOS"), + models.DeviceType(name="MTCA-MCH"), + models.DeviceType(name="MTCA-RTM"), models.DeviceType(name="VME"), models.DeviceType(name="PLC"), ] diff --git a/app/models.py b/app/models.py index 5c6d5c33aebf6bbf555d33fd74203da38ed300ef..86685dc132dae2b42606e4190c0da9661e60c60c 100644 --- a/app/models.py +++ b/app/models.py @@ -300,14 +300,17 @@ class User(db.Model, UserMixin): def can_set_boot_profile(self, host): """Return True if the user can set the network boot profile - - host.device_type shall be PhysicalMachine + - host.device_type shall be in ALLOWED_SET_BOOT_PROFILE_DEVICE_TYPES - admin users can always set the profile - normal users must have access to the network - normal users can only set the boot profile if the host is in one of the allowed network scopes - LOGIN_DISABLED can be set to True to turn off authentication check when testing. In this case, this function always returns True. """ - if str(host.device_type) != "PhysicalMachine": + if ( + str(host.device_type) + not in current_app.config["ALLOWED_SET_BOOT_PROFILE_DEVICE_TYPES"] + ): return False if current_app.config.get("LOGIN_DISABLED") or self.is_admin: return True diff --git a/app/network/views.py b/app/network/views.py index 4af004ecacaf0e6581b12bd4d040f51a226611fb..951af4dfc42732b49f3f57c1eb7e9442dbc5f6fd 100644 --- a/app/network/views.py +++ b/app/network/views.py @@ -161,7 +161,10 @@ def view_host(name): f" Please rename it '{host.name}'.", "warning", ) - if host.device_type.name == "PhysicalMachine": + if ( + host.device_type.name + in current_app.config["ALLOWED_SET_BOOT_PROFILE_DEVICE_TYPES"] + ): form = BootProfileForm() elif host.device_type.name.startswith("Virtual"): form = CreateVMForm() @@ -174,7 +177,10 @@ def view_host(name): else: form = None if form is not None and form.validate_on_submit(): - if host.device_type.name == "PhysicalMachine": + if ( + host.device_type.name + in current_app.config["ALLOWED_SET_BOOT_PROFILE_DEVICE_TYPES"] + ): if not current_user.can_set_boot_profile(host): flash( f"You don't have the proper permissions to set the boot profile. Please contact an admin user.", diff --git a/app/settings.py b/app/settings.py index 1ea283206d5aced61d7cdfc6c3f8605f50932bbe..2c193bdf040f5e8719c998f4f2c94d739e221841 100644 --- a/app/settings.py +++ b/app/settings.py @@ -85,6 +85,8 @@ CSENTRY_NETWORK_SCOPES_LDAP_GROUPS = { ALLOWED_VM_CREATION_NETWORK_SCOPES = ["LabNetworks"] # List of network scopes where users can set the boot profile for physical machines ALLOWED_SET_BOOT_PROFILE_NETWORK_SCOPES = ["LabNetworks"] +# List of device types for which the boot profile can be set +ALLOWED_SET_BOOT_PROFILE_DEVICE_TYPES = ["PhysicalMachine", "MTCA-AMC"] # List of existing boot profiles # Shall be kept in sync with the ics-ans-role-autoinstall Ansible role AUTOINSTALL_BOOT_PROFILES = ["localboot", "default", "cct", "LCR", "thinclient"] diff --git a/app/templates/network/view_host.html b/app/templates/network/view_host.html index 5032f434ea65b64c4d0608856c4b48322e26b243..d2f271277841b13baa737a947908d9a2e6865e23 100644 --- a/app/templates/network/view_host.html +++ b/app/templates/network/view_host.html @@ -83,7 +83,7 @@ {{ submit_button_with_confirmation('Create ' + vm_type, 'Do you really want to create the ' + vm_type + ' ' + host.name + '?') }} </form> </div> - {% elif host.device_type.name == 'PhysicalMachine' %} + {% elif host.device_type.name in config.ALLOWED_SET_BOOT_PROFILE_DEVICE_TYPES %} <div class="col-sm-4"> <form id="BootProfileForm" method="POST"> {{ form.hidden_tag() }} diff --git a/app/validators.py b/app/validators.py index afdba7fee538b0c9ea22d4723d8acef1946454dc..aad28d9a14859a57ddd91e784565109cdaa8af25 100644 --- a/app/validators.py +++ b/app/validators.py @@ -19,7 +19,7 @@ HOST_NAME_RE = re.compile(r"^[a-z0-9\-]{2,20}$") INTERFACE_NAME_RE = re.compile(r"^[a-z0-9\-]{2,25}$") VLAN_NAME_RE = re.compile(r"^[A-Za-z0-9\-]{3,25}$") MAC_ADDRESS_RE = re.compile(r"^(?:[0-9a-fA-F]{2}[:-]?){5}[0-9a-fA-F]{2}$") -DEVICE_TYPE_RE = re.compile(r"^[A-Za-z0-9]{3,25}$") +DEVICE_TYPE_RE = re.compile(r"^[A-Za-z0-9\-]{3,25}$") class NoValidateSelectField(SelectField): diff --git a/docs/network.rst b/docs/network.rst index a8fe8811a8bfb8b3bcf35210850bc34848f9d1ae..6f7f0dcf18e2fb649d94ad25ae3407a639589c2c 100644 --- a/docs/network.rst +++ b/docs/network.rst @@ -186,7 +186,7 @@ Please contact an admin user if you don't have the proper permissions. Physical Machine installation ----------------------------- -From the *View host* page, you can set the boot profile of a Physical Machine. This can be used to perform a network installation: +From the *View host* page, you can set the boot profile of a Physical Machine or MTCA-AMC. This can be used to perform a network installation: .. image:: _static/network/set_boot_profile.png diff --git a/migrations/versions/91b0093a5e13_rename_microtca_to_mtca_amc.py b/migrations/versions/91b0093a5e13_rename_microtca_to_mtca_amc.py new file mode 100644 index 0000000000000000000000000000000000000000..91e702cf3bfa7d439707eb39ab9f457fd347fc4f --- /dev/null +++ b/migrations/versions/91b0093a5e13_rename_microtca_to_mtca_amc.py @@ -0,0 +1,38 @@ +"""Rename MicroTCA to MTCA-AMC + +Revision ID: 91b0093a5e13 +Revises: b1eda5cb7d9d +Create Date: 2020-03-05 12:55:35.804867 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = "91b0093a5e13" +down_revision = "b1eda5cb7d9d" +branch_labels = None +depends_on = None + + +def upgrade(): + device_type = sa.sql.table( + "device_type", sa.sql.column("id"), sa.sql.column("name") + ) + op.execute( + device_type.update() + .where(device_type.c.name == "MicroTCA") + .values(name="MTCA-AMC") + ) + + +def downgrade(): + device_type = sa.sql.table( + "device_type", sa.sql.column("id"), sa.sql.column("name") + ) + op.execute( + device_type.update() + .where(device_type.c.name == "MTCA-AMC") + .values(name="MicroTCA") + )