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

DUPLO-21449: Added --wait flag for Service Start, Stop and Restart #120

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

- Added support for SSM Parameter CRUD operations.
- start, stop, restart for service with `--wait`

## [0.2.41] - 2024-12-06

Expand Down
23 changes: 19 additions & 4 deletions src/duplo_resource/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,8 @@ def bulk_update_image(self,

@Command()
def restart(self,
name: args.NAME) -> dict:
name: args.NAME,
wait: args.WAIT = False) -> dict:
"""Restart a service.

Restart a service.
Expand All @@ -417,6 +418,7 @@ def restart(self,

Args:
name: The name of the service to restart.
wait: Boolean flag to wait for service updates.

Returns:
A success message if the service was restarted successfully.
Expand All @@ -425,11 +427,15 @@ def restart(self,
DuploError: If the service could not be restarted.
"""
self.duplo.post(self.endpoint(f"ReplicationControllerReboot/{name}"))
if wait:
service = self.find(name)
self.wait(service, service)
return {"message": f"Successfully restarted service '{name}'"}

@Command()
def stop(self,
name: args.NAME) -> dict:
name: args.NAME,
wait: args.WAIT = False) -> dict:
"""Stop a service.

Stop a service.
Expand All @@ -440,7 +446,8 @@ def stop(self,
```

Args:
name (str): The name of the service to stop.
name (str): The name of the service to stop.
wait: Boolean flag to wait for service updates.

Returns:
A success message if the service was stopped successfully.
Expand All @@ -449,11 +456,15 @@ def stop(self,
DuploError: If the service could not be stopped.
"""
self.duplo.post(self.endpoint(f"ReplicationControllerStop/{name}"))
if wait:
service = self.find(name)
self.wait(service, service)
return {"message": f"Successfully stopped service '{name}'"}

@Command()
def start(self,
name: args.NAME) -> dict:
name: args.NAME,
wait: args.WAIT = False) -> dict:
"""Start a service.

Start a service.
Expand All @@ -465,6 +476,7 @@ def start(self,

Args:
name (str): The name of the service to start.
wait: Boolean flag to wait for service updates.

Returns:
A success message if the service was started successfully.
Expand All @@ -473,6 +485,9 @@ def start(self,
DuploError: If the service could not be started.
"""
self.duplo.post(self.endpoint(f"ReplicationControllerstart/{name}"))
if wait:
service = self.find(name)
self.wait(service, service)
return {"message": f"Successfully started service '{name}'"}

@Command()
Expand Down
Loading