10
10
import click
11
11
from boltons .urlutils import URL
12
12
13
- from cratedb_toolkit .cluster .croud import CloudManager
13
+ from cratedb_toolkit .cluster .croud import CloudClusterServices , CloudRootServices
14
14
from cratedb_toolkit .cluster .guide import DataImportGuide
15
15
from cratedb_toolkit .cluster .model import ClientBundle , ClusterBase , ClusterInformation
16
16
from cratedb_toolkit .config import CONFIG
@@ -132,7 +132,8 @@ def __init__(
132
132
"Failed to address cluster: Either cluster identifier or name needs to be specified"
133
133
)
134
134
135
- self .cm = CloudManager ()
135
+ self .root = CloudRootServices ()
136
+ self .cluster : t .Optional [CloudClusterServices ] = None
136
137
self ._jwt_ctx : t .ContextManager = nullcontext ()
137
138
self ._client_bundle : t .Optional [ClientBundle ] = None
138
139
@@ -209,6 +210,8 @@ def probe(self) -> "ManagedCluster":
209
210
self .cluster_name = self .info .cloud ["name" ]
210
211
self .address = DatabaseAddress .from_httpuri (self .info .cloud ["url" ])
211
212
self ._jwt_ctx = jwt_token_patch (self .info .jwt .token )
213
+ if self .cluster_id :
214
+ self .cluster = CloudClusterServices (cluster_id = self .cluster_id )
212
215
213
216
except (CroudException , DatabaseAddressMissingError ) as ex :
214
217
self .exists = False
@@ -276,7 +279,7 @@ def deploy(self) -> "ManagedCluster":
276
279
# Find the existing project by name (equals cluster name).
277
280
project_id = None
278
281
try :
279
- projects = self .cm .list_projects ()
282
+ projects = self .root .list_projects ()
280
283
for project in projects :
281
284
if project ["name" ] == self .cluster_name :
282
285
project_id = project ["id" ]
@@ -287,11 +290,11 @@ def deploy(self) -> "ManagedCluster":
287
290
288
291
# Create a new project if none exists.
289
292
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 )
291
294
project_id = project ["id" ]
292
295
logger .info (f"Created project: { project_id } " )
293
296
294
- cluster_info = self .cm .deploy_cluster (
297
+ cluster_info = self .root .deploy_cluster (
295
298
name = self .cluster_name , project_id = project_id , subscription_id = self .settings .subscription_id
296
299
)
297
300
@@ -309,7 +312,8 @@ def resume(self) -> "ManagedCluster":
309
312
if self .cluster_id is None :
310
313
raise DatabaseAddressMissingError ("Need cluster identifier to resume cluster" )
311
314
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 ()
313
317
self .probe ()
314
318
return self
315
319
@@ -322,7 +326,8 @@ def stop(self) -> "ManagedCluster":
322
326
if self .cluster_id is None :
323
327
raise DatabaseAddressMissingError ("Need cluster identifier to stop cluster" )
324
328
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 ()
326
331
self .probe ()
327
332
return self
328
333
0 commit comments