فهرست منبع

Enabled export templates for services

Jeremy Stretch 7 سال پیش
والد
کامیت
81b1d54859
3فایلهای تغییر یافته به همراه16 افزوده شده و 1 حذف شده
  1. 1 1
      netbox/extras/constants.py
  2. 11 0
      netbox/ipam/models.py
  3. 4 0
      netbox/templates/ipam/service_list.html

+ 1 - 1
netbox/extras/constants.py

@@ -51,7 +51,7 @@ EXPORTTEMPLATE_MODELS = [
     'provider', 'circuit',                                                          # Circuits
     'site', 'region', 'rack', 'rackgroup', 'manufacturer', 'devicetype', 'device',  # DCIM
     'consoleport', 'powerport', 'interfaceconnection', 'virtualchassis',            # DCIM
-    'aggregate', 'prefix', 'ipaddress', 'vlan', 'vrf',                              # IPAM
+    'aggregate', 'prefix', 'ipaddress', 'vlan', 'vrf', 'service',                   # IPAM
     'tenant',                                                                       # Tenancy
     'cluster', 'virtualmachine',                                                    # Virtualization
 ]

+ 11 - 0
netbox/ipam/models.py

@@ -880,6 +880,7 @@ class Service(ChangeLoggedModel, CustomFieldModel):
     tags = TaggableManager()
 
     serializer = 'ipam.api.serializers.ServiceSerializer'
+    csv_headers = ['device', 'virtual_machine', 'name', 'protocol', 'description']
 
     class Meta:
         ordering = ['protocol', 'port']
@@ -901,3 +902,13 @@ class Service(ChangeLoggedModel, CustomFieldModel):
             raise ValidationError("A service cannot be associated with both a device and a virtual machine.")
         if not self.device and not self.virtual_machine:
             raise ValidationError("A service must be associated with either a device or a virtual machine.")
+
+    def to_csv(self):
+        return (
+            self.device.name if self.device else None,
+            self.virtual_machine.name if self.virtual_machine else None,
+            self.name,
+            self.get_protocol_display(),
+            self.port,
+            self.description,
+        )

+ 4 - 0
netbox/templates/ipam/service_list.html

@@ -1,6 +1,10 @@
 {% extends '_base.html' %}
+{% load buttons %}
 
 {% block content %}
+<div class="pull-right">
+    {% export_button content_type %}
+</div>
 <h1>{% block title %}Services{% endblock %}</h1>
 <div class="row">
 	<div class="col-md-9">