소스 검색

Add rack panel

Jeremy Stretch 3 달 전
부모
커밋
90874adf14
5개의 변경된 파일46개의 추가작업 그리고 13개의 파일을 삭제
  1. 30 13
      netbox/dcim/ui/panels.py
  2. 1 0
      netbox/dcim/views.py
  3. 12 0
      netbox/netbox/ui/attrs.py
  4. 2 0
      netbox/templates/components/attrs/utilization.html
  5. 1 0
      netbox/templates/dcim/rack.html

+ 30 - 13
netbox/dcim/ui/panels.py

@@ -3,6 +3,19 @@ from django.utils.translation import gettext_lazy as _
 from netbox.ui import attrs, components
 from netbox.ui import attrs, components
 
 
 
 
+class SitePanel(components.ObjectPanel):
+    region = attrs.NestedObjectAttr('region', label=_('Region'), linkify=True)
+    group = attrs.NestedObjectAttr('group', label=_('Group'), linkify=True)
+    status = attrs.ChoiceAttr('status', label=_('Status'))
+    tenant = attrs.ObjectAttr('tenant', label=_('Tenant'), linkify=True, grouped_by='group')
+    facility = attrs.TextAttr('facility', label=_('Facility'))
+    description = attrs.TextAttr('description', label=_('Description'))
+    timezone = attrs.TimezoneAttr('time_zone', label=_('Timezone'))
+    physical_address = attrs.AddressAttr('physical_address', label=_('Physical address'), map_url=True)
+    shipping_address = attrs.AddressAttr('shipping_address', label=_('Shipping address'), map_url=True)
+    gps_coordinates = attrs.GPSCoordinatesAttr()
+
+
 class LocationPanel(components.NestedGroupObjectPanel):
 class LocationPanel(components.NestedGroupObjectPanel):
     site = attrs.ObjectAttr('site', label=_('Site'), linkify=True, grouped_by='group')
     site = attrs.ObjectAttr('site', label=_('Site'), linkify=True, grouped_by='group')
     status = attrs.ChoiceAttr('status', label=_('Status'))
     status = attrs.ChoiceAttr('status', label=_('Status'))
@@ -10,6 +23,23 @@ class LocationPanel(components.NestedGroupObjectPanel):
     facility = attrs.TextAttr('facility', label=_('Facility'))
     facility = attrs.TextAttr('facility', label=_('Facility'))
 
 
 
 
+class RackPanel(components.ObjectPanel):
+    region = attrs.NestedObjectAttr('site.region', label=_('Region'), linkify=True)
+    site = attrs.ObjectAttr('site', label=_('Site'), linkify=True, grouped_by='group')
+    location = attrs.NestedObjectAttr('location', label=_('Location'), linkify=True)
+    facility = attrs.TextAttr('facility', label=_('Facility'))
+    tenant = attrs.ObjectAttr('tenant', label=_('Tenant'), linkify=True, grouped_by='group')
+    status = attrs.ChoiceAttr('status', label=_('Status'))
+    rack_type = attrs.ObjectAttr('rack_type', label=_('Rack type'), linkify=True, grouped_by='manufacturer')
+    role = attrs.ObjectAttr('role', label=_('Role'), linkify=True)
+    description = attrs.TextAttr('description', label=_('Description'))
+    serial = attrs.TextAttr('serial', label=_('Serial number'), style='font-monospace', copy_button=True)
+    asset_tag = attrs.TextAttr('asset_tag', label=_('Asset tag'), style='font-monospace', copy_button=True)
+    airflow = attrs.ChoiceAttr('airflow', label=_('Airflow'))
+    space_utilization = attrs.UtilizationAttr('get_utilization', label=_('Space utilization'))
+    power_utilization = attrs.UtilizationAttr('get_power_utilization', label=_('Power utilization'))
+
+
 class DevicePanel(components.ObjectPanel):
 class DevicePanel(components.ObjectPanel):
     region = attrs.NestedObjectAttr('site.region', label=_('Region'), linkify=True)
     region = attrs.NestedObjectAttr('site.region', label=_('Region'), linkify=True)
     site = attrs.ObjectAttr('site', label=_('Site'), linkify=True, grouped_by='group')
     site = attrs.ObjectAttr('site', label=_('Site'), linkify=True, grouped_by='group')
@@ -50,16 +80,3 @@ class DeviceManagementPanel(components.ObjectPanel):
         label=_('Out-of-band IP'),
         label=_('Out-of-band IP'),
         template_name='dcim/device/attrs/ipaddress.html',
         template_name='dcim/device/attrs/ipaddress.html',
     )
     )
-
-
-class SitePanel(components.ObjectPanel):
-    region = attrs.NestedObjectAttr('region', label=_('Region'), linkify=True)
-    group = attrs.NestedObjectAttr('group', label=_('Group'), linkify=True)
-    status = attrs.ChoiceAttr('status', label=_('Status'))
-    tenant = attrs.ObjectAttr('tenant', label=_('Tenant'), linkify=True, grouped_by='group')
-    facility = attrs.TextAttr('facility', label=_('Facility'))
-    description = attrs.TextAttr('description', label=_('Description'))
-    timezone = attrs.TimezoneAttr('time_zone', label=_('Timezone'))
-    physical_address = attrs.AddressAttr('physical_address', label=_('Physical address'), map_url=True)
-    shipping_address = attrs.AddressAttr('shipping_address', label=_('Shipping address'), map_url=True)
-    gps_coordinates = attrs.GPSCoordinatesAttr()

+ 1 - 0
netbox/dcim/views.py

@@ -868,6 +868,7 @@ class RackView(GetRelatedModelsMixin, generic.ObjectView):
         ])
         ])
 
 
         return {
         return {
+            'rack_panel': panels.RackPanel(instance, _('Rack')),
             'related_models': self.get_related_models(
             'related_models': self.get_related_models(
                 request,
                 request,
                 instance,
                 instance,

+ 12 - 0
netbox/netbox/ui/attrs.py

@@ -210,3 +210,15 @@ class TemplatedAttr(Attr):
                 'value': value,
                 'value': value,
             }
             }
         )
         )
+
+
+class UtilizationAttr(Attr):
+    template_name = 'components/attrs/utilization.html'
+
+    def render(self, obj, context=None):
+        context = context or {}
+        value = self._resolve_attr(obj, self.accessor)
+        return render_to_string(self.template_name, {
+            **context,
+            'value': value,
+        })

+ 2 - 0
netbox/templates/components/attrs/utilization.html

@@ -0,0 +1,2 @@
+{% load helpers %}
+{% utilization_graph value %}

+ 1 - 0
netbox/templates/dcim/rack.html

@@ -120,6 +120,7 @@
       {% plugin_left_page object %}
       {% plugin_left_page object %}
 	  </div>
 	  </div>
     <div class="col col-12 col-xl-7">
     <div class="col col-12 col-xl-7">
+      {{ rack_panel }}
       <div class="text-end mb-4">
       <div class="text-end mb-4">
         <select class="btn btn-outline-secondary no-ts rack-view">
         <select class="btn btn-outline-secondary no-ts rack-view">
           <option value="images-and-labels" selected="selected">{% trans "Images and Labels" %}</option>
           <option value="images-and-labels" selected="selected">{% trans "Images and Labels" %}</option>