Commit 219cdc45 authored by nanahira's avatar nanahira

catchup and possibly locale updates

parent dd6b7e85
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@avaflow/libvirt": "^0.0.7", "@avaflow/libvirt": "^0.0.7",
"koishi-thirdeye": "^9.1.1", "koishi-thirdeye": "^9.2.4",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"source-map-support": "^0.5.21" "source-map-support": "^0.5.21"
}, },
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
"ws": "^8.5.0" "ws": "^8.5.0"
}, },
"peerDependencies": { "peerDependencies": {
"koishi": "^4.4.0" "koishi": "^4.4.1"
} }
}, },
"node_modules/@ampproject/remapping": { "node_modules/@ampproject/remapping": {
...@@ -1071,9 +1071,9 @@ ...@@ -1071,9 +1071,9 @@
} }
}, },
"node_modules/@koishijs/core": { "node_modules/@koishijs/core": {
"version": "4.4.0", "version": "4.4.1",
"resolved": "https://registry.npmjs.org/@koishijs/core/-/core-4.4.0.tgz", "resolved": "https://registry.npmjs.org/@koishijs/core/-/core-4.4.1.tgz",
"integrity": "sha512-MmKVlCx89M5icof92+U8U5QnywQ7dIjkGGUnzGlcBr59OrylHdRMKqZIIrtnqZo5EONehqh3k1Zbxr5V/6X5Eg==", "integrity": "sha512-nd/QAm9ejk4KQP8BjnyuDCxg4rpyq4fyYtTvFOuafj9G/vN6gHL11YLF5R7g2WimnN1S2sN1txB7WNx8dnGI1A==",
"peer": true, "peer": true,
"dependencies": { "dependencies": {
"@koishijs/utils": "^5.2.0", "@koishijs/utils": "^5.2.0",
...@@ -1541,9 +1541,9 @@ ...@@ -1541,9 +1541,9 @@
"dev": true "dev": true
}, },
"node_modules/@types/ws": { "node_modules/@types/ws": {
"version": "8.2.3", "version": "8.5.2",
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.2.3.tgz", "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.2.tgz",
"integrity": "sha512-ahRJZquUYCdOZf/rCsWg88S0/+cb9wazUBHv6HZEe3XdYaBe2zr/slM8J28X07Hn88Pnm4ezo7N8/ofnOgrPVQ==", "integrity": "sha512-VXI82ykONr5tacHEojnErTQk+KQSoYbW1NB6iz6wUwrNd+BqfkfggQNoNdCqhJSzbNumShPERbM+Pc5zpfhlbw==",
"peer": true, "peer": true,
"dependencies": { "dependencies": {
"@types/node": "*" "@types/node": "*"
...@@ -5216,17 +5216,17 @@ ...@@ -5216,17 +5216,17 @@
} }
}, },
"node_modules/koishi": { "node_modules/koishi": {
"version": "4.4.0", "version": "4.4.1",
"resolved": "https://registry.npmjs.org/koishi/-/koishi-4.4.0.tgz", "resolved": "https://registry.npmjs.org/koishi/-/koishi-4.4.1.tgz",
"integrity": "sha512-ar4V0oBJ2by9gT0Hey3w/japL80ddtF2A48jP+UrPZ17Z3ha505lB79sQyPVyFdM78BY7wRkFw/qMc8eKZG3+g==", "integrity": "sha512-yTJlAwsbF7ecjqRGUX5l2LT8HROusAZj1UjzxEevXGWklRrzABWTifIXDEKd9H+oC5xq4hJQeXRCQCogiPe+SQ==",
"peer": true, "peer": true,
"dependencies": { "dependencies": {
"@koa/router": "^10.1.1", "@koa/router": "^10.1.1",
"@koishijs/core": "^4.4.0", "@koishijs/core": "^4.4.1",
"@koishijs/utils": "^5.2.0", "@koishijs/utils": "^5.2.0",
"@types/koa": "*", "@types/koa": "*",
"@types/koa__router": "*", "@types/koa__router": "*",
"@types/ws": "^8.2.2", "@types/ws": "^8.5.2",
"axios": "^0.24.0", "axios": "^0.24.0",
"file-type": "^16.5.3", "file-type": "^16.5.3",
"koa": "^2.13.4", "koa": "^2.13.4",
...@@ -5234,16 +5234,16 @@ ...@@ -5234,16 +5234,16 @@
"parseurl": "^1.3.3", "parseurl": "^1.3.3",
"path-to-regexp": "^6.2.0", "path-to-regexp": "^6.2.0",
"proxy-agent": "^5.0.0", "proxy-agent": "^5.0.0",
"ws": "^8.4.2" "ws": "^8.5.0"
}, },
"engines": { "engines": {
"node": ">=12.0.0" "node": ">=12.0.0"
} }
}, },
"node_modules/koishi-decorators": { "node_modules/koishi-decorators": {
"version": "1.1.1", "version": "1.2.5",
"resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-1.1.1.tgz", "resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-1.2.5.tgz",
"integrity": "sha512-AaumjnVTT8N7jJ67w16blSez9z+Pi+duuJusheIq3Hmkvx+iRxkpp3w0IvlU69gHqdQRK3Z4qNNC+KrMPDORUg==", "integrity": "sha512-PYVXFNdSCbifr12L0JSiIZGQsax1cENyxzWg0LTRemgTp5iZgj/QPXqgh4p3IWZ8YIPYQ53vSS6lBG2PnhKOWA==",
"dependencies": { "dependencies": {
"@types/koa": "^2.13.4", "@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11", "@types/koa__router": "^8.0.11",
...@@ -5252,24 +5252,24 @@ ...@@ -5252,24 +5252,24 @@
"typed-reflector": "^1.0.9" "typed-reflector": "^1.0.9"
}, },
"peerDependencies": { "peerDependencies": {
"koishi": "^4.2.1" "koishi": "^4.4.1"
} }
}, },
"node_modules/koishi-thirdeye": { "node_modules/koishi-thirdeye": {
"version": "9.1.1", "version": "9.2.4",
"resolved": "https://registry.npmjs.org/koishi-thirdeye/-/koishi-thirdeye-9.1.1.tgz", "resolved": "https://registry.npmjs.org/koishi-thirdeye/-/koishi-thirdeye-9.2.4.tgz",
"integrity": "sha512-Oy5Y36Jq9ZnJJLRKmbEx0yFP7lqazBXMxjBLdfl5+5Oyx1JdiYWlPLVQ8ggbmLTKmDXZ87s3c5nfxAN/4iBA8A==", "integrity": "sha512-maJkIivNEjDZaTDeOa2GSDxUX4pjie0zzjk7VxPnt/RONS9UHGUJ2A6CkcqYdz4CY6OKoWyhX0wzDnJkk/rUOg==",
"dependencies": { "dependencies": {
"@types/koa": "^2.13.4", "@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11", "@types/koa__router": "^8.0.11",
"koishi-decorators": "^1.1.1", "koishi-decorators": "^1.2.5",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"schemastery-gen": "^3.1.2", "schemastery-gen": "^3.1.2",
"typed-reflector": "^1.0.9" "typed-reflector": "^1.0.9"
}, },
"peerDependencies": { "peerDependencies": {
"koishi": "^4.4.0", "koishi": "^4.4.1",
"schemastery": "^3.1.0" "schemastery": "^3.1.0"
} }
}, },
...@@ -8508,9 +8508,9 @@ ...@@ -8508,9 +8508,9 @@
} }
}, },
"@koishijs/core": { "@koishijs/core": {
"version": "4.4.0", "version": "4.4.1",
"resolved": "https://registry.npmjs.org/@koishijs/core/-/core-4.4.0.tgz", "resolved": "https://registry.npmjs.org/@koishijs/core/-/core-4.4.1.tgz",
"integrity": "sha512-MmKVlCx89M5icof92+U8U5QnywQ7dIjkGGUnzGlcBr59OrylHdRMKqZIIrtnqZo5EONehqh3k1Zbxr5V/6X5Eg==", "integrity": "sha512-nd/QAm9ejk4KQP8BjnyuDCxg4rpyq4fyYtTvFOuafj9G/vN6gHL11YLF5R7g2WimnN1S2sN1txB7WNx8dnGI1A==",
"peer": true, "peer": true,
"requires": { "requires": {
"@koishijs/utils": "^5.2.0", "@koishijs/utils": "^5.2.0",
...@@ -8945,9 +8945,9 @@ ...@@ -8945,9 +8945,9 @@
"dev": true "dev": true
}, },
"@types/ws": { "@types/ws": {
"version": "8.2.3", "version": "8.5.2",
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.2.3.tgz", "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.2.tgz",
"integrity": "sha512-ahRJZquUYCdOZf/rCsWg88S0/+cb9wazUBHv6HZEe3XdYaBe2zr/slM8J28X07Hn88Pnm4ezo7N8/ofnOgrPVQ==", "integrity": "sha512-VXI82ykONr5tacHEojnErTQk+KQSoYbW1NB6iz6wUwrNd+BqfkfggQNoNdCqhJSzbNumShPERbM+Pc5zpfhlbw==",
"peer": true, "peer": true,
"requires": { "requires": {
"@types/node": "*" "@types/node": "*"
...@@ -11727,17 +11727,17 @@ ...@@ -11727,17 +11727,17 @@
} }
}, },
"koishi": { "koishi": {
"version": "4.4.0", "version": "4.4.1",
"resolved": "https://registry.npmjs.org/koishi/-/koishi-4.4.0.tgz", "resolved": "https://registry.npmjs.org/koishi/-/koishi-4.4.1.tgz",
"integrity": "sha512-ar4V0oBJ2by9gT0Hey3w/japL80ddtF2A48jP+UrPZ17Z3ha505lB79sQyPVyFdM78BY7wRkFw/qMc8eKZG3+g==", "integrity": "sha512-yTJlAwsbF7ecjqRGUX5l2LT8HROusAZj1UjzxEevXGWklRrzABWTifIXDEKd9H+oC5xq4hJQeXRCQCogiPe+SQ==",
"peer": true, "peer": true,
"requires": { "requires": {
"@koa/router": "^10.1.1", "@koa/router": "^10.1.1",
"@koishijs/core": "^4.4.0", "@koishijs/core": "^4.4.1",
"@koishijs/utils": "^5.2.0", "@koishijs/utils": "^5.2.0",
"@types/koa": "*", "@types/koa": "*",
"@types/koa__router": "*", "@types/koa__router": "*",
"@types/ws": "^8.2.2", "@types/ws": "^8.5.2",
"axios": "^0.24.0", "axios": "^0.24.0",
"file-type": "^16.5.3", "file-type": "^16.5.3",
"koa": "^2.13.4", "koa": "^2.13.4",
...@@ -11745,13 +11745,13 @@ ...@@ -11745,13 +11745,13 @@
"parseurl": "^1.3.3", "parseurl": "^1.3.3",
"path-to-regexp": "^6.2.0", "path-to-regexp": "^6.2.0",
"proxy-agent": "^5.0.0", "proxy-agent": "^5.0.0",
"ws": "^8.4.2" "ws": "^8.5.0"
} }
}, },
"koishi-decorators": { "koishi-decorators": {
"version": "1.1.1", "version": "1.2.5",
"resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-1.1.1.tgz", "resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-1.2.5.tgz",
"integrity": "sha512-AaumjnVTT8N7jJ67w16blSez9z+Pi+duuJusheIq3Hmkvx+iRxkpp3w0IvlU69gHqdQRK3Z4qNNC+KrMPDORUg==", "integrity": "sha512-PYVXFNdSCbifr12L0JSiIZGQsax1cENyxzWg0LTRemgTp5iZgj/QPXqgh4p3IWZ8YIPYQ53vSS6lBG2PnhKOWA==",
"requires": { "requires": {
"@types/koa": "^2.13.4", "@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11", "@types/koa__router": "^8.0.11",
...@@ -11761,13 +11761,13 @@ ...@@ -11761,13 +11761,13 @@
} }
}, },
"koishi-thirdeye": { "koishi-thirdeye": {
"version": "9.1.1", "version": "9.2.4",
"resolved": "https://registry.npmjs.org/koishi-thirdeye/-/koishi-thirdeye-9.1.1.tgz", "resolved": "https://registry.npmjs.org/koishi-thirdeye/-/koishi-thirdeye-9.2.4.tgz",
"integrity": "sha512-Oy5Y36Jq9ZnJJLRKmbEx0yFP7lqazBXMxjBLdfl5+5Oyx1JdiYWlPLVQ8ggbmLTKmDXZ87s3c5nfxAN/4iBA8A==", "integrity": "sha512-maJkIivNEjDZaTDeOa2GSDxUX4pjie0zzjk7VxPnt/RONS9UHGUJ2A6CkcqYdz4CY6OKoWyhX0wzDnJkk/rUOg==",
"requires": { "requires": {
"@types/koa": "^2.13.4", "@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11", "@types/koa__router": "^8.0.11",
"koishi-decorators": "^1.1.1", "koishi-decorators": "^1.2.5",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"schemastery-gen": "^3.1.2", "schemastery-gen": "^3.1.2",
......
{ {
"name": "koishi-plugin-libvirt", "name": "koishi-plugin-libvirt",
"description": "Koishi 的 LibVirt 管理器。", "description": "Libvirt plugin for Koishi",
"version": "1.2.1", "version": "1.2.1",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/src/index.d.ts", "types": "dist/src/index.d.ts",
...@@ -45,12 +45,12 @@ ...@@ -45,12 +45,12 @@
}, },
"dependencies": { "dependencies": {
"@avaflow/libvirt": "^0.0.7", "@avaflow/libvirt": "^0.0.7",
"koishi-thirdeye": "^9.1.1", "koishi-thirdeye": "^9.2.4",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"source-map-support": "^0.5.21" "source-map-support": "^0.5.21"
}, },
"peerDependencies": { "peerDependencies": {
"koishi": "^4.4.0" "koishi": "^4.4.1"
}, },
"devDependencies": { "devDependencies": {
"@koishijs/plugin-cache-lru": "^1.0.0-rc.0", "@koishijs/plugin-cache-lru": "^1.0.0-rc.0",
......
...@@ -8,8 +8,12 @@ import { ...@@ -8,8 +8,12 @@ import {
PutOption, PutOption,
CommandExample, CommandExample,
LifecycleEvents, LifecycleEvents,
CommandDescription,
Inject,
PutTemplate,
Renderer,
} from 'koishi-thirdeye'; } from 'koishi-thirdeye';
import { Logger } from 'koishi'; import { Logger, Template } from 'koishi';
import _ from 'lodash'; import _ from 'lodash';
import { DomainStateToText, getDomainsFromHypervisor } from './utils'; import { DomainStateToText, getDomainsFromHypervisor } from './utils';
export * from './config'; export * from './config';
...@@ -37,17 +41,27 @@ export default class LibVirtPlugin ...@@ -37,17 +41,27 @@ export default class LibVirtPlugin
} }
@UseCommand('virt', '虚拟机管理', { empty: true }) @UseCommand('virt', '虚拟机管理', { empty: true })
@CommandDescription({ en: 'Virtual machine management' })
async virtCommand() {} async virtCommand() {}
@UseCommand('virt.hosts', '查看主机列表') @UseCommand('virt.hosts', '查看主机列表')
@CommandDescription({ en: 'List hypervisors' })
async virtHostsCommand( async virtHostsCommand(
@PutOption('host', '-s <name:string> 指定主机') host: string, @PutOption('host', '-s <name:string> 指定主机', {
description: { en: 'Specify host' },
})
host: string,
@PutTemplate('noAvailableHosts', {
zh: '没有可用的主机。',
en: 'No available hosts.',
})
noAvailableHosts: Renderer<void>,
) { ) {
const defs = _.compact( const defs = _.compact(
host ? [this.config.findHypervisorDef(host)] : this.config.servers, host ? [this.config.findHypervisorDef(host)] : this.config.servers,
); );
if (!defs.length) { if (!defs.length) {
return '没有可用的主机。'; return noAvailableHosts();
} }
return (await Promise.all(defs.map((def) => def.hypervisorInfo()))).join( return (await Promise.all(defs.map((def) => def.hypervisorInfo()))).join(
'\n', '\n',
...@@ -55,14 +69,34 @@ export default class LibVirtPlugin ...@@ -55,14 +69,34 @@ export default class LibVirtPlugin
} }
@UseCommand('virt.vm', '查看虚拟机列表') @UseCommand('virt.vm', '查看虚拟机列表')
@CommandDescription({ en: 'List virtual machines' })
@CommandExample('virt.vm -s localhost 查看 localhost 主机的虚拟机列表。') @CommandExample('virt.vm -s localhost 查看 localhost 主机的虚拟机列表。')
@CommandExample( @CommandExample(
'virt.vm -s localhost -m ubuntu 查看 localhost 主机的 ubuntu 虚拟机信息。', 'virt.vm -s localhost -m ubuntu 查看 localhost 主机的 ubuntu 虚拟机信息。',
) )
async virtVmsCommand( async virtVmsCommand(
@PutOption('host', '-s <name:string> 指定主机') host: string, @PutOption('host', '-s <name:string> 指定主机', {
@PutOption('vm', '-m <name:string> 指定虚拟机') vm: string, description: { en: 'Specify host' },
@PutOption('displayUuid', '-u 显示 uuid') displayUuid: boolean, })
host: string,
@PutOption('vm', '-m <name:string> 指定虚拟机', {
description: { en: 'Specify VM' },
})
vm: string,
@PutOption('displayUuid', '-u 显示 uuid', {
description: { en: 'Display UUID' },
})
displayUuid: boolean,
@PutTemplate('noAvailableVMs', {
zh: '没有可用的虚拟机。',
en: 'No available VMs.',
})
noAvailableVMs: Renderer<void>,
@PutTemplate('list', {
zh: '{name} 主机的虚拟机列表:',
en: 'VMs of {name}:',
})
vmOf: Renderer<{ name: string }>,
) { ) {
const { name, hypervisor } = (await this.connect(host)) || {}; const { name, hypervisor } = (await this.connect(host)) || {};
if (!hypervisor) return connectFailMessage; if (!hypervisor) return connectFailMessage;
...@@ -74,7 +108,7 @@ export default class LibVirtPlugin ...@@ -74,7 +108,7 @@ export default class LibVirtPlugin
} }
if (!domains.length) { if (!domains.length) {
await hypervisor.connectClose(); await hypervisor.connectClose();
return '没有可用的虚拟机。'; return noAvailableVMs();
} }
const result = domains const result = domains
.map( .map(
...@@ -87,7 +121,7 @@ export default class LibVirtPlugin ...@@ -87,7 +121,7 @@ export default class LibVirtPlugin
) )
.join('\n'); .join('\n');
await hypervisor.connectClose(); await hypervisor.connectClose();
return `${name} 主机的虚拟机列表:\n${result}`; return `${vmOf({ name })}\n${result}`;
} }
private async virtActionCommand( private async virtActionCommand(
...@@ -124,7 +158,13 @@ export default class LibVirtPlugin ...@@ -124,7 +158,13 @@ export default class LibVirtPlugin
} }
} }
@Inject()
private i18n: Template;
private defineActionCommand(action: string, verb: string = action) { private defineActionCommand(action: string, verb: string = action) {
this.i18n.define('en', `commands.virt.${action}`, {
description: `Perform ${action} on virtual machine`,
});
this.ctx this.ctx
.command(`virt.${action}`, `${verb}虚拟机`) .command(`virt.${action}`, `${verb}虚拟机`)
.example( .example(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment