1010import click
1111from boltons .urlutils import URL
1212
13- from cratedb_toolkit .cluster .croud import CloudManager
13+ from cratedb_toolkit .cluster .croud import CloudClusterServices , CloudRootServices
1414from cratedb_toolkit .cluster .guide import DataImportGuide
1515from cratedb_toolkit .cluster .model import ClientBundle , ClusterBase , ClusterInformation
1616from cratedb_toolkit .config import CONFIG
@@ -132,7 +132,8 @@ def __init__(
132132 "Failed to address cluster: Either cluster identifier or name needs to be specified"
133133 )
134134
135- self .cm = CloudManager ()
135+ self .root = CloudRootServices ()
136+ self .cluster : t .Optional [CloudClusterServices ] = None
136137 self ._jwt_ctx : t .ContextManager = nullcontext ()
137138 self ._client_bundle : t .Optional [ClientBundle ] = None
138139
@@ -209,6 +210,8 @@ def probe(self) -> "ManagedCluster":
209210 self .cluster_name = self .info .cloud ["name" ]
210211 self .address = DatabaseAddress .from_httpuri (self .info .cloud ["url" ])
211212 self ._jwt_ctx = jwt_token_patch (self .info .jwt .token )
213+ if self .cluster_id :
214+ self .cluster = CloudClusterServices (cluster_id = self .cluster_id )
212215
213216 except (CroudException , DatabaseAddressMissingError ) as ex :
214217 self .exists = False
@@ -276,7 +279,7 @@ def deploy(self) -> "ManagedCluster":
276279 # Find the existing project by name (equals cluster name).
277280 project_id = None
278281 try :
279- projects = self .cm .list_projects ()
282+ projects = self .root .list_projects ()
280283 for project in projects :
281284 if project ["name" ] == self .cluster_name :
282285 project_id = project ["id" ]
@@ -287,11 +290,11 @@ def deploy(self) -> "ManagedCluster":
287290
288291 # Create a new project if none exists.
289292 if not project_id :
290- project = self .cm .create_project (name = self .cluster_name , organization_id = self .settings .organization_id )
293+ project = self .root .create_project (name = self .cluster_name , organization_id = self .settings .organization_id )
291294 project_id = project ["id" ]
292295 logger .info (f"Created project: { project_id } " )
293296
294- cluster_info = self .cm .deploy_cluster (
297+ cluster_info = self .root .deploy_cluster (
295298 name = self .cluster_name , project_id = project_id , subscription_id = self .settings .subscription_id
296299 )
297300
@@ -309,7 +312,8 @@ def resume(self) -> "ManagedCluster":
309312 if self .cluster_id is None :
310313 raise DatabaseAddressMissingError ("Need cluster identifier to resume cluster" )
311314 logger .info (f"Resuming CrateDB Cloud Cluster: id={ self .cluster_id } , name={ self .cluster_name } " )
312- self .cm .resume_cluster (identifier = self .cluster_id )
315+ if self .cluster :
316+ self .cluster .resume ()
313317 self .probe ()
314318 return self
315319
@@ -322,7 +326,8 @@ def stop(self) -> "ManagedCluster":
322326 if self .cluster_id is None :
323327 raise DatabaseAddressMissingError ("Need cluster identifier to stop cluster" )
324328 logger .info (f"Stopping CrateDB Cloud Cluster: id={ self .cluster_id } , name={ self .cluster_name } " )
325- self .cm .suspend_cluster (identifier = self .cluster_id )
329+ if self .cluster :
330+ self .cluster .suspend ()
326331 self .probe ()
327332 return self
328333
0 commit comments