|
|
|
|
@ -689,6 +689,17 @@ function settingsEditor(vm) {
|
|
|
|
|
const current = section.querySelector('[data-settings-current-hostname]');
|
|
|
|
|
if (current) current.textContent = `当前主机名:${text(vm.guest_hostname, vm.hostname, '未记录')}`;
|
|
|
|
|
if (!form) return section;
|
|
|
|
|
if (vm.instance_settings_supported !== true) {
|
|
|
|
|
form.remove();
|
|
|
|
|
const description = section.querySelector('.admin-instance-settings-heading p');
|
|
|
|
|
if (description) {
|
|
|
|
|
description.className = 'text-warning fs-13 mb-0';
|
|
|
|
|
description.textContent = vm.instance_status && vm.instance_status !== 'active'
|
|
|
|
|
? `当前实例处于“${text(vm.display?.lifecycle, vm.instance_status)}”状态,暂不能修改主机名、密码或 SSH 公钥。`
|
|
|
|
|
: '当前实例缺少已验证的面板云镜像元数据,暂不能修改主机名、密码或 SSH 公钥。请先核对实例元数据。';
|
|
|
|
|
}
|
|
|
|
|
return section;
|
|
|
|
|
}
|
|
|
|
|
const activeJob = Boolean(vm.active_job && ['queued', 'running', 'uncertain'].includes(String(vm.active_job.status)));
|
|
|
|
|
if (activeJob) {
|
|
|
|
|
unlockSettingsForm(form, true);
|
|
|
|
|
@ -755,14 +766,12 @@ function networkJobState(job) {
|
|
|
|
|
return String(job?.status || job?.job?.status || '').toLowerCase();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function networkOptionsView(section, options, fallback = false, fallbackMessage = '') {
|
|
|
|
|
function networkOptionsView(section, options) {
|
|
|
|
|
const summary = networkOptionSummary(options);
|
|
|
|
|
const status = section.querySelector('[data-network-options-status]');
|
|
|
|
|
if (status) {
|
|
|
|
|
status.textContent = fallback
|
|
|
|
|
? (fallbackMessage || '地址池详情暂不可用,暂不能选择新的公网 IP。')
|
|
|
|
|
: (options.message || '已读取宿主机地址池约束,提交前仍会再次实时校验。');
|
|
|
|
|
status.className = `text-muted fs-12 mb-0${fallback ? ' text-warning' : ''}`;
|
|
|
|
|
status.textContent = options.message || '已读取宿主机地址池约束,提交前仍会再次实时校验。';
|
|
|
|
|
status.className = 'text-muted fs-12 mb-0';
|
|
|
|
|
}
|
|
|
|
|
const values = section.querySelector('[data-network-options-values]');
|
|
|
|
|
if (!values) return;
|
|
|
|
|
@ -815,32 +824,46 @@ function networkOptionsView(section, options, fallback = false, fallbackMessage
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function networkOptionsErrorView(section, message) {
|
|
|
|
|
section._networkOptions = null;
|
|
|
|
|
section.querySelector('[data-network-options-values]')?.replaceChildren();
|
|
|
|
|
const status = section.querySelector('[data-network-options-status]');
|
|
|
|
|
if (status) {
|
|
|
|
|
status.textContent = message;
|
|
|
|
|
status.className = 'text-warning fs-12 mb-0';
|
|
|
|
|
}
|
|
|
|
|
const edit = section.querySelector('[data-network-edit="open"]');
|
|
|
|
|
if (edit instanceof HTMLButtonElement) {
|
|
|
|
|
edit.disabled = true;
|
|
|
|
|
edit.setAttribute('aria-expanded', 'false');
|
|
|
|
|
edit.title = message;
|
|
|
|
|
}
|
|
|
|
|
const form = section.querySelector('.admin-instance-network-form');
|
|
|
|
|
if (form) form.hidden = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function loadNetworkOptions(vm, section) {
|
|
|
|
|
const serial = state.networkSerial;
|
|
|
|
|
const controller = new AbortController();
|
|
|
|
|
state.networkOptionsRequest = controller;
|
|
|
|
|
let options = networkOptionsFromVm(vm);
|
|
|
|
|
let fallback = true;
|
|
|
|
|
let fallbackMessage = '';
|
|
|
|
|
let options;
|
|
|
|
|
try {
|
|
|
|
|
const payload = await api(`/api/v1/admin/instances/${encodeURIComponent(vm.id)}/network-options`, controller);
|
|
|
|
|
if (serial !== state.networkSerial || controller.signal.aborted) return;
|
|
|
|
|
options = networkOptionsPayload(payload, vm);
|
|
|
|
|
fallback = false;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
if (controller.signal.aborted && controller.signal.reason !== 'timeout') return;
|
|
|
|
|
if (serial !== state.networkSerial) return;
|
|
|
|
|
// The options endpoint is additive. Older deployments can still use the
|
|
|
|
|
// existing detail fields while the Agent remains the final validator.
|
|
|
|
|
options = networkOptionsFromVm(vm);
|
|
|
|
|
fallbackMessage = error.status === 409
|
|
|
|
|
const message = error.status === 409
|
|
|
|
|
? error.message : '无法读取宿主机地址池,暂不能选择新的公网 IP。';
|
|
|
|
|
if (state.detailId === String(vm.id)) networkOptionsErrorView(section, message);
|
|
|
|
|
return;
|
|
|
|
|
} finally {
|
|
|
|
|
if (state.networkOptionsRequest === controller) state.networkOptionsRequest = null;
|
|
|
|
|
}
|
|
|
|
|
if (serial !== state.networkSerial || state.detailId !== String(vm.id)) return;
|
|
|
|
|
section._networkOptions = options;
|
|
|
|
|
networkOptionsView(section, options, fallback, fallbackMessage);
|
|
|
|
|
networkOptionsView(section, options);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function targetNetworkValue(section, vm) {
|
|
|
|
|
@ -1016,7 +1039,7 @@ function networkEditor(vm) {
|
|
|
|
|
const template = byId('admin-instance-network-controls');
|
|
|
|
|
const controls = template?.content?.cloneNode(true);
|
|
|
|
|
const edit = controls?.querySelector('[data-network-edit="open"]');
|
|
|
|
|
if (edit) heading.append(edit);
|
|
|
|
|
if (edit && vm.network_change_supported === true) heading.append(edit);
|
|
|
|
|
section.append(heading);
|
|
|
|
|
|
|
|
|
|
const current = el('div', 'admin-instance-network-current mt-3');
|
|
|
|
|
@ -1026,6 +1049,18 @@ function networkEditor(vm) {
|
|
|
|
|
current.append(el('span', 'text-muted fs-13', '当前公网地址'), currentValue);
|
|
|
|
|
section.append(current);
|
|
|
|
|
|
|
|
|
|
if (!edit) {
|
|
|
|
|
if (controls) section.append(controls);
|
|
|
|
|
return section;
|
|
|
|
|
}
|
|
|
|
|
if (vm.network_change_supported !== true) {
|
|
|
|
|
section.append(el('p', 'text-warning fs-13 mt-3 mb-0',
|
|
|
|
|
vm.instance_status && vm.instance_status !== 'active'
|
|
|
|
|
? `当前实例处于“${text(vm.display?.lifecycle, vm.instance_status)}”状态,暂不能更换公网 IP。`
|
|
|
|
|
: '当前实例缺少已验证的面板云镜像元数据,暂不能更换公网 IP。请先核对实例元数据。'));
|
|
|
|
|
return section;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const optionsBox = el('div', 'admin-instance-network-options-box mt-3');
|
|
|
|
|
optionsBox.append(el('p', 'text-muted fs-13 mb-2', '宿主机网络约束'));
|
|
|
|
|
const optionsValues = el('dl', 'admin-instance-network-options');
|
|
|
|
|
@ -1248,6 +1283,9 @@ async function openDetail(id, opener) {
|
|
|
|
|
cancelSettingsActivity('detail-switch');
|
|
|
|
|
state.detailId = id;
|
|
|
|
|
state.opener = opener;
|
|
|
|
|
const dialog = byId('instance-detail');
|
|
|
|
|
const drawerBody = dialog.querySelector('.admin-instance-drawer-body');
|
|
|
|
|
if (drawerBody) drawerBody.scrollTop = 0;
|
|
|
|
|
const controller = new AbortController();
|
|
|
|
|
state.detailRequest = controller;
|
|
|
|
|
byId('instance-detail-title').textContent = `实例 #${id}`;
|
|
|
|
|
@ -1256,9 +1294,9 @@ async function openDetail(id, opener) {
|
|
|
|
|
tabs.forEach(tab => byId(`instance-panel-${tab}`).replaceChildren());
|
|
|
|
|
chooseTab('basic');
|
|
|
|
|
detailNotice('正在读取详情…');
|
|
|
|
|
if (!byId('instance-detail').open) {
|
|
|
|
|
if (!dialog.open) {
|
|
|
|
|
lockDetailScroll();
|
|
|
|
|
window.VenixDrawerMotion.openDrawerWithMotion(byId('instance-detail'));
|
|
|
|
|
window.VenixDrawerMotion.openDrawerWithMotion(dialog);
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
const payload = await api(`/api/v1/admin/instances/${id}`, controller);
|
|
|
|
|
|