mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-27 02:48:38 -06:00
Formating updates
This commit is contained in:
parent
b6adfa1a17
commit
3b79b7e44c
@ -506,7 +506,7 @@ class Rack(ChangeLoggedModel, CustomFieldModel):
|
|||||||
|
|
||||||
def get_utilization(self):
|
def get_utilization(self):
|
||||||
"""Gets utilization numerator and denominator for racks.
|
"""Gets utilization numerator and denominator for racks.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
UtilizationData: (numerator=Occupied Unit Count, denominator=U Height of the rack)
|
UtilizationData: (numerator=Occupied Unit Count, denominator=U Height of the rack)
|
||||||
"""
|
"""
|
||||||
|
@ -308,7 +308,6 @@ class Aggregate(ChangeLoggedModel, CustomFieldModel):
|
|||||||
return self.prefix.version
|
return self.prefix.version
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_percent_utilized(self):
|
def get_percent_utilized(self):
|
||||||
"""Gets the percentage utilized from the get_utilization method.
|
"""Gets the percentage utilized from the get_utilization method.
|
||||||
|
|
||||||
@ -318,7 +317,6 @@ class Aggregate(ChangeLoggedModel, CustomFieldModel):
|
|||||||
utilization = self.get_utilization()
|
utilization = self.get_utilization()
|
||||||
return int(utilization.numerator / float(utilization.denominator) * 100)
|
return int(utilization.numerator / float(utilization.denominator) * 100)
|
||||||
|
|
||||||
|
|
||||||
def get_utilization(self):
|
def get_utilization(self):
|
||||||
"""Gets the numerator and denominator for calculating utilization of an Aggregrate.
|
"""Gets the numerator and denominator for calculating utilization of an Aggregrate.
|
||||||
Returns:
|
Returns:
|
||||||
@ -326,7 +324,7 @@ class Aggregate(ChangeLoggedModel, CustomFieldModel):
|
|||||||
"""
|
"""
|
||||||
queryset = Prefix.objects.filter(prefix__net_contained_or_equal=str(self.prefix))
|
queryset = Prefix.objects.filter(prefix__net_contained_or_equal=str(self.prefix))
|
||||||
child_prefixes = netaddr.IPSet([p.prefix for p in queryset])
|
child_prefixes = netaddr.IPSet([p.prefix for p in queryset])
|
||||||
|
|
||||||
return UtilizationData(numerator=child_prefixes.size, denominator=self.prefix.size)
|
return UtilizationData(numerator=child_prefixes.size, denominator=self.prefix.size)
|
||||||
|
|
||||||
|
|
||||||
@ -609,9 +607,9 @@ class Prefix(ChangeLoggedModel, CustomFieldModel):
|
|||||||
|
|
||||||
def get_utilization(self):
|
def get_utilization(self):
|
||||||
"""Get the child prefix size and parent size.
|
"""Get the child prefix size and parent size.
|
||||||
|
|
||||||
For Prefixes with a status of "container", get the number child prefixes. For all others, count child IP addresses.
|
For Prefixes with a status of "container", get the number child prefixes. For all others, count child IP addresses.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
UtilizationData (namedtuple): (numerator, denominator)
|
UtilizationData (namedtuple): (numerator, denominator)
|
||||||
"""
|
"""
|
||||||
|
@ -245,15 +245,15 @@ def querystring(request, **kwargs):
|
|||||||
@register.inclusion_tag('utilities/templatetags/utilization_graph.html')
|
@register.inclusion_tag('utilities/templatetags/utilization_graph.html')
|
||||||
def utilization_graph(utilization_data, warning_threshold=75, danger_threshold=90):
|
def utilization_graph(utilization_data, warning_threshold=75, danger_threshold=90):
|
||||||
"""Wrapper for a horizontal bar graph indicating a percentage of utilization from a tuple of data.
|
"""Wrapper for a horizontal bar graph indicating a percentage of utilization from a tuple of data.
|
||||||
|
|
||||||
Takes the utilization_data that is a namedtuple with numerator and denominator field names and passes them into
|
Takes the utilization_data that is a namedtuple with numerator and denominator field names and passes them into
|
||||||
the utilization_graph_raw_data to handle the generation graph data.
|
the utilization_graph_raw_data to handle the generation graph data.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
utilization_data (UtilizationData): Namedtuple with numerator and denominator keys
|
utilization_data (UtilizationData): Namedtuple with numerator and denominator keys
|
||||||
warning_threshold (int, optional): Warning Threshold Value. Defaults to 75.
|
warning_threshold (int, optional): Warning Threshold Value. Defaults to 75.
|
||||||
danger_threshold (int, optional): Danger Threshold Value. Defaults to 90.
|
danger_threshold (int, optional): Danger Threshold Value. Defaults to 90.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict: Dictionary with utilization, warning threshold, danger threshold, utilization count, and total count for
|
dict: Dictionary with utilization, warning threshold, danger threshold, utilization count, and total count for
|
||||||
display
|
display
|
||||||
@ -269,13 +269,13 @@ def utilization_graph(utilization_data, warning_threshold=75, danger_threshold=9
|
|||||||
@register.inclusion_tag("utilities/templatetags/utilization_graph_raw_data.html")
|
@register.inclusion_tag("utilities/templatetags/utilization_graph_raw_data.html")
|
||||||
def utilization_graph_raw_data(numerator, denominator, warning_threshold=75, danger_threshold=90):
|
def utilization_graph_raw_data(numerator, denominator, warning_threshold=75, danger_threshold=90):
|
||||||
"""Display a horizontal bar graph indicating a percentage of utilization.
|
"""Display a horizontal bar graph indicating a percentage of utilization.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
numerator (int): Numerator for creating a percentage
|
numerator (int): Numerator for creating a percentage
|
||||||
denominator (int): Denominator for creating a percentage
|
denominator (int): Denominator for creating a percentage
|
||||||
warning_threshold (int, optional): Warning Threshold Value. Defaults to 75.
|
warning_threshold (int, optional): Warning Threshold Value. Defaults to 75.
|
||||||
danger_threshold (int, optional): Danger Threshold Value. Defaults to 90.
|
danger_threshold (int, optional): Danger Threshold Value. Defaults to 90.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict: Dictionary with utilization, warning threshold, danger threshold, utilization count, and total count for
|
dict: Dictionary with utilization, warning threshold, danger threshold, utilization count, and total count for
|
||||||
display
|
display
|
||||||
|
@ -327,5 +327,6 @@ def copy_safe_request(request):
|
|||||||
'id': getattr(request, 'id', None), # UUID assigned by middleware
|
'id': getattr(request, 'id', None), # UUID assigned by middleware
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
# Setup UtilizationData named tuple for use by multiple methods
|
# Setup UtilizationData named tuple for use by multiple methods
|
||||||
UtilizationData = namedtuple("UtilizationData", ["numerator", "denominator"])
|
UtilizationData = namedtuple("UtilizationData", ["numerator", "denominator"])
|
||||||
|
Loading…
Reference in New Issue
Block a user