Sfoglia il codice sorgente

实现启动、重启、强制重启、停止、强制停止、暂停、恢复功能

James Iter 9 anni fa
parent
commit
a200cd6157
2 ha cambiato i file con 153 aggiunte e 13 eliminazioni
  1. 8 8
      models/utils.py
  2. 145 5
      templates/guest_show.html

+ 8 - 8
models/utils.py

@@ -161,37 +161,37 @@ def utility_processor():
 
         elif status == GuestState.blocked.value:
             color = '3D4245'
-            icon = 'glyph-icon icon-spinner'
+            icon = 'glyph-icon icon-minus-square'
             desc = '被阻塞'
 
         elif status == GuestState.paused.value:
-            color = 'FCFF07'
-            icon = 'glyph-icon icon-spinner'
+            color = 'B7B904'
+            icon = 'glyph-icon icon-pause'
             desc = '暂停'
 
         elif status == GuestState.shutdown.value:
             color = '4E5356'
-            icon = 'glyph-icon icon-spinner'
+            icon = 'glyph-icon icon-terminal'
             desc = '关闭'
 
         elif status == GuestState.shutoff.value:
             color = 'FFC543'
-            icon = 'glyph-icon icon-spinner'
+            icon = 'glyph-icon icon-plug'
             desc = '断电'
 
         elif status == GuestState.crashed.value:
             color = '9E2927'
-            icon = 'glyph-icon icon-spinner'
+            icon = 'glyph-icon icon-question'
             desc = '已崩溃'
 
         elif status == GuestState.pm_suspended.value:
             color = 'FCFF07'
-            icon = 'glyph-icon icon-spinner'
+            icon = 'glyph-icon icon-anchor'
             desc = '悬挂'
 
         elif status == GuestState.dirty.value:
             color = 'FCFF07'
-            icon = 'glyph-icon icon-spinner'
+            icon = 'glyph-icon icon-remove'
             desc = '创建失败,待清理'
 
         else:

+ 145 - 5
templates/guest_show.html

@@ -154,6 +154,140 @@
             }
         });
     }
+
+    function boot(uuids) {
+        $.ajax({
+            url : '/api/guests/_boot/' + uuids.join(','),
+            type : 'PUT',
+            contentType: "application/json; charset=utf-8",
+            error : function() {
+                alter_danger('实例启动指令发送失败!');
+            },
+            success : function() {
+                alter_success('实例启动指令发送成功!');
+            }
+        });
+    }
+
+    function reboot(uuids) {
+        $.ajax({
+            url : '/api/guests/_reboot/' + uuids.join(','),
+            type : 'PUT',
+            contentType: "application/json; charset=utf-8",
+            error : function() {
+                alter_danger('实例重启指令发送失败!');
+            },
+            success : function() {
+                alter_success('实例重启指令发送成功!');
+            }
+        });
+    }
+
+    function force_reboot(uuids) {
+        $.ajax({
+            url : '/api/guests/_force_reboot/' + uuids.join(','),
+            type : 'PUT',
+            contentType: "application/json; charset=utf-8",
+            error : function() {
+                alter_danger('实例强制重启指令发送失败!');
+            },
+            success : function() {
+                alter_success('实例强制重启指令发送成功!');
+            }
+        });
+    }
+
+    function shutdown(uuids) {
+        $.ajax({
+            url : '/api/guests/_shutdown/' + uuids.join(','),
+            type : 'PUT',
+            contentType: "application/json; charset=utf-8",
+            error : function() {
+                alter_danger('实例停止指令发送失败!');
+            },
+            success : function() {
+                alter_success('实例停止指令发送成功!');
+            }
+        });
+    }
+
+    function force_shutdown(uuids) {
+        $.ajax({
+            url : '/api/guests/_force_shutdown/' + uuids.join(','),
+            type : 'PUT',
+            contentType: "application/json; charset=utf-8",
+            error : function() {
+                alter_danger('实例强制停止指令发送失败!');
+            },
+            success : function() {
+                alter_success('实例强制停止指令发送成功!');
+            }
+        });
+    }
+
+    function suspend(uuids) {
+        $.ajax({
+            url : '/api/guests/_suspend/' + uuids.join(','),
+            type : 'PUT',
+            contentType: "application/json; charset=utf-8",
+            error : function() {
+                alter_danger('实例暂停指令发送失败!');
+            },
+            success : function() {
+                alter_success('实例暂停指令发送成功!');
+            }
+        });
+    }
+
+    function resume(uuids) {
+        $.ajax({
+            url : '/api/guests/_resume/' + uuids.join(','),
+            type : 'PUT',
+            contentType: "application/json; charset=utf-8",
+            error : function() {
+                alter_danger('实例恢复指令发送失败!');
+            },
+            success : function() {
+                alter_success('实例恢复指令发送成功!');
+            }
+        });
+    }
+
+    function boot_at(me) {
+        var uuid = $(me).parent().parent().parent().parent().parent().children()[0].textContent;
+        boot([uuid]);
+    }
+
+    function reboot_at(me) {
+        var uuid = $(me).parent().parent().parent().parent().parent().children()[0].textContent;
+        reboot([uuid]);
+    }
+
+    function force_reboot_at(me) {
+        var uuid = $(me).parent().parent().parent().parent().parent().children()[0].textContent;
+        force_reboot([uuid]);
+    }
+
+    function shutdown_at(me) {
+        var uuid = $(me).parent().parent().parent().parent().parent().children()[0].textContent;
+        shutdown([uuid]);
+    }
+
+    function force_shutdown_at(me) {
+        var uuid = $(me).parent().parent().parent().parent().parent().children()[0].textContent;
+        force_shutdown([uuid]);
+    }
+
+    function suspend_at(me) {
+        var uuid = $(me).parent().parent().parent().parent().parent().children()[0].textContent;
+        suspend([uuid]);
+    }
+
+    function resume_at(me) {
+        var uuid = $(me).parent().parent().parent().parent().parent().children()[0].textContent;
+        resume([uuid]);
+    }
+
 </script>
 <div class="panel">
     <div class="panel-body">
@@ -220,20 +354,26 @@
                             </a>
                             <ul class="dropdown-menu">
                                 <li class="{% if item.status not in [4, 5, 6] %} disabled {% endif %}">
-                                    <a href="javascript:;">启动</a>
+                                    <a href="javascript:;" onclick="boot_at(this);">启动</a>
+                                </li>
+                                <li class="{% if item.status not in [1] %} disabled {% endif %}">
+                                    <a href="javascript:;" onclick="reboot_at(this);">重启</a>
+                                </li>
+                                <li class="{% if item.status not in [1] %} disabled {% endif %}">
+                                    <a href="javascript:;" onclick="force_reboot_at(this);">强制重启</a>
                                 </li>
                                 <li class="{% if item.status not in [1] %} disabled {% endif %}">
-                                    <a href="javascript:;">重启</a>
+                                    <a href="javascript:;" onclick="shutdown_at(this);">停止</a>
                                 </li>
                                 <li class="{% if item.status not in [1] %} disabled {% endif %}">
-                                    <a href="javascript:;">停止</a>
+                                    <a href="javascript:;" onclick="force_shutdown_at(this);">强制停止</a>
                                 </li>
                                 <li class="divider"></li>
                                 <li class="{% if item.status not in [1] %} disabled {% endif %}">
-                                    <a href="javascript:;">暂停</a>
+                                    <a href="javascript:;" onclick="suspend_at(this);">暂停</a>
                                 </li>
                                 <li class="{% if item.status not in [3] %} disabled {% endif %}">
-                                    <a href="javascript:;">恢复</a>
+                                    <a href="javascript:;" onclick="resume_at(this);">恢复</a>
                                 </li>
                                 <li class="divider"></li>
                                 <li class="">