|
|
|
|
@ -321,6 +321,156 @@ function detailField(list, label, value) {
|
|
|
|
|
list.append(create('dt', '', label), create('dd', '', value || '未记录'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function detailSection(title, description) {
|
|
|
|
|
const section = create('section', 'admin-vpc-detail-section');
|
|
|
|
|
const header = create('header');
|
|
|
|
|
header.append(create('h3', '', title), create('p', '', description));
|
|
|
|
|
const content = create('div', 'admin-vpc-detail-list');
|
|
|
|
|
section.append(header, content);
|
|
|
|
|
return { section, content };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function detailState(label, tone = 'warning') {
|
|
|
|
|
return create('span', `admin-vpc-state is-${tone}`, label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function portCard(port) {
|
|
|
|
|
const labels = {
|
|
|
|
|
reserved: '已预留', preparing: '准备中', attached: '已连接',
|
|
|
|
|
detaching: '移出中', migrating: '迁移中', release_pending: '等待清理',
|
|
|
|
|
};
|
|
|
|
|
const healthy = port.state === 'attached'
|
|
|
|
|
&& Number(port.desired_revision) === Number(port.applied_revision)
|
|
|
|
|
&& !port.last_error_code;
|
|
|
|
|
const card = create('article', 'admin-vpc-detail-card');
|
|
|
|
|
const header = create('header');
|
|
|
|
|
const heading = create('div');
|
|
|
|
|
heading.append(create('h4', '', port.instance_name || `实例 #${port.instance_id}`),
|
|
|
|
|
create('p', 'admin-mono', port.instance_uuid || `ID ${port.instance_id}`));
|
|
|
|
|
header.append(heading, detailState(labels[port.state] || port.state,
|
|
|
|
|
healthy ? 'success' : (port.last_error_code ? 'danger' : 'warning')));
|
|
|
|
|
const details = create('dl');
|
|
|
|
|
detailField(details, '公网 IPv4', port.public_ip);
|
|
|
|
|
detailField(details, '私网 IPv4', port.private_ip);
|
|
|
|
|
detailField(details, '所在节点', port.host_name || `节点 #${port.host_id}`);
|
|
|
|
|
detailField(details, '版本', `${port.applied_revision} / ${port.desired_revision}`);
|
|
|
|
|
if (port.last_error_code) detailField(details, '最近错误', port.last_error_code);
|
|
|
|
|
const footer = create('footer');
|
|
|
|
|
const link = create('a', 'btn btn-light btn-sm', '查看实例');
|
|
|
|
|
link.href = port.instance_url;
|
|
|
|
|
footer.append(link);
|
|
|
|
|
card.append(header, details, footer);
|
|
|
|
|
return card;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function hostStateCard(host) {
|
|
|
|
|
const labels = { ready: '已收敛', pending: '等待应用', applying: '应用中',
|
|
|
|
|
failed: '应用失败', unknown: '效果未知' };
|
|
|
|
|
const card = create('article', 'admin-vpc-detail-card');
|
|
|
|
|
const header = create('header');
|
|
|
|
|
const heading = create('div');
|
|
|
|
|
heading.append(create('h4', '', host.host_name || `节点 #${host.host_id}`),
|
|
|
|
|
create('p', '', `节点 ID ${host.host_id}`));
|
|
|
|
|
header.append(heading, detailState(labels[host.sync_state] || host.sync_state,
|
|
|
|
|
host.ready ? 'success' : (['failed', 'unknown'].includes(host.sync_state)
|
|
|
|
|
? 'danger' : 'warning')));
|
|
|
|
|
const details = create('dl');
|
|
|
|
|
detailField(details, '期望 / 已应用', `${host.desired_revision} / ${host.applied_revision}`);
|
|
|
|
|
detailField(details, '摘要核对', host.digest_match ? '一致' : '不一致');
|
|
|
|
|
detailField(details, '最近成功', formatTime(host.last_success_at));
|
|
|
|
|
detailField(details, '最近失败', formatTime(host.last_failure_at));
|
|
|
|
|
if (host.last_error_code) detailField(details, '最近错误', host.last_error_code);
|
|
|
|
|
const footer = create('footer');
|
|
|
|
|
const link = create('a', 'btn btn-light btn-sm', '查看计算节点');
|
|
|
|
|
link.href = host.host_url;
|
|
|
|
|
footer.append(link);
|
|
|
|
|
card.append(header, details, footer);
|
|
|
|
|
return card;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function batchCard(batch) {
|
|
|
|
|
const labels = { routing: '应用路由', ports: '应用实例端口', cleanup: '清理中',
|
|
|
|
|
blocked: '需要处理', succeeded: '已完成', failed: '失败' };
|
|
|
|
|
const card = create('article', 'admin-vpc-detail-card is-compact');
|
|
|
|
|
const header = create('header');
|
|
|
|
|
const heading = create('div');
|
|
|
|
|
heading.append(create('h4', '', `${batch.kind === 'attach' ? '批量加入' : '批量移出'} · #${batch.id}`),
|
|
|
|
|
create('p', '', `任务 #${batch.job_id} · 目标版本 ${batch.desired_revision}`));
|
|
|
|
|
const tone = batch.state === 'succeeded' ? 'success'
|
|
|
|
|
: (['blocked', 'failed'].includes(batch.state) ? 'danger' : 'warning');
|
|
|
|
|
header.append(heading, detailState(labels[batch.state] || batch.state, tone));
|
|
|
|
|
const progress = batch.items || {};
|
|
|
|
|
const note = create('p', 'admin-vpc-detail-note',
|
|
|
|
|
progress.total ? `实例进度 ${progress.finished || 0} / ${progress.total};成功 ${progress.succeeded || 0},失败 ${progress.failed || 0},未知 ${progress.unknown || 0}`
|
|
|
|
|
: '该批次没有实例明细或明细已清理。');
|
|
|
|
|
if (batch.last_error_code) note.append(document.createTextNode(` · ${batch.last_error_code}`));
|
|
|
|
|
const footer = create('footer');
|
|
|
|
|
const link = create('a', 'btn btn-light btn-sm', '查看任务');
|
|
|
|
|
link.href = batch.job_url;
|
|
|
|
|
footer.append(link);
|
|
|
|
|
card.append(header, note, footer);
|
|
|
|
|
return card;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function jobCard(job) {
|
|
|
|
|
const tone = job.status_label === '已完成' ? 'success'
|
|
|
|
|
: (job.status_label === '失败' ? 'danger' : 'warning');
|
|
|
|
|
const card = create('article', 'admin-vpc-detail-card is-compact');
|
|
|
|
|
const header = create('header');
|
|
|
|
|
const heading = create('div');
|
|
|
|
|
heading.append(create('h4', '', `${job.kind_label} · #${job.id}`),
|
|
|
|
|
create('p', 'admin-mono', job.operation_id));
|
|
|
|
|
header.append(heading, detailState(job.status_label, tone));
|
|
|
|
|
const note = create('p', 'admin-vpc-detail-note',
|
|
|
|
|
job.error_code ? `错误:${job.error_code}` : `最近更新:${formatTime(job.updated_at)}`);
|
|
|
|
|
const footer = create('footer');
|
|
|
|
|
const link = create('a', 'btn btn-light btn-sm', '查看任务详情');
|
|
|
|
|
link.href = job.url;
|
|
|
|
|
footer.append(link);
|
|
|
|
|
card.append(header, note, footer);
|
|
|
|
|
return card;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderDetail(payload) {
|
|
|
|
|
const body = byId('admin-vpc-detail-body');
|
|
|
|
|
const network = payload.vpc;
|
|
|
|
|
body.replaceChildren();
|
|
|
|
|
byId('admin-vpc-detail-title').textContent = network.name;
|
|
|
|
|
const overview = detailSection('网络概览', '面板期望状态与当前资源归属。');
|
|
|
|
|
const details = create('dl', 'admin-instance-details');
|
|
|
|
|
detailField(details, '所有者', `${network.owner_name || '未记录'} · ID ${network.user_id}`);
|
|
|
|
|
detailField(details, '地区', network.region_name);
|
|
|
|
|
detailField(details, '私网网段', network.cidr);
|
|
|
|
|
detailField(details, '默认网关', network.gateway);
|
|
|
|
|
detailField(details, '目标版本', String(network.desired_revision));
|
|
|
|
|
detailField(details, '运行状态', network.display?.label);
|
|
|
|
|
overview.content.append(details);
|
|
|
|
|
body.append(overview.section);
|
|
|
|
|
|
|
|
|
|
const ports = detailSection('实例端口', '显示当前有效私网网卡;不会在此处强制加入或移出。');
|
|
|
|
|
for (const port of payload.ports || []) ports.content.append(portCard(port));
|
|
|
|
|
if (!payload.ports?.length) ports.content.append(create('p', 'admin-vpc-detail-empty', '当前没有有效实例端口。'));
|
|
|
|
|
body.append(ports.section);
|
|
|
|
|
|
|
|
|
|
const hosts = detailSection('宿主机投影', '期望版本、已应用版本和摘要必须同时一致。');
|
|
|
|
|
for (const host of payload.host_states || []) hosts.content.append(hostStateCard(host));
|
|
|
|
|
if (!payload.host_states?.length) hosts.content.append(create('p', 'admin-vpc-detail-empty', '当前没有宿主机路由投影。'));
|
|
|
|
|
body.append(hosts.section);
|
|
|
|
|
|
|
|
|
|
const batches = detailSection('批量变更', '批量加入或移出的持久化协调状态。');
|
|
|
|
|
for (const batch of payload.batches || []) batches.content.append(batchCard(batch));
|
|
|
|
|
if (!payload.batches?.length) batches.content.append(create('p', 'admin-vpc-detail-empty', '没有近期批量变更。'));
|
|
|
|
|
body.append(batches.section);
|
|
|
|
|
|
|
|
|
|
const jobs = detailSection('相关任务', '恢复和人工核查必须进入原任务,禁止直接重复提交。');
|
|
|
|
|
for (const job of payload.jobs || []) jobs.content.append(jobCard(job));
|
|
|
|
|
if (!payload.jobs?.length) jobs.content.append(create('p', 'admin-vpc-detail-empty', '没有近期相关任务。'));
|
|
|
|
|
body.append(jobs.section);
|
|
|
|
|
const focusJob = (payload.jobs || []).find(job => job.status_label !== '已完成')
|
|
|
|
|
|| payload.jobs?.[0];
|
|
|
|
|
byId('admin-vpc-detail-operations').href = focusJob?.url || '/admin/operations';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function openDetail(id) {
|
|
|
|
|
const dialog = byId('admin-vpc-detail');
|
|
|
|
|
const body = byId('admin-vpc-detail-body');
|
|
|
|
|
@ -332,17 +482,7 @@ async function openDetail(id) {
|
|
|
|
|
window.VenixDrawerMotion?.openDrawerWithMotion(dialog) || dialog.showModal();
|
|
|
|
|
try {
|
|
|
|
|
const payload = await api(`/api/v1/admin/vpc-control/vpcs/${encodeURIComponent(id)}`);
|
|
|
|
|
const network = payload.vpc;
|
|
|
|
|
byId('admin-vpc-detail-title').textContent = network.name;
|
|
|
|
|
const details = create('dl', 'admin-instance-details');
|
|
|
|
|
detailField(details, '所有者', `${network.owner_name || '未记录'} · ID ${network.user_id}`);
|
|
|
|
|
detailField(details, '地区', network.region_name);
|
|
|
|
|
detailField(details, '私网网段', network.cidr);
|
|
|
|
|
detailField(details, '默认网关', network.gateway);
|
|
|
|
|
detailField(details, '实例端口', String(network.port_count));
|
|
|
|
|
detailField(details, '宿主机投影',
|
|
|
|
|
`${network.host_summary.ready} / ${network.host_summary.total} 已收敛`);
|
|
|
|
|
body.append(details);
|
|
|
|
|
renderDetail(payload);
|
|
|
|
|
message.hidden = true;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
message.className = 'alert alert-danger';
|
|
|
|
|
|