guest_show.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. {% extends "layout.html" %}
  2. {% block title %} Guest {% 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: #6d6e6f;
  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. </style>
  41. {% endblock head %}
  42. {% block content %}
  43. <script type="text/javascript">
  44. var page = 1;
  45. var page_size = 10;
  46. var keyword = '';
  47. var cur_url = '/guests';
  48. $(document).ready(function() {
  49. page_size = $('#page_size').val();
  50. cur_url = '/guests?page=' + page + '&page_size=' + page_size;
  51. var last_ready = null;
  52. $('#content_search').keydown(function() {
  53. if (last_ready !== null) {
  54. clearTimeout(last_ready);
  55. }
  56. last_ready = setTimeout(function () {
  57. keyword = $('#content_search').val();
  58. cur_url = '/guests?page=' + page + '&page_size=' + page_size;
  59. if (keyword.length > 0) {
  60. cur_url = '/guests?page=' + page + '&page_size=' + page_size + '&keyword=' + keyword;
  61. }
  62. window.location.href=cur_url;
  63. }, 1000);
  64. });
  65. $('#page_size').change(function () {
  66. keyword = $('#content_search').val();
  67. page_size = $('#page_size').val();
  68. cur_url = '/guests?page=' + page + '&page_size=' + page_size;
  69. if (keyword.length > 0) {
  70. cur_url = '/guests?page=' + page + '&page_size=' + page_size + '&keyword=' + keyword;
  71. }
  72. window.location.href=cur_url;
  73. });
  74. $("thead").on('click', ".all_selector", function() {
  75. if ($("thead .all_selector").is(':checked')) {
  76. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', true);
  77. $(".all_selector").prop('checked', true);
  78. } else {
  79. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', false);
  80. $(".all_selector").prop('checked', false);
  81. }
  82. });
  83. $("tfoot").on('click', ".all_selector", function() {
  84. if ($("tfoot .all_selector").is(':checked')) {
  85. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', true);
  86. $(".all_selector").prop('checked', true);
  87. } else {
  88. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', false);
  89. $(".all_selector").prop('checked', false);
  90. }
  91. });
  92. $('body').addClass('add-transition');
  93. $('.add-page-transition').on('click', function(){
  94. var transAttr = $(this).attr('data-transition');
  95. $('.add-transition').attr('class', 'add-transition');
  96. $('.add-transition').addClass(transAttr);
  97. });
  98. $('#edit_remark_modal').on('show.bs.modal', function (me) {
  99. $('#instance_uuid').val($(me.relatedTarget).parent().parent().prev().prev().text());
  100. $('#edit_remark').val($(me.relatedTarget).prev().text());
  101. })
  102. });
  103. function refresh() {
  104. keyword = $('#content_search').val();
  105. page = $('#pagination li.active a').text();
  106. page_size = $('#page_size').val();
  107. cur_url = '/guests?page=' + page + '&page_size=' + page_size;
  108. if (keyword.length > 0) {
  109. cur_url = '/guests?page=' + page + '&page_size=' + page_size + '&keyword=' + keyword;
  110. }
  111. window.location.href=cur_url;
  112. }
  113. function row_onmouseover(me) {
  114. $(me).find(".edit_remark_trigger").css('display','inline-flex');
  115. }
  116. function row_onmouseout(me) {
  117. $(me).find(".edit_remark_trigger").css('display','none');
  118. }
  119. function remark_update(me) {
  120. var uuid = $('#instance_uuid').val();
  121. var remark = $('#edit_remark').val();
  122. $('#edit_remark_modal').modal('hide');
  123. $.ajax({
  124. url : '/api/guest/' + uuid,
  125. type : 'PATCH',
  126. contentType: "application/json; charset=utf-8",
  127. data : JSON.stringify({
  128. remark: remark
  129. }),
  130. error : function() {
  131. alter_danger('实例备注更新失败!');
  132. },
  133. success : function() {
  134. $('#guest_list tbody').find('td:contains(' + uuid + ')').next().next().find('p').text(remark);
  135. alter_success('实例备注更新成功!');
  136. }
  137. });
  138. }
  139. function boot(uuids) {
  140. $.ajax({
  141. url : '/api/guests/_boot/' + uuids.join(','),
  142. type : 'PUT',
  143. contentType: "application/json; charset=utf-8",
  144. error : function() {
  145. alter_danger('实例启动指令发送失败!');
  146. },
  147. success : function() {
  148. alter_success('实例启动指令发送成功!');
  149. }
  150. });
  151. }
  152. function reboot(uuids) {
  153. $.ajax({
  154. url : '/api/guests/_reboot/' + uuids.join(','),
  155. type : 'PUT',
  156. contentType: "application/json; charset=utf-8",
  157. error : function() {
  158. alter_danger('实例重启指令发送失败!');
  159. },
  160. success : function() {
  161. alter_success('实例重启指令发送成功!');
  162. }
  163. });
  164. }
  165. function force_reboot(uuids) {
  166. $.ajax({
  167. url : '/api/guests/_force_reboot/' + uuids.join(','),
  168. type : 'PUT',
  169. contentType: "application/json; charset=utf-8",
  170. error : function() {
  171. alter_danger('实例强制重启指令发送失败!');
  172. },
  173. success : function() {
  174. alter_success('实例强制重启指令发送成功!');
  175. }
  176. });
  177. }
  178. function shutdown(uuids) {
  179. $.ajax({
  180. url : '/api/guests/_shutdown/' + uuids.join(','),
  181. type : 'PUT',
  182. contentType: "application/json; charset=utf-8",
  183. error : function() {
  184. alter_danger('实例停止指令发送失败!');
  185. },
  186. success : function() {
  187. alter_success('实例停止指令发送成功!');
  188. }
  189. });
  190. }
  191. function force_shutdown(uuids) {
  192. $.ajax({
  193. url : '/api/guests/_force_shutdown/' + uuids.join(','),
  194. type : 'PUT',
  195. contentType: "application/json; charset=utf-8",
  196. error : function() {
  197. alter_danger('实例强制停止指令发送失败!');
  198. },
  199. success : function() {
  200. alter_success('实例强制停止指令发送成功!');
  201. }
  202. });
  203. }
  204. function suspend(uuids) {
  205. $.ajax({
  206. url : '/api/guests/_suspend/' + uuids.join(','),
  207. type : 'PUT',
  208. contentType: "application/json; charset=utf-8",
  209. error : function() {
  210. alter_danger('实例暂停指令发送失败!');
  211. },
  212. success : function() {
  213. alter_success('实例暂停指令发送成功!');
  214. }
  215. });
  216. }
  217. function resume(uuids) {
  218. $.ajax({
  219. url : '/api/guests/_resume/' + uuids.join(','),
  220. type : 'PUT',
  221. contentType: "application/json; charset=utf-8",
  222. error : function() {
  223. alter_danger('实例恢复指令发送失败!');
  224. },
  225. success : function() {
  226. alter_success('实例恢复指令发送成功!');
  227. }
  228. });
  229. }
  230. function boot_at(me) {
  231. var uuid = $(me).parent().parent().parent().parent().parent().children()[0].textContent;
  232. boot([uuid]);
  233. }
  234. function reboot_at(me) {
  235. var uuid = $(me).parent().parent().parent().parent().parent().children()[0].textContent;
  236. reboot([uuid]);
  237. }
  238. function force_reboot_at(me) {
  239. var uuid = $(me).parent().parent().parent().parent().parent().children()[0].textContent;
  240. force_reboot([uuid]);
  241. }
  242. function shutdown_at(me) {
  243. var uuid = $(me).parent().parent().parent().parent().parent().children()[0].textContent;
  244. shutdown([uuid]);
  245. }
  246. function force_shutdown_at(me) {
  247. var uuid = $(me).parent().parent().parent().parent().parent().children()[0].textContent;
  248. force_shutdown([uuid]);
  249. }
  250. function suspend_at(me) {
  251. var uuid = $(me).parent().parent().parent().parent().parent().children()[0].textContent;
  252. suspend([uuid]);
  253. }
  254. function resume_at(me) {
  255. var uuid = $(me).parent().parent().parent().parent().parent().children()[0].textContent;
  256. resume([uuid]);
  257. }
  258. </script>
  259. <div class="panel">
  260. <div class="panel-body">
  261. <h3 class="title-hero" style="font-size: 24px;">
  262. 虚拟机实例
  263. </h3>
  264. <div>
  265. <div id="datatable-row-highlight_wrapper" class="dataTables_wrapper form-inline">
  266. <div class="row" style="padding: 10px 10px 10px 0; width: 100%;">
  267. <div class="col-sm-12" style="padding-right: 0;">
  268. <div id="datatable-row-highlight_filter" class="dataTables_filter" style="display: inline-block;">
  269. <input id="content_search" type="search" class="form-control" placeholder="模糊搜索..." value="{%- if keyword -%} {{ keyword }} {%- endif -%}" style="margin-left: 0; border-radius: 0;">
  270. </div>
  271. <div class="pull-right">
  272. <button class="btn btn-default" onclick="refresh()" style="border-radius: 0;"><span class="glyph-icon icon-elusive-arrows-cw"></span></button>
  273. <a class="btn btn-info add-page-transition" href="/guests/create" data-transition="pt-page-moveFromRight-init" style="border-radius: 0; padding-left: 40px; padding-right: 40px;">创建实例</a>
  274. </div>
  275. </div>
  276. </div>
  277. <table id="guest_list" class="table table-bordered table-hover" cellspacing="0" width="100%" role="grid"
  278. style="width: 100%; margin-bottom: 0; border-bottom-width: 0;">
  279. <thead>
  280. <tr role="row">
  281. <th style="display: none;">UUID</th>
  282. <th><input class="all_selector" title="选取所有" type="checkbox"></th>
  283. <th width="180px;">名称</th>
  284. <th></th>
  285. <th>状态</th>
  286. <th>计算节点</th>
  287. <th>配置</th>
  288. <th>IP</th>
  289. <th>密码</th>
  290. <th>创建时间</th>
  291. <th>操作</th>
  292. </tr>
  293. </thead>
  294. <tbody>
  295. {% for item in guests_ret.data %}
  296. <tr role="row" class="odd" onmouseover="row_onmouseover(this);" onmouseout="row_onmouseout(this);">
  297. <td style="display: none;">{{ item.uuid }}</td>
  298. <td><input title="选中" type="checkbox"></td>
  299. <td>
  300. <div>
  301. <a href="javascript:;">{{ item.name }}</a>
  302. </div>
  303. <div>
  304. <p style="display: inline-block;">{{ item.remark }}</p>
  305. <a href="javascript:;" class="edit_remark_trigger" data-toggle="modal" data-target="#edit_remark_modal" style="display: none; float: right;">
  306. <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>
  307. </a>
  308. </div>
  309. </td>
  310. <td><span class="{{ os_template_mapping_by_id[item.os_template_id].icon }}"></span></td>
  311. <td>{{ format_guest_status(item.status)|safe }}</td>
  312. <td>{{ item.on_host }}</td>
  313. <td>CPU :&nbsp;&nbsp;{{ item.cpu }}&nbsp;核<br />内存 :&nbsp;&nbsp;{{ item.memory }}&nbsp;GB</td>
  314. <td>{{ item.ip }}</td>
  315. <td>{{ item.password }}</td>
  316. <td>{{ format_datetime_by_tus(item.create_time) }}</td>
  317. <td>
  318. <div class="dropdown inline-block">
  319. <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown">
  320. 更多
  321. </a>
  322. <ul class="dropdown-menu">
  323. <li class="{% if item.status not in [4, 5, 6] %} disabled {% endif %}">
  324. <a href="javascript:;" onclick="boot_at(this);">启动</a>
  325. </li>
  326. <li class="{% if item.status not in [1] %} disabled {% endif %}">
  327. <a href="javascript:;" onclick="reboot_at(this);">重启</a>
  328. </li>
  329. <li class="{% if item.status not in [1] %} disabled {% endif %}">
  330. <a href="javascript:;" onclick="force_reboot_at(this);">强制重启</a>
  331. </li>
  332. <li class="{% if item.status not in [1] %} disabled {% endif %}">
  333. <a href="javascript:;" onclick="shutdown_at(this);">停止</a>
  334. </li>
  335. <li class="{% if item.status not in [1] %} disabled {% endif %}">
  336. <a href="javascript:;" onclick="force_shutdown_at(this);">强制停止</a>
  337. </li>
  338. <li class="divider"></li>
  339. <li class="{% if item.status not in [1] %} disabled {% endif %}">
  340. <a href="javascript:;" onclick="suspend_at(this);">暂停</a>
  341. </li>
  342. <li class="{% if item.status not in [3] %} disabled {% endif %}">
  343. <a href="javascript:;" onclick="resume_at(this);">恢复</a>
  344. </li>
  345. <li class="divider"></li>
  346. <li class="">
  347. <a href="javascript:;">密码重置</a>
  348. </li>
  349. <li class="{% if item.status not in [1, 3, 4, 5, 6] %} disabled {% endif %}">
  350. <a href="javascript:;">迁移到</a>
  351. </li>
  352. <li class="divider"></li>
  353. <li class="{% if item.status not in [4, 5, 6, 255] %} disabled {% endif %}">
  354. <a href="javascript:;">删除</a>
  355. </li>
  356. </ul>
  357. </div>
  358. </td>
  359. </tr>
  360. {% endfor %}
  361. </tbody>
  362. </table>
  363. <table class="table table-bordered" style="border-top-width: 0; z-index: 99; position: sticky; bottom: 0;">
  364. <tfoot>
  365. <tr>
  366. <th><input type="checkbox" title="选取所有" class="all_selector"></th>
  367. <th>
  368. <div class="row">
  369. <div class="col-sm-8" style="font-size: 12px; padding-top: 5px; text-align: right;">
  370. 共有{{ guests_ret.paging.total }}条,每页显示:
  371. <select id="page_size" name="datatable-row-highlight_length" title="page_size" class="form-control" style="height: 22px; vertical-align: baseline;">
  372. <option value="1" {% if page_size == 1 %} selected {% endif %}>1</option>
  373. <option value="2" {% if page_size == 2 %} selected {% endif %}>2</option>
  374. <option value="10" {% if page_size == 10 %} selected {% endif %}>10</option>
  375. <option value="20" {% if page_size == 20 %} selected {% endif %}>20</option>
  376. <option value="50" {% if page_size == 50 %} selected {% endif %}>50</option>
  377. </select>&nbsp;&nbsp;条
  378. </div>
  379. <div class="col-sm-4" style="text-align: left;">
  380. <div class="dataTables_paginate paging_bootstrap" id="datatable-row-highlight_paginate">
  381. <ul id="pagination" class="pagination">
  382. <li class="{% if page == 1 %} disabled {% endif %}">
  383. <a href="/guests?page={{ page - 1 }}&page_size={{ page_size }}{% if keyword %} &keyword={{ keyword }} {% endif %}">«</a>
  384. </li>
  385. {% for item in pages %}
  386. <li class="{% if item == page %} active {% endif %}">
  387. <a href="/guests?page={{ item }}&page_size={{ page_size }}{% if keyword %} &keyword={{ keyword }} {% endif %}">{{ item }}</a>
  388. </li>
  389. {% endfor %}
  390. <li class="{% if page == last_page %} disabled {% endif %}">
  391. <a href="/guests?page={{ page + 1 }}&page_size={{ page_size }}{% if keyword %} &keyword={{ keyword }} {% endif %}">»</a>
  392. </li>
  393. </ul>
  394. </div>
  395. </div>
  396. </div>
  397. </th>
  398. </tr>
  399. </tfoot>
  400. </table>
  401. </div>
  402. </div>
  403. </div>
  404. </div>
  405. <div class="modal" id="edit_remark_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  406. <div class="modal-dialog modal-sm">
  407. <div class="modal-content">
  408. <div class="modal-header">
  409. <h4 class="modal-title">编辑实例名称:</h4>
  410. </div>
  411. <div class="modal-body">
  412. <input id="instance_uuid" title="实例 UUID" class="form-control" name="uuid" hidden>
  413. <input id="edit_remark" title="实例名称" class="form-control" name="remark">
  414. </div>
  415. <div class="modal-footer">
  416. <button type="button" class="btn btn-sm btn-primary" onclick="remark_update();">确定</button>
  417. <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">取消</button>
  418. </div>
  419. </div>
  420. </div>
  421. </div>
  422. {% endblock content %}