device.html 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. {% extends '_base.html' %}
  2. {% load static from staticfiles %}
  3. {% load render_table from django_tables2 %}
  4. {% load helpers %}
  5. {% block title %}{{ device }}{% endblock %}
  6. {% block content %}
  7. {% include 'dcim/inc/_device_header.html' with active_tab='info' %}
  8. <div class="row">
  9. <div class="col-md-6">
  10. <div class="panel panel-default">
  11. <div class="panel-heading">
  12. <strong>Device</strong>
  13. </div>
  14. <table class="table table-hover panel-body">
  15. <tr>
  16. <td>Tenant</td>
  17. <td>
  18. {% if device.tenant %}
  19. <a href="{{ device.tenant.get_absolute_url }}">{{ device.tenant }}</a>
  20. {% else %}
  21. <span class="text-muted">None</span>
  22. {% endif %}
  23. </td>
  24. </tr>
  25. <tr>
  26. <td>Site</td>
  27. <td>
  28. <a href="{% url 'dcim:site' slug=device.rack.site.slug %}">{{ device.rack.site }}</a>
  29. </td>
  30. </tr>
  31. <tr>
  32. <td>Rack</td>
  33. <td>
  34. <span><a href="{% url 'dcim:rack' pk=device.rack.pk %}">{{ device.rack.name }}</a>{% if device.rack.facility_id %} ({{ device.rack.facility_id }}){% endif %}</span>
  35. </td>
  36. </tr>
  37. <tr>
  38. <td>Position</td>
  39. <td>
  40. {% if device.parent_bay %}
  41. {% with device.parent_bay.device as parent %}
  42. <span>U{{ parent.position }} / {{ parent.get_face_display }}
  43. (<a href="{{ parent.get_absolute_url }}">{{ parent }}</a> - {{ device.parent_bay.name }})</span>
  44. {% endwith %}
  45. {% elif device.position %}
  46. <span>U{{ device.position }} / {{ device.get_face_display }}</span>
  47. {% elif device.device_type.u_height %}
  48. <span class="label label-warning">Not racked</span>
  49. {% else %}
  50. <span class="text-muted">N/A</span>
  51. {% endif %}
  52. </td>
  53. </tr>
  54. <tr>
  55. <td>Device Type</td>
  56. <td>
  57. <span><a href="{% url 'dcim:devicetype' pk=device.device_type.pk %}">{{ device.device_type }}</a> ({{ device.device_type.u_height }}U)</span>
  58. </td>
  59. </tr>
  60. <tr>
  61. <td>Serial</td>
  62. <td>
  63. {% if device.serial %}
  64. <span>{{ device.serial }}</span>
  65. {% else %}
  66. <span class="text-muted">Not defined</span>
  67. {% endif %}
  68. </td>
  69. </tr>
  70. <tr>
  71. <td>Created</td>
  72. <td>{{ device.created }}</td>
  73. </tr>
  74. <tr>
  75. <td>Last Updated</td>
  76. <td>{{ device.last_updated }}</td>
  77. </tr>
  78. </table>
  79. </div>
  80. <div class="panel panel-default">
  81. <div class="panel-heading">
  82. <strong>Management</strong>
  83. </div>
  84. <table class="table table-hover panel-body">
  85. <tr>
  86. <td>Role</td>
  87. <td>
  88. <a href="{% url 'dcim:device_list' %}?role={{ device.device_role.slug }}">{{ device.device_role }}</a>
  89. </td>
  90. </tr>
  91. <tr>
  92. <td>Platform</td>
  93. <td>
  94. {% if device.platform %}
  95. <span>{{ device.platform }}</span>
  96. {% else %}
  97. <span class="text-warning">Not assigned</span>
  98. {% endif %}
  99. </td>
  100. </tr>
  101. <tr>
  102. <td>Status</td>
  103. <td>
  104. {% if device.status %}
  105. <span class="label label-success">{{ device.get_status_display }}</span>
  106. {% else %}
  107. <span class="label label-danger">{{ device.get_status_display }}</span>
  108. {% endif %}
  109. </td>
  110. </tr>
  111. <tr>
  112. <td>Primary IPv4</td>
  113. <td>
  114. {% if device.primary_ip4 %}
  115. <a href="{% url 'ipam:ipaddress' pk=device.primary_ip4.pk %}">{{ device.primary_ip4.address.ip }}</a>
  116. {% if device.primary_ip4.nat_inside %}
  117. <span>(NAT for {{ device.primary_ip4.nat_inside.address.ip }})</span>
  118. {% elif device.primary_ip4.nat_outside %}
  119. <span>(NAT: {{ device.primary_ip4.nat_outside.address.ip }})</span>
  120. {% endif %}
  121. {% else %}
  122. <span class="text-muted">Not defined</span>
  123. {% endif %}
  124. </td>
  125. </tr>
  126. <tr>
  127. <td>Primary IPv6</td>
  128. <td>
  129. {% if device.primary_ip6 %}
  130. <a href="{% url 'ipam:ipaddress' pk=device.primary_ip6.pk %}">{{ device.primary_ip6.address.ip }}</a>
  131. {% if device.primary_ip6.nat_inside %}
  132. <span>(NAT for {{ device.primary_ip6.nat_inside.address.ip }})</span>
  133. {% elif device.primary_ip6.nat_outside %}
  134. <span>(NAT: {{ device.primary_ip6.nat_outside.address.ip }})</span>
  135. {% endif %}
  136. {% else %}
  137. <span class="text-muted">Not defined</span>
  138. {% endif %}
  139. </td>
  140. </tr>
  141. </table>
  142. </div>
  143. {% if request.user.is_authenticated %}
  144. <div class="panel panel-default">
  145. <div class="panel-heading">
  146. <strong>Secrets</strong>
  147. </div>
  148. {% if secrets %}
  149. <table class="table table-hover panel-body">
  150. {% for secret in secrets %}
  151. {% include 'secrets/inc/secret_tr.html' %}
  152. {% endfor %}
  153. </table>
  154. {% else %}
  155. <div class="panel-body text-muted">
  156. None found
  157. </div>
  158. {% endif %}
  159. {% if perms.secrets.add_secret %}
  160. <form id="secret_form">
  161. {% csrf_token %}
  162. </form>
  163. <div class="panel-footer text-right">
  164. <a href="{% url 'dcim:device_addsecret' pk=device.pk %}" class="btn btn-xs btn-primary">
  165. <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
  166. Add secret
  167. </a>
  168. </div>
  169. {% endif %}
  170. </div>
  171. {% endif %}
  172. <div class="panel panel-default">
  173. <div class="panel-heading">
  174. <strong>IP Addresses</strong>
  175. </div>
  176. {% if ip_addresses %}
  177. <table class="table table-hover panel-body">
  178. {% for ip in ip_addresses %}
  179. {% include 'dcim/inc/_ipaddress.html' %}
  180. {% endfor %}
  181. </table>
  182. {% else %}
  183. <div class="panel-body text-muted">
  184. None found
  185. </div>
  186. {% endif %}
  187. {% if perms.ipam.add_ipaddress %}
  188. <div class="panel-footer text-right">
  189. <a href="{% url 'dcim:ipaddress_assign' pk=device.pk %}" class="btn btn-xs btn-primary">
  190. <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
  191. Assign IP address
  192. </a>
  193. </div>
  194. {% endif %}
  195. </div>
  196. <div class="panel panel-default">
  197. <div class="panel-heading">
  198. <strong>Critical Connections</strong>
  199. </div>
  200. <table class="table table-hover panel-body">
  201. {% for iface in mgmt_interfaces %}
  202. {% include 'dcim/inc/_interface.html' with icon='wrench' %}
  203. {% empty %}
  204. <tr>
  205. <td colspan="5" class="alert-warning">
  206. <i class="fa fa-fw fa-warning"></i> No management interfaces defined!
  207. {% if perms.dcim.add_interface %}
  208. <a href="{% url 'dcim:interface_add' pk=device.pk %}?mgmt_only=1" class="btn btn-primary btn-xs pull-right"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></a>
  209. {% endif %}
  210. </td>
  211. </tr>
  212. {% endfor %}
  213. {% for cp in console_ports %}
  214. {% include 'dcim/inc/_consoleport.html' %}
  215. {% empty %}
  216. <tr>
  217. <td colspan="5" class="alert-warning">
  218. <i class="fa fa-fw fa-warning"></i> No console ports defined!
  219. {% if perms.dcim.add_consoleport %}
  220. <a href="{% url 'dcim:consoleport_add' pk=device.pk %}" class="btn btn-primary btn-xs pull-right"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></a>
  221. {% endif %}
  222. </td>
  223. </tr>
  224. {% endfor %}
  225. {% for pp in power_ports %}
  226. {% include 'dcim/inc/_powerport.html' %}
  227. {% empty %}
  228. {% if not device.device_type.is_pdu %}
  229. <tr>
  230. <td colspan="5" class="alert-warning">
  231. <i class="fa fa-fw fa-warning"></i> No power ports defined!
  232. {% if perms.dcim.add_powerport %}
  233. <a href="{% url 'dcim:powerport_add' pk=device.pk %}" class="btn btn-primary btn-xs pull-right"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></a>
  234. {% endif %}
  235. </td>
  236. </tr>
  237. {% endif %}
  238. {% endfor %}
  239. </table>
  240. {% if perms.dcim.add_interface or perms.dcim.add_consoleport or perms.dcim.add_powerport %}
  241. <div class="panel-footer text-right">
  242. {% if perms.dcim.add_interface %}
  243. <a href="{% url 'dcim:interface_add' pk=device.pk %}?mgmt_only=1" class="btn btn-xs btn-primary">
  244. <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
  245. Add interface
  246. </a>
  247. {% endif %}
  248. {% if perms.dcim.add_consoleport %}
  249. <a href="{% url 'dcim:consoleport_add' pk=device.pk %}" class="btn btn-xs btn-primary">
  250. <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
  251. Add console
  252. </a>
  253. {% endif %}
  254. {% if perms.dcim.add_powerport and not device.device_type.is_pdu %}
  255. <a href="{% url 'dcim:powerport_add' pk=device.pk %}" class="btn btn-xs btn-primary">
  256. <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
  257. Add power
  258. </a>
  259. {% endif %}
  260. </div>
  261. {% endif %}
  262. </div>
  263. <div class="panel panel-default">
  264. <div class="panel-heading">
  265. <strong>Comments</strong>
  266. </div>
  267. <div class="panel-body">
  268. {% if device.comments %}
  269. {{ device.comments|gfm }}
  270. {% else %}
  271. <span class="text-muted">None</span>
  272. {% endif %}
  273. </div>
  274. </div>
  275. <div class="panel panel-default">
  276. <div class="panel-heading">
  277. <strong>Related Devices</strong>
  278. </div>
  279. {% if related_devices %}
  280. <table class="table table-hover panel-body">
  281. {% for rd in related_devices %}
  282. <tr>
  283. <td>
  284. <a href="{% url 'dcim:device' pk=rd.pk %}">{{ rd }}</a>
  285. </td>
  286. <td>
  287. <a href="{% url 'dcim:rack' pk=rd.rack.pk %}">Rack {{ rd.rack }}</a>
  288. </td>
  289. <td>{{ rd.device_type }}</td>
  290. </tr>
  291. {% endfor %}
  292. </table>
  293. {% else %}
  294. <div class="panel-body text-muted">None found</div>
  295. {% endif %}
  296. </div>
  297. </div>
  298. <div class="col-md-6">
  299. {% if device_bays or device.device_type.is_parent_device %}
  300. {% if perms.dcim.delete_devicebay %}
  301. <form method="post" action="{% url 'dcim:devicebay_bulk_delete' pk=device.pk %}">
  302. {% csrf_token %}
  303. {% endif %}
  304. <div class="panel panel-default">
  305. <div class="panel-heading">
  306. <strong>Device Bays</strong>
  307. </div>
  308. <table class="table table-hover panel-body">
  309. {% for devicebay in device_bays %}
  310. {% include 'dcim/inc/_devicebay.html' with selectable=True %}
  311. {% empty %}
  312. <tr>
  313. <td colspan="4">No device bays defined</td>
  314. </tr>
  315. {% endfor %}
  316. </table>
  317. {% if perms.dcim.add_devicebay or perms.dcim.delete_devicebay %}
  318. <div class="panel-footer">
  319. <div class="row">
  320. <div class="col-md-6">
  321. {% if device_bays and perms.dcim.delete_devicebay %}
  322. <button type="submit" class="btn btn-xs btn-danger">
  323. <span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete Selected
  324. </button>
  325. {% endif %}
  326. </div>
  327. <div class="col-md-6 text-right">
  328. {% if perms.dcim.add_devicebay %}
  329. <a href="{% url 'dcim:devicebay_add' pk=device.pk %}" class="btn btn-primary btn-xs">
  330. <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
  331. Add device bay
  332. </a>
  333. {% endif %}
  334. </div>
  335. </div>
  336. </div>
  337. {% endif %}
  338. </div>
  339. {% if perms.dcim.delete_devicebay %}
  340. </form>
  341. {% endif %}
  342. {% endif %}
  343. {% if interfaces or device.device_type.is_network_device %}
  344. {% if perms.dcim.delete_interface %}
  345. <form method="post" action="{% url 'dcim:interface_bulk_delete' pk=device.pk %}">
  346. {% csrf_token %}
  347. {% endif %}
  348. <div class="panel panel-default">
  349. <div class="panel-heading">
  350. <strong>Interfaces</strong>
  351. </div>
  352. <table class="table table-hover panel-body">
  353. {% for iface in interfaces %}
  354. {% include 'dcim/inc/_interface.html' with selectable=True %}
  355. {% empty %}
  356. <tr>
  357. <td colspan="4">No interfaces defined</td>
  358. </tr>
  359. {% endfor %}
  360. </table>
  361. {% if perms.dcim.add_interface or perms.dcim.delete_interface %}
  362. <div class="panel-footer">
  363. <div class="row">
  364. <div class="col-md-6">
  365. {% if interfaces and perms.dcim.delete_interface %}
  366. <button type="submit" class="btn btn-xs btn-danger">
  367. <span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete Selected
  368. </button>
  369. {% endif %}
  370. </div>
  371. <div class="col-md-6 text-right">
  372. {% if perms.dcim.add_interface %}
  373. <a href="{% url 'dcim:interface_add' pk=device.pk %}" class="btn btn-primary btn-xs">
  374. <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
  375. Add interface
  376. </a>
  377. {% endif %}
  378. </div>
  379. </div>
  380. </div>
  381. {% endif %}
  382. </div>
  383. {% if perms.dcim.delete_interface %}
  384. </form>
  385. {% endif %}
  386. {% endif %}
  387. {% if cs_ports or device.device_type.is_console_server %}
  388. {% if perms.dcim.delete_consoleserverport %}
  389. <form method="post" action="{% url 'dcim:consoleserverport_bulk_delete' pk=device.pk %}">
  390. {% csrf_token %}
  391. {% endif %}
  392. <div class="panel panel-default">
  393. <div class="panel-heading">
  394. <strong>Console Server Ports</strong>
  395. </div>
  396. <table class="table table-hover panel-body">
  397. {% for csp in cs_ports %}
  398. {% include 'dcim/inc/_consoleserverport.html' with selectable=True %}
  399. {% empty %}
  400. <tr>
  401. <td colspan="4">No console server ports defined</td>
  402. </tr>
  403. {% endfor %}
  404. </table>
  405. {% if perms.dcim.add_consoleserverport or perms.dcim.delete_consoleserverport %}
  406. <div class="panel-footer">
  407. <div class="row">
  408. <div class="col-md-6">
  409. {% if cs_ports and perms.dcim.delete_consoleserverport %}
  410. <button type="submit" class="btn btn-xs btn-danger">
  411. <span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete Selected
  412. </button>
  413. {% endif %}
  414. </div>
  415. <div class="col-md-6 text-right">
  416. {% if perms.dcim.add_consoleserverport %}
  417. <a href="{% url 'dcim:consoleserverport_add' pk=device.pk %}" class="btn btn-primary btn-xs">
  418. <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
  419. Add console server ports
  420. </a>
  421. {% endif %}
  422. </div>
  423. </div>
  424. </div>
  425. {% endif %}
  426. </div>
  427. {% if perms.dcim.delete_consoleserverport %}
  428. </form>
  429. {% endif %}
  430. {% endif %}
  431. {% if power_outlets or device.device_type.is_pdu %}
  432. {% if perms.dcim.delete_poweroutlet %}
  433. <form method="post" action="{% url 'dcim:poweroutlet_bulk_delete' pk=device.pk %}">
  434. {% csrf_token %}
  435. {% endif %}
  436. <div class="panel panel-default">
  437. <div class="panel-heading">
  438. <strong>Power Outlets</strong>
  439. </div>
  440. <table class="table table-hover panel-body">
  441. {% for po in power_outlets %}
  442. {% include 'dcim/inc/_poweroutlet.html' with selectable=True %}
  443. {% empty %}
  444. <tr>
  445. <td colspan="4">No power outlets defined</td>
  446. </tr>
  447. {% endfor %}
  448. </table>
  449. {% if perms.dcim.add_poweroutlet or perms.dcim.delete_poweroutlet %}
  450. <div class="panel-footer">
  451. <div class="row">
  452. <div class="col-md-6">
  453. {% if power_outlets and perms.dcim.delete_poweroutlet %}
  454. <button type="submit" class="btn btn-xs btn-danger">
  455. <span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete Selected
  456. </button>
  457. {% endif %}
  458. </div>
  459. <div class="col-md-6 text-right">
  460. {% if perms.dcim.add_poweroutlet %}
  461. <a href="{% url 'dcim:poweroutlet_add' pk=device.pk %}" class="btn btn-primary btn-xs">
  462. <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
  463. Add power outlets
  464. </a>
  465. {% endif %}
  466. </div>
  467. </div>
  468. </div>
  469. {% endif %}
  470. </div>
  471. {% if perms.dcim.delete_poweroutlet %}
  472. </form>
  473. {% endif %}
  474. {% endif %}
  475. </div>
  476. </div>
  477. {% include 'inc/graphs_modal.html' %}
  478. {% include 'secrets/inc/private_key_modal.html' %}
  479. {% endblock %}
  480. {% block javascript %}
  481. <script type="text/javascript">
  482. function toggleConnection(elem, api_url) {
  483. if (elem.hasClass('connected')) {
  484. $.ajax({
  485. url: api_url + elem.attr('data') + "/",
  486. method: 'PATCH',
  487. dataType: 'json',
  488. beforeSend: function(xhr, settings) {
  489. xhr.setRequestHeader("X-CSRFToken", "{{ csrf_token }}");
  490. },
  491. data: {
  492. 'connection_status': 'False'
  493. },
  494. context: this,
  495. success: function() {
  496. elem.parents('tr').removeClass('success').addClass('info');
  497. elem.removeClass('connected btn-warning').addClass('btn-success');
  498. elem.attr('title', 'Mark connected');
  499. elem.children('i').removeClass('glyphicon glyphicon-ban-circle').addClass('fa fa-plug')
  500. }
  501. });
  502. } else {
  503. $.ajax({
  504. url: api_url + elem.attr('data') + "/",
  505. method: 'PATCH',
  506. dataType: 'json',
  507. beforeSend: function(xhr, settings) {
  508. xhr.setRequestHeader("X-CSRFToken", "{{ csrf_token }}");
  509. },
  510. data: {
  511. 'connection_status': 'True'
  512. },
  513. context: this,
  514. success: function() {
  515. elem.parents('tr').removeClass('info').addClass('success');
  516. elem.removeClass('btn-success').addClass('connected btn-warning');
  517. elem.attr('title', 'Mark disconnected');
  518. elem.children('i').removeClass('fa fa-plug').addClass('glyphicon glyphicon-ban-circle')
  519. }
  520. });
  521. }
  522. return false;
  523. }
  524. $(".consoleport-toggle").click(function() {
  525. return toggleConnection($(this), "/api/dcim/console-ports/");
  526. });
  527. $(".powerport-toggle").click(function() {
  528. return toggleConnection($(this), "/api/dcim/power-ports/");
  529. });
  530. $(".interface-toggle").click(function() {
  531. return toggleConnection($(this), "/api/dcim/interface-connections/");
  532. });
  533. </script>
  534. <script src="{% static 'js/graphs.js' %}"></script>
  535. <script src="{% static 'js/secrets.js' %}"></script>
  536. {% endblock %}