|
| 1 | +from django.utils.translation import gettext_lazy as _ |
| 2 | + |
| 3 | +from netbox.ui import attrs, panels |
| 4 | + |
| 5 | + |
| 6 | +class SitePanel(panels.ObjectAttributesPanel): |
| 7 | + region = attrs.NestedObjectAttr('region', linkify=True) |
| 8 | + group = attrs.NestedObjectAttr('group', linkify=True) |
| 9 | + name = attrs.TextAttr('name') |
| 10 | + status = attrs.ChoiceAttr('status') |
| 11 | + tenant = attrs.RelatedObjectAttr('tenant', linkify=True, grouped_by='group') |
| 12 | + facility = attrs.TextAttr('facility') |
| 13 | + description = attrs.TextAttr('description') |
| 14 | + timezone = attrs.TimezoneAttr('time_zone') |
| 15 | + physical_address = attrs.AddressAttr('physical_address', map_url=True) |
| 16 | + shipping_address = attrs.AddressAttr('shipping_address', map_url=True) |
| 17 | + gps_coordinates = attrs.GPSCoordinatesAttr() |
| 18 | + |
| 19 | + |
| 20 | +class LocationPanel(panels.NestedGroupObjectPanel): |
| 21 | + site = attrs.RelatedObjectAttr('site', linkify=True, grouped_by='group') |
| 22 | + status = attrs.ChoiceAttr('status') |
| 23 | + tenant = attrs.RelatedObjectAttr('tenant', linkify=True, grouped_by='group') |
| 24 | + facility = attrs.TextAttr('facility') |
| 25 | + |
| 26 | + |
| 27 | +class RackDimensionsPanel(panels.ObjectAttributesPanel): |
| 28 | + form_factor = attrs.ChoiceAttr('form_factor') |
| 29 | + width = attrs.ChoiceAttr('width') |
| 30 | + height = attrs.TextAttr('u_height', format_string='{}U', label=_('Height')) |
| 31 | + outer_width = attrs.NumericAttr('outer_width', unit_accessor='get_outer_unit_display') |
| 32 | + outer_height = attrs.NumericAttr('outer_height', unit_accessor='get_outer_unit_display') |
| 33 | + outer_depth = attrs.NumericAttr('outer_depth', unit_accessor='get_outer_unit_display') |
| 34 | + mounting_depth = attrs.TextAttr('mounting_depth', format_string='{}mm') |
| 35 | + |
| 36 | + |
| 37 | +class RackNumberingPanel(panels.ObjectAttributesPanel): |
| 38 | + starting_unit = attrs.TextAttr('starting_unit') |
| 39 | + desc_units = attrs.BooleanAttr('desc_units', label=_('Descending units')) |
| 40 | + |
| 41 | + |
| 42 | +class RackPanel(panels.ObjectAttributesPanel): |
| 43 | + region = attrs.NestedObjectAttr('site.region', linkify=True) |
| 44 | + site = attrs.RelatedObjectAttr('site', linkify=True, grouped_by='group') |
| 45 | + location = attrs.NestedObjectAttr('location', linkify=True) |
| 46 | + name = attrs.TextAttr('name') |
| 47 | + facility = attrs.TextAttr('facility', label=_('Facility ID')) |
| 48 | + tenant = attrs.RelatedObjectAttr('tenant', linkify=True, grouped_by='group') |
| 49 | + status = attrs.ChoiceAttr('status') |
| 50 | + rack_type = attrs.RelatedObjectAttr('rack_type', linkify=True, grouped_by='manufacturer') |
| 51 | + role = attrs.RelatedObjectAttr('role', linkify=True) |
| 52 | + description = attrs.TextAttr('description') |
| 53 | + serial = attrs.TextAttr('serial', label=_('Serial number'), style='font-monospace', copy_button=True) |
| 54 | + asset_tag = attrs.TextAttr('asset_tag', style='font-monospace', copy_button=True) |
| 55 | + airflow = attrs.ChoiceAttr('airflow') |
| 56 | + space_utilization = attrs.UtilizationAttr('get_utilization') |
| 57 | + power_utilization = attrs.UtilizationAttr('get_power_utilization') |
| 58 | + |
| 59 | + |
| 60 | +class RackWeightPanel(panels.ObjectAttributesPanel): |
| 61 | + weight = attrs.NumericAttr('weight', unit_accessor='get_weight_unit_display') |
| 62 | + max_weight = attrs.NumericAttr('max_weight', unit_accessor='get_weight_unit_display', label=_('Maximum weight')) |
| 63 | + total_weight = attrs.TemplatedAttr('total_weight', template_name='dcim/rack/attrs/total_weight.html') |
| 64 | + |
| 65 | + |
| 66 | +class RackRolePanel(panels.OrganizationalObjectPanel): |
| 67 | + color = attrs.ColorAttr('color') |
| 68 | + |
| 69 | + |
| 70 | +class RackReservationPanel(panels.ObjectAttributesPanel): |
| 71 | + units = attrs.TextAttr('unit_list') |
| 72 | + status = attrs.ChoiceAttr('status') |
| 73 | + tenant = attrs.RelatedObjectAttr('tenant', linkify=True, grouped_by='group') |
| 74 | + user = attrs.RelatedObjectAttr('user') |
| 75 | + description = attrs.TextAttr('description') |
| 76 | + |
| 77 | + |
| 78 | +class RackTypePanel(panels.ObjectAttributesPanel): |
| 79 | + manufacturer = attrs.RelatedObjectAttr('manufacturer', linkify=True) |
| 80 | + model = attrs.TextAttr('model') |
| 81 | + description = attrs.TextAttr('description') |
| 82 | + |
| 83 | + |
| 84 | +class DevicePanel(panels.ObjectAttributesPanel): |
| 85 | + region = attrs.NestedObjectAttr('site.region', linkify=True) |
| 86 | + site = attrs.RelatedObjectAttr('site', linkify=True, grouped_by='group') |
| 87 | + location = attrs.NestedObjectAttr('location', linkify=True) |
| 88 | + rack = attrs.TemplatedAttr('rack', template_name='dcim/device/attrs/rack.html') |
| 89 | + virtual_chassis = attrs.RelatedObjectAttr('virtual_chassis', linkify=True) |
| 90 | + parent_device = attrs.TemplatedAttr('parent_bay', template_name='dcim/device/attrs/parent_device.html') |
| 91 | + gps_coordinates = attrs.GPSCoordinatesAttr() |
| 92 | + tenant = attrs.RelatedObjectAttr('tenant', linkify=True, grouped_by='group') |
| 93 | + device_type = attrs.RelatedObjectAttr('device_type', linkify=True, grouped_by='manufacturer') |
| 94 | + description = attrs.TextAttr('description') |
| 95 | + airflow = attrs.ChoiceAttr('airflow') |
| 96 | + serial = attrs.TextAttr('serial', label=_('Serial number'), style='font-monospace', copy_button=True) |
| 97 | + asset_tag = attrs.TextAttr('asset_tag', style='font-monospace', copy_button=True) |
| 98 | + config_template = attrs.RelatedObjectAttr('config_template', linkify=True) |
| 99 | + |
| 100 | + |
| 101 | +class DeviceManagementPanel(panels.ObjectAttributesPanel): |
| 102 | + title = _('Management') |
| 103 | + |
| 104 | + status = attrs.ChoiceAttr('status') |
| 105 | + role = attrs.NestedObjectAttr('role', linkify=True, max_depth=3) |
| 106 | + platform = attrs.NestedObjectAttr('platform', linkify=True, max_depth=3) |
| 107 | + primary_ip4 = attrs.TemplatedAttr( |
| 108 | + 'primary_ip4', |
| 109 | + label=_('Primary IPv4'), |
| 110 | + template_name='dcim/device/attrs/ipaddress.html', |
| 111 | + ) |
| 112 | + primary_ip6 = attrs.TemplatedAttr( |
| 113 | + 'primary_ip6', |
| 114 | + label=_('Primary IPv6'), |
| 115 | + template_name='dcim/device/attrs/ipaddress.html', |
| 116 | + ) |
| 117 | + oob_ip = attrs.TemplatedAttr( |
| 118 | + 'oob_ip', |
| 119 | + label=_('Out-of-band IP'), |
| 120 | + template_name='dcim/device/attrs/ipaddress.html', |
| 121 | + ) |
| 122 | + cluster = attrs.RelatedObjectAttr('cluster', linkify=True) |
| 123 | + |
| 124 | + |
| 125 | +class DeviceDimensionsPanel(panels.ObjectAttributesPanel): |
| 126 | + title = _('Dimensions') |
| 127 | + |
| 128 | + height = attrs.TextAttr('device_type.u_height', format_string='{}U') |
| 129 | + total_weight = attrs.TemplatedAttr('total_weight', template_name='dcim/device/attrs/total_weight.html') |
| 130 | + |
| 131 | + |
| 132 | +class DeviceTypePanel(panels.ObjectAttributesPanel): |
| 133 | + manufacturer = attrs.RelatedObjectAttr('manufacturer', linkify=True) |
| 134 | + model = attrs.TextAttr('model') |
| 135 | + part_number = attrs.TextAttr('part_number') |
| 136 | + default_platform = attrs.RelatedObjectAttr('default_platform', linkify=True) |
| 137 | + description = attrs.TextAttr('description') |
| 138 | + height = attrs.TextAttr('u_height', format_string='{}U', label=_('Height')) |
| 139 | + exclude_from_utilization = attrs.BooleanAttr('exclude_from_utilization') |
| 140 | + full_depth = attrs.BooleanAttr('is_full_depth') |
| 141 | + weight = attrs.NumericAttr('weight', unit_accessor='get_weight_unit_display') |
| 142 | + subdevice_role = attrs.ChoiceAttr('subdevice_role', label=_('Parent/child')) |
| 143 | + airflow = attrs.ChoiceAttr('airflow') |
| 144 | + front_image = attrs.ImageAttr('front_image') |
| 145 | + rear_image = attrs.ImageAttr('rear_image') |
| 146 | + |
| 147 | + |
| 148 | +class ModuleTypeProfilePanel(panels.ObjectAttributesPanel): |
| 149 | + name = attrs.TextAttr('name') |
| 150 | + description = attrs.TextAttr('description') |
| 151 | + |
| 152 | + |
| 153 | +class VirtualChassisMembersPanel(panels.ObjectPanel): |
| 154 | + """ |
| 155 | + A panel which lists all members of a virtual chassis. |
| 156 | + """ |
| 157 | + template_name = 'dcim/panels/virtual_chassis_members.html' |
| 158 | + title = _('Virtual Chassis Members') |
| 159 | + |
| 160 | + def get_context(self, context): |
| 161 | + return { |
| 162 | + **super().get_context(context), |
| 163 | + 'vc_members': context.get('vc_members'), |
| 164 | + } |
| 165 | + |
| 166 | + def render(self, context): |
| 167 | + if not context.get('vc_members'): |
| 168 | + return '' |
| 169 | + return super().render(context) |
| 170 | + |
| 171 | + |
| 172 | +class PowerUtilizationPanel(panels.ObjectPanel): |
| 173 | + """ |
| 174 | + A panel which displays the power utilization statistics for a device. |
| 175 | + """ |
| 176 | + template_name = 'dcim/panels/power_utilization.html' |
| 177 | + title = _('Power Utilization') |
| 178 | + |
| 179 | + def get_context(self, context): |
| 180 | + return { |
| 181 | + **super().get_context(context), |
| 182 | + 'vc_members': context.get('vc_members'), |
| 183 | + } |
| 184 | + |
| 185 | + def render(self, context): |
| 186 | + obj = context['object'] |
| 187 | + if not obj.powerports.exists() or not obj.poweroutlets.exists(): |
| 188 | + return '' |
| 189 | + return super().render(context) |
0 commit comments