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

Implement server actions via an enum #144

Merged
merged 4 commits into from
Oct 30, 2023

Conversation

milliams
Copy link
Contributor

@milliams milliams commented Oct 5, 2023

This moves the server actions to use a typed enum to represent the possible actions that can be performed on a server.

In the future, I wouldn't expect that every single action would have a special method associated with it, so I opted for a generic action method which takes the new enum as an argument.

This now allows you to do:

server.action(ServerAction::Stop).await?
server.action(ServerAction::Reboot {reboot_type: Soft}).await?

which is equivalent to (the still-present)

server.stop().await?
server.reboot(Soft).await?

This is more verbose but will make it easier to implement the rest of the actions in the future as I would like to add the createImage action next, but I wanted to do the refactor separately first.

I'm happy to take feedback on API and code structure, or of you think there's another way to implement it. For example, if you think that you'd rather have each future-implemented action done as a Server method then this new approach gains less. Also, if the definition of the ServerAction enum or unit_to_null function make more sense in another file, I'm happy to move them.

This moves the server actions to use a typed enum to represent the
possible actions that can be performed on a server.

This will make it easier to implement the rest of the actions in the
future.
src/compute/servers.rs Outdated Show resolved Hide resolved
src/compute/servers.rs Outdated Show resolved Hide resolved
src/compute/servers.rs Outdated Show resolved Hide resolved
@dtantsur
Copy link
Owner

dtantsur commented Oct 7, 2023

if you think that you'd rather have each future-implemented action done as a Server method

I'm not sure I want ALL OF THEM as methods. Maybe the most popular ones. This approach makes sense - please see the comments.

It no longer needs to be Copy in this case, and
shouldn't be anyway.
@milliams
Copy link
Contributor Author

milliams commented Oct 8, 2023

I think I've resolved the requested changes. Let me know if there's anything else.

@dtantsur
Copy link
Owner

Sigh, it still fails because of missing_copy_implementation. I suggest you add an override for it (bonus for reporting it to the Rust team).

As we will be adding more actions to this enum in
the future, it will soon become non-Copyable so
we don't want this lint triggering.
@milliams
Copy link
Contributor Author

milliams commented Oct 15, 2023

I've disabled the lint for now. As soon as I add some more actions (in a future PR), it will stop being needed (since they will be holding Strings) so I will remove it at that time.

Also, bug Rust report raised at rust-lang/rust#116766.

@dtantsur
Copy link
Owner

Your CI patch is in a merge conflict now, could you split it away?

@dtantsur dtantsur merged commit 20cd638 into dtantsur:master Oct 30, 2023
16 checks passed
@milliams milliams deleted the server_actions branch October 30, 2023 18:57
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.

2 participants