fix(xo-server): connect servers after config import (#5672)

Fixes #5670
This commit is contained in:
Julien Fontanet
2021-03-15 11:49:41 +01:00
committed by GitHub
parent 482299e765
commit 2fbfc97cca
2 changed files with 20 additions and 16 deletions

View File

@@ -12,6 +12,7 @@
> Users must be able to say: “I had this issue, happy to know it's fixed”
- [Pool] Fix `an error has occurred` when using the "Disconnect" button from the pool page [#5669](https://github.com/vatesfr/xen-orchestra/issues/5669) (PR [#5671](https://github.com/vatesfr/xen-orchestra/pull/5671))
- [Configuration] Automatically connect enabled servers after import [#5660](https://github.com/vatesfr/xen-orchestra/issues/5660) (PR [#5672](https://github.com/vatesfr/xen-orchestra/pull/5672))
### Packages to release
@@ -30,4 +31,5 @@
>
> In case of conflict, the highest (lowest in previous list) `$version` wins.
- xo-server patch
- xo-web patch

View File

@@ -55,37 +55,39 @@ export default class {
xo.on('clean', () => serversDb.rebuildIndexes())
xo.on('start', async () => {
async function connectServers() {
// Connects to existing servers.
for (const server of await serversDb.get()) {
if (server.enabled) {
this.connectXenServer(server.id).catch(error => {
log.warn('failed to connect to XenServer', {
host: server.host,
error,
})
})
}
}
}
xo.addConfigManager(
'xenServers',
() => serversDb.get(),
servers => serversDb.update(servers)
servers => serversDb.update(servers).then(connectServers)
)
const servers = await serversDb.get()
// Add servers in XenStore
if (servers.length === 0) {
if (!(await serversDb.exists())) {
const key = 'vm-data/xen-servers'
const xenStoreServers = await XenStore.read(key)
.then(JSON.parse)
.catch(() => [])
for (const server of xenStoreServers) {
servers.push(await this.registerXenServer(server))
await this.registerXenServer(server)
}
ignoreErrors.call(XenStore.rm(key))
}
// Connects to existing servers.
for (const server of servers) {
if (server.enabled) {
this.connectXenServer(server.id).catch(error => {
log.warn('failed to connect to XenServer', {
host: server.host,
error,
})
})
}
}
await connectServers()
})
// TODO: disconnect servers on stop.