mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-24 16:03:47 +00:00
Returns correct port profile
This commit is contained in:
parent
3ec4fdd9d9
commit
5b112657c9
1 changed files with 19 additions and 3 deletions
|
@ -379,6 +379,14 @@ class Switch(AclMixin, Machine):
|
||||||
modules.append((module_of_self.slot, module_of_self.module.reference))
|
modules.append((module_of_self.slot, module_of_self.module.reference))
|
||||||
return modules
|
return modules
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def get_dormitory(self):
|
||||||
|
"""Returns the dormitory of that switch"""
|
||||||
|
if self.switchbay:
|
||||||
|
return self.switchbay.building.dormitory
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.get_name)
|
return str(self.get_name)
|
||||||
|
|
||||||
|
@ -647,10 +655,18 @@ class Port(AclMixin, RevMixin, models.Model):
|
||||||
@cached_property
|
@cached_property
|
||||||
def get_port_profile(self):
|
def get_port_profile(self):
|
||||||
"""Return the config profil for this port
|
"""Return the config profil for this port
|
||||||
:returns: the profile of self (port)"""
|
:returns: the profile of self (port)
|
||||||
|
|
||||||
|
If is defined a custom profile, returns it
|
||||||
|
elIf a default profile is defined for its dormitory, returns it
|
||||||
|
Else, returns the global default profil
|
||||||
|
If not exists, create a nothing profile"""
|
||||||
def profile_or_nothing(profile):
|
def profile_or_nothing(profile):
|
||||||
port_profile = PortProfile.objects.filter(
|
if self.switch.get_dormitory:
|
||||||
profil_default=profile).filter(switch__switchbay__building__dormitory).first()
|
port_profile = PortProfile.objects.filter(
|
||||||
|
profil_default=profile).filter(on_dormitory=self.switch.get_dormitory).first()
|
||||||
|
if not port_profile:
|
||||||
|
port_profile = PortProfile.objects.filter(profil_default=profile).first()
|
||||||
if port_profile:
|
if port_profile:
|
||||||
return port_profile
|
return port_profile
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue