Browse Source

Ca me broute donc je fais simple

autocreation
Gabriel Detraz 8 years ago
committed by chirac
parent
commit
9f153c49d8
  1. 18
      re2o/mixins.py
  2. 40
      topologie/models.py

18
re2o/mixins.py

@ -160,21 +160,3 @@ class AclMixin(object):
) )
class SwitchPluggedMixin(object):
"""Mixin to get building.switch where the device is plugged"""
def switch(self):
"""Return the switch where this is plugged"""
return Switch.objects.filter(
ports__machine_interface__machine=self
)
def building(self):
"""Return the building of the AP/Server (building of the switchs connected to...)"""
return Building.objects.filter(
switchbay__switch=self.switch()
)
@cached_property
def short_name(self):
return str(self.interface_set.first().domain.name)

40
topologie/models.py

@ -49,7 +49,9 @@ from django.db import transaction
from reversion import revisions as reversion from reversion import revisions as reversion
from machines.models import Machine, regen from machines.models import Machine, regen
from re2o.mixins import AclMixin, RevMixin, SwitchPluggedMixin from re2o.mixins import AclMixin, RevMixin
class Stack(AclMixin, RevMixin, models.Model): class Stack(AclMixin, RevMixin, models.Model):
@ -85,7 +87,7 @@ class Stack(AclMixin, RevMixin, models.Model):
inférieure à l'id minimale"}) inférieure à l'id minimale"})
class AccessPoint(AclMixin, SwitchPluggedMixin, Machine): class AccessPoint(AclMixin, Machine):
"""Define a wireless AP. Inherit from machines.interfaces """Define a wireless AP. Inherit from machines.interfaces
Definition pour une borne wifi , hérite de machines.interfaces Definition pour une borne wifi , hérite de machines.interfaces
@ -104,6 +106,22 @@ class AccessPoint(AclMixin, SwitchPluggedMixin, Machine):
("view_accesspoint", "Peut voir une borne"), ("view_accesspoint", "Peut voir une borne"),
) )
def switch(self):
"""Return the switch where this is plugged"""
return Switch.objects.filter(
ports__machine_interface__machine=self
)
def building(self):
"""Return the building of the AP/Server (building of the switchs connected to...)"""
return Building.objects.filter(
switchbay__switch=self.switch()
)
@cached_property
def short_name(self):
return str(self.interface_set.first().domain.name)
@classmethod @classmethod
def all_ap_in(cls, building_instance): def all_ap_in(cls, building_instance):
"""Get a building as argument, returns all ap of a building""" """Get a building as argument, returns all ap of a building"""
@ -113,12 +131,28 @@ class AccessPoint(AclMixin, SwitchPluggedMixin, Machine):
return str(self.interface_set.first()) return str(self.interface_set.first())
class Server(Machine, SwitchPluggedMixin): class Server(Machine):
"""Dummy class, to retrieve servers of a building, or get switch of a server""" """Dummy class, to retrieve servers of a building, or get switch of a server"""
class Meta: class Meta:
proxy = True proxy = True
def switch(self):
"""Return the switch where this is plugged"""
return Switch.objects.filter(
ports__machine_interface__machine=self
)
def building(self):
"""Return the building of the AP/Server (building of the switchs connected to...)"""
return Building.objects.filter(
switchbay__switch=self.switch()
)
@cached_property
def short_name(self):
return str(self.interface_set.first().domain.name)
@classmethod @classmethod
def all_server_in(cls, building_instance): def all_server_in(cls, building_instance):
"""Get a building as argument, returns all server of a building""" """Get a building as argument, returns all server of a building"""

Loading…
Cancel
Save