disk_show.html 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. {% extends "layout.html" %}
  2. {% block title %} Disk {% endblock %}
  3. {% block head %}
  4. {{ super() }}
  5. <style type="text/css">
  6. .table {
  7. font-size: 12px;
  8. border-width: 1px;
  9. line-height: 20px;
  10. }
  11. .table > thead > tr > th,
  12. .table > tfoot > tr > th {
  13. color: #999999;
  14. font-weight: normal;
  15. border-bottom: 0 solid #e1e6eb;
  16. background-color: #F5F6FA;
  17. }
  18. .table > tbody > tr > td {
  19. color: #424547;
  20. }
  21. .table-bordered > tbody > tr {
  22. padding-top: 10px;
  23. padding-bottom: 10px;
  24. height: 106px;
  25. }
  26. .table-bordered > thead > tr > th,
  27. .table-bordered > tbody > tr > th,
  28. .table-bordered > tfoot > tr > th,
  29. .table-bordered > thead > tr > td,
  30. .table-bordered > tbody > tr > td,
  31. .table-bordered > tfoot > tr > td {
  32. border-style: solid;
  33. border-width: 1px 0 0 0;
  34. }
  35. .btn,
  36. .form-control,
  37. .modal-content {
  38. border-radius: 0 !important;
  39. }
  40. .btn-shortcut {
  41. font-size: 12px !important;
  42. padding: 0 26px;
  43. }
  44. .show {
  45. display: inline-block !important;
  46. }
  47. .tr-selected td,
  48. .tr-selected {
  49. color: #000 !important;
  50. background: #fffdf4 !important;
  51. }
  52. </style>
  53. {% endblock head %}
  54. {% block content %}
  55. <script type="text/javascript">
  56. var page = 1;
  57. var page_size = 10;
  58. var keyword = '';
  59. var resource_path = window.location.pathname;
  60. var cur_url = resource_path;
  61. $(document).ready(function() {
  62. page_size = $('#page_size').val();
  63. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size;
  64. var last_ready = null;
  65. $('#content_search').keydown(function() {
  66. if (last_ready !== null) {
  67. clearTimeout(last_ready);
  68. }
  69. last_ready = setTimeout(function () {
  70. keyword = $('#content_search').val();
  71. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size;
  72. if (keyword.length > 0) {
  73. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size + '&keyword=' + keyword;
  74. }
  75. window.location.href=cur_url;
  76. }, 1000);
  77. });
  78. $('#page_size').change(function () {
  79. keyword = $('#content_search').val();
  80. page_size = $('#page_size').val();
  81. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size;
  82. if (keyword.length > 0) {
  83. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size + '&keyword=' + keyword;
  84. }
  85. window.location.href=cur_url;
  86. });
  87. $("thead").on('click', ".all_selector", function() {
  88. if ($("thead .all_selector").is(':checked')) {
  89. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', true);
  90. $(".all_selector").prop('checked', true);
  91. } else {
  92. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', false);
  93. $(".all_selector").prop('checked', false);
  94. }
  95. select_item_action();
  96. });
  97. $("tfoot").on('click', ".all_selector", function() {
  98. if ($("tfoot .all_selector").is(':checked')) {
  99. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', true);
  100. $(".all_selector").prop('checked', true);
  101. } else {
  102. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', false);
  103. $(".all_selector").prop('checked', false);
  104. }
  105. select_item_action();
  106. });
  107. $("tbody tr").on('click', "input[type='checkbox']", function() {
  108. select_item_action();
  109. });
  110. $('body').addClass('add-transition');
  111. $('.add-page-transition').on('click', function(){
  112. var transAttr = $(this).attr('data-transition');
  113. $('.add-transition').attr('class', 'add-transition');
  114. $('.add-transition').addClass(transAttr);
  115. });
  116. $('#edit_remark_modal').on('show.bs.modal', function (me) {
  117. $('#instance_uuid').val($(me.relatedTarget).parent().parent().find('div a')[0].text);
  118. $('#edit_remark').val($(me.relatedTarget).prev().text());
  119. });
  120. $('#mountable_guest').chosen({
  121. "search_contains": true
  122. });
  123. $('#mount_modal').on('show.bs.modal', function (me) {
  124. $.ajax({
  125. url : '/api/guests?page=1&page_size=10000',
  126. type : 'GET',
  127. contentType: "application/json; charset=utf-8",
  128. dataType: 'json',
  129. error : function() {
  130. },
  131. success : function(data, textStatus, xhr) {
  132. $('#mountable_guest').empty();
  133. $('#mountable_guest').append(
  134. $('<option>')
  135. );
  136. $.each(data.data, function(k, v) {
  137. $('#mountable_guest').append(
  138. $('<option>', {value: v['uuid'], text: v['label'] + '/' + v['remark']})
  139. );
  140. });
  141. $('#mountable_guest').trigger("chosen:updated");
  142. }
  143. });
  144. });
  145. });
  146. function refresh() {
  147. keyword = $('#content_search').val();
  148. page = $('#pagination li.active a').text();
  149. page_size = $('#page_size').val();
  150. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size;
  151. if (keyword.length > 0) {
  152. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size + '&keyword=' + keyword;
  153. }
  154. window.location.href=cur_url;
  155. }
  156. function row_onmouseover(me) {
  157. $(me).find(".edit_remark_trigger").css('display','inline-flex');
  158. }
  159. function row_onmouseout(me) {
  160. $(me).find(".edit_remark_trigger").css('display','none');
  161. }
  162. function remark_update(me) {
  163. var uuid = $('#instance_uuid').val();
  164. var remark = $('#edit_remark').val();
  165. $('#edit_remark_modal').modal('hide');
  166. $.ajax({
  167. url : '/api/disk/' + uuid,
  168. type : 'PATCH',
  169. contentType: "application/json; charset=utf-8",
  170. data : JSON.stringify({
  171. remark: remark
  172. }),
  173. error : function() {
  174. alter_danger('磁盘备注更新失败!');
  175. },
  176. success : function() {
  177. $('#disk_list tbody').find('td:contains(' + uuid + ')').find('p').text(remark);
  178. alter_success('磁盘备注更新成功!');
  179. }
  180. });
  181. }
  182. function get_selected_element(checked) {
  183. if (checked === null) {
  184. checked = true;
  185. }
  186. if (checked) {
  187. return $('tbody :checked');
  188. } else {
  189. return $('tbody input:not(:checked)');
  190. }
  191. }
  192. function highlight_selected_element() {
  193. var selected_element = get_selected_element(true);
  194. var no_selected_element = get_selected_element(false);
  195. selected_element.each(function(i, e) {
  196. $(e).parent().parent().toggleClass('tr-selected', true);
  197. });
  198. no_selected_element.each(function(i, e) {
  199. $(e).parent().parent().toggleClass('tr-selected', false);
  200. });
  201. }
  202. function shortcut_bar_enable() {
  203. var selected_element = get_selected_element(true);
  204. if (selected_element.length > 0) {
  205. $('.btn-shortcut').toggleClass('disabled', false);
  206. } else {
  207. $('.btn-shortcut').toggleClass('disabled', true);
  208. }
  209. }
  210. function select_item_action() {
  211. highlight_selected_element();
  212. shortcut_bar_enable();
  213. }
  214. function mount(uuid, disk_uuid) {
  215. $.ajax({
  216. url : '/api/guest/_attach_disk/' + uuid + '/' + disk_uuid,
  217. type : 'PUT',
  218. contentType: "application/json; charset=utf-8",
  219. error : function() {
  220. alter_danger('实例挂载指令发送失败!');
  221. },
  222. success : function() {
  223. alter_success('实例挂载指令发送成功!');
  224. }
  225. });
  226. }
  227. function unmount(disk_uuid) {
  228. $.ajax({
  229. url : '/api/guest/_detach_disk/' + disk_uuid,
  230. type : 'PUT',
  231. contentType: "application/json; charset=utf-8",
  232. error : function() {
  233. alter_danger('实例卸载指令发送失败!');
  234. },
  235. success : function() {
  236. alter_success('实例卸载指令发送成功!');
  237. }
  238. });
  239. }
  240. function resize(disk_uuid, size) {
  241. $.ajax({
  242. url : '/api/disk/_disk_resize/' + disk_uuid + '/' + size,
  243. type : 'PUT',
  244. contentType: "application/json; charset=utf-8",
  245. error : function() {
  246. alter_danger('实例扩容指令发送失败!');
  247. },
  248. success : function() {
  249. alter_success('实例扩容指令发送成功!');
  250. }
  251. });
  252. }
  253. function remove(disk_uuid) {
  254. $.ajax({
  255. url : '/api/disks/' + disk_uuid,
  256. type : 'DELETE',
  257. contentType: "application/json; charset=utf-8",
  258. error : function() {
  259. alter_danger('实例删除指令发送失败!');
  260. },
  261. success : function() {
  262. alter_success('实例删除指令发送成功!');
  263. }
  264. });
  265. }
  266. function mount_at(me) {
  267. var guest_uuid = $('#mountable_guest').val();
  268. var disk_uuid = $('#instance_uuid').val();
  269. mount(guest_uuid, disk_uuid);
  270. $('#mount_modal').modal('hide');
  271. }
  272. function unmount_at(me) {
  273. var disk_uuid = $($(me).parent().parent().parent().parent().parent().children()[1]).find('div a')[0].text;
  274. unmount(disk_uuid);
  275. }
  276. function resize_at(me) {
  277. var disk_uuid = $('#instance_uuid').val();
  278. var size = $('#size').val();
  279. resize(disk_uuid, size);
  280. $('#resize_modal').modal('hide');
  281. }
  282. function reset_resize_value(me) {
  283. var min = $(me).parent().parent().parent().parent().parent().children()[3].textContent.split(' ')[0];
  284. $(function() { "use strict";
  285. $("#size").TouchSpin({
  286. max: 10240,
  287. min: min,
  288. verticalbuttons: true,
  289. verticalupclass: 'glyph-icon icon-plus',
  290. verticaldownclass: 'glyph-icon icon-minus'
  291. });
  292. });
  293. }
  294. function delete_at(me) {
  295. var disk_uuid = $('#instance_uuid').val();
  296. remove(disk_uuid);
  297. $('#delete_modal').modal('hide');
  298. }
  299. </script>
  300. <div class="panel">
  301. <div class="panel-body">
  302. <h3 class="title-hero" style="font-size: 24px;">
  303. 磁盘实例
  304. </h3>
  305. <div>
  306. <div id="datatable-row-highlight_wrapper" class="dataTables_wrapper form-inline">
  307. <div class="row" style="padding: 10px 10px 10px 0; width: 100%;">
  308. <div class="col-sm-12" style="padding-right: 0;">
  309. <div id="datatable-row-highlight_filter" class="dataTables_filter" style="display: inline-block;">
  310. <input id="content_search" type="search" class="form-control" placeholder="模糊搜索..." value="{%- if keyword -%} {{ keyword }} {%- endif -%}" style="margin-left: 0; border-radius: 0;">
  311. </div>
  312. <div class="pull-right">
  313. <button class="btn btn-default" onclick="refresh()" style="border-radius: 0;"><span class="glyph-icon icon-elusive-arrows-cw"></span></button>
  314. <a class="btn btn-info add-page-transition" href="/disks/create" data-transition="pt-page-moveFromRight-init" style="border-radius: 0; padding-left: 40px; padding-right: 40px;">创建磁盘</a>
  315. </div>
  316. </div>
  317. </div>
  318. <table id="disk_list" class="table table-bordered table-hover" cellspacing="0" width="100%" role="grid"
  319. style="width: 100%; margin-bottom: 0; border-bottom-width: 0;">
  320. <thead>
  321. <tr role="row">
  322. <th><input class="all_selector" title="选取所有" type="checkbox"></th>
  323. <th width="280px;">UUID</th>
  324. <th>状态</th>
  325. <th>大小</th>
  326. <th>设备号</th>
  327. <th>所属 Guest</th>
  328. <th>创建时间</th>
  329. <th>操作</th>
  330. </tr>
  331. </thead>
  332. <tbody>
  333. {% for item in disks_ret.data %}
  334. <tr role="row" class="odd" onmouseover="row_onmouseover(this);" onmouseout="row_onmouseout(this);">
  335. <td><input title="选中" type="checkbox"></td>
  336. <td>
  337. <div>
  338. <a href="/disk/detail/{{ item.uuid }}">{{ item.uuid }}</a>
  339. </div>
  340. <div>
  341. <p style="display: inline-block;">{{ item.remark }}</p>
  342. <a href="javascript:;" class="edit_remark_trigger" data-toggle="modal" data-target="#edit_remark_modal" style="display: none; float: right;">
  343. <span class="glyph-icon icon-elusive-pencil" style="width: 20px; height: 20px; margin-left: 10px; border-radius: 0; border: 1px solid rgb(220, 233, 255); background-color: #ffffff;"></span>
  344. </a>
  345. </div>
  346. </td>
  347. <td>{{ format_disk_state(item.state)|safe }}</td>
  348. <td>{{ item.size }} GB</td>
  349. <td>{{ format_sequence_to_device_name(item.sequence) }}</td>
  350. <td><a href="/guest/detail/{{ item.guest_uuid }}" {% if 'guest' not in item %}style="display: none"{% endif %}>{% if 'guest' in item %}
  351. {{ item.guest.label }}/{{ item.guest.remark }}
  352. {% endif %}</a></td>
  353. <td>{{ format_datetime_by_tus(item.create_time) }}</td>
  354. <td>
  355. <div class="dropdown inline-block">
  356. <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown">
  357. 更多
  358. </a>
  359. <ul class="dropdown-menu">
  360. <li class="{% if item.state not in [1] %} disabled {% endif %}" style="{% if item.sequence == 0 %} display: none; {% endif %}">
  361. <a href="javascript:;" data-toggle="modal" data-target="#mount_modal"
  362. onclick="$('#instance_uuid').val($($(this).parent().parent().parent().parent().parent().children()[1]).find('div a')[0].text);">
  363. 挂载
  364. </a>
  365. </li>
  366. <li class="{% if item.sequence == 0 or item.state not in [2] %} disabled {% endif %}" style="{% if item.sequence == 0 %}display: none;{% endif %}">
  367. <a href="javascript:;" onclick="unmount_at(this);">卸载</a>
  368. </li>
  369. <li class="divider" style="{% if item.sequence == 0 %} display: none; {% endif %}"></li>
  370. <li class="{% if item.state not in [1, 2] %} disabled {% endif %}">
  371. <a href="javascript:;" data-toggle="modal" data-target="#resize_modal"
  372. onclick="$('#instance_uuid').val($($(this).parent().parent().parent().parent().parent().children()[1]).find('div a')[0].text);reset_resize_value(this);">
  373. 磁盘扩容
  374. </a>
  375. </li>
  376. <li class="divider" style="{% if item.sequence == 0 %} display: none; {% endif %}"></li>
  377. <li class="{% if item.state not in [1, 255] %} disabled {% endif %}" style="{% if item.sequence == 0 %} display: none; {% endif %}">
  378. <a href="javascript:;" data-toggle="modal" data-target="#delete_modal"
  379. onclick="$('#instance_uuid').val($($(this).parent().parent().parent().parent().parent().children()[1]).find('div a')[0].text);
  380. $('#delete_instance_desc').text($('#instance_uuid').val().split('-')[0] + '/' + $($(this).parent().parent().parent().parent().parent().children()[1]).find('div p')[0].textContent)">
  381. 删除
  382. </a>
  383. </li>
  384. </ul>
  385. </div>
  386. </td>
  387. </tr>
  388. {% endfor %}
  389. </tbody>
  390. </table>
  391. <table class="table table-bordered" style="border-top-width: 0; z-index: 99; position: sticky; bottom: 0;">
  392. <tfoot>
  393. <tr style="height: 70px;">
  394. <th><input type="checkbox" title="选取所有" class="all_selector"></th>
  395. <th>
  396. <div class="row">
  397. <div class="col-sm-6">
  398. <button class="btn btn-default btn-shortcut disabled" onclick="batch_boot();">备注</button>
  399. </div>
  400. <div class="col-sm-3" style="font-size: 12px; padding-top: 5px; text-align: right;">
  401. 共有{{ disks_ret.paging.total }}条,每页显示:
  402. <select id="page_size" name="datatable-row-highlight_length" title="page_size" class="form-control" style="height: 22px; vertical-align: baseline;">
  403. <option value="10" {% if page_size == 10 %} selected {% endif %}>10</option>
  404. <option value="20" {% if page_size == 20 %} selected {% endif %}>20</option>
  405. <option value="50" {% if page_size == 50 %} selected {% endif %}>50</option>
  406. </select>&nbsp;&nbsp;条
  407. </div>
  408. <div class="col-sm-3" style="text-align: left;">
  409. <div class="dataTables_paginate paging_bootstrap" id="datatable-row-highlight_paginate">
  410. <ul id="pagination" class="pagination">
  411. <li class="{% if page == 1 %} disabled {% endif %}">
  412. <a href="{{ resource_path }}?page={{ page - 1 }}&page_size={{ page_size }}{% if keyword %}&keyword={{ keyword }}{% endif %}{% if order_by %}&order_by={{ order_by }}{% endif %}{% if order %}&order={{ order }}{% endif %}">«</a>
  413. </li>
  414. {% for item in pages %}
  415. <li class="{% if item == page %} active {% endif %}">
  416. <a href="{{ resource_path }}?page={{ item }}&page_size={{ page_size }}{% if keyword %}&keyword={{ keyword }}{% endif %}{% if order_by %}&order_by={{ order_by }}{% endif %}{% if order %}&order={{ order }}{% endif %}">{{ item }}</a>
  417. </li>
  418. {% endfor %}
  419. <li class="{% if page == last_page %} disabled {% endif %}">
  420. <a href="{{ resource_path }}?page={{ page + 1 }}&page_size={{ page_size }}{% if keyword %}&keyword={{ keyword }}{% endif %}{% if order_by %}&order_by={{ order_by }}{% endif %}{% if order %}&order={{ order }}{% endif %}">»</a>
  421. </li>
  422. </ul>
  423. </div>
  424. </div>
  425. </div>
  426. </th>
  427. </tr>
  428. </tfoot>
  429. </table>
  430. </div>
  431. </div>
  432. </div>
  433. </div>
  434. <input id="instance_uuid" title="实例 UUID" class="form-control" name="uuid" hidden>
  435. <div class="modal" id="edit_remark_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  436. <div class="modal-dialog modal-sm">
  437. <div class="modal-content">
  438. <div class="modal-header">
  439. <h4 class="modal-title">编辑实例名称:</h4>
  440. </div>
  441. <div class="modal-body">
  442. <input id="edit_remark" title="实例名称" class="form-control" name="remark">
  443. </div>
  444. <div class="modal-footer">
  445. <button type="button" class="btn btn-sm btn-primary" onclick="remark_update();">确定</button>
  446. <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">取消</button>
  447. </div>
  448. </div>
  449. </div>
  450. </div>
  451. <div class="modal" id="mount_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  452. <div class="modal-dialog modal-sm">
  453. <div class="modal-content">
  454. <div class="modal-header">
  455. <h4 class="modal-title">挂载至:</h4>
  456. </div>
  457. <div class="modal-body">
  458. <select id="mountable_guest" name="mountable_host" title="可被挂载的 Guest" class="chosen-select" data-placeholder="挂载至 ...">
  459. <option></option>
  460. </select>
  461. </div>
  462. <div class="modal-footer">
  463. <button type="button" class="btn btn-sm btn-primary" onclick="mount_at();">确定</button>
  464. <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">取消</button>
  465. </div>
  466. </div>
  467. </div>
  468. </div>
  469. <div class="modal" id="resize_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  470. <div class="modal-dialog modal-sm">
  471. <div class="modal-content">
  472. <div class="modal-header">
  473. <h4 class="modal-title">磁盘扩容:</h4>
  474. </div>
  475. <div class="modal-body">
  476. <div class="form-group">
  477. <input id="size" title="磁盘大小" class="form-control" type="text" value="100" name="size">
  478. </div>
  479. </div>
  480. <div class="modal-footer">
  481. <button type="button" class="btn btn-sm btn-primary" onclick="resize_at();">确定</button>
  482. <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">取消</button>
  483. </div>
  484. </div>
  485. </div>
  486. </div>
  487. <div class="modal" id="delete_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  488. <div class="modal-dialog">
  489. <div class="modal-content">
  490. <div class="modal-header">
  491. <h4 class="modal-title">删除磁盘:</h4>
  492. </div>
  493. <div class="modal-body">
  494. <p>删除的磁盘将无法找回,上面数据将永久消失。你确定要删除该磁盘吗?</p>
  495. <h3 style="color: orangered;" id="delete_instance_desc"></h3>
  496. </div>
  497. <div class="modal-footer">
  498. <button type="button" class="btn btn-sm btn-primary" onclick="delete_at();">确定</button>
  499. <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">取消</button>
  500. </div>
  501. </div>
  502. </div>
  503. </div>
  504. {% endblock content %}