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(if_exists: bool | None = None) None¶
Drop the service.
- Parameters:
if_exists (bool, optional) – Check the existence of this service before dropping it. Default is
None, which is equivalent toFalse.
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() Iterator[ServiceContainer]¶
Show the containers corresponding to this service.
Examples
Showing the containers of a service using its reference:
>>> service_reference.get_containers()
- get_endpoints() Iterator[ServiceEndpoint]¶
Show the endpoints corresponding to this service.
Examples
Showing the endpoints of a service using its reference:
>>> service_reference.get_endpoints()
- get_instances() Iterator[ServiceInstance]¶
Show the instances corresponding to this service.
Examples
Showing the instances of a service using its reference:
>>> service_reference.get_instances()
- get_roles() Iterator[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)
- iter_grants_of_service_role(role_name: str) Iterator[GrantOf]¶
Show the grants of the service role associated with this service.
- Parameters:
role_name (str) – Name of the service role.
Examples
Showing the grants of the service role associated with a service using the service reference:
>>> service_reference.iter_grants_of_service_role("all_endpoints_usage")
- iter_grants_to_service_role(role_name: str) Iterator[ServiceRoleGrantTo]¶
Show the grants given to the service role associated with this service.
- Parameters:
role_name (str) – Name of the service role.
Examples
Showing the grants given to the service role associated with a service using the service reference:
>>> service_reference.iter_grants_to_service_role("all_endpoints_usage")
- resume(if_exists: bool | None = None) None¶
Resumes the service.
- Parameters:
if_exists (bool, optional) – Check the existence of this service before resuming it. Default is
None, which is equivalent toFalse.
Examples
Resuming a service using its reference:
>>> service_reference.resume()
- suspend(if_exists: bool | None = None) None¶
Suspend the service.
- Parameters:
if_exists (bool, optional) – Check the existence of this service before suspending it. Default is
None, which is equivalent toFalse.
Examples
Suspending a service using its reference:
>>> service_reference.suspend()