Skip to content
Snippets Groups Projects
Commit 33acf3c7 authored by Benjamin Bertrand's avatar Benjamin Bertrand
Browse files

Introduced new device types for MTCA

- Allow to use "-" in device type name
- Add ALLOWED_SET_BOOT_PROFILE_DEVICE_TYPES variable
- Rename MicroTCA to MTCA-AMC

JIRA INFRA-1835 #action In Progress
parent f05136f6
No related branches found
No related tags found
No related merge requests found
...@@ -23,7 +23,10 @@ defaults = [ ...@@ -23,7 +23,10 @@ defaults = [
models.DeviceType(name="PhysicalMachine"), models.DeviceType(name="PhysicalMachine"),
models.DeviceType(name="VirtualMachine"), models.DeviceType(name="VirtualMachine"),
models.DeviceType(name="Network"), 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="VME"),
models.DeviceType(name="PLC"), models.DeviceType(name="PLC"),
] ]
...@@ -300,14 +300,17 @@ class User(db.Model, UserMixin): ...@@ -300,14 +300,17 @@ class User(db.Model, UserMixin):
def can_set_boot_profile(self, host): def can_set_boot_profile(self, host):
"""Return True if the user can set the network boot profile """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 - admin users can always set the profile
- normal users must have access to the network - 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 - 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. - LOGIN_DISABLED can be set to True to turn off authentication check when testing.
In this case, this function always returns True. 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 return False
if current_app.config.get("LOGIN_DISABLED") or self.is_admin: if current_app.config.get("LOGIN_DISABLED") or self.is_admin:
return True return True
......
...@@ -161,7 +161,10 @@ def view_host(name): ...@@ -161,7 +161,10 @@ def view_host(name):
f" Please rename it '{host.name}'.", f" Please rename it '{host.name}'.",
"warning", "warning",
) )
if host.device_type.name == "PhysicalMachine": if (
host.device_type.name
in current_app.config["ALLOWED_SET_BOOT_PROFILE_DEVICE_TYPES"]
):
form = BootProfileForm() form = BootProfileForm()
elif host.device_type.name.startswith("Virtual"): elif host.device_type.name.startswith("Virtual"):
form = CreateVMForm() form = CreateVMForm()
...@@ -174,7 +177,10 @@ def view_host(name): ...@@ -174,7 +177,10 @@ def view_host(name):
else: else:
form = None form = None
if form is not None and form.validate_on_submit(): 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): if not current_user.can_set_boot_profile(host):
flash( flash(
f"You don't have the proper permissions to set the boot profile. Please contact an admin user.", f"You don't have the proper permissions to set the boot profile. Please contact an admin user.",
......
...@@ -85,6 +85,8 @@ CSENTRY_NETWORK_SCOPES_LDAP_GROUPS = { ...@@ -85,6 +85,8 @@ CSENTRY_NETWORK_SCOPES_LDAP_GROUPS = {
ALLOWED_VM_CREATION_NETWORK_SCOPES = ["LabNetworks"] ALLOWED_VM_CREATION_NETWORK_SCOPES = ["LabNetworks"]
# List of network scopes where users can set the boot profile for physical machines # List of network scopes where users can set the boot profile for physical machines
ALLOWED_SET_BOOT_PROFILE_NETWORK_SCOPES = ["LabNetworks"] 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 # List of existing boot profiles
# Shall be kept in sync with the ics-ans-role-autoinstall Ansible role # Shall be kept in sync with the ics-ans-role-autoinstall Ansible role
AUTOINSTALL_BOOT_PROFILES = ["localboot", "default", "cct", "LCR", "thinclient"] AUTOINSTALL_BOOT_PROFILES = ["localboot", "default", "cct", "LCR", "thinclient"]
......
...@@ -83,7 +83,7 @@ ...@@ -83,7 +83,7 @@
{{ submit_button_with_confirmation('Create ' + vm_type, 'Do you really want to create the ' + vm_type + ' ' + host.name + '?') }} {{ submit_button_with_confirmation('Create ' + vm_type, 'Do you really want to create the ' + vm_type + ' ' + host.name + '?') }}
</form> </form>
</div> </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"> <div class="col-sm-4">
<form id="BootProfileForm" method="POST"> <form id="BootProfileForm" method="POST">
{{ form.hidden_tag() }} {{ form.hidden_tag() }}
......
...@@ -19,7 +19,7 @@ HOST_NAME_RE = re.compile(r"^[a-z0-9\-]{2,20}$") ...@@ -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}$") INTERFACE_NAME_RE = re.compile(r"^[a-z0-9\-]{2,25}$")
VLAN_NAME_RE = re.compile(r"^[A-Za-z0-9\-]{3,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}$") 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): class NoValidateSelectField(SelectField):
......
...@@ -186,7 +186,7 @@ Please contact an admin user if you don't have the proper permissions. ...@@ -186,7 +186,7 @@ Please contact an admin user if you don't have the proper permissions.
Physical Machine installation 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 .. image:: _static/network/set_boot_profile.png
......
"""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")
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment