Files
console-dev/app/lib/instance-status.js
T

100 lines
2.9 KiB
JavaScript

/** 实例业务状态与电源状态的统一显示;暂停原因只在确实暂停时展示。 */
function e(e, t) {
let n =
typeof t == `string` &&
[`suspend`, `suspended`, `paused`].includes(t.trim().toLowerCase());
return e.status !== `Suspended` && !(e.status === `Active` && n)
? ``
: e.suspend_reason?.trim() ||
{
overtraffic: `流量用尽,服务已暂停`,
overdue: `服务到期,已暂停`,
certification_not_complete: `实名认证未完成,服务已暂停`,
upstream: `上游暂停服务`,
downstream: `下游暂停服务`,
}[e.suspend_type || ``] ||
`暂停原因暂未提供,请联系支持`;
}
// 业务状态优先于电源状态;只有 Active 实例才显示运行/关机等即时状态。
function t(e, t = `Active`, n = !1) {
let r = {
Unpaid: `未付款`,
Pending: `开通中`,
Suspended: `暂停`,
Deleted: `已删除`,
Failed: `开通失败`,
Grace: `宽限期`,
Keep: `保留期`,
};
if (t && t !== `Active`)
return {
label: r[t] || `状态未知`,
tone: `warning`,
severity: `warn`,
};
let i = typeof e == `string` ? e.trim().toLowerCase() : ``;
return i === `on`
? {
label: `运行中`,
tone: `running`,
severity: `success`,
}
: i === `off`
? {
label: `已关机`,
tone: `stopped`,
severity: `danger`,
}
: {
label:
{
suspend: `暂停`,
suspended: `暂停`,
paused: `暂停`,
pending: `开通中`,
operating: `操作中`,
fault: `故障`,
}[i] || (n ? `查询中` : `状态未知`),
tone: `warning`,
severity: `warn`,
};
}
// 为已支持的模块选择状态接口;未知模块或非法实例编号返回 null,不拼接猜测路径。
function n(e, t) {
if (!/^[1-9]\d*$/.test(String(t))) return null;
let n = e.replace(/^mf_finance(?=$|_)/, `remf_finance`);
return n === `idcsmart_common` || n === `reidcsmart_common`
? {
method: `post`,
path: `/${n}/host/${t}/provision/status`,
}
: [
`mf_cloud`,
`kky_ecs`,
`mf_dcim`,
`remf_dcim`,
`remf_cloud`,
`remf_finance`,
`remf_finance_dcim`,
`remf_finance_common`,
`jy_cloud`,
`jy_dcim`,
].includes(n)
? {
method: `get`,
path: `/${n}/${t}/status`,
}
: null;
}
/** e 为 API 客户端;仅返回字符串电源状态,缺少状态时返回空串供 UI 显示未知。 */
async function r(e, t, r) {
let i = n(t, r);
if (!i) return ``;
let a = await e[i.method](i.path, void 0, !1, {
timeoutMs: 12e3,
}),
o = a && typeof a == `object` ? a.status : void 0;
return typeof o == `string` ? o : ``;
}
export { e as n, r, t };