Skip to content

Commit 0fc8c56

Browse files
committed
Upgrade to new version of Astra SDK
1 parent d87f656 commit 0fc8c56

File tree

5 files changed

+51
-20
lines changed

5 files changed

+51
-20
lines changed

netapp_dataops_k8s/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ The NetApp DataOps Toolkit provides several extended capabilities that require [
7373
7474
The toolkit uses the Astra Control Python SDK to interface with the Astra Control API. The Astra Control Python SDK is installed automatically when you install the NetApp DataOps Toolkit using pip.
7575
76-
In order for the Astra Control Python SDK to be able to communicate with the Astra Control API, you must create a 'config.yaml' file containing your Astra Control API connection details. Refer to the [Astra Control Python SDK README](https://github.com/NetApp/netapp-astra-toolkits/tree/b478109b084ad387753d085219a8a8d3d399a4e6) for formatting details. Note that you do not need to follow the installation instructions outlined in the Astra Control Python SDK README; you only need to create the 'config.yaml' file. Once you have created the 'config.yaml' file, you must store it in one of the following locations:
76+
In order for the Astra Control Python SDK to be able to communicate with the Astra Control API, you must create a 'config.yaml' file containing your Astra Control API connection details. Refer to the [Astra Control Python SDK README](https://github.com/NetApp/netapp-astra-toolkits/tree/v2.1.3) for formatting details. Note that you do not need to follow the installation instructions outlined in the Astra Control Python SDK README; you only need to create the 'config.yaml' file. Once you have created the 'config.yaml' file, you must store it in one of the following locations:
7777
- ~/.config/astra-toolkits/
7878
- /etc/astra-toolkits/
7979
- The directory pointed to by the shell environment variable 'ASTRATOOLKITS_CONF'

netapp_dataops_k8s/docs/workspace_management.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,7 @@ If an error is encountered, the function will raise an exception of one of the f
858858
```py
859859
InvalidConfigError # kubeconfig or AstraSDK config file is missing or is invalid.
860860
APIConnectionError # The Kubernetes or Astra Control API returned an error.
861+
AstraAppDoesNotExistError # App does not exist in Astra. Are you sure that the workspace name is correct?
861862
```
862863
863864
<a name="lib-backup-jupyterlab"></a>
@@ -890,4 +891,5 @@ If an error is encountered, the function will raise an exception of one of the f
890891
```py
891892
InvalidConfigError # kubeconfig or AstraSDK config file is missing or is invalid.
892893
APIConnectionError # The Kubernetes or Astra Control API returned an error.
894+
AstraAppNotManagedError # JupyterLab workspace has not been registered with Astra Control.
893895
```

netapp_dataops_k8s/netapp_dataops/k8s/__init__.py

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ class AstraClusterDoesNotExistError(Exception):
6363
pass
6464

6565

66+
class AstraAppDoesNotExistError(Exception):
67+
'''Error that will be raised when an app doesn't exist within Astra Control'''
68+
pass
69+
70+
6671
class ServiceUnavailableError(Exception):
6772
'''Error that will be raised when a service is not available'''
6873
pass
@@ -511,20 +516,34 @@ def _wait_for_triton_dev_deployment(server_name: str, namespace: str = "default"
511516
sleep(5)
512517

513518

514-
def _retrieve_astra_app_id_for_jupyter_lab(astra_apps: dict, workspace_name: str) -> str :
519+
def _retrieve_astra_app_id_for_jupyter_lab(astra_apps: dict, workspace_name: str, include_full_app_details: bool = False) -> str :
515520
# Get Astra K8s cluster name
516521
try :
517522
astra_k8s_cluster_name = _get_astra_k8s_cluster_name()
518523
except KeyError :
519524
raise InvalidConfigError()
520525

521526
# Parse Astra Apps
522-
for app_id,app_details in astra_apps.items() :
527+
for app_details in astra_apps["items"] :
528+
# Check cluster name
529+
if app_details["clusterName"] != astra_k8s_cluster_name :
530+
pass
531+
532+
# Get app label for workspace
523533
workspace_app_label = _get_jupyter_lab_labels(workspaceName=workspace_name)["app"]
524-
if (app_details[0] == workspace_app_label) and (app_details[1] == astra_k8s_cluster_name) :
525-
return app_id
526534

527-
return ""
535+
# See if app label matches
536+
for app_labels in app_details["appLabels"] :
537+
if (app_labels["name"] == "app") and (app_labels["value"] == workspace_app_label) :
538+
if include_full_app_details :
539+
return app_details["id"], app_details
540+
else :
541+
return app_details["id"]
542+
543+
if include_full_app_details :
544+
return "", None
545+
else :
546+
return ""
528547

529548

530549
#
@@ -648,7 +667,7 @@ def clone_jupyter_lab_to_new_namespace(source_workspace_name: str, new_namespace
648667

649668
# Determine Astra App ID for source workspace
650669
try :
651-
source_astra_app_id = _retrieve_astra_app_id_for_jupyter_lab(astra_apps=astra_apps, workspace_name=source_workspace_name)
670+
source_astra_app_id, source_astra_app_details = _retrieve_astra_app_id_for_jupyter_lab(astra_apps=astra_apps, workspace_name=source_workspace_name, include_full_app_details=True)
652671
except InvalidConfigError :
653672
if print_output :
654673
_print_astra_k8s_cluster_name_error()
@@ -663,7 +682,7 @@ def clone_jupyter_lab_to_new_namespace(source_workspace_name: str, new_namespace
663682
raise AstraAppNotManagedError(error_message)
664683

665684
# Determine Astra cluster ID for source workspace
666-
source_astra_cluster_id = astra_apps[source_astra_app_id][2]
685+
source_astra_cluster_id = source_astra_app_details["clusterID"]
667686

668687
# Determine Astra cluster ID for "clone-to" cluster
669688
if clone_to_cluster_name :
@@ -675,9 +694,9 @@ def clone_jupyter_lab_to_new_namespace(source_workspace_name: str, new_namespace
675694
print("Error: Astra Control API Error: ", err)
676695
raise APIConnectionError(err)
677696

678-
for cluster_id,cluster_info in astra_clusters.items() :
679-
if cluster_info[0] == clone_to_cluster_name :
680-
clone_to_cluster_id = cluster_id
697+
for cluster_info in astra_clusters["items"] :
698+
if cluster_info["name"] == clone_to_cluster_name :
699+
clone_to_cluster_id = cluster_info["id"]
681700

682701
if not clone_to_cluster_id :
683702
error_message = "Cluster '" + clone_to_cluster_name + "' does not exist in Astra Control."
@@ -2018,16 +2037,22 @@ def register_jupyter_lab_with_astra(workspace_name: str, namespace: str = "defau
20182037

20192038
# Determine Astra App ID for workspace
20202039
try :
2021-
astra_app_id = _retrieve_astra_app_id_for_jupyter_lab(astra_apps=astra_apps_unmanaged, workspace_name=workspace_name)
2040+
astra_app_id, astra_app_details = _retrieve_astra_app_id_for_jupyter_lab(astra_apps=astra_apps_unmanaged, workspace_name=workspace_name, include_full_app_details=True)
20222041
except InvalidConfigError :
20232042
if print_output :
20242043
_print_astra_k8s_cluster_name_error()
20252044
raise InvalidConfigError()
20262045

2027-
# Wait until app has a status of "running" in Astraa
2046+
# Fail if app doesn't exist in Astra
2047+
if not astra_app_details :
2048+
if print_output :
2049+
print("Error: App does not exist in Astra. Are you sure that the workspace name is correct?")
2050+
raise AstraAppDoesNotExistError()
2051+
2052+
# Wait until app has a status of "running" in Astra
20282053
while True :
20292054
try :
2030-
if astra_apps_unmanaged[astra_app_id][4] == "running" :
2055+
if astra_app_details["state"] == "running" :
20312056
break
20322057
except KeyError :
20332058
pass
@@ -2039,6 +2064,7 @@ def register_jupyter_lab_with_astra(workspace_name: str, namespace: str = "defau
20392064
# Retrieve list of unmanaged Astra apps again
20402065
try :
20412066
astra_apps_unmanaged = astraSDK.getApps().main(discovered=True, namespace=namespace)
2067+
astra_app_id, astra_app_details = _retrieve_astra_app_id_for_jupyter_lab(astra_apps=astra_apps_unmanaged, workspace_name=workspace_name, include_full_app_details=True)
20422068
except Exception as err :
20432069
if print_output:
20442070
print("Error: Astra Control API Error: ", err)

netapp_dataops_k8s/netapp_dataops/netapp_dataops_k8s_cli.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
APIConnectionError,
2727
AstraAppNotManagedError,
2828
AstraClusterDoesNotExistError,
29+
AstraAppDoesNotExistError,
2930
CAConfigMap,
3031
InvalidConfigError
3132
)
@@ -787,10 +788,10 @@ def getTarget(args: list) -> str:
787788
if not workspace_name or not backup_name:
788789
handleInvalidCommand(helpText=helpTextBackupJupyterLab, invalidOptArg=True)
789790

790-
# Register JupyterLab workspace
791+
# Back up JupyterLab workspace
791792
try:
792793
backup_jupyter_lab_with_astra(workspace_name=workspace_name, backup_name=backup_name, namespace=namespace, print_output=True)
793-
except (InvalidConfigError, APIConnectionError):
794+
except (InvalidConfigError, APIConnectionError, AstraAppNotManagedError):
794795
sys.exit(1)
795796

796797
else:
@@ -2225,7 +2226,7 @@ def getTarget(args: list) -> str:
22252226
# Register JupyterLab workspace
22262227
try:
22272228
register_jupyter_lab_with_astra(workspace_name=workspaceName, namespace=namespace, print_output=True)
2228-
except (InvalidConfigError, APIConnectionError):
2229+
except (InvalidConfigError, APIConnectionError, AstraAppDoesNotExistError):
22292230
sys.exit(1)
22302231

22312232
else:

netapp_dataops_k8s/setup.cfg

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,20 @@ scripts =
2626
netapp_dataops/netapp_dataops_k8s_cli.py
2727
install_requires =
2828
notebook
29-
kubernetes
3029
pandas
31-
tabulate
3230
numpy>=1.22.0
33-
netapp-astra-toolkits==2.0
31+
actoolkit==2.1.3
3432
certifi==2020.12.5
3533
chardet==4.0.0
34+
dnspython==2.1.0
3635
idna==2.10
3736
PyYAML==5.4.1
3837
requests==2.25.1
38+
tabulate==0.8.9
3939
termcolor==1.1.0
4040
urllib3==1.26.5
41+
func_timeout==4.3.5
42+
kubernetes==23.6.0
4143
python_requires = >=3.8
4244

4345
[options.packages.find]

0 commit comments

Comments
 (0)