hosts_show.html 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. {% extends "layout.html" %}
  2. {% block head %}
  3. {{ super() }}
  4. {% endblock head %}
  5. {% block content %}
  6. <script type="text/javascript">
  7. var page = 1;
  8. var page_size = 10;
  9. var keyword = '';
  10. var resource_path = window.location.pathname;
  11. var cur_url = resource_path;
  12. $(document).ready(function() {
  13. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size;
  14. var last_ready = null;
  15. $('#content_search').keydown(function() {
  16. if (last_ready !== null) {
  17. clearTimeout(last_ready);
  18. }
  19. last_ready = setTimeout(function () {
  20. keyword = $('#content_search').val();
  21. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size;
  22. if (keyword.length > 0) {
  23. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size + '&keyword=' + keyword;
  24. }
  25. window.location.href=cur_url;
  26. }, 1000);
  27. });
  28. $('body').addClass('add-transition');
  29. $('.add-page-transition').on('click', function(){
  30. var transAttr = $(this).attr('data-transition');
  31. $('.add-transition').attr('class', 'add-transition');
  32. $('.add-transition').addClass(transAttr);
  33. });
  34. });
  35. function refresh() {
  36. window.location.href=resource_path;
  37. }
  38. function remove(uuids) {
  39. $.ajax({
  40. url : '/api/hosts/' + uuids.join(','),
  41. type : 'DELETE',
  42. contentType: "application/json; charset=utf-8",
  43. error : function() {
  44. alter_danger('计算节点删除指令发送失败!');
  45. },
  46. success : function() {
  47. alter_success('计算节点删除指令发送成功!');
  48. }
  49. });
  50. }
  51. function delete_at(me) {
  52. var node_id = $('#instance_node_id').val();
  53. remove([node_id]);
  54. refresh()
  55. }
  56. function panel_onmouseover(me) {
  57. $(me).find(".show_detail_link").css('display','block');
  58. }
  59. function panel_onmouseout(me) {
  60. $(me).find(".show_detail_link").css('display','none');
  61. }
  62. function nonrandom_click_handler(hostname, nonrandom) {
  63. $.ajax({
  64. url : '/api/hosts/' + hostname + '/' + (! nonrandom),
  65. type : 'PUT',
  66. error : function() {
  67. alter_danger('计算节点随机分配模式指令发送失败!');
  68. },
  69. success : function() {
  70. alter_success('计算节点随机分配模式指令发送成功!');
  71. setTimeout(function() {
  72. refresh();
  73. }, 1000);
  74. }
  75. });
  76. }
  77. </script>
  78. <div class="panel">
  79. <div class="panel-body">
  80. <h3 class="title-hero" style="font-size: 24px;">
  81. 计算节点
  82. </h3>
  83. <div>
  84. <div id="datatable-row-highlight_wrapper" class="dataTables_wrapper form-inline">
  85. <div class="row" style="padding: 10px 10px 10px 0; width: 100%;">
  86. <div class="col-sm-12" style="padding-right: 0;">
  87. <div id="datatable-row-highlight_filter" class="dataTables_filter" style="display: inline-block;">
  88. <input id="content_search" type="search" class="form-control" placeholder="模糊搜索..." value="{%- if keyword -%} {{ keyword }} {%- endif -%}" style="margin-left: 0; border-radius: 0;">
  89. </div>
  90. <div class="pull-right">
  91. </div>
  92. </div>
  93. </div>
  94. </div>
  95. <div class="row">
  96. {% for item in hosts %}
  97. <div class="col-md-4" onmouseover="panel_onmouseover(this);" onmouseout="panel_onmouseout(this);">
  98. <div class="host-box content-box {% if not item.alive %}panel-gray{% endif %}">
  99. <h2 class="bg-black host-title">{{ item.hostname }}
  100. <i style="float: right;" class="glyph-icon icon-circle font-size-23 {% if item.alive == true %}font-green{% else %}font-red{% endif %}"></i>
  101. <a href="javascript:;" onclick="nonrandom_click_handler('{{ item.hostname }}', {{ item.nonrandom | lower }});" title="{% if item.nonrandom == true %}加入{% else %}取消{% endif %}自动分配" style="float: left; margin-top: 8%;" class="glyph-icon icon-elusive-shuffle font-size-12 {% if item.nonrandom == true %}font-gray{% else %}font-green{% endif %}"></a>
  102. </h2>
  103. <div class="bg-blue host-specs">
  104. <div class="show_detail_link" style="display: none; position: absolute; z-index: 9999; margin-top: 20px; right: 2%;">
  105. <a href="/host/detail/{{ item.node_id }}" style="color: white; background-color: black;">&nbsp;&nbsp;&nbsp;&nbsp;主机详情&nbsp;&nbsp;&nbsp;&nbsp;</a>
  106. </div>
  107. <div style="{% if item.alive == true %}display: none;{% endif %}position: absolute; z-index: 9999; margin-top: 0; top: 56px; right: 0; left: 0;">
  108. <span style="color: white; background-color: black; font-size: 13px; display: block; color: #2d2d2d; background-color: #cbcbcb;">&nbsp;&nbsp;&nbsp;&nbsp;最后在线时间: {{ format_datetime_by_tus(item.timestamp * 1000 * 1000) }}&nbsp;&nbsp;&nbsp;&nbsp;
  109. <span style="display: none;">{{ item.node_id }}</span>
  110. <a href="javascript:;" style="color: black;" data-toggle="modal" data-target="#delete_modal"
  111. onclick="$('#instance_node_id').val($(this).prev().text());
  112. $('#delete_instance_desc').text($(this).parent().parent().parent().prev()[0].innerText)">
  113. 删除该计算节点
  114. </a>
  115. </span>
  116. </div>
  117. <span>{{ '%0.2f'| format(item.system_load[0] / item.cpu) }}</span>
  118. <i>当前系统负载</i>
  119. </div>
  120. <div class="bg-orange host-specs">
  121. <span>{{(((item.memory - item.memory_available) / item.memory) * 100) | int}}%</span>
  122. <i>内存使用率</i>
  123. </div>
  124. <ul {% if not item.alive %}class="bg-gray"{% endif %}>
  125. <li>CPU: {{ item.cpu }} 核</li>
  126. <li>内存: {{ (item.memory / 1024 / 1024 / 1024)|int }} GB</li>
  127. <!--<li><i class="glyph-icon icon-circle font-size-23 {% if item.alive == true %}font-green{% else %}font-red{% endif %}"></i></li>-->
  128. {% for nic_name, nic in item.interfaces.iteritems() %}
  129. <li>网卡: {{ nic_name }} | IP: {{ nic.ip }}</li>
  130. {% endfor %}
  131. {% for mountpoint, disk in item.disks.iteritems() %}
  132. <li>挂载点: {{ mountpoint }} | {{ (disk.total / 1024 / 1024 / 1024) | int }} GB | 使用率: {{ disk.percent }}%</li>
  133. {% endfor %}
  134. </ul>
  135. </div>
  136. </div>
  137. {% endfor %}
  138. </div>
  139. </div>
  140. </div>
  141. </div>
  142. <input id="instance_node_id" title="实例 node id" class="form-control" name="node_id" hidden>
  143. <div class="modal" id="delete_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  144. <div class="modal-dialog">
  145. <div class="modal-content">
  146. <div class="modal-header">
  147. <h4 class="modal-title">删除离线的计算节点:</h4>
  148. </div>
  149. <div class="modal-body">
  150. <p>删除的计算节点,上面的统计数据将永久消失。您确定要删除该计算节点吗?</p>
  151. <h3 style="color: orangered;" id="delete_instance_desc"></h3>
  152. </div>
  153. <div class="modal-footer">
  154. <button type="button" class="btn btn-sm btn-primary" onclick="delete_at();">确定</button>
  155. <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">取消</button>
  156. </div>
  157. </div>
  158. </div>
  159. </div>
  160. {% endblock content %}