-
Notifications
You must be signed in to change notification settings - Fork 270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(xo-server): remember server's pool name and description #8206
base: master
Are you sure you want to change the base?
Conversation
d233b11
to
b05365a
Compare
packages/xo-server/src/api/pool.mjs
Outdated
if (nameLabel !== undefined || nameDescription !== undefined) { | ||
const serverId = this.getXenServerIdByObject(pool.uuid, 'pool') | ||
await this.updateXenServer(serverId, { poolNameDescription: nameDescription, poolNameLabel: nameLabel }) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A pool's name may be changed by another client. Also, I think the most common use case for this feature would be to get the name of the pool as soon as the user connects to the server. Updating it when the pool's name_label changes is almost a bonus because it doesn't change that often.
So I think a better approach for this would probably be a sort of hook on the XAPI events to catch any changes of the pools' names and update their servers accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I did does display the name of the pool when a server is added or connected to.
But you're right, I did not realize the pool's name could be changed by another client.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you need to watch objects and update the record if there was a change.
A good place for this coold be:
// handle pool UUID change |
await this.updateXenServer(id, { | ||
poolNameLabel: xapi.pool.name_label, | ||
poolNameDescription: xapi.pool.name_description, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it also possible to not update it if the value do not change ?
Are we sure the xapi.pool.name_xx are correctly loaded here ?
4650fd4
to
e1b5325
Compare
e1b5325
to
1623ae1
Compare
@@ -223,6 +262,11 @@ export default class XenServers { | |||
serverIdsByPool[xapiObject.$id] = conId | |||
} | |||
|
|||
// save pool name and description in server properties | |||
if (xapiObject.$type === 'pool') { | |||
updatePoolServer(xapiObject, xapiId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if this function reject?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function is not awaited, so if it rejects it does not prevent the rest of the code from executing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Promise rejections should always be handled, either:
await
them- log the error
- explicitly ignore it
.catch(noop)
or betterignoreErrors.call(promise)
(which does not ignore programming errors)
CHANGELOG.unreleased.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to change xo-server patch
to xo-server minor
in "Packages to release".
poolNameDescription: xapiObject.name_description, | ||
}) | ||
} | ||
}.bind(this) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not using an arrow function?
const xenServer = await this.getXenServer(serverId) | ||
|
||
const serverPropertiesUpdate = { | ||
...(xapiObject.name_label !== undefined && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can a pool's name_label
be undefined
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, I'll have to check
const serverPropertiesUpdate = { | ||
...(xapiObject.name_label !== undefined && | ||
xapiObject.name_label !== xenServer.poolNameLabel && { poolNameLabel: xapiObject.name_label }), | ||
...(xapiObject.name_description !== undefined && | ||
xapiObject.name_description !== xenServer.poolNameDescription && { | ||
poolNameDescription: xapiObject.name_description, | ||
}), | ||
...(xenServer.poolNameLabel === undefined && | ||
xapiObject.name_label !== undefined && { label: xapiObject.name_label }), | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it easier to read with explicit if
s and assignments:
const serverPropertiesUpdate = {}
if (xapiObject.name_label !== xenServer.poolNameLabel) {
serverPropertiesUpdate.poolNameLabel = xapiObject.name_label
}
// ...
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really like it as it uses a lot of lines for a simple purpose, but if you had trouble reading what I did then I guess you're right
if (poolNameDescription !== undefined) server.poolNameDescription = poolNameDescription || undefined | ||
if (poolNameLabel !== undefined) server.poolNameLabel = poolNameLabel || undefined | ||
// using pool name as default server name | ||
if (server.label === undefined) server.label = server.poolNameLabel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then if the pool's name_label
changes twice, the server's label
will keep the pool's old name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but I don't think we have much other choice if we still want the server label
to be directly configurable. (we could maybe use a boolean to tell if the pool label has ever been directly modified, but it would look really ugly)
Description
Remember server's pool name and description, and display the pool name as server default label.
I did multiple commits to keep the original changes around, but I would advise not to review by commit.
XO-437
Checklist
Fixes #007
,See xoa-support#42
,See https://...
)Introduced by
CHANGELOG.unreleased.md
Review process
Notes: