snowflake.core.service.ServiceResource¶
- class snowflake.core.service.ServiceResource(name: str, collection: ServiceCollection)¶
Bases:
SchemaObjectReferenceMixin[ServiceCollection]Represents a reference to a Snowflake Snowpark Container Service.
With this service reference, you can create, alter, and fetch information about services, as well as perform certain actions on them.
Attributes
- database¶
- fully_qualified_name¶
- root¶
Methods
- create_or_alter(service: Service) None¶
Create a service in Snowflake or alter one if it already exists.
- Parameters:
service (Service) – The
Serviceobject, together with theService’s properties: name, compute_pool, spec; auto_resume, min_instances, max_instances, status, external_access_integrations, query_warehouse, comment are optional.
Examples
Creating or updating a service in Snowflake:
>>> service_parameters = Service( ... name="your-service-name", ... compute_pool="my_cp" ... spec=ServiceSpecStageFile(stage="stage_name", spec_file=spec_file), ...) >>> services = root.databases["my_db"].schemas["my_schema"].services >>> services["your-service-name"].create_or_alter(service_parameters)
- delete() None¶
The delete method is deprecated; use drop instead.
- drop() None¶
Drop the service.
Examples
Deleting a service using its reference:
>>> service_reference.drop()
- fetch() Service¶
Fetch the details of a service.
Examples
Fetching a service using its reference:
>>> service_reference.fetch()
- get_containers() Iterable[ServiceContainer]¶
Show the containers corresponding to this service.
Examples
Showing the containers of a service using its reference:
>>> service_reference.get_containers()
- get_endpoints() Iterable[ServiceEndpoint]¶
Show the endpoints corresponding to this service.
Examples
Showing the endpoints of a service using its reference:
>>> service_reference.get_endpoints()
- get_instances() Iterable[ServiceInstance]¶
Show the instances corresponding to this service.
Examples
Showing the instances of a service using its reference:
>>> service_reference.get_instances()
- get_roles() Iterable[ServiceRole]¶
Show the roles corresponding to this service.
Examples
Showing the roles of a service using its reference: >>> service_reference.get_roles()
- get_service_logs(instance_id: str, container_name: str, num_lines: int | None = None) str¶
Get the service logs of the service.
- Parameters:
instance_id (str) – Instance ID of the service.
container_name (str) – Container name of the service.
num_lines (int, optional) – Number of the most recent log lines to retrieve.
get_service_status()returns theinstance_idandcontainer_nameas a part of its results.Examples
Getting the logs of a service using its reference:
>>> service_reference.get_service_logs(instance_id="instance_id", container_name="container_name")
- get_service_status(timeout: int = 0) List[Dict[str, Any]]¶
Get the status of the service.
- Parameters:
timeout (int) –
Number of seconds to wait for the service to reach a steady state (for example, READY) before returning the status. If the service does not reach steady state within the specified time, Snowflake returns the current state.
If not specified or
0, Snowflake returns the current state immediately.Default:
0seconds.
Examples
Getting the status of a service using its reference:
>>> service_reference.get_service_status()
Getting the status of a service using its reference with a timeout:
>>> service_reference.get_service_status(timeout=10)
- resume() None¶
Resumes the service.
Examples
Resuming a service using its reference:
>>> service_reference.resume()
- suspend() None¶
Suspend the service.
Examples
Suspending a service using its reference:
>>> service_reference.suspend()