瀏覽代碼

修正计算节点离线被删除,虚拟机展现bug

James Iter 7 年之前
父節點
當前提交
7eb069820b

+ 1 - 0
README.md

@@ -2,6 +2,7 @@
 [![Format](https://img.shields.io/badge/Format-JSON-blue.svg)](http://www.json.org/json-zh.html)
 [![Python versions](https://img.shields.io/badge/Python-2.7.10-blue.svg)](https://www.python.org)
 [![API](https://img.shields.io/badge/API-RESTful-blue.svg)](http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm)
+[![996.icu](https://img.shields.io/badge/link-996.icu-red.svg)](https://996.icu)
 
 
 [TOC]: # "目录"

+ 3 - 2
docs/todo.md

@@ -102,6 +102,7 @@
 - [ ] 加入虚拟机排序功能
 - [ ] 企业版分叉
 - [ ] 加入邮件、短信报警功能
-- [ ] 参照公有云,设计、实现资源搜索过滤功能
+- [x] 参照公有云,设计、实现资源搜索过滤功能
+- [ ] 虚拟机锁,使被锁定的虚拟机,无法被操作
 - [ ] 加入自定义主题颜色供。具体的颜色参考(http://ylbook.com/cms/web/chuantongsecai/chuantongsecai.htm)
-
+- [ ] 独立出 JimV 专有的 Nginx 配置文件

+ 14 - 7
jimvc/api/guest.py

@@ -1017,7 +1017,8 @@ def r_get(uuids):
 
                 ret['data']['ssh_keys'].append(ssh_key_id_mapping[ssh_key_id])
 
-            if not hosts_mapping_by_node_id[ret['data']['node_id']]['alive']:
+            if ret['data']['node_id'] not in hosts_mapping_by_node_id or \
+                    not hosts_mapping_by_node_id[ret['data']['node_id']]['alive']:
                 ret['data']['status'] = GuestState.no_state.value
 
         ret['data']['vlan'] = vlans_mapping_by_vlan_id[ret['data']['vlan_id']]
@@ -1035,7 +1036,8 @@ def r_get(uuids):
 
                     ret['data'][i]['ssh_keys'].append(ssh_key_id_mapping[ssh_key_id])
 
-            if not hosts_mapping_by_node_id[ret['data'][i]['node_id']]['alive']:
+            if ret['data'][i]['node_id'] not in hosts_mapping_by_node_id or \
+                    not hosts_mapping_by_node_id[ret['data'][i]['node_id']]['alive']:
                 ret['data'][i]['status'] = GuestState.no_state.value
 
             ret['data'][i]['vlan'] = vlans_mapping_by_vlan_id[ret['data'][i]['vlan_id']]
@@ -1244,10 +1246,13 @@ def r_get_by_filter():
                 else:
                     ret['data'][i]['snapshot']['creatable'] = False
 
-        if not hosts_mapping_by_node_id[ret['data'][i]['node_id']]['alive']:
+        if ret['data'][i]['node_id'] not in hosts_mapping_by_node_id or \
+                not hosts_mapping_by_node_id[ret['data'][i]['node_id']]['alive']:
             ret['data'][i]['status'] = GuestState.no_state.value
 
-        ret['data'][i]['hostname'] = hosts_mapping_by_node_id[guest['node_id']]['hostname']
+        ret['data'][i]['hostname'] = hosts_mapping_by_node_id[guest['node_id']]['hostname'] \
+            if guest['node_id'] in hosts_mapping_by_node_id else 'Unknown'
+
         ret['data'][i]['vlan'] = vlans_mapping_by_vlan_id[guest['vlan_id']]
 
         ret['data'][i]['html'] = dict()
@@ -1360,10 +1365,12 @@ def r_content_search():
                 else:
                     ret['data'][i]['snapshot']['creatable'] = False
 
-        if not hosts_mapping_by_node_id[ret['data'][i]['node_id']]['alive']:
+        if ret['data'][i]['node_id'] not in hosts_mapping_by_node_id or \
+                not hosts_mapping_by_node_id[ret['data'][i]['node_id']]['alive']:
             ret['data'][i]['status'] = GuestState.no_state.value
 
-        ret['data'][i]['hostname'] = hosts_mapping_by_node_id[guest['node_id']]['hostname']
+        ret['data'][i]['hostname'] = hosts_mapping_by_node_id[guest['node_id']]['hostname'] \
+            if guest['node_id'] in hosts_mapping_by_node_id else 'Unknown'
         ret['data'][i]['vlan'] = vlans_mapping_by_vlan_id[guest['vlan_id']]
 
         ret['data'][i]['html'] = dict()
@@ -1930,7 +1937,7 @@ def r_detail(uuid):
     disks_ret = requests.get(url=disks_url, cookies=request.cookies, verify=False)
     disks = json.loads(disks_ret.content)['data']
 
-    if not hosts_mapping_by_node_id[guest.node_id]['alive']:
+    if guest.node_id not in hosts_mapping_by_node_id or not hosts_mapping_by_node_id[guest.node_id]['alive']:
         guest.status = GuestState.no_state.value
 
     config = Config()

+ 1 - 1
jimvc/themes/default/templates/disks_show.html

@@ -666,7 +666,7 @@
                         {{ item.guest.label }}/{{ item.guest.remark }}
                     {% endif %}</a>
                     </td>
-                    <td style="{% if not show_on_host %}display: none;{% endif %}">{{ hosts_mapping_by_node_id[item.node_id | string].hostname }}</td>
+                    <td style="{% if not show_on_host %}display: none;{% endif %}">{% if item.node_id | string in hosts_mapping_by_node_id %}{{ hosts_mapping_by_node_id[item.node_id | string].hostname }}{% else %}<span style="color: #FF645B;">Unknown</span>{% endif %}</td>
                     <td style="display: none;">{{ item.node_id }}</td>
                     <td>
                         {% if item.sequence == 0 %}

+ 1 - 1
jimvc/themes/default/templates/guest_create.html

@@ -329,7 +329,7 @@
                                     <input title="4 CPU 32GB Memory" name="ability" type="radio" value="4c32g">4&nbsp;&nbsp;核&nbsp;&nbsp;32GB
                                 </label>
                                 <label class="btn btn-default btn-ability">
-                                    <input title="4 CPU 64GB Memory" name="ability" type="radio" value="4c64g">4&nbsp;&nbsp;核&nbsp;&nbsp;64GB
+                                    <input title="8 CPU 32GB Memory" name="ability" type="radio" value="8c32g">8&nbsp;&nbsp;核&nbsp;&nbsp;32GB
                                 </label>
                                 <label class="btn btn-default btn-ability">
                                     <input title="8 CPU 64GB Memory" name="ability" type="radio" value="8c64g">8&nbsp;&nbsp;核&nbsp;&nbsp;64GB

+ 1 - 1
jimvc/themes/default/templates/guest_detail.html

@@ -1138,7 +1138,7 @@
                             <td>
                                 <span class="guest-label">计算节点:&nbsp;&nbsp;&nbsp;&nbsp;</span>
                                 <span class="guest-desc">
-                                {{ hosts_mapping_by_node_id[guest.node_id | string].hostname }}
+                                {% if guest.node_id | string in hosts_mapping_by_node_id %}{{ hosts_mapping_by_node_id[guest.node_id | string].hostname }}{% else %}<span style="color: #FF645B;">Unknown</span>{% endif %}
                                 </span>
                             </td>
                         </tr>

+ 3 - 3
jimvc/themes/default/templates/guests_show.html

@@ -1820,7 +1820,7 @@
                         <a data-autostart="{{ item.autostart }}" class="icon-os icon-autostart" title="{% if item.autostart != 0 %}切至手动启动{% else %}切至开机启动{% endif %}" href="javascript:;" onclick="autostart_at(this);" style="{% if item.autostart == 0 %}filter: grayscale(100%);{% endif %}"></a>
                     </td>
                     <td>{{ format_guest_status(item.status, item.progress)|safe }}</td>
-                    <td><a href="/guests?filter=node_id:eq:{{ item.node_id | string }}">{{ hosts_mapping_by_node_id[item.node_id | string].hostname }}</a></td>
+                    <td><a href="/guests?filter=node_id:eq:{{ item.node_id | string }}">{% if item.node_id | string in hosts_mapping_by_node_id %}{{ hosts_mapping_by_node_id[item.node_id | string].hostname }}{% else %}<span style="color: #FF645B;">Unknown</span>{% endif %}</a></td>
                     <td>
                         CPU :&nbsp;&nbsp;{{ item.cpu }}&nbsp;核<br />
                         内存 :&nbsp;&nbsp;{{ item.memory }}&nbsp;GB<br />
@@ -2687,7 +2687,7 @@
                                         <input title="4 CPU 32GB Memory" name="ability" type="radio" value="4c32g">4&nbsp;&nbsp;核&nbsp;&nbsp;32GB
                                     </label>
                                     <label class="btn btn-default btn-ability">
-                                        <input title="4 CPU 64GB Memory" name="ability" type="radio" value="4c64g">4&nbsp;&nbsp;核&nbsp;&nbsp;64GB
+                                        <input title="8 CPU 32GB Memory" name="ability" type="radio" value="8c32g">8&nbsp;&nbsp;核&nbsp;&nbsp;32GB
                                     </label>
                                     <label class="btn btn-default btn-ability">
                                         <input title="8 CPU 64GB Memory" name="ability" type="radio" value="8c64g">8&nbsp;&nbsp;核&nbsp;&nbsp;64GB
@@ -2766,7 +2766,7 @@
                                         <input title="4 CPU 32GB Memory" name="ability" type="radio" value="4c32g">4&nbsp;&nbsp;核&nbsp;&nbsp;32GB
                                     </label>
                                     <label class="btn btn-default btn-ability">
-                                        <input title="4 CPU 64GB Memory" name="ability" type="radio" value="4c64g">4&nbsp;&nbsp;核&nbsp;&nbsp;64GB
+                                        <input title="8 CPU 32GB Memory" name="ability" type="radio" value="8c32g">8&nbsp;&nbsp;核&nbsp;&nbsp;32GB
                                     </label>
                                     <label class="btn btn-default btn-ability">
                                         <input title="8 CPU 64GB Memory" name="ability" type="radio" value="8c64g">8&nbsp;&nbsp;核&nbsp;&nbsp;64GB