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

Add Network.remove and auto cleanup #677

Merged
merged 8 commits into from
Sep 27, 2021
Merged

Conversation

kmazurek
Copy link
Contributor

Resolves #615

@kmazurek kmazurek self-assigned this Sep 23, 2021
@@ -89,6 +111,7 @@ async def create(
# add requestor's own address to the network
await network.add_owner_address(network.owner_ip)

network._state_machine.create()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is it here twice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This follows the create lifecycle - the first call advances the state machine from initialized to creating, the second one from creating to ready.
The approach taken here is analogous to how the Service lifecycle is defined (ServiceState.lifecycle).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be clearer to have two separate, explicit transitions here then -> initialize? that moves from initialized to creating and create that moves from creating to ready

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or maybe create -> creating, start -> ready ? ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in b319b73

removed = State("removed")

# transitions
add_address = creating.to.itself() | ready.to.itself()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm... I'm unsure I like how the state transitions are used to control when the methods can be run... I'd expect that logic to be part of those methods and not declared on the state machine ... is this some kind of a well-understood pattern? ... asking since I might not realize that this "transition" is used to control method's usage and rather think that it indeed somehow changes the state of the network...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is an established pattern, I just found this more elegant.
Let's take add_owner_address as an example. If we wanted to ensure the correct state in the function directly this would look something like this:

        if self.state is not NetworkStateMachine.creating or self.state is not NetworkStateMachine.ready:
            raise SomeKindOfError("here")

I think that expressing this using possible transitions is cleaner and scales better if we need to handle different situations or new states in the future.
However, if you find this confusing I can think of a different approach.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nah, maybe it's okay ...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
add_address = creating.to.itself() | ready.to.itself()
add_owner_address = creating.to.itself() | ready.to.itself()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed in b319b73

@kmazurek kmazurek marked this pull request as ready for review September 24, 2021 14:09
@kmazurek kmazurek requested a review from a team September 24, 2021 14:09
@@ -54,6 +55,26 @@ def get_websocket_uri(self, port: int) -> str:
return f"{net_api_ws}/net/{self.network.network_id}/tcp/{self.ip}/{port}"


class NetworkStateMachine(StateMachine):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd call this class NetworkState for a bit more brevity and to make it consistent with ServiceState

Suggested change
class NetworkStateMachine(StateMachine):
class NetworkState(StateMachine):

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in c5d425c


# lifecycle
create = initialized.to(creating) | creating.to(ready)
remove = ready.to(removing) | removing.to(removed)
Copy link
Contributor

@shadeofblue shadeofblue Sep 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and actually, I'd do the same with remove -> have e.g. stop which transitions from ready to removing and remove that moves from removing to removed ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in b319b73

Copy link
Contributor

@shadeofblue shadeofblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woman-yeah-all-ok-118281589

LGTM! :)

BUT -> maybe we should also update the examples (http-proxy and ssh) already in this pull request? ....

@kmazurek kmazurek merged commit 106b02a into master Sep 27, 2021
@kmazurek kmazurek deleted the km/vpn-network-cleanup branch September 27, 2021 16:05
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.

[VPN] support clean-up for no-longer-used Networks
2 participants