Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

b-Nollet
Copy link
Contributor

@b-Nollet b-Nollet commented Dec 19, 2024

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

  • Commit
    • Title follows commit conventions
    • Reference the relevant issue (Fixes #007, See xoa-support#42, See https://...)
    • If bug fix, add Introduced by
  • Changelog
    • If visible by XOA users, add changelog entry
    • Update "Packages to release" in CHANGELOG.unreleased.md
  • PR
    • If UI changes, add screenshots
    • If not finished or not tested, open as Draft

Review process

This 2-passes review process aims to:

  • develop skills of junior reviewers
  • limit the workload for senior reviewers
  • limit the number of unnecessary changes by the author
  1. The author creates a PR.
  2. Review process:
    1. The author assigns the junior reviewer.
    2. The junior reviewer conducts their review:
      • Resolves their comments if they are addressed.
      • Adds comments if necessary or approves the PR.
    3. The junior reviewer assigns the senior reviewer.
    4. The senior reviewer conducts their review:
      • If there are no unresolved comments on the PR → merge.
      • Otherwise, we continue with 3.
  3. The author responds to comments and/or makes corrections, and we go back to 2.

Notes:

  1. The author can request a review at any time, even if the PR is still a Draft.
  2. In theory, there should not be more than one reviewer at a time.
  3. The author should not make any changes:
    • When a reviewer is assigned.
    • Between the junior and senior reviews.

@b-Nollet b-Nollet marked this pull request as ready for review December 19, 2024 15:40
@b-Nollet b-Nollet requested a review from pdonias December 19, 2024 15:46
Comment on lines 46 to 49
if (nameLabel !== undefined || nameDescription !== undefined) {
const serverId = this.getXenServerIdByObject(pool.uuid, 'pool')
await this.updateXenServer(serverId, { poolNameDescription: nameDescription, poolNameLabel: nameLabel })
}
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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:

@b-Nollet b-Nollet requested a review from fbeauchamp December 19, 2024 16:28
Comment on lines 358 to 361
await this.updateXenServer(id, {
poolNameLabel: xapi.pool.name_label,
poolNameDescription: xapi.pool.name_description,
})
Copy link
Collaborator

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 ?

@b-Nollet b-Nollet requested a review from pdonias January 20, 2025 11:03
@@ -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)
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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 better ignoreErrors.call(promise) (which does not ignore programming errors)

Copy link
Member

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)
Copy link
Member

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 &&
Copy link
Member

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?

Copy link
Contributor Author

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

Comment on lines 239 to 248
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 }),
}
Copy link
Member

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 ifs and assignments:

const serverPropertiesUpdate = {}
if (xapiObject.name_label !== xenServer.poolNameLabel) {
  serverPropertiesUpdate.poolNameLabel = xapiObject.name_label
}
// ...

What do you think?

Copy link
Contributor Author

@b-Nollet b-Nollet Jan 21, 2025

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
Copy link
Member

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?

Copy link
Contributor Author

@b-Nollet b-Nollet Jan 21, 2025

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)

@b-Nollet b-Nollet requested a review from pdonias January 24, 2025 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants