Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
singlestore-labs
GitHub Repository: singlestore-labs/singlestoredb-python
Path: blob/main/resources/drop_test_cluster.py
469 views
1
#!/usr/bin/env python
2
# type: ignore
3
from __future__ import annotations
4
5
import re
6
import sys
7
from optparse import OptionParser
8
9
import singlestoredb as s2
10
11
12
# Handle command-line options
13
usage = 'usage: %prog [options] workspace-id'
14
parser = OptionParser(usage=usage)
15
parser.add_option(
16
'-t', '--token',
17
help='API key for the workspace management API',
18
)
19
(options, args) = parser.parse_args()
20
21
if len(args) != 1:
22
parser.print_help()
23
sys.exit(1)
24
25
26
# Connect to workspace
27
wm = s2.manage_workspaces(options.token or None)
28
29
wg_name = 'Python Client Testing'
30
31
wgs = [x for x in wm.workspace_groups if x.name == wg_name]
32
if len(wgs) > 1:
33
print('ERROR: There is more than one workspace group with the specified name.')
34
sys.exit(1)
35
elif len(wgs) == 0:
36
print('ERROR: There is no workspace group with the specified name.')
37
sys.exit(1)
38
wg = wgs[0]
39
40
ws_name = re.sub(r'^-|-$', r'', re.sub(r'-+', r'-', re.sub(r'\s+', '-', args[0].lower())))
41
42
wss = [x for x in wg.workspaces if x.name == ws_name]
43
if len(wss) > 1:
44
print('ERROR: There is more than one workspace with the specified name.')
45
sys.exit(1)
46
elif len(wss) == 0:
47
print('ERROR: There is no workspace with the specified name.')
48
sys.exit(1)
49
ws = wss[0]
50
51
# Terminate workspace
52
ws.terminate()
53
54