dashboard服务器管理界面增加强制重启按钮
This commit is contained in:
parent
6ed95bfaaa
commit
43e0a993fa
@ -171,6 +171,14 @@
|
|||||||
>
|
>
|
||||||
重启
|
重启
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button
|
||||||
|
@click="forceRestartServer"
|
||||||
|
:loading="forceRestartLoading"
|
||||||
|
variant="outline"
|
||||||
|
class="bg-orange-50 text-orange-700 hover:bg-orange-100 border-orange-200"
|
||||||
|
>
|
||||||
|
强制重启
|
||||||
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
@click="resetPassword"
|
@click="resetPassword"
|
||||||
:loading="resetPasswordLoading"
|
:loading="resetPasswordLoading"
|
||||||
@ -293,6 +301,7 @@ export default {
|
|||||||
showPassword: false,
|
showPassword: false,
|
||||||
decryptedPassword: null,
|
decryptedPassword: null,
|
||||||
restartLoading: false,
|
restartLoading: false,
|
||||||
|
forceRestartLoading: false,
|
||||||
resetPasswordLoading: false,
|
resetPasswordLoading: false,
|
||||||
resetKeyPairLoading: false,
|
resetKeyPairLoading: false,
|
||||||
deleteKeyPairLoading: false,
|
deleteKeyPairLoading: false,
|
||||||
@ -417,6 +426,40 @@ export default {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
async forceRestartServer() {
|
||||||
|
if (!this.$jsiteServer.pg.instance_id) {
|
||||||
|
toast.error('服务器实例ID不存在');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
confirmDialog({
|
||||||
|
title: '强制重启',
|
||||||
|
message: '确定要强制重启服务器吗?该操作可能会导致未保存的数据丢失。',
|
||||||
|
primaryAction: {
|
||||||
|
label: '确定',
|
||||||
|
onClick: ({ hide }) => {
|
||||||
|
toast.success('强制重启请求已提交');
|
||||||
|
hide();
|
||||||
|
this.forceRestartLoading = true;
|
||||||
|
const req = createResource({
|
||||||
|
url: '/api/action/jcloud.api.aliyun_server_light.force_reboot_aliyun_instance',
|
||||||
|
params: {
|
||||||
|
instance_id: this.$jsiteServer.pg.instance_id,
|
||||||
|
region_id: this.$jsiteServer.pg.region
|
||||||
|
},
|
||||||
|
onSuccess: () => {
|
||||||
|
this.forceRestartLoading = false;
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
toast.error(getToastErrorMessage(error));
|
||||||
|
this.forceRestartLoading = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
req.submit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
async resetPassword() {
|
async resetPassword() {
|
||||||
if (!this.$jsiteServer.pg.instance_id) {
|
if (!this.$jsiteServer.pg.instance_id) {
|
||||||
toast.error('服务器实例ID不存在');
|
toast.error('服务器实例ID不存在');
|
||||||
|
|||||||
@ -166,6 +166,27 @@ class AliyunLightServerManager:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
jingrow.log_error("重启实例失败", f"重启实例 {instance_id} 时发生错误: {str(e)}")
|
jingrow.log_error("重启实例失败", f"重启实例 {instance_id} 时发生错误: {str(e)}")
|
||||||
return {'success': False, 'error': str(e), 'message': '实例重启失败'}
|
return {'success': False, 'error': str(e), 'message': '实例重启失败'}
|
||||||
|
|
||||||
|
def force_reboot_instances(self, instance_ids, region_id='cn-shanghai'):
|
||||||
|
"""强制重启实例(支持批量)"""
|
||||||
|
client = self._get_client(region_id)
|
||||||
|
try:
|
||||||
|
if isinstance(instance_ids, list):
|
||||||
|
instance_ids_str = json.dumps(instance_ids)
|
||||||
|
else:
|
||||||
|
instance_ids_str = instance_ids
|
||||||
|
|
||||||
|
request = swas__open20200601_models.RebootInstancesRequest(
|
||||||
|
region_id=region_id,
|
||||||
|
force_reboot=True,
|
||||||
|
instance_ids=instance_ids_str
|
||||||
|
)
|
||||||
|
runtime = util_models.RuntimeOptions()
|
||||||
|
response = client.reboot_instances_with_options(request, runtime)
|
||||||
|
return {'success': True, 'data': self._convert_response_to_dict(response.body), 'message': '实例强制重启命令已发送'}
|
||||||
|
except Exception as e:
|
||||||
|
jingrow.log_error("强制重启实例失败", f"强制重启实例 {instance_ids} 时发生错误: {str(e)}")
|
||||||
|
return {'success': False, 'error': str(e), 'message': '实例强制重启失败'}
|
||||||
|
|
||||||
def upgrade_instance(self, instance_id, plan_id, region_id='cn-shanghai'):
|
def upgrade_instance(self, instance_id, plan_id, region_id='cn-shanghai'):
|
||||||
"""升级实例配置"""
|
"""升级实例配置"""
|
||||||
@ -603,6 +624,46 @@ def reboot_aliyun_instance(instance_id, region_id='cn-shanghai'):
|
|||||||
jingrow.log_error("重启实例失败", f"重启实例 {instance_id} 时发生错误: {str(e)}")
|
jingrow.log_error("重启实例失败", f"重启实例 {instance_id} 时发生错误: {str(e)}")
|
||||||
return {"success": False, "error": str(e), "message": "重启实例失败"}
|
return {"success": False, "error": str(e), "message": "重启实例失败"}
|
||||||
|
|
||||||
|
@jingrow.whitelist()
|
||||||
|
def force_reboot_aliyun_instance(instance_id, region_id='cn-shanghai'):
|
||||||
|
"""强制重启实例并更新状态"""
|
||||||
|
try:
|
||||||
|
# 1. 查找对应的Jsite Server记录
|
||||||
|
server = jingrow.get_pg("Jsite Server", {"instance_id": instance_id})
|
||||||
|
if not server:
|
||||||
|
return {"success": False, "message": "找不到对应的服务器记录"}
|
||||||
|
|
||||||
|
# 2. 立即更新状态为"启动中"(与普通重启保持一致)
|
||||||
|
server.status = "Starting"
|
||||||
|
server.save(ignore_permissions=True)
|
||||||
|
jingrow.db.commit()
|
||||||
|
|
||||||
|
# 3. 调用阿里云API强制重启实例
|
||||||
|
manager = _get_manager()
|
||||||
|
result = manager.force_reboot_instances([instance_id], region_id)
|
||||||
|
|
||||||
|
if not result or not result.get('success'):
|
||||||
|
return result
|
||||||
|
|
||||||
|
# 4. 启动后台任务监控重启状态(延迟10秒开始)
|
||||||
|
time.sleep(10)
|
||||||
|
jingrow.enqueue(
|
||||||
|
"jcloud.api.aliyun_server_light.monitor_server_status",
|
||||||
|
instance_id=instance_id,
|
||||||
|
region_id=region_id,
|
||||||
|
timeout=600
|
||||||
|
)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"success": True,
|
||||||
|
"message": "强制重启命令已发送,正在监控重启状态...",
|
||||||
|
"server_name": server.name
|
||||||
|
}
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
jingrow.log_error("强制重启实例失败", f"强制重启实例 {instance_id} 时发生错误: {str(e)}")
|
||||||
|
return {"success": False, "error": str(e), "message": "强制重启实例失败"}
|
||||||
|
|
||||||
|
|
||||||
def monitor_server_status(instance_id, region_id):
|
def monitor_server_status(instance_id, region_id):
|
||||||
"""通用的服务器状态监控 - 监控服务器状态直到Running"""
|
"""通用的服务器状态监控 - 监控服务器状态直到Running"""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user