Bläddra i källkod

实现手动删除离线的计算节点功能

James Iter 8 år sedan
förälder
incheckning
91d01f1af2
5 ändrade filer med 69 tillägg och 10 borttagningar
  1. 39 0
      api/host.py
  2. 1 0
      api_route_table.py
  3. 2 1
      docs/todo.md
  4. 0 1
      models/event_processor.py
  5. 27 8
      templates/hosts_show.html

+ 39 - 0
api/host.py

@@ -121,3 +121,42 @@ def r_content_search():
     except ji.PreviewingError, e:
         return json.loads(e.message)
 
+
+@Utils.dumps2response
+def r_delete(nodes_id):
+
+    args_rules = [
+        Rules.IDS.value
+    ]
+
+    try:
+        ji.Check.previewing(args_rules, {args_rules[0][1]: nodes_id})
+
+        ret = dict()
+        ret['state'] = ji.Common.exchange_state(20000)
+        ret['data'] = list()
+
+        if -1 == nodes_id.find(','):
+            node_id = nodes_id
+            if db.r.hexists(app.config['hosts_info'], node_id):
+                v = json.loads(db.r.hget(app.config['hosts_info'], node_id))
+                v['node_id'] = node_id
+                ret['data'] = v
+                db.r.hdel(app.config['hosts_info'], node_id)
+
+        else:
+            for node_id in nodes_id.split(','):
+                if db.r.hexists(app.config['hosts_info'], node_id):
+                    v = json.loads(db.r.hget(app.config['hosts_info'], node_id))
+                    v['node_id'] = node_id
+                    ret['data'].append(v)
+                    db.r.hdel(app.config['hosts_info'], node_id)
+
+            if ret['data'].__len__() > 1:
+                ret['data'].sort(key=lambda _k: _k['boot_time'])
+
+        return ret
+
+    except ji.PreviewingError, e:
+        return json.loads(e.message)
+

+ 1 - 0
api_route_table.py

@@ -106,6 +106,7 @@ add_rule_api(log.blueprints, '/_search', api_func='log.r_content_search', method
 add_rule_api(host.blueprints, '/<nodes_id>', api_func='host.r_get', methods=['GET'])
 add_rule_api(host.blueprints, '', api_func='host.r_get_by_filter', methods=['GET'])
 add_rule_api(host.blueprints, '/_search', api_func='host.r_content_search', methods=['GET'])
+add_rule_api(host.blueprints, '/<nodes_id>', api_func='host.r_delete', methods=['DELETE'])
 
 # Guest 性能查询
 add_rule_api(performance.blueprint, '/cpu_memory', api_func='performance.r_cpu_memory_get_by_filter', methods=['GET'])

+ 2 - 1
docs/todo.md

@@ -46,6 +46,7 @@
 - [x] 修改密码功能
 - [x] 密码[找回|重置]功能
 - [ ] 前端页面校验字段有效值
-- [ ] 当计算节点离线时,计算节点页面显示,清除离线计算节点显示的倒计时
+- [x] 加入手动清除已经离线的宿主机功能
+- [x] 显示计算节点离线时间
 - [ ] 系统模板加入是否为Windows类系统的标记
 - [ ] 系统模板为 Windows 时,时钟偏移值设定为 localtime,否则为 utc

+ 0 - 1
models/event_processor.py

@@ -124,7 +124,6 @@ class EventProcessor(object):
         }
 
         db.r.hset(app.config['hosts_info'], key=key, value=json.dumps(value, ensure_ascii=False))
-        db.r.expire(app.config['hosts_info'], 10)
 
     @classmethod
     def response_processor(cls):

+ 27 - 8
templates/hosts_show.html

@@ -38,14 +38,27 @@
     });
 
     function refresh() {
-        keyword = $('#content_search').val();
-        page = $('#pagination li.active a').text();
-        page_size = $('#page_size').val();
-        cur_url = resource_path + '?page=' + page + '&page_size=' + page_size;
-        if (keyword.length > 0) {
-            cur_url = resource_path + '?page=' + page + '&page_size=' + page_size + '&keyword=' + keyword;
-        }
-        window.location.href=cur_url;
+        window.location.href=resource_path;
+    }
+
+    function remove(uuids) {
+        $.ajax({
+            url : '/api/hosts/' + uuids.join(','),
+            type : 'DELETE',
+            contentType: "application/json; charset=utf-8",
+            error : function() {
+                alter_danger('计算节点删除指令发送失败!');
+            },
+            success : function() {
+                alter_success('计算节点删除指令发送成功!');
+            }
+        });
+    }
+
+    function delete_at(me) {
+        var node_id = $(me).prev().text();
+        remove([node_id]);
+        refresh()
     }
 
     function panel_onmouseover(me) {
@@ -84,6 +97,12 @@
                                 <div class="show_detail_link" style="display: none; position: absolute; z-index: 9999; margin-top: 20px; right: 2%;">
                                     <a href="/host/detail/{{ item.node_id }}" style="color: white; background-color: black;">&nbsp;&nbsp;&nbsp;&nbsp;主机详情&nbsp;&nbsp;&nbsp;&nbsp;</a>
                                 </div>
+                                <div style="{% if item.alive == true %}display: none;{% endif %}position: absolute; z-index: 9999; margin-top: 0; top: 56px; right: 0; left: 0;">
+                                    <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;
+                                        <span style="display: none;">{{ item.node_id }}</span>
+                                        <a href="javascript:;" onclick="delete_at(this);" style="color: black;">删除该计算节点</a>
+                                    </span>
+                                </div>
                                 <span>{{ '%0.2f'| format(item.system_load[0] / item.cpu) }}</span>
                                 <i>当前系统负载</i>
                             </div>