| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250 |
- import django_tables2 as tables
- from django_tables2.utils import Accessor
- from tenancy.tables import COL_TENANT
- from utilities.tables import BaseTable, BooleanColumn, ColorColumn, ColoredLabelColumn, TagColumn, ToggleColumn
- from .models import (
- Cable, ConsolePort, ConsolePortTemplate, ConsoleServerPort, ConsoleServerPortTemplate, Device, DeviceBay,
- DeviceBayTemplate, DeviceRole, DeviceType, FrontPort, FrontPortTemplate, Interface, InterfaceTemplate,
- InventoryItem, Manufacturer, Platform, PowerFeed, PowerOutlet, PowerOutletTemplate, PowerPanel, PowerPort,
- PowerPortTemplate, Rack, RackGroup, RackReservation, RackRole, RearPort, RearPortTemplate, Region, Site,
- VirtualChassis,
- )
- MPTT_LINK = """
- {% if record.get_children %}
- <span style="padding-left: {{ record.get_ancestors|length }}0px "><i class="fa fa-caret-right"></i>
- {% else %}
- <span style="padding-left: {{ record.get_ancestors|length }}9px">
- {% endif %}
- <a href="{{ record.get_absolute_url }}">{{ record.name }}</a>
- </span>
- """
- SITE_REGION_LINK = """
- {% if record.region %}
- <a href="{% url 'dcim:site_list' %}?region={{ record.region.slug }}">{{ record.region }}</a>
- {% else %}
- —
- {% endif %}
- """
- COLOR_LABEL = """
- {% load helpers %}
- <label class="label" style="color: {{ record.color|fgcolor }}; background-color: #{{ record.color }}">{{ record }}</label>
- """
- DEVICE_LINK = """
- <a href="{% url 'dcim:device' pk=record.pk %}">
- {{ record.name|default:'<span class="label label-info">Unnamed device</span>' }}
- </a>
- """
- REGION_ACTIONS = """
- <a href="{% url 'dcim:region_changelog' pk=record.pk %}" class="btn btn-default btn-xs" title="Change log">
- <i class="fa fa-history"></i>
- </a>
- {% if perms.dcim.change_region %}
- <a href="{% url 'dcim:region_edit' pk=record.pk %}?return_url={{ request.path }}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
- {% endif %}
- """
- RACKGROUP_ACTIONS = """
- <a href="{% url 'dcim:rackgroup_changelog' pk=record.pk %}" class="btn btn-default btn-xs" title="Change log">
- <i class="fa fa-history"></i>
- </a>
- <a href="{% url 'dcim:rack_elevation_list' %}?site={{ record.site.slug }}&group_id={{ record.pk }}" class="btn btn-xs btn-primary" title="View elevations">
- <i class="fa fa-eye"></i>
- </a>
- {% if perms.dcim.change_rackgroup %}
- <a href="{% url 'dcim:rackgroup_edit' pk=record.pk %}?return_url={{ request.path }}" class="btn btn-xs btn-warning" title="Edit">
- <i class="glyphicon glyphicon-pencil"></i>
- </a>
- {% endif %}
- """
- RACKROLE_ACTIONS = """
- <a href="{% url 'dcim:rackrole_changelog' pk=record.pk %}" class="btn btn-default btn-xs" title="Change log">
- <i class="fa fa-history"></i>
- </a>
- {% if perms.dcim.change_rackrole %}
- <a href="{% url 'dcim:rackrole_edit' pk=record.pk %}?return_url={{ request.path }}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
- {% endif %}
- """
- RACK_DEVICE_COUNT = """
- <a href="{% url 'dcim:device_list' %}?rack_id={{ record.pk }}">{{ value }}</a>
- """
- RACKRESERVATION_ACTIONS = """
- <a href="{% url 'dcim:rackreservation_changelog' pk=record.pk %}" class="btn btn-default btn-xs" title="Change log">
- <i class="fa fa-history"></i>
- </a>
- {% if perms.dcim.change_rackreservation %}
- <a href="{% url 'dcim:rackreservation_edit' pk=record.pk %}?return_url={{ request.path }}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
- {% endif %}
- """
- MANUFACTURER_ACTIONS = """
- <a href="{% url 'dcim:manufacturer_changelog' slug=record.slug %}" class="btn btn-default btn-xs" title="Change log">
- <i class="fa fa-history"></i>
- </a>
- {% if perms.dcim.change_manufacturer %}
- <a href="{% url 'dcim:manufacturer_edit' slug=record.slug %}?return_url={{ request.path }}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
- {% endif %}
- """
- DEVICEROLE_ACTIONS = """
- <a href="{% url 'dcim:devicerole_changelog' slug=record.slug %}" class="btn btn-default btn-xs" title="Change log">
- <i class="fa fa-history"></i>
- </a>
- {% if perms.dcim.change_devicerole %}
- <a href="{% url 'dcim:devicerole_edit' slug=record.slug %}?return_url={{ request.path }}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
- {% endif %}
- """
- DEVICEROLE_DEVICE_COUNT = """
- <a href="{% url 'dcim:device_list' %}?role={{ record.slug }}">{{ value }}</a>
- """
- DEVICEROLE_VM_COUNT = """
- <a href="{% url 'virtualization:virtualmachine_list' %}?role={{ record.slug }}">{{ value }}</a>
- """
- PLATFORM_DEVICE_COUNT = """
- <a href="{% url 'dcim:device_list' %}?platform={{ record.slug }}">{{ value }}</a>
- """
- PLATFORM_VM_COUNT = """
- <a href="{% url 'virtualization:virtualmachine_list' %}?platform={{ record.slug }}">{{ value }}</a>
- """
- PLATFORM_ACTIONS = """
- <a href="{% url 'dcim:platform_changelog' slug=record.slug %}" class="btn btn-default btn-xs" title="Change log">
- <i class="fa fa-history"></i>
- </a>
- {% if perms.dcim.change_platform %}
- <a href="{% url 'dcim:platform_edit' slug=record.slug %}?return_url={{ request.path }}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
- {% endif %}
- """
- STATUS_LABEL = """
- <span class="label label-{{ record.get_status_class }}">{{ record.get_status_display }}</span>
- """
- TYPE_LABEL = """
- <span class="label label-{{ record.get_type_class }}">{{ record.get_type_display }}</span>
- """
- DEVICE_PRIMARY_IP = """
- {{ record.primary_ip6.address.ip|default:"" }}
- {% if record.primary_ip6 and record.primary_ip4 %}<br />{% endif %}
- {{ record.primary_ip4.address.ip|default:"" }}
- """
- DEVICETYPE_INSTANCES_TEMPLATE = """
- <a href="{% url 'dcim:device_list' %}?manufacturer_id={{ record.manufacturer_id }}&device_type_id={{ record.pk }}">{{ record.instance_count }}</a>
- """
- UTILIZATION_GRAPH = """
- {% load helpers %}
- {% utilization_graph value %}
- """
- CABLE_TERMINATION_PARENT = """
- {% if value.device %}
- <a href="{{ value.device.get_absolute_url }}">{{ value.device }}</a>
- {% elif value.circuit %}
- <a href="{{ value.circuit.get_absolute_url }}">{{ value.circuit }}</a>
- {% elif value.power_panel %}
- <a href="{{ value.power_panel.get_absolute_url }}">{{ value.power_panel }}</a>
- {% endif %}
- """
- CABLE_LENGTH = """
- {% if record.length %}{{ record.length }} {{ record.get_length_unit_display }}{% else %}—{% endif %}
- """
- POWERPANEL_POWERFEED_COUNT = """
- <a href="{% url 'dcim:powerfeed_list' %}?power_panel_id={{ record.pk }}">{{ value }}</a>
- """
- def get_component_template_actions(model_name):
- return """
- {{% if perms.dcim.change_{model_name} %}}
- <a href="{{% url 'dcim:{model_name}_edit' pk=record.pk %}}?return_url={{{{ request.path }}}}" class="btn btn-xs btn-warning">
- <i class="glyphicon glyphicon-pencil" aria-hidden="true"></i>
- </a>
- {{% endif %}}
- {{% if perms.dcim.delete_{model_name} %}}
- <a href="{{% url 'dcim:{model_name}_delete' pk=record.pk %}}?return_url={{{{ request.path }}}}" class="btn btn-xs btn-danger">
- <i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
- </a>
- {{% endif %}}
- """.format(model_name=model_name).strip()
- #
- # Regions
- #
- class RegionTable(BaseTable):
- pk = ToggleColumn()
- name = tables.TemplateColumn(
- template_code=MPTT_LINK,
- orderable=False
- )
- site_count = tables.Column(
- verbose_name='Sites'
- )
- actions = tables.TemplateColumn(
- template_code=REGION_ACTIONS,
- attrs={'td': {'class': 'text-right noprint'}},
- verbose_name=''
- )
- class Meta(BaseTable.Meta):
- model = Region
- fields = ('pk', 'name', 'slug', 'site_count', 'description', 'actions')
- default_columns = ('pk', 'name', 'site_count', 'description', 'actions')
- #
- # Sites
- #
- class SiteTable(BaseTable):
- pk = ToggleColumn()
- name = tables.LinkColumn(
- order_by=('_name',)
- )
- status = tables.TemplateColumn(
- template_code=STATUS_LABEL
- )
- region = tables.TemplateColumn(
- template_code=SITE_REGION_LINK
- )
- tenant = tables.TemplateColumn(
- template_code=COL_TENANT
- )
- tags = TagColumn(
- url_name='dcim:site_list'
- )
- class Meta(BaseTable.Meta):
- model = Site
- fields = (
- 'pk', 'name', 'slug', 'status', 'facility', 'region', 'tenant', 'asn', 'time_zone', 'description',
- 'physical_address', 'shipping_address', 'latitude', 'longitude', 'contact_name', 'contact_phone',
- 'contact_email', 'tags',
- )
- default_columns = ('pk', 'name', 'status', 'facility', 'region', 'tenant', 'asn', 'description')
- #
- # Rack groups
- #
- class RackGroupTable(BaseTable):
- pk = ToggleColumn()
- name = tables.TemplateColumn(
- template_code=MPTT_LINK,
- orderable=False
- )
- site = tables.LinkColumn(
- viewname='dcim:site',
- args=[Accessor('site.slug')],
- verbose_name='Site'
- )
- rack_count = tables.Column(
- verbose_name='Racks'
- )
- actions = tables.TemplateColumn(
- template_code=RACKGROUP_ACTIONS,
- attrs={'td': {'class': 'text-right noprint'}},
- verbose_name=''
- )
- class Meta(BaseTable.Meta):
- model = RackGroup
- fields = ('pk', 'name', 'site', 'rack_count', 'description', 'slug', 'actions')
- default_columns = ('pk', 'name', 'site', 'rack_count', 'description', 'actions')
- #
- # Rack roles
- #
- class RackRoleTable(BaseTable):
- pk = ToggleColumn()
- rack_count = tables.Column(verbose_name='Racks')
- color = tables.TemplateColumn(COLOR_LABEL)
- actions = tables.TemplateColumn(
- template_code=RACKROLE_ACTIONS,
- attrs={'td': {'class': 'text-right noprint'}},
- verbose_name=''
- )
- class Meta(BaseTable.Meta):
- model = RackRole
- fields = ('pk', 'name', 'rack_count', 'color', 'description', 'slug', 'actions')
- default_columns = ('pk', 'name', 'rack_count', 'color', 'description', 'actions')
- #
- # Racks
- #
- class RackTable(BaseTable):
- pk = ToggleColumn()
- name = tables.LinkColumn(
- order_by=('_name',)
- )
- site = tables.LinkColumn(
- viewname='dcim:site',
- args=[Accessor('site.slug')]
- )
- tenant = tables.TemplateColumn(
- template_code=COL_TENANT
- )
- status = tables.TemplateColumn(
- template_code=STATUS_LABEL
- )
- role = ColoredLabelColumn()
- u_height = tables.TemplateColumn(
- template_code="{{ record.u_height }}U",
- verbose_name='Height'
- )
- class Meta(BaseTable.Meta):
- model = Rack
- fields = (
- 'pk', 'name', 'site', 'group', 'status', 'facility_id', 'tenant', 'role', 'serial', 'asset_tag', 'type',
- 'width', 'u_height',
- )
- default_columns = ('pk', 'name', 'site', 'group', 'status', 'facility_id', 'tenant', 'role', 'u_height')
- class RackDetailTable(RackTable):
- device_count = tables.TemplateColumn(
- template_code=RACK_DEVICE_COUNT,
- verbose_name='Devices'
- )
- get_utilization = tables.TemplateColumn(
- template_code=UTILIZATION_GRAPH,
- orderable=False,
- verbose_name='Space'
- )
- get_power_utilization = tables.TemplateColumn(
- template_code=UTILIZATION_GRAPH,
- orderable=False,
- verbose_name='Power'
- )
- tags = TagColumn(
- url_name='dcim:rack_list'
- )
- class Meta(RackTable.Meta):
- fields = (
- 'pk', 'name', 'site', 'group', 'status', 'facility_id', 'tenant', 'role', 'serial', 'asset_tag', 'type',
- 'width', 'u_height', 'device_count', 'get_utilization', 'get_power_utilization', 'tags',
- )
- default_columns = (
- 'pk', 'name', 'site', 'group', 'status', 'facility_id', 'tenant', 'role', 'u_height', 'device_count',
- 'get_utilization', 'get_power_utilization',
- )
- #
- # Rack reservations
- #
- class RackReservationTable(BaseTable):
- pk = ToggleColumn()
- reservation = tables.LinkColumn(
- viewname='dcim:rackreservation',
- args=[Accessor('pk')],
- accessor='pk'
- )
- site = tables.LinkColumn(
- viewname='dcim:site',
- accessor=Accessor('rack.site'),
- args=[Accessor('rack.site.slug')],
- )
- tenant = tables.TemplateColumn(
- template_code=COL_TENANT
- )
- rack = tables.LinkColumn(
- viewname='dcim:rack',
- args=[Accessor('rack.pk')]
- )
- unit_list = tables.Column(
- orderable=False,
- verbose_name='Units'
- )
- tags = TagColumn(
- url_name='dcim:rackreservation_list'
- )
- actions = tables.TemplateColumn(
- template_code=RACKRESERVATION_ACTIONS,
- attrs={'td': {'class': 'text-right noprint'}},
- verbose_name=''
- )
- class Meta(BaseTable.Meta):
- model = RackReservation
- fields = (
- 'pk', 'reservation', 'site', 'rack', 'unit_list', 'user', 'created', 'tenant', 'description', 'tags',
- 'actions',
- )
- default_columns = (
- 'pk', 'reservation', 'site', 'rack', 'unit_list', 'user', 'description', 'actions',
- )
- #
- # Manufacturers
- #
- class ManufacturerTable(BaseTable):
- pk = ToggleColumn()
- name = tables.LinkColumn()
- devicetype_count = tables.Column(
- verbose_name='Device Types'
- )
- inventoryitem_count = tables.Column(
- verbose_name='Inventory Items'
- )
- platform_count = tables.Column(
- verbose_name='Platforms'
- )
- slug = tables.Column()
- actions = tables.TemplateColumn(
- template_code=MANUFACTURER_ACTIONS,
- attrs={'td': {'class': 'text-right noprint'}},
- verbose_name=''
- )
- class Meta(BaseTable.Meta):
- model = Manufacturer
- fields = (
- 'pk', 'name', 'devicetype_count', 'inventoryitem_count', 'platform_count', 'description', 'slug', 'actions',
- )
- #
- # Device types
- #
- class DeviceTypeTable(BaseTable):
- pk = ToggleColumn()
- model = tables.LinkColumn(
- viewname='dcim:devicetype',
- args=[Accessor('pk')],
- verbose_name='Device Type'
- )
- is_full_depth = BooleanColumn(
- verbose_name='Full Depth'
- )
- instance_count = tables.TemplateColumn(
- template_code=DEVICETYPE_INSTANCES_TEMPLATE,
- verbose_name='Instances'
- )
- tags = TagColumn(
- url_name='dcim:devicetype_list'
- )
- class Meta(BaseTable.Meta):
- model = DeviceType
- fields = (
- 'pk', 'model', 'manufacturer', 'slug', 'part_number', 'u_height', 'is_full_depth', 'subdevice_role',
- 'instance_count', 'tags',
- )
- default_columns = (
- 'pk', 'model', 'manufacturer', 'part_number', 'u_height', 'is_full_depth', 'instance_count',
- )
- #
- # Device type components
- #
- class ComponentTemplateTable(BaseTable):
- pk = ToggleColumn()
- name = tables.Column(
- order_by=('_name',)
- )
- class ConsolePortTemplateTable(ComponentTemplateTable):
- actions = tables.TemplateColumn(
- template_code=get_component_template_actions('consoleporttemplate'),
- attrs={'td': {'class': 'text-right noprint'}},
- verbose_name=''
- )
- class Meta(BaseTable.Meta):
- model = ConsolePortTemplate
- fields = ('pk', 'name', 'label', 'type', 'actions')
- empty_text = "None"
- class ConsolePortImportTable(BaseTable):
- device = tables.LinkColumn(
- viewname='dcim:device',
- args=[Accessor('device.pk')]
- )
- class Meta(BaseTable.Meta):
- model = ConsolePort
- fields = ('device', 'name', 'description')
- empty_text = False
- class ConsoleServerPortTemplateTable(ComponentTemplateTable):
- actions = tables.TemplateColumn(
- template_code=get_component_template_actions('consoleserverporttemplate'),
- attrs={'td': {'class': 'text-right noprint'}},
- verbose_name=''
- )
- class Meta(BaseTable.Meta):
- model = ConsoleServerPortTemplate
- fields = ('pk', 'name', 'label', 'type', 'actions')
- empty_text = "None"
- class ConsoleServerPortImportTable(BaseTable):
- device = tables.LinkColumn(
- viewname='dcim:device',
- args=[Accessor('device.pk')]
- )
- class Meta(BaseTable.Meta):
- model = ConsoleServerPort
- fields = ('device', 'name', 'description')
- empty_text = False
- class PowerPortTemplateTable(ComponentTemplateTable):
- actions = tables.TemplateColumn(
- template_code=get_component_template_actions('powerporttemplate'),
- attrs={'td': {'class': 'text-right noprint'}},
- verbose_name=''
- )
- class Meta(BaseTable.Meta):
- model = PowerPortTemplate
- fields = ('pk', 'name', 'label', 'type', 'maximum_draw', 'allocated_draw', 'actions')
- empty_text = "None"
- class PowerPortImportTable(BaseTable):
- device = tables.LinkColumn(
- viewname='dcim:device',
- args=[Accessor('device.pk')]
- )
- class Meta(BaseTable.Meta):
- model = PowerPort
- fields = ('device', 'name', 'description', 'maximum_draw', 'allocated_draw')
- empty_text = False
- class PowerOutletTemplateTable(ComponentTemplateTable):
- actions = tables.TemplateColumn(
- template_code=get_component_template_actions('poweroutlettemplate'),
- attrs={'td': {'class': 'text-right noprint'}},
- verbose_name=''
- )
- class Meta(BaseTable.Meta):
- model = PowerOutletTemplate
- fields = ('pk', 'name', 'label', 'type', 'power_port', 'feed_leg', 'actions')
- empty_text = "None"
- class PowerOutletImportTable(BaseTable):
- device = tables.LinkColumn(
- viewname='dcim:device',
- args=[Accessor('device.pk')]
- )
- class Meta(BaseTable.Meta):
- model = PowerOutlet
- fields = ('device', 'name', 'description', 'power_port', 'feed_leg')
- empty_text = False
- class InterfaceTemplateTable(ComponentTemplateTable):
- mgmt_only = BooleanColumn(
- verbose_name='Management Only'
- )
- actions = tables.TemplateColumn(
- template_code=get_component_template_actions('interfacetemplate'),
- attrs={'td': {'class': 'text-right noprint'}},
- verbose_name=''
- )
- class Meta(BaseTable.Meta):
- model = InterfaceTemplate
- fields = ('pk', 'name', 'label', 'mgmt_only', 'type', 'actions')
- empty_text = "None"
- class InterfaceImportTable(BaseTable):
- device = tables.LinkColumn(
- viewname='dcim:device',
- args=[Accessor('device.pk')]
- )
- class Meta(BaseTable.Meta):
- model = Interface
- fields = (
- 'device', 'name', 'description', 'lag', 'type', 'enabled', 'mac_address', 'mtu', 'mgmt_only', 'mode',
- )
- empty_text = False
- class FrontPortTemplateTable(ComponentTemplateTable):
- rear_port_position = tables.Column(
- verbose_name='Position'
- )
- actions = tables.TemplateColumn(
- template_code=get_component_template_actions('frontporttemplate'),
- attrs={'td': {'class': 'text-right noprint'}},
- verbose_name=''
- )
- class Meta(BaseTable.Meta):
- model = FrontPortTemplate
- fields = ('pk', 'name', 'label', 'type', 'rear_port', 'rear_port_position', 'actions')
- empty_text = "None"
- class FrontPortImportTable(BaseTable):
- device = tables.LinkColumn(
- viewname='dcim:device',
- args=[Accessor('device.pk')]
- )
- class Meta(BaseTable.Meta):
- model = FrontPort
- fields = ('device', 'name', 'description', 'type', 'rear_port', 'rear_port_position')
- empty_text = False
- class RearPortTemplateTable(ComponentTemplateTable):
- actions = tables.TemplateColumn(
- template_code=get_component_template_actions('rearporttemplate'),
- attrs={'td': {'class': 'text-right noprint'}},
- verbose_name=''
- )
- class Meta(BaseTable.Meta):
- model = RearPortTemplate
- fields = ('pk', 'name', 'label', 'type', 'positions', 'actions')
- empty_text = "None"
- class RearPortImportTable(BaseTable):
- device = tables.LinkColumn(
- viewname='dcim:device',
- args=[Accessor('device.pk')]
- )
- class Meta(BaseTable.Meta):
- model = RearPort
- fields = ('device', 'name', 'description', 'type', 'position')
- empty_text = False
- class DeviceBayTemplateTable(ComponentTemplateTable):
- actions = tables.TemplateColumn(
- template_code=get_component_template_actions('devicebaytemplate'),
- attrs={'td': {'class': 'text-right noprint'}},
- verbose_name=''
- )
- class Meta(BaseTable.Meta):
- model = DeviceBayTemplate
- fields = ('pk', 'name', 'label', 'actions')
- empty_text = "None"
- #
- # Device roles
- #
- class DeviceRoleTable(BaseTable):
- pk = ToggleColumn()
- device_count = tables.TemplateColumn(
- template_code=DEVICEROLE_DEVICE_COUNT,
- accessor=Accessor('devices.count'),
- orderable=False,
- verbose_name='Devices'
- )
- vm_count = tables.TemplateColumn(
- template_code=DEVICEROLE_VM_COUNT,
- accessor=Accessor('virtual_machines.count'),
- orderable=False,
- verbose_name='VMs'
- )
- color = tables.TemplateColumn(
- template_code=COLOR_LABEL,
- verbose_name='Label'
- )
- actions = tables.TemplateColumn(
- template_code=DEVICEROLE_ACTIONS,
- attrs={'td': {'class': 'text-right noprint'}},
- verbose_name=''
- )
- class Meta(BaseTable.Meta):
- model = DeviceRole
- fields = ('pk', 'name', 'device_count', 'vm_count', 'color', 'vm_role', 'description', 'slug', 'actions')
- default_columns = ('pk', 'name', 'device_count', 'vm_count', 'color', 'vm_role', 'description', 'actions')
- #
- # Platforms
- #
- class PlatformTable(BaseTable):
- pk = ToggleColumn()
- device_count = tables.TemplateColumn(
- template_code=PLATFORM_DEVICE_COUNT,
- accessor=Accessor('devices.count'),
- orderable=False,
- verbose_name='Devices'
- )
- vm_count = tables.TemplateColumn(
- template_code=PLATFORM_VM_COUNT,
- accessor=Accessor('virtual_machines.count'),
- orderable=False,
- verbose_name='VMs'
- )
- actions = tables.TemplateColumn(
- template_code=PLATFORM_ACTIONS,
- attrs={'td': {'class': 'text-right noprint'}},
- verbose_name=''
- )
- class Meta(BaseTable.Meta):
- model = Platform
- fields = (
- 'pk', 'name', 'manufacturer', 'device_count', 'vm_count', 'slug', 'napalm_driver', 'napalm_args',
- 'description', 'actions',
- )
- default_columns = (
- 'pk', 'name', 'manufacturer', 'device_count', 'vm_count', 'napalm_driver', 'description', 'actions',
- )
- #
- # Devices
- #
- class DeviceTable(BaseTable):
- pk = ToggleColumn()
- name = tables.TemplateColumn(
- order_by=('_name',),
- template_code=DEVICE_LINK
- )
- status = tables.TemplateColumn(
- template_code=STATUS_LABEL
- )
- tenant = tables.TemplateColumn(
- template_code=COL_TENANT
- )
- site = tables.LinkColumn(
- viewname='dcim:site',
- args=[Accessor('site.slug')]
- )
- rack = tables.LinkColumn(
- viewname='dcim:rack',
- args=[Accessor('rack.pk')]
- )
- device_role = ColoredLabelColumn(
- verbose_name='Role'
- )
- device_type = tables.LinkColumn(
- viewname='dcim:devicetype',
- args=[Accessor('device_type.pk')],
- verbose_name='Type',
- text=lambda record: record.device_type.display_name
- )
- primary_ip = tables.TemplateColumn(
- template_code=DEVICE_PRIMARY_IP,
- orderable=False,
- verbose_name='IP Address'
- )
- primary_ip4 = tables.LinkColumn(
- viewname='ipam:ipaddress',
- args=[Accessor('primary_ip4.pk')],
- verbose_name='IPv4 Address'
- )
- primary_ip6 = tables.LinkColumn(
- viewname='ipam:ipaddress',
- args=[Accessor('primary_ip6.pk')],
- verbose_name='IPv6 Address'
- )
- cluster = tables.LinkColumn(
- viewname='virtualization:cluster',
- args=[Accessor('cluster.pk')]
- )
- virtual_chassis = tables.LinkColumn(
- viewname='dcim:virtualchassis',
- args=[Accessor('virtual_chassis.pk')]
- )
- vc_position = tables.Column(
- verbose_name='VC Position'
- )
- vc_priority = tables.Column(
- verbose_name='VC Priority'
- )
- tags = TagColumn(
- url_name='dcim:device_list'
- )
- class Meta(BaseTable.Meta):
- model = Device
- fields = (
- 'pk', 'name', 'status', 'tenant', 'device_role', 'device_type', 'platform', 'serial', 'asset_tag', 'site',
- 'rack', 'position', 'face', 'primary_ip', 'primary_ip4', 'primary_ip6', 'cluster', 'virtual_chassis',
- 'vc_position', 'vc_priority', 'tags',
- )
- default_columns = (
- 'pk', 'name', 'status', 'tenant', 'site', 'rack', 'device_role', 'device_type', 'primary_ip',
- )
- class DeviceImportTable(BaseTable):
- name = tables.TemplateColumn(
- template_code=DEVICE_LINK
- )
- status = tables.TemplateColumn(
- template_code=STATUS_LABEL
- )
- tenant = tables.TemplateColumn(
- template_code=COL_TENANT
- )
- site = tables.LinkColumn(
- viewname='dcim:site',
- args=[Accessor('site.slug')]
- )
- rack = tables.LinkColumn(
- viewname='dcim:rack',
- args=[Accessor('rack.pk')]
- )
- device_role = tables.Column(
- verbose_name='Role'
- )
- device_type = tables.Column(
- verbose_name='Type'
- )
- class Meta(BaseTable.Meta):
- model = Device
- fields = ('name', 'status', 'tenant', 'site', 'rack', 'position', 'device_role', 'device_type')
- empty_text = False
- #
- # Device components
- #
- class DeviceComponentDetailTable(BaseTable):
- pk = ToggleColumn()
- device = tables.LinkColumn()
- name = tables.Column(order_by=('_name',))
- cable = tables.LinkColumn()
- class Meta(BaseTable.Meta):
- order_by = ('device', 'name')
- fields = ('pk', 'device', 'name', 'label', 'type', 'description', 'cable')
- sequence = ('pk', 'device', 'name', 'label', 'type', 'description', 'cable')
- class ConsolePortTable(BaseTable):
- name = tables.Column(order_by=('_name',))
- class Meta(BaseTable.Meta):
- model = ConsolePort
- fields = ('name', 'label', 'type')
- class ConsolePortDetailTable(DeviceComponentDetailTable):
- class Meta(DeviceComponentDetailTable.Meta, ConsolePortTable.Meta):
- pass
- class ConsoleServerPortTable(BaseTable):
- name = tables.Column(order_by=('_name',))
- class Meta(BaseTable.Meta):
- model = ConsoleServerPort
- fields = ('name', 'label', 'description')
- class ConsoleServerPortDetailTable(DeviceComponentDetailTable):
- class Meta(DeviceComponentDetailTable.Meta, ConsoleServerPortTable.Meta):
- pass
- class PowerPortTable(BaseTable):
- name = tables.Column(order_by=('_name',))
- class Meta(BaseTable.Meta):
- model = PowerPort
- fields = ('name', 'label', 'type')
- class PowerPortDetailTable(DeviceComponentDetailTable):
- class Meta(DeviceComponentDetailTable.Meta, PowerPortTable.Meta):
- pass
- class PowerOutletTable(BaseTable):
- name = tables.Column(order_by=('_name',))
- class Meta(BaseTable.Meta):
- model = PowerOutlet
- fields = ('name', 'label', 'type', 'description')
- class PowerOutletDetailTable(DeviceComponentDetailTable):
- class Meta(DeviceComponentDetailTable.Meta, PowerOutletTable.Meta):
- pass
- class InterfaceTable(BaseTable):
- class Meta(BaseTable.Meta):
- model = Interface
- fields = ('name', 'label', 'type', 'lag', 'enabled', 'mgmt_only', 'description')
- class InterfaceDetailTable(DeviceComponentDetailTable):
- enabled = BooleanColumn()
- class Meta(DeviceComponentDetailTable.Meta, InterfaceTable.Meta):
- fields = ('pk', 'device', 'name', 'label', 'enabled', 'type', 'description', 'cable')
- sequence = ('pk', 'device', 'name', 'label', 'enabled', 'type', 'description', 'cable')
- class FrontPortTable(BaseTable):
- name = tables.Column(order_by=('_name',))
- class Meta(BaseTable.Meta):
- model = FrontPort
- fields = ('name', 'label', 'type', 'rear_port', 'rear_port_position', 'description')
- empty_text = "None"
- class FrontPortDetailTable(DeviceComponentDetailTable):
- class Meta(DeviceComponentDetailTable.Meta, FrontPortTable.Meta):
- pass
- class RearPortTable(BaseTable):
- name = tables.Column(order_by=('_name',))
- class Meta(BaseTable.Meta):
- model = RearPort
- fields = ('name', 'label', 'type', 'positions', 'description')
- empty_text = "None"
- class RearPortDetailTable(DeviceComponentDetailTable):
- class Meta(DeviceComponentDetailTable.Meta, RearPortTable.Meta):
- pass
- class DeviceBayTable(BaseTable):
- name = tables.Column(order_by=('_name',))
- class Meta(BaseTable.Meta):
- model = DeviceBay
- fields = ('name', 'label', 'description')
- class DeviceBayDetailTable(DeviceComponentDetailTable):
- installed_device = tables.LinkColumn()
- class Meta(DeviceBayTable.Meta):
- fields = ('pk', 'device', 'name', 'label', 'installed_device', 'description')
- sequence = ('pk', 'device', 'name', 'label', 'installed_device', 'description')
- exclude = ('cable',)
- class DeviceBayImportTable(BaseTable):
- device = tables.LinkColumn('dcim:device', args=[Accessor('device.pk')], verbose_name='Device')
- installed_device = tables.LinkColumn('dcim:device', args=[Accessor('installed_device.pk')], verbose_name='Installed Device')
- class Meta(BaseTable.Meta):
- model = DeviceBay
- fields = ('device', 'name', 'installed_device', 'description')
- empty_text = False
- #
- # Cables
- #
- class CableTable(BaseTable):
- pk = ToggleColumn()
- id = tables.LinkColumn(
- viewname='dcim:cable',
- args=[Accessor('pk')],
- verbose_name='ID'
- )
- termination_a_parent = tables.TemplateColumn(
- template_code=CABLE_TERMINATION_PARENT,
- accessor=Accessor('termination_a'),
- orderable=False,
- verbose_name='Side A'
- )
- termination_a = tables.LinkColumn(
- accessor=Accessor('termination_a'),
- orderable=False,
- verbose_name='Termination A'
- )
- termination_b_parent = tables.TemplateColumn(
- template_code=CABLE_TERMINATION_PARENT,
- accessor=Accessor('termination_b'),
- orderable=False,
- verbose_name='Side B'
- )
- termination_b = tables.LinkColumn(
- accessor=Accessor('termination_b'),
- orderable=False,
- verbose_name='Termination B'
- )
- status = tables.TemplateColumn(
- template_code=STATUS_LABEL
- )
- length = tables.TemplateColumn(
- template_code=CABLE_LENGTH,
- order_by='_abs_length'
- )
- color = ColorColumn()
- tags = TagColumn(
- url_name='dcim:cable_list'
- )
- class Meta(BaseTable.Meta):
- model = Cable
- fields = (
- 'pk', 'id', 'label', 'termination_a_parent', 'termination_a', 'termination_b_parent', 'termination_b',
- 'status', 'type', 'color', 'length', 'tags',
- )
- default_columns = (
- 'pk', 'id', 'label', 'termination_a_parent', 'termination_a', 'termination_b_parent', 'termination_b',
- 'status', 'type',
- )
- #
- # Device connections
- #
- class ConsoleConnectionTable(BaseTable):
- console_server = tables.LinkColumn(
- viewname='dcim:device',
- accessor=Accessor('connected_endpoint.device'),
- args=[Accessor('connected_endpoint.device.pk')],
- verbose_name='Console Server'
- )
- connected_endpoint = tables.Column(
- verbose_name='Port'
- )
- device = tables.LinkColumn(
- viewname='dcim:device',
- args=[Accessor('device.pk')]
- )
- name = tables.Column(
- verbose_name='Console Port'
- )
- class Meta(BaseTable.Meta):
- model = ConsolePort
- fields = ('console_server', 'connected_endpoint', 'device', 'name', 'connection_status')
- class PowerConnectionTable(BaseTable):
- pdu = tables.LinkColumn(
- viewname='dcim:device',
- accessor=Accessor('connected_endpoint.device'),
- args=[Accessor('connected_endpoint.device.pk')],
- order_by='_connected_poweroutlet__device',
- verbose_name='PDU'
- )
- outlet = tables.Column(
- accessor=Accessor('_connected_poweroutlet'),
- verbose_name='Outlet'
- )
- device = tables.LinkColumn(
- viewname='dcim:device',
- args=[Accessor('device.pk')]
- )
- name = tables.Column(
- verbose_name='Power Port'
- )
- class Meta(BaseTable.Meta):
- model = PowerPort
- fields = ('pdu', 'outlet', 'device', 'name', 'connection_status')
- class InterfaceConnectionTable(BaseTable):
- device_a = tables.LinkColumn(
- viewname='dcim:device',
- accessor=Accessor('device'),
- args=[Accessor('device.pk')],
- verbose_name='Device A'
- )
- interface_a = tables.LinkColumn(
- viewname='dcim:interface',
- accessor=Accessor('name'),
- args=[Accessor('pk')],
- verbose_name='Interface A'
- )
- device_b = tables.LinkColumn(
- viewname='dcim:device',
- accessor=Accessor('_connected_interface.device'),
- args=[Accessor('_connected_interface.device.pk')],
- verbose_name='Device B'
- )
- interface_b = tables.LinkColumn(
- viewname='dcim:interface',
- accessor=Accessor('_connected_interface'),
- args=[Accessor('_connected_interface.pk')],
- verbose_name='Interface B'
- )
- class Meta(BaseTable.Meta):
- model = Interface
- fields = (
- 'device_a', 'interface_a', 'device_b', 'interface_b', 'connection_status',
- )
- #
- # InventoryItems
- #
- class InventoryItemTable(BaseTable):
- pk = ToggleColumn()
- device = tables.LinkColumn(
- viewname='dcim:device_inventory',
- args=[Accessor('device.pk')]
- )
- manufacturer = tables.Column(
- accessor=Accessor('manufacturer')
- )
- discovered = BooleanColumn()
- class Meta(BaseTable.Meta):
- model = InventoryItem
- fields = (
- 'pk', 'device', 'name', 'manufacturer', 'part_id', 'serial', 'asset_tag', 'description', 'discovered'
- )
- default_columns = ('pk', 'device', 'name', 'manufacturer', 'part_id', 'serial', 'asset_tag')
- #
- # Virtual chassis
- #
- class VirtualChassisTable(BaseTable):
- pk = ToggleColumn()
- name = tables.Column(
- accessor=Accessor('master__name'),
- linkify=True
- )
- member_count = tables.Column(
- verbose_name='Members'
- )
- tags = TagColumn(
- url_name='dcim:virtualchassis_list'
- )
- class Meta(BaseTable.Meta):
- model = VirtualChassis
- fields = ('pk', 'name', 'domain', 'member_count', 'tags')
- default_columns = ('pk', 'name', 'domain', 'member_count')
- #
- # Power panels
- #
- class PowerPanelTable(BaseTable):
- pk = ToggleColumn()
- name = tables.LinkColumn()
- site = tables.LinkColumn(
- viewname='dcim:site',
- args=[Accessor('site.slug')]
- )
- powerfeed_count = tables.TemplateColumn(
- template_code=POWERPANEL_POWERFEED_COUNT,
- verbose_name='Feeds'
- )
- tags = TagColumn(
- url_name='dcim:powerpanel_list'
- )
- class Meta(BaseTable.Meta):
- model = PowerPanel
- fields = ('pk', 'name', 'site', 'rack_group', 'powerfeed_count', 'tags')
- default_columns = ('pk', 'name', 'site', 'rack_group', 'powerfeed_count')
- #
- # Power feeds
- #
- class PowerFeedTable(BaseTable):
- pk = ToggleColumn()
- name = tables.LinkColumn()
- power_panel = tables.LinkColumn(
- viewname='dcim:powerpanel',
- args=[Accessor('power_panel.pk')],
- )
- rack = tables.LinkColumn(
- viewname='dcim:rack',
- args=[Accessor('rack.pk')]
- )
- status = tables.TemplateColumn(
- template_code=STATUS_LABEL
- )
- type = tables.TemplateColumn(
- template_code=TYPE_LABEL
- )
- max_utilization = tables.TemplateColumn(
- template_code="{{ value }}%"
- )
- available_power = tables.Column(
- verbose_name='Available power (VA)'
- )
- tags = TagColumn(
- url_name='dcim:powerfeed_list'
- )
- class Meta(BaseTable.Meta):
- model = PowerFeed
- fields = (
- 'pk', 'name', 'power_panel', 'rack', 'status', 'type', 'supply', 'voltage', 'amperage', 'phase',
- 'max_utilization', 'available_power', 'tags',
- )
- default_columns = (
- 'pk', 'name', 'power_panel', 'rack', 'status', 'type', 'supply', 'voltage', 'amperage', 'phase',
- )
|