disk_show.html 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  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 show_area = '';
  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. $('#show_area').on('changed.bs.select', function (me) {
  146. $('#content_search').val('');
  147. refresh();
  148. });
  149. });
  150. function refresh() {
  151. keyword = $('#content_search').val();
  152. page = $('#pagination li.active a').text();
  153. page_size = $('#page_size').val();
  154. show_area = $('#show_area').val();
  155. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size;
  156. if (keyword.length > 0) {
  157. cur_url += '&keyword=' + keyword;
  158. }
  159. if (show_area.length > 0) {
  160. cur_url += '&show_area=' + show_area;
  161. }
  162. window.location.href=cur_url;
  163. }
  164. function row_onmouseover(me) {
  165. $(me).find(".edit_remark_trigger").css('display','inline-flex');
  166. }
  167. function row_onmouseout(me) {
  168. $(me).find(".edit_remark_trigger").css('display','none');
  169. }
  170. function remark_update(me) {
  171. var uuid = $('#instance_uuid').val();
  172. var remark = $('#edit_remark').val();
  173. $('#edit_remark_modal').modal('hide');
  174. $.ajax({
  175. url : '/api/disk/' + uuid,
  176. type : 'PATCH',
  177. contentType: "application/json; charset=utf-8",
  178. data : JSON.stringify({
  179. remark: remark
  180. }),
  181. error : function() {
  182. alter_danger('磁盘备注更新失败!');
  183. },
  184. success : function() {
  185. $('#disk_list tbody').find('td:contains(' + uuid + ')').find('p').text(remark);
  186. alter_success('磁盘备注更新成功!');
  187. }
  188. });
  189. }
  190. function get_selected_element(checked) {
  191. if (checked === null) {
  192. checked = true;
  193. }
  194. if (checked) {
  195. return $('tbody :checked');
  196. } else {
  197. return $('tbody input:not(:checked)');
  198. }
  199. }
  200. function highlight_selected_element() {
  201. var selected_element = get_selected_element(true);
  202. var no_selected_element = get_selected_element(false);
  203. selected_element.each(function(i, e) {
  204. $(e).parent().parent().toggleClass('tr-selected', true);
  205. });
  206. no_selected_element.each(function(i, e) {
  207. $(e).parent().parent().toggleClass('tr-selected', false);
  208. });
  209. }
  210. function shortcut_bar_enable() {
  211. var selected_element = get_selected_element(true);
  212. if (selected_element.length > 0) {
  213. $('.btn-shortcut').toggleClass('disabled', false);
  214. } else {
  215. $('.btn-shortcut').toggleClass('disabled', true);
  216. }
  217. }
  218. function select_item_action() {
  219. highlight_selected_element();
  220. shortcut_bar_enable();
  221. }
  222. function mount(uuid, disk_uuid) {
  223. $.ajax({
  224. url : '/api/guest/_attach_disk/' + uuid + '/' + disk_uuid,
  225. type : 'PUT',
  226. contentType: "application/json; charset=utf-8",
  227. error : function() {
  228. alter_danger('实例挂载指令发送失败!');
  229. },
  230. success : function() {
  231. alter_success('实例挂载指令发送成功!');
  232. }
  233. });
  234. }
  235. function unmount(disk_uuid) {
  236. $.ajax({
  237. url : '/api/guest/_detach_disk/' + disk_uuid,
  238. type : 'PUT',
  239. contentType: "application/json; charset=utf-8",
  240. error : function() {
  241. alter_danger('实例卸载指令发送失败!');
  242. },
  243. success : function() {
  244. alter_success('实例卸载指令发送成功!');
  245. }
  246. });
  247. }
  248. function resize(disk_uuid, size) {
  249. $.ajax({
  250. url : '/api/disk/_disk_resize/' + disk_uuid + '/' + size,
  251. type : 'PUT',
  252. contentType: "application/json; charset=utf-8",
  253. error : function() {
  254. alter_danger('实例扩容指令发送失败!');
  255. },
  256. success : function() {
  257. alter_success('实例扩容指令发送成功!');
  258. }
  259. });
  260. }
  261. function remove(disk_uuid) {
  262. $.ajax({
  263. url : '/api/disks/' + disk_uuid,
  264. type : 'DELETE',
  265. contentType: "application/json; charset=utf-8",
  266. error : function() {
  267. alter_danger('实例删除指令发送失败!');
  268. },
  269. success : function() {
  270. alter_success('实例删除指令发送成功!');
  271. }
  272. });
  273. }
  274. function mount_at(me) {
  275. var guest_uuid = $('#mountable_guest').val();
  276. var disk_uuid = $('#instance_uuid').val();
  277. mount(guest_uuid, disk_uuid);
  278. $('#mount_modal').modal('hide');
  279. }
  280. function unmount_at(me) {
  281. var disk_uuid = $($(me).parent().parent().parent().parent().parent().children()[1]).find('div a')[0].text;
  282. unmount(disk_uuid);
  283. }
  284. function resize_at(me) {
  285. var disk_uuid = $('#instance_uuid').val();
  286. var size = $('#size').val();
  287. resize(disk_uuid, size);
  288. $('#resize_modal').modal('hide');
  289. }
  290. function reset_resize_value(me) {
  291. var min = $(me).parent().parent().parent().parent().parent().children()[3].textContent.split(' ')[0];
  292. $(function() { "use strict";
  293. $("#size").TouchSpin({
  294. max: 10240,
  295. min: min,
  296. verticalbuttons: true,
  297. verticalupclass: 'glyph-icon icon-plus',
  298. verticaldownclass: 'glyph-icon icon-minus'
  299. });
  300. });
  301. }
  302. function delete_at(me) {
  303. var disk_uuid = $('#instance_uuid').val();
  304. remove(disk_uuid);
  305. $('#delete_modal').modal('hide');
  306. }
  307. </script>
  308. <div class="panel">
  309. <div class="panel-body">
  310. <h3 class="title-hero" style="font-size: 24px;">
  311. 磁盘实例
  312. </h3>
  313. <div>
  314. <div id="datatable-row-highlight_wrapper" class="dataTables_wrapper form-inline">
  315. <div class="row" style="padding: 10px 10px 10px 0; width: 100%;">
  316. <div class="col-sm-12" style="padding-right: 0;">
  317. <div id="datatable-row-highlight_filter" class="dataTables_filter" style="display: inline-block;">
  318. <input id="content_search" type="search" class="form-control" placeholder="模糊搜索..." value="{%- if keyword -%} {{ keyword }} {%- endif -%}" style="margin-left: 0; border-radius: 0;">
  319. <select id="show_area" name="show_area" title="显示域" class="selectpicker">
  320. <option value="unmount" data-subtext="显示所有未挂载的磁盘" {% if show_area == 'unmount' %} selected {% endif %}>未挂载</option>
  321. <option value="data_disk" data-subtext="显示所有数据盘" {% if show_area == 'data_disk' %} selected {% endif %}>数据盘</option>
  322. <option value="all" data-subtext="显示所有磁盘,包含系统盘" {% if show_area == 'all' %} selected {% endif %}>ALL</option>
  323. </select>
  324. </div>
  325. <div class="pull-right">
  326. <button class="btn btn-default" onclick="refresh()" style="border-radius: 0;"><span class="glyph-icon icon-elusive-arrows-cw"></span></button>
  327. <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>
  328. </div>
  329. </div>
  330. </div>
  331. <table id="disk_list" class="table table-bordered table-hover" cellspacing="0" width="100%" role="grid"
  332. style="width: 100%; margin-bottom: 0; border-bottom-width: 0;">
  333. <thead>
  334. <tr role="row">
  335. <th><input class="all_selector" title="选取所有" type="checkbox"></th>
  336. <th width="280px;">UUID</th>
  337. <th>状态</th>
  338. <th>大小</th>
  339. <th>设备号</th>
  340. <th>所属 Guest</th>
  341. <th>磁盘性别</th>
  342. <th>创建时间</th>
  343. <th>操作</th>
  344. </tr>
  345. </thead>
  346. <tbody>
  347. {% for item in disks_ret.data %}
  348. <tr role="row" class="odd" onmouseover="row_onmouseover(this);" onmouseout="row_onmouseout(this);">
  349. <td><input title="选中" type="checkbox"></td>
  350. <td>
  351. <div>
  352. <a href="/disk/detail/{{ item.uuid }}">{{ item.uuid }}</a>
  353. </div>
  354. <div>
  355. <p style="display: inline-block;">{{ item.remark }}</p>
  356. <a href="javascript:;" class="edit_remark_trigger" data-toggle="modal" data-target="#edit_remark_modal" style="display: none; float: right;">
  357. <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>
  358. </a>
  359. </div>
  360. </td>
  361. <td>{{ format_disk_state(item.state)|safe }}</td>
  362. <td>{{ item.size }} GB</td>
  363. <td>{{ format_sequence_to_device_name(item.sequence) }}</td>
  364. <td><a href="/guest/detail/{{ item.guest_uuid }}" {% if 'guest' not in item %}style="display: none"{% endif %}>{% if 'guest' in item %}
  365. {{ item.guest.label }}/{{ item.guest.remark }}
  366. {% endif %}</a></td>
  367. <td>
  368. {% if item.sequence == 0 %}
  369. 系统盘
  370. {% else %}
  371. 数据盘
  372. {% endif %}
  373. </td>
  374. <td>{{ format_datetime_by_tus(item.create_time) }}</td>
  375. <td>
  376. <div class="dropdown inline-block">
  377. <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown">
  378. 更多
  379. </a>
  380. <ul class="dropdown-menu">
  381. <li class="{% if item.state not in [1] %} disabled {% endif %}" style="{% if item.sequence == 0 %} display: none; {% endif %}">
  382. <a href="javascript:;" data-toggle="modal" data-target="#mount_modal"
  383. onclick="$('#instance_uuid').val($($(this).parent().parent().parent().parent().parent().children()[1]).find('div a')[0].text);">
  384. 挂载
  385. </a>
  386. </li>
  387. <li class="{% if item.sequence == 0 or item.state not in [2] %} disabled {% endif %}" style="{% if item.sequence == 0 %}display: none;{% endif %}">
  388. <a href="javascript:;" onclick="unmount_at(this);">卸载</a>
  389. </li>
  390. <li class="divider" style="{% if item.sequence == 0 %} display: none; {% endif %}"></li>
  391. <li class="{% if item.state not in [1, 2] %} disabled {% endif %}">
  392. <a href="javascript:;" data-toggle="modal" data-target="#resize_modal"
  393. onclick="$('#instance_uuid').val($($(this).parent().parent().parent().parent().parent().children()[1]).find('div a')[0].text);reset_resize_value(this);">
  394. 磁盘扩容
  395. </a>
  396. </li>
  397. <li class="divider" style="{% if item.sequence == 0 %} display: none; {% endif %}"></li>
  398. <li class="{% if item.state not in [1, 255] %} disabled {% endif %}" style="{% if item.sequence == 0 %} display: none; {% endif %}">
  399. <a href="javascript:;" data-toggle="modal" data-target="#delete_modal"
  400. onclick="$('#instance_uuid').val($($(this).parent().parent().parent().parent().parent().children()[1]).find('div a')[0].text);
  401. $('#delete_instance_desc').text($('#instance_uuid').val().split('-')[0] + '/' + $($(this).parent().parent().parent().parent().parent().children()[1]).find('div p')[0].textContent)">
  402. 删除
  403. </a>
  404. </li>
  405. </ul>
  406. </div>
  407. </td>
  408. </tr>
  409. {% endfor %}
  410. </tbody>
  411. </table>
  412. <table class="table table-bordered" style="border-top-width: 0; z-index: 99; position: sticky; bottom: 0;">
  413. <tfoot>
  414. <tr style="height: 70px;">
  415. <th><input type="checkbox" title="选取所有" class="all_selector"></th>
  416. <th>
  417. <div class="row">
  418. <div class="col-sm-6">
  419. <button class="btn btn-default btn-shortcut disabled" onclick="batch_boot();">备注</button>
  420. </div>
  421. <div class="col-sm-3" style="font-size: 12px; padding-top: 5px; text-align: right;">
  422. 共有{{ disks_ret.paging.total }}条,每页显示:
  423. <select id="page_size" name="datatable-row-highlight_length" title="page_size" class="form-control" style="height: 22px; vertical-align: baseline;">
  424. <option value="10" {% if page_size == 10 %} selected {% endif %}>10</option>
  425. <option value="20" {% if page_size == 20 %} selected {% endif %}>20</option>
  426. <option value="50" {% if page_size == 50 %} selected {% endif %}>50</option>
  427. </select>&nbsp;&nbsp;条
  428. </div>
  429. <div class="col-sm-3" style="text-align: left;">
  430. <div class="dataTables_paginate paging_bootstrap" id="datatable-row-highlight_paginate">
  431. <ul id="pagination" class="pagination">
  432. <li class="{% if page == 1 %} disabled {% endif %}">
  433. <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>
  434. </li>
  435. {% for item in pages %}
  436. <li class="{% if item == page %} active {% endif %}">
  437. <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>
  438. </li>
  439. {% endfor %}
  440. <li class="{% if page == last_page %} disabled {% endif %}">
  441. <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>
  442. </li>
  443. </ul>
  444. </div>
  445. </div>
  446. </div>
  447. </th>
  448. </tr>
  449. </tfoot>
  450. </table>
  451. </div>
  452. </div>
  453. </div>
  454. </div>
  455. <input id="instance_uuid" title="实例 UUID" class="form-control" name="uuid" hidden>
  456. <div class="modal" id="edit_remark_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  457. <div class="modal-dialog modal-sm">
  458. <div class="modal-content">
  459. <div class="modal-header">
  460. <h4 class="modal-title">编辑实例名称:</h4>
  461. </div>
  462. <div class="modal-body">
  463. <input id="edit_remark" title="实例名称" class="form-control" name="remark">
  464. </div>
  465. <div class="modal-footer">
  466. <button type="button" class="btn btn-sm btn-primary" onclick="remark_update();">确定</button>
  467. <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">取消</button>
  468. </div>
  469. </div>
  470. </div>
  471. </div>
  472. <div class="modal" id="mount_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  473. <div class="modal-dialog modal-sm">
  474. <div class="modal-content">
  475. <div class="modal-header">
  476. <h4 class="modal-title">挂载至:</h4>
  477. </div>
  478. <div class="modal-body">
  479. <select id="mountable_guest" name="mountable_host" title="可被挂载的 Guest" class="chosen-select" data-placeholder="挂载至 ...">
  480. <option></option>
  481. </select>
  482. </div>
  483. <div class="modal-footer">
  484. <button type="button" class="btn btn-sm btn-primary" onclick="mount_at();">确定</button>
  485. <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">取消</button>
  486. </div>
  487. </div>
  488. </div>
  489. </div>
  490. <div class="modal" id="resize_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  491. <div class="modal-dialog modal-sm">
  492. <div class="modal-content">
  493. <div class="modal-header">
  494. <h4 class="modal-title">磁盘扩容:</h4>
  495. </div>
  496. <div class="modal-body">
  497. <div class="form-group">
  498. <input id="size" title="磁盘大小" class="form-control" type="text" value="100" name="size">
  499. </div>
  500. </div>
  501. <div class="modal-footer">
  502. <button type="button" class="btn btn-sm btn-primary" onclick="resize_at();">确定</button>
  503. <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">取消</button>
  504. </div>
  505. </div>
  506. </div>
  507. </div>
  508. <div class="modal" id="delete_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  509. <div class="modal-dialog">
  510. <div class="modal-content">
  511. <div class="modal-header">
  512. <h4 class="modal-title">删除磁盘:</h4>
  513. </div>
  514. <div class="modal-body">
  515. <p>删除的磁盘将无法找回,上面数据将永久消失。你确定要删除该磁盘吗?</p>
  516. <h3 style="color: orangered;" id="delete_instance_desc"></h3>
  517. </div>
  518. <div class="modal-footer">
  519. <button type="button" class="btn btn-sm btn-primary" onclick="delete_at();">确定</button>
  520. <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">取消</button>
  521. </div>
  522. </div>
  523. </div>
  524. </div>
  525. {% endblock content %}