-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy path02_jupyter_service.py
71 lines (59 loc) · 2.36 KB
/
02_jupyter_service.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/opt/conda/bin/python3
import os
from snowflake.core import Root
from snowflake.core._common import CreateMode
from snowflake.core.service import Service, ServiceSpecStageFile
from snowflake.connector import connect
CONNECTION_PARAMETERS_CONTAINER_USER_ROLE = {
"account": os.environ["snowflake_account"],
"user": os.environ["snowflake_user"],
"password": os.environ["snowflake_password"],
"database": "CONTAINER_HOL_DB",
"schema": "PUBLIC",
"warehouse": "CONTAINER_HOL_WH",
"role": "CONTAINER_USER_ROLE",
}
# Connect as CONTANTAINER_USE_ROLE
connection_container_user_role = connect(**CONNECTION_PARAMETERS_CONTAINER_USER_ROLE)
try:
# create a root as the entry point for all object
root = Root(connection_container_user_role)
# create service CONTAINER_HOL_DB.PUBLIC.JUPYTER_SNOWPARK_SERVICE
# in compute pool CONTAINER_HOL_POOL
# from @specs
# specification_file='jupyter-snowpark.yaml'
# external_access_integrations = (ALLOW_ALL_EAI);
s = (
root.databases["CONTAINER_HOL_DB"]
.schemas["PUBLIC"]
.services.create(
Service(
name="JUPYTER_SNOWPARK_SERVICE",
compute_pool="CONTAINER_HOL_POOL",
spec=ServiceSpecStageFile(
stage="specs", spec_file="jupyter-snowpark.yaml"
),
external_access_integrations=["ALLOW_ALL_EAI"],
),
mode=CreateMode.if_not_exists,
)
)
# CALL SYSTEM$GET_SERVICE_STATUS('CONTAINER_HOL_DB.PUBLIC.jupyter_snowpark_service');
status = s.get_service_status()
print(status)
# CALL SYSTEM$GET_SERVICE_LOGS('CONTAINER_HOL_DB.PUBLIC.JUPYTER_SNOWPARK_SERVICE', '0', 'jupyter-snowpark',10);
logs = s.get_service_logs("0", "jupyter-snowpark", 10)
print(logs)
# SHOW ENDPOINTS IN SERVICE JUPYTER_SNOWPARK_SERVICE;
endpoints = s.get_endpoints()
for endpoint in endpoints:
print(endpoint)
# --- After we make a change to our Jupyter notebook,
# --- we will suspend and resume the service
# --- and you can see that the changes we made in our Notebook are still there!
# ALTER SERVICE CONTAINER_HOL_DB.PUBLIC.JUPYTER_SNOWPARK_SERVICE SUSPEND;
s.suspend()
# ALTER SERVICE CONTAINER_HOL_DB.PUBLIC.JUPYTER_SNOWPARK_SERVICE RESUME;
s.resume()
finally:
connection_container_user_role.close()