Service
Bases: DuploTenantResourceV2
Duplocloud Service Resource
This resource is used to manage services in Duplocloud. Using the duploctl
command line tool, you can manage services with actions:
_perform_action
Generic method to perform a start or stop action on services.
_process_service
Helper function to process a service action (start/stop) and handle errors.
apply
Apply a service.
bulk_update_image
Bulk update the image of multiple services.
Basic CLI Use
Parameters:
Name | Type | Description | Default |
---|---|---|---|
serviceimage
|
SERVICEIMAGE
|
Takes n sets of two arguments, service name and image name. e.g., -S service1 image1:tag -S service2 image2:tag |
required |
wait
|
WAIT
|
Boolean flag to wait for service updates. |
False
|
create
current_replicaset
Get the current replicaset for a service.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the service to get replicaset for. |
required |
Returns: The current replicaset for the service. Raises: DuploError: If the service could not be found.
delete
Delete a service.
Delete a service in Duplocloud.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
NAME
|
The name of the service to delete. |
required |
Returns:
Name | Type | Description |
---|---|---|
message |
dict
|
Success message. |
expose
Expose a service.
Basic CLI Use
Parameters:
Name | Type | Description | Default |
---|---|---|---|
container-port
|
int
|
The internal port of the container to expose. |
required |
external-port
|
int
|
The external port exposed by the load balancer. This is not used for targetgrouponly or k8clusterip load balancer types. |
required |
lb-type
|
str
|
The load balancer type. Valid options are ['applicationlb', 'k8clusterip', 'k8nodeport', 'networklb', 'targetgrouponly']. |
required |
protocol
|
str
|
The protocol to use, based on |
None
|
visibility
|
str
|
The load balancer visibility. Valid options are 'public' or 'private'. |
'public'
|
mode
|
str
|
The load balancer application mode. Valid options are 'docker-mode' or 'native-app'. |
'docker-mode'
|
health_check_url
|
str
|
The health check URL path. This must be empty for networklb, as it does not support health check paths. |
None
|
find
Find a Service by name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
NAME
|
The name of the Service to find. |
required |
Returns:
Name | Type | Description |
---|---|---|
resource |
dict
|
The Service object. |
Raises:
Type | Description |
---|---|
DuploError
|
If the {{kind}} could not be found. |
image_from_body
Get the image from a service body.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
body
|
dict
|
The body of the service. |
required |
Returns: The image for the service.
list
logs
pods
Get the pods for a service.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
NAME
|
The name of the service to get pods for. |
required |
Returns: message: A list of pods for the service. Raises: DuploError: If the service could not be found.
restart
Restart a service.
Restart a service.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
NAME
|
The name of the service to restart. |
required |
wait
|
WAIT
|
Boolean flag to wait for service updates. |
False
|
Returns:
Type | Description |
---|---|
dict
|
A success message if the service was restarted successfully. |
Raises:
Type | Description |
---|---|
DuploError
|
If the service could not be restarted. |
start
Start a service.
Start a service.
Basic CLI Use
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the service to start. |
None
|
all
|
bool
|
Boolean flag to start all services. Defaults to False. |
False
|
targets
|
list[str]
|
List of service names to start. Cannot be used with name or all. |
None
|
wait
|
WAIT
|
Boolean flag to wait for service updates. |
False
|
Returns:
Type | Description |
---|---|
dict
|
A summary containing services that were started successfully and those that encountered errors. |
Raises:
Type | Description |
---|---|
DuploError
|
If the service could not be started. |
stop
Stop a service.
Stop a service.
Basic CLI Use
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the service to stop. |
None
|
all
|
bool
|
Boolean flag to stop all services. Defaults to False. |
False
|
targets
|
list[str]
|
List of service names to stop. Cannot be used with name or all. |
None
|
wait
|
WAIT
|
Boolean flag to wait for service updates. |
False
|
Returns:
Type | Description |
---|---|
dict
|
A summary containing services that were stopped successfully and those that encountered errors. |
Raises:
Type | Description |
---|---|
DuploError
|
If the service could not be stopped. |
update
Update a service.
Update the state of a service.
Basic CLI Use
Update the replicas to 3 for a service.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
NAME
|
The name of the service to update. |
required |
body
|
BODY
|
The body of the service to update. |
None
|
patches
|
PATCHES
|
A list of JSON patches as args to apply to the service.
The options are |
None
|
wait
|
WAIT
|
Whether to wait for the service to update. |
False
|
update_env
Update the environment variables of a service. If service has no environment variables set, use -strat replace to set new values. Usage: Basic CLI Use
duploctl service update_env <service-name> --setvar env-key1 env-val1 --setvar env-key2 env-val2 --setvar env-key3 env-val3 -strat merge --host $DUPLO_HOST --tenant $DUPLO_TENANT --token $DUPLO_TOKEN
setvar/-V (list): A list of key value pairs to set as environment variables.
strategy/strat (str): The merge strategy to use for env vars. Valid options are "merge" or "replace". Default is merge.
deletevar/-D (list): A list of keys to delete from the environment variables.
update_image
update_pod_label
Update the pod labels of a service. If service has no pod labels set, use -strat replace to set new values. Usage: Basic CLI Use
duploctl service update_pod_label <service-name> --setvar env-key1 env-val1 --setvar env-key2 env-val2 --setvar env-key3 env-val3 -strat merge --host $DUPLO_HOST --tenant $DUPLO_TENANT --token $DUPLO_TOKEN
duploctl service update_pod_label <service-name> --setvar env-key1 env-val1 --setvar env-key2 env-val2 -strat replace --host $DUPLO_HOST --tenant $DUPLO_TENANT --token $DUPLO_TOKEN
duploctl service update_pod_label <service-name> --deletevar env-key1 --host $DUPLO_HOST --tenant $DUPLO_TENANT --token $DUPLO_TOKEN
update_replicas
wait
Wait for a service to update.