guests_boot_jobs.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  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. }
  24. .table-bordered > thead > tr > th,
  25. .table-bordered > tbody > tr > th,
  26. .table-bordered > tfoot > tr > th,
  27. .table-bordered > thead > tr > td,
  28. .table-bordered > tbody > tr > td,
  29. .table-bordered > tfoot > tr > td {
  30. border-style: solid;
  31. border-width: 1px 0 0 0;
  32. }
  33. .btn,
  34. .form-control,
  35. .modal-content {
  36. border-radius: 0 !important;
  37. }
  38. .tr-selected td,
  39. .tr-selected {
  40. color: #000 !important;
  41. background: #fffdf4 !important;
  42. }
  43. </style>
  44. {% endblock head %}
  45. {% block content %}
  46. <script type="text/javascript">
  47. var page = 1;
  48. var page_size = 10;
  49. var keyword = '';
  50. var resource_path = window.location.pathname;
  51. var cur_url = resource_path;
  52. $(document).ready(function() {
  53. page_size = $('#page_size').val();
  54. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size;
  55. var last_ready = null;
  56. $('#content_search').keydown(function() {
  57. if (last_ready !== null) {
  58. clearTimeout(last_ready);
  59. }
  60. last_ready = setTimeout(function () {
  61. keyword = $('#content_search').val();
  62. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size;
  63. if (keyword.length > 0) {
  64. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size + '&keyword=' + keyword;
  65. }
  66. window.location.href=cur_url;
  67. }, 1000);
  68. });
  69. $('#page_size').change(function () {
  70. keyword = $('#content_search').val();
  71. page_size = $('#page_size').val();
  72. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size;
  73. if (keyword.length > 0) {
  74. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size + '&keyword=' + keyword;
  75. }
  76. window.location.href=cur_url;
  77. });
  78. $("thead").on('click', ".all_selector", function() {
  79. if ($("thead .all_selector").is(':checked')) {
  80. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', true);
  81. $(".all_selector").prop('checked', true);
  82. } else {
  83. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', false);
  84. $(".all_selector").prop('checked', false);
  85. }
  86. select_item_action();
  87. });
  88. $("tfoot").on('click', ".all_selector", function() {
  89. if ($("tfoot .all_selector").is(':checked')) {
  90. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', true);
  91. $(".all_selector").prop('checked', true);
  92. } else {
  93. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', false);
  94. $(".all_selector").prop('checked', false);
  95. }
  96. select_item_action();
  97. });
  98. $("tbody tr").on('click', "input[type='checkbox']", function() {
  99. select_item_action();
  100. });
  101. $('body').addClass('add-transition');
  102. $('.add-page-transition').on('click', function(){
  103. var transAttr = $(this).attr('data-transition');
  104. $('.add-transition').attr('class', 'add-transition');
  105. $('.add-transition').addClass(transAttr);
  106. });
  107. });
  108. function get_selected_element(checked) {
  109. if (checked === null) {
  110. checked = true;
  111. }
  112. if (checked) {
  113. return $('tbody :checked');
  114. } else {
  115. return $('tbody input:not(:checked)');
  116. }
  117. }
  118. function highlight_selected_element() {
  119. var selected_element = get_selected_element(true);
  120. var no_selected_element = get_selected_element(false);
  121. selected_element.each(function(i, e) {
  122. $(e).parent().parent().toggleClass('tr-selected', true);
  123. });
  124. no_selected_element.each(function(i, e) {
  125. $(e).parent().parent().toggleClass('tr-selected', false);
  126. });
  127. }
  128. function shortcut_bar_enable() {
  129. var selected_element = get_selected_element(true);
  130. if (selected_element.length > 0) {
  131. $('.btn-shortcut').toggleClass('disabled', false);
  132. } else {
  133. $('.btn-shortcut').toggleClass('disabled', true);
  134. }
  135. }
  136. function select_item_action() {
  137. highlight_selected_element();
  138. shortcut_bar_enable();
  139. }
  140. function refresh() {
  141. keyword = $('#content_search').val();
  142. page = $('#pagination li.active a').text();
  143. page_size = $('#page_size').val();
  144. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size;
  145. if (keyword.length > 0) {
  146. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size + '&keyword=' + keyword;
  147. }
  148. window.location.href=cur_url;
  149. }
  150. function remove(uuid, boot_job_id, do_refresh) {
  151. $.ajax({
  152. url : '/api/guests/_boot_jobs/' + uuid + '/' + boot_job_id,
  153. type : 'DELETE',
  154. contentType: "application/json; charset=utf-8",
  155. error : function() {
  156. alter_danger('启动作业删除指令发送失败!');
  157. },
  158. success : function() {
  159. // 未指定值的参数为 undefined
  160. if (do_refresh) {
  161. alter_success('启动作业删除指令发送成功!');
  162. refresh();
  163. }
  164. }
  165. });
  166. }
  167. function delete_at(me) {
  168. var uuid = $('#instance_uuid').val();
  169. var boot_job_id = $('#instance_boot_job_id').val();
  170. remove(uuid, boot_job_id, true);
  171. $('#delete_modal').modal('hide');
  172. }
  173. function get_selected_uuids_and_boot_jobs_id() {
  174. var selected_element = get_selected_element(true);
  175. var uuids = [];
  176. var boot_jobs_id = [];
  177. selected_element.each(function(i, e) {
  178. var uuid = $(e).parent().prev().prev().text();
  179. var boot_job_id = $(e).parent().prev().text();
  180. uuids.push(uuid);
  181. boot_jobs_id.push(boot_job_id);
  182. });
  183. return {'uuids': uuids, 'boot_jobs_id': boot_jobs_id};
  184. }
  185. function get_checked_uuids_and_boot_jobs_id() {
  186. var uuids_and_boot_jobs_id = get_selected_uuids_and_boot_jobs_id();
  187. if (uuids_and_boot_jobs_id['uuids'].length < 1) {
  188. alter_warning('未选择任何可操作的实例!');
  189. return false;
  190. }
  191. return uuids_and_boot_jobs_id;
  192. }
  193. function batch_delete() {
  194. var uuids_and_boot_jobs_id = get_checked_uuids_and_boot_jobs_id();
  195. if (uuids_and_boot_jobs_id['uuids'] && uuids_and_boot_jobs_id['boot_jobs_id']) {
  196. for (var i=0; i<uuids_and_boot_jobs_id['uuids'].length; i++) {
  197. if (i === uuids_and_boot_jobs_id['uuids'].length - 1) {
  198. remove(uuids_and_boot_jobs_id['uuids'][i], uuids_and_boot_jobs_id['boot_jobs_id'][i], true);
  199. } else {
  200. remove(uuids_and_boot_jobs_id['uuids'][i], uuids_and_boot_jobs_id['boot_jobs_id'][i], false);
  201. }
  202. }
  203. }
  204. $('#batch_delete_modal').modal('hide');
  205. }
  206. </script>
  207. <div class="panel">
  208. <div class="panel-body">
  209. <h3 class="title-hero" style="font-size: 24px;">
  210. 虚拟机启动作业
  211. </h3>
  212. <div>
  213. <div id="datatable-row-highlight_wrapper" class="dataTables_wrapper form-inline">
  214. <div class="row" style="padding: 10px 10px 10px 0; width: 100%;">
  215. <div class="col-sm-12" style="padding-right: 0;">
  216. <div class="pull-right">
  217. <button class="btn btn-default" onclick="refresh()" style="border-radius: 0;"><span class="glyph-icon icon-elusive-arrows-cw"></span></button>
  218. </div>
  219. </div>
  220. </div>
  221. <table id="guests_boot_jobs_list" class="table table-bordered table-hover" cellspacing="0" width="100%" role="grid"
  222. style="width: 100%; margin-bottom: 0; border-bottom-width: 0;">
  223. <thead>
  224. <tr role="row">
  225. <th style="display: none;">UUID</th>
  226. <th style="display: none;">启动作业 ID</th>
  227. <th><input class="all_selector" title="选取所有" type="checkbox"></th>
  228. <th width="180px;">有效时间</th>
  229. <th width="180px;">启动作业</th>
  230. <th width="180px;">名称</th>
  231. <th></th>
  232. <th>状态</th>
  233. <th>IP</th>
  234. <th>操作</th>
  235. </tr>
  236. </thead>
  237. <tbody>
  238. {% for uuid, boot_jobs in guests_boot_jobs_ret.data.iteritems() %}
  239. {% for boot_job_id in boot_jobs.boot_jobs %}
  240. <tr role="row" class="odd">
  241. <td style="display: none;">{{ uuid }}</td>
  242. <td style="display: none;">{{ boot_job_id }}</td>
  243. <td><input title="选中" type="checkbox"></td>
  244. <td>
  245. <span style="color: #b94a48; {% if boot_jobs.ttl // 60 == 0 %}display: none;{% endif %}">{{ boot_jobs.ttl // 60 }}分</span>
  246. <span style="color: #b94a48; {% if boot_jobs.ttl % 60 == 0 %}display: none;{% endif %}">{{ boot_jobs.ttl % 60 }}秒</span>
  247. </td>
  248. <td>
  249. <div>
  250. <a href="/operate_rules?boot_job_id={{ boot_job_id }}">
  251. <p style="display: inline-block;">{{ boot_jobs_mapping_by_id[boot_job_id | int].name }}</p>
  252. </a>
  253. </div>
  254. </td>
  255. <td>
  256. <div>
  257. <a href="/guest/detail/{{ uuid }}">
  258. <p style="display: inline-block;">
  259. {{ guests_mapping_by_uuid[uuid].label }}
  260. </p>
  261. </a>
  262. <div>
  263. <p style="display: inline-block;">{{ guests_mapping_by_uuid[uuid].remark }}</p>
  264. </div>
  265. </div>
  266. </td>
  267. <td><span class="{{ os_templates_mapping_by_id[guests_mapping_by_uuid[uuid].os_template_id].icon }}"></span></td>
  268. <td>{{ format_guest_status(guests_mapping_by_uuid[uuid].status)|safe }}</td>
  269. <td>{{ guests_mapping_by_uuid[uuid].ip }}</td>
  270. <td>
  271. <div class="dropdown inline-block">
  272. <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown">
  273. 更多
  274. </a>
  275. <ul class="dropdown-menu">
  276. <li>
  277. <a href="javascript:;" data-toggle="modal" data-target="#delete_modal"
  278. onclick="$('#instance_uuid').val($(this).parent().parent().parent().parent().parent().children()[0].textContent);
  279. $('#instance_boot_job_id').val($(this).parent().parent().parent().parent().parent().children()[1].textContent);
  280. $('#delete_instance_desc').text($($(this).parent().parent().parent().parent().parent().children()[5]).find('div a')[0].text);
  281. $('#delete_instance_desc').append('/' + $($(this).parent().parent().parent().parent().parent().children()[4]).find('div a')[0].text)">
  282. 删除
  283. </a>
  284. </li>
  285. </ul>
  286. </div>
  287. </td>
  288. </tr>
  289. {% endfor %}
  290. {% endfor %}
  291. </tbody>
  292. </table>
  293. <table class="table table-bordered" style="border-top-width: 0; z-index: 99; position: sticky; bottom: 0;">
  294. <tfoot>
  295. <tr style="height: 70px;">
  296. <th><input type="checkbox" title="选取所有" class="all_selector"></th>
  297. <th>
  298. <div class="row">
  299. <div class="col-sm-6">
  300. <button class="btn btn-default btn-shortcut disabled" data-toggle="modal" data-target="#batch_delete_modal">删除</button>
  301. </div>
  302. <div class="col-sm-3" style="font-size: 12px; padding-top: 5px; text-align: right;">
  303. 共有{{ paging_total }}个,每页显示:
  304. <select id="page_size" name="datatable-row-highlight_length" title="page_size" class="form-control" style="height: 22px; vertical-align: baseline;">
  305. <option value="10" {% if page_size == 10 %} selected {% endif %}>10</option>
  306. <option value="20" {% if page_size == 20 %} selected {% endif %}>20</option>
  307. <option value="50" {% if page_size == 50 %} selected {% endif %}>50</option>
  308. </select>&nbsp;&nbsp;个
  309. </div>
  310. <div class="col-sm-3" style="text-align: left;">
  311. <div class="dataTables_paginate paging_bootstrap" id="datatable-row-highlight_paginate">
  312. <ul id="pagination" class="pagination">
  313. <li class="{% if page == 1 %} disabled {% endif %}">
  314. <a href="{{ resource_path }}?page={{ page - 1 }}&page_size={{ page_size }}{% if keyword %}&keyword={{ keyword }}{% endif %}">«</a>
  315. </li>
  316. {% for item in pages %}
  317. <li class="{% if item == page %} active {% endif %}">
  318. <a href="{{ resource_path }}?page={{ item }}&page_size={{ page_size }}{% if keyword %}&keyword={{ keyword }}{% endif %}">{{ item }}</a>
  319. </li>
  320. {% endfor %}
  321. <li class="{% if page == last_page %} disabled {% endif %}">
  322. <a href="{{ resource_path }}?page={{ page + 1 }}&page_size={{ page_size }}{% if keyword %}&keyword={{ keyword }}{% endif %}">»</a>
  323. </li>
  324. </ul>
  325. </div>
  326. </div>
  327. </div>
  328. </th>
  329. </tr>
  330. </tfoot>
  331. </table>
  332. </div>
  333. </div>
  334. </div>
  335. </div>
  336. <input id="instance_uuid" title="实例 UUID" class="form-control" name="uuid" hidden>
  337. <input id="instance_boot_job_id" title="实例启动作业 ID" class="form-control" name="boot_job_id" hidden>
  338. <div class="modal" id="delete_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  339. <div class="modal-dialog">
  340. <div class="modal-content">
  341. <div class="modal-header">
  342. <h4 class="modal-title">删除启动作业:</h4>
  343. </div>
  344. <div class="modal-body">
  345. <p>你确定要删除该启动作业吗?</p>
  346. <h3 style="color: orangered;" id="delete_instance_desc"></h3>
  347. </div>
  348. <div class="modal-footer">
  349. <button type="button" class="btn btn-sm btn-primary" onclick="delete_at();">确定</button>
  350. <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">取消</button>
  351. </div>
  352. </div>
  353. </div>
  354. </div>
  355. <div class="modal" id="batch_delete_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  356. <div class="modal-dialog">
  357. <div class="modal-content">
  358. <div class="modal-header">
  359. <h4 class="modal-title">批量删除启动作业:</h4>
  360. </div>
  361. <div class="modal-body">
  362. <p>您确定要执行批量删除选择的启动作业吗?</p>
  363. </div>
  364. <div class="modal-footer">
  365. <button type="button" class="btn btn-sm btn-primary" onclick="batch_delete();">确定</button>
  366. <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">取消</button>
  367. </div>
  368. </div>
  369. </div>
  370. </div>
  371. {% endblock content %}