chore: 补充其他access的测试按钮

This commit is contained in:
xiaojunnuo
2026-02-15 22:45:22 +08:00
parent 9671348dc1
commit 7cd8a645a8
16 changed files with 420 additions and 136 deletions
@@ -70,6 +70,47 @@ export class ProxmoxAccess extends BaseAccess {
encrypt: false,
})
realm = '';
@AccessInput({
title: "测试",
component: {
name: "api-test",
action: "onTestRequest",
},
helper: "点击测试接口看是否正常",
})
testRequest = true;
async onTestRequest() {
await this.getNodeList();
return "ok";
}
async getNodeList() {
const client = await this.getClient();
const nodesRes = await client.nodes.index();
// this.logger.info('nodes:', nodesRes.response);
if (!nodesRes.response?.data) {
return []
}
return nodesRes.response.data
}
async getClient() {
const pve = await import('@certd/cv4pve-api-javascript');
const client = new pve.PveClient(this.host, this.port);
const login = await client.login(this.username, this.password, this.realm || 'pam');
if (!login) {
throw new Error(`Login failed:${JSON.stringify(login)}`);
}
const versionRes = await client.version.version();
this.ctx.logger.info('Proxmox version:', versionRes.response);
return client;
}
}
new ProxmoxAccess();
@@ -66,8 +66,8 @@ export class ProxmoxUploadCert extends AbstractPlusTaskPlugin {
//插件执行方法
async execute(): Promise<void> {
const { cert } = this;
const client = await this.getClient();
const access = await this.getAccess<ProxmoxAccess>(this.accessId);
const client = await access.getClient();
for (const node of this.nodes) {
this.logger.info(`开始上传证书到节点:${node}`);
@@ -84,31 +84,17 @@ export class ProxmoxUploadCert extends AbstractPlusTaskPlugin {
this.logger.info('部署成功');
}
async onGetNodeList() {
const client = await this.getClient();
async onGetNodeList() {
const nodesRes = await client.nodes.index();
// this.logger.info('nodes:', nodesRes.response);
return nodesRes.response.data.map((node: any) => {
const access = await this.getAccess<ProxmoxAccess>(this.accessId);
const nodesRes = await access.getNodeList();
return nodesRes.map((node: any) => {
return {
value: node.node,
label: node.node,
};
});
}
async getClient() {
const access: ProxmoxAccess = await this.getAccess<ProxmoxAccess>(this.accessId);
const pve = await import('@certd/cv4pve-api-javascript');
const client = new pve.PveClient(access.host, access.port);
const login = await client.login(access.username, access.password, access.realm || 'pam');
if (!login) {
throw new Error(`Login failed:${JSON.stringify(login)}`);
}
const versionRes = await client.version.version();
this.logger.info('Proxmox version:', versionRes.response);
return client;
}
}
//实例化一下,注册插件
new ProxmoxUploadCert();