disk_show.html 24 KB

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