Connection to a Xen Server in read-only mode. (Fix vatesfr/xo-web#439)
`updateXenServer` applies changes in database and also changes the connection's read-only status if the client is connected to this server.
This commit is contained in:
parent
eb0c963332
commit
ab6c83a3fc
@ -109,7 +109,7 @@
|
||||
"stack-chain": "^1.3.3",
|
||||
"trace": "^2.0.1",
|
||||
"ws": "~0.8.0",
|
||||
"xen-api": "^0.6.4",
|
||||
"xen-api": "^0.7.2",
|
||||
"xml2js": "~0.4.6",
|
||||
"xo-collection": "^0.4.0"
|
||||
},
|
||||
|
@ -4,9 +4,10 @@ export async function add ({
|
||||
host,
|
||||
username,
|
||||
password,
|
||||
readOnly,
|
||||
autoConnect = true
|
||||
}) {
|
||||
const server = await this.registerXenServer({host, username, password})
|
||||
const server = await this.registerXenServer({host, username, password, readOnly})
|
||||
|
||||
if (autoConnect) {
|
||||
// Connect asynchronously, ignore any errors.
|
||||
@ -72,8 +73,8 @@ getAll.permission = 'admin'
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function set ({id, host, username, password}) {
|
||||
await this.updateXenServer(id, {host, username, password})
|
||||
export async function set ({id, host, username, password, readOnly}) {
|
||||
await this.updateXenServer(id, {host, username, password, readOnly})
|
||||
}
|
||||
|
||||
set.description = 'changes the properties of a Xen server'
|
||||
|
@ -386,7 +386,7 @@ const apiHelpers = {
|
||||
// Handles both properties and wrapped models.
|
||||
const properties = server.properties || server
|
||||
|
||||
server = pick(properties, 'id', 'host', 'username')
|
||||
server = pick(properties, 'id', 'host', 'username', 'readOnly')
|
||||
|
||||
// Injects connection status.
|
||||
const xapi = this._xapis[server.id]
|
||||
|
@ -12,11 +12,11 @@ export class Servers extends Collection {
|
||||
return Server
|
||||
}
|
||||
|
||||
async create ({host, username, password}) {
|
||||
async create ({host, username, password, readOnly}) {
|
||||
if (await this.exists({host})) {
|
||||
throw new Error('server already exists')
|
||||
}
|
||||
|
||||
return await this.add({host, username, password})
|
||||
return await this.add({host, username, password, readOnly})
|
||||
}
|
||||
}
|
||||
|
23
src/xo.js
23
src/xo.js
@ -968,11 +968,17 @@ export default class Xo extends EventEmitter {
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
|
||||
async registerXenServer ({host, username, password}) {
|
||||
async registerXenServer ({host, username, password, readOnly = false}) {
|
||||
// FIXME: We are storing passwords which is bad!
|
||||
// Could we use tokens instead?
|
||||
// TODO: use plain objects
|
||||
const server = await this._servers.create({host, username, password, enabled: 'true'})
|
||||
const server = await this._servers.create({
|
||||
host,
|
||||
username,
|
||||
password,
|
||||
readOnly: readOnly ? 'true' : undefined,
|
||||
enabled: 'true'
|
||||
})
|
||||
|
||||
return server.properties
|
||||
}
|
||||
@ -985,7 +991,7 @@ export default class Xo extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
async updateXenServer (id, {host, username, password, enabled}) {
|
||||
async updateXenServer (id, {host, username, password, readOnly, enabled}) {
|
||||
const server = await this._getXenServer(id)
|
||||
|
||||
if (host) server.set('host', host)
|
||||
@ -996,6 +1002,14 @@ export default class Xo extends EventEmitter {
|
||||
server.set('enabled', enabled ? 'true' : undefined)
|
||||
}
|
||||
|
||||
if (readOnly !== undefined) {
|
||||
server.set('readOnly', readOnly ? 'true' : undefined)
|
||||
const xapi = this._xapis[id]
|
||||
if (xapi) {
|
||||
xapi.readOnly = readOnly
|
||||
}
|
||||
}
|
||||
|
||||
await this._servers.update(server)
|
||||
}
|
||||
|
||||
@ -1055,7 +1069,8 @@ export default class Xo extends EventEmitter {
|
||||
auth: {
|
||||
user: server.username,
|
||||
password: server.password
|
||||
}
|
||||
},
|
||||
readOnly: Boolean(server.readOnly)
|
||||
})
|
||||
|
||||
xapi.xo = (() => {
|
||||
|
Loading…
Reference in New Issue
Block a user