Skip to content

Commit 0ad704c

Browse files
Harry SnartHarry Snart
authored andcommitted
added feature for default networking and flexible shapes on create_notebook_session. Related to FR:1276
1 parent 06dd598 commit 0ad704c

File tree

1 file changed

+70
-14
lines changed

1 file changed

+70
-14
lines changed

ads/catalog/notebook.py

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
CreateNotebookSessionDetails,
2323
NotebookSession,
2424
NotebookSessionConfigurationDetails,
25+
NotebookSessionConfigDetails,
26+
NotebookSessionShapeConfigDetails,
2527
)
2628
from oci.exceptions import ServiceError
2729
from types import MethodType
@@ -295,6 +297,8 @@ def create_notebook_session(
295297
shape=None,
296298
block_storage_size_in_gbs=None,
297299
subnet_id=None,
300+
ocpus=None,
301+
memory_in_gbs=None,
298302
**kwargs,
299303
):
300304
"""
@@ -310,11 +314,15 @@ def create_notebook_session(
310314
The value to assign to the shape property of this NotebookSessionConfigurationDetails.
311315
Allowed values for this property are: "VM.Standard.E2.2", "VM.Standard.E2.4",
312316
"VM.Standard.E2.8", "VM.Standard2.1", "VM.Standard2.2", "VM.Standard2.4", "VM.Standard2.8",
313-
"VM.Standard2.16","VM.Standard2.24".
317+
"VM.Standard2.16","VM.Standard2.24". Flexible shapes also supported but require addition of ocpus and memory_in_gbs parameters
314318
block_storage_size_in_gbs: int, required
315319
Size of the block storage drive. Limited to values between 50 (GB) and 1024 (1024GB = 1TB)
316-
subnet_id: str, required
317-
The OCID of the subnet resource where the notebook is to be created.
320+
subnet_id: str, optional
321+
The OCID of the subnet resource where the notebook is to be created. If no subnet_id is specified the session will use managed egress
322+
ocpus: int, optional
323+
OCPUs assigned to flexible shapes, such as VM.Standard.E4.Flex
324+
memory_in_gbs: int, optional
325+
memory (in GBs) assigned to flexible shapes, such as VM.Standard.E4.Flex
318326
kwargs: dict, optional
319327
Additional kwargs passed to `DataScienceClient.create_notebook_session()`
320328
@@ -326,18 +334,66 @@ def create_notebook_session(
326334
------
327335
KeyError: If the resource was not found or do not have authorization to access that resource.
328336
"""
329-
notebook_session_configuration_details = NotebookSessionConfigurationDetails(
330-
shape=shape,
331-
block_storage_size_in_gbs=block_storage_size_in_gbs,
332-
subnet_id=subnet_id,
333-
)
337+
334338
project_id = PROJECT_OCID if project_id is None else project_id
335-
create_notebook_details = CreateNotebookSessionDetails(
336-
display_name=display_name,
337-
project_id=project_id,
338-
compartment_id=self.compartment_id,
339-
notebook_session_configuration_details=notebook_session_configuration_details,
340-
)
339+
340+
if ocpus and memory_in_gbs:
341+
if subnet_id:
342+
notebook_session_configuration_details = NotebookSessionConfigurationDetails(
343+
shape=shape,
344+
block_storage_size_in_gbs=block_storage_size_in_gbs,
345+
subnet_id=subnet_id,
346+
notebook_session_shape_config_details=oci.data_science.models.NotebookSessionShapeConfigDetails(
347+
ocpus=ocpus,
348+
memory_in_gbs=memory_in_gbs)
349+
)
350+
create_notebook_details = CreateNotebookSessionDetails(
351+
display_name=display_name,
352+
project_id=project_id,
353+
compartment_id=self.compartment_id,
354+
notebook_session_configuration_details=notebook_session_configuration_details,)
355+
356+
else:
357+
notebook_session_configuration_details = NotebookSessionConfigDetails(
358+
shape=shape,
359+
block_storage_size_in_gbs=block_storage_size_in_gbs,
360+
notebook_session_shape_config_details=oci.data_science.models.NotebookSessionShapeConfigDetails(
361+
ocpus=ocpus,
362+
memory_in_gbs=memory_in_gbs)
363+
)
364+
create_notebook_details = CreateNotebookSessionDetails(
365+
display_name=display_name,
366+
project_id=project_id,
367+
compartment_id=self.compartment_id,
368+
notebook_session_config_details=notebook_session_configuration_details,
369+
)
370+
371+
372+
else:
373+
374+
if subnet_id:
375+
notebook_session_configuration_details = NotebookSessionConfigurationDetails(
376+
shape=shape,
377+
block_storage_size_in_gbs=block_storage_size_in_gbs,
378+
subnet_id=subnet_id,
379+
)
380+
create_notebook_details = CreateNotebookSessionDetails(
381+
display_name=display_name,
382+
project_id=project_id,
383+
compartment_id=self.compartment_id,
384+
notebook_session_configuration_details=notebook_session_configuration_details,)
385+
else:
386+
notebook_session_configuration_details = NotebookSessionConfigDetails(
387+
shape=shape,
388+
block_storage_size_in_gbs=block_storage_size_in_gbs,
389+
)
390+
create_notebook_details = CreateNotebookSessionDetails(
391+
display_name=display_name,
392+
project_id=project_id,
393+
compartment_id=self.compartment_id,
394+
notebook_session_config_details=notebook_session_configuration_details,
395+
)
396+
341397
try:
342398
create_notebook_response = self.ds_client.create_notebook_session(
343399
create_notebook_details, **kwargs

0 commit comments

Comments
 (0)