Path: blob/main/resources/drop_test_cluster.py
469 views
#!/usr/bin/env python1# type: ignore2from __future__ import annotations34import re5import sys6from optparse import OptionParser78import singlestoredb as s291011# Handle command-line options12usage = 'usage: %prog [options] workspace-id'13parser = OptionParser(usage=usage)14parser.add_option(15'-t', '--token',16help='API key for the workspace management API',17)18(options, args) = parser.parse_args()1920if len(args) != 1:21parser.print_help()22sys.exit(1)232425# Connect to workspace26wm = s2.manage_workspaces(options.token or None)2728wg_name = 'Python Client Testing'2930wgs = [x for x in wm.workspace_groups if x.name == wg_name]31if len(wgs) > 1:32print('ERROR: There is more than one workspace group with the specified name.')33sys.exit(1)34elif len(wgs) == 0:35print('ERROR: There is no workspace group with the specified name.')36sys.exit(1)37wg = wgs[0]3839ws_name = re.sub(r'^-|-$', r'', re.sub(r'-+', r'-', re.sub(r'\s+', '-', args[0].lower())))4041wss = [x for x in wg.workspaces if x.name == ws_name]42if len(wss) > 1:43print('ERROR: There is more than one workspace with the specified name.')44sys.exit(1)45elif len(wss) == 0:46print('ERROR: There is no workspace with the specified name.')47sys.exit(1)48ws = wss[0]4950# Terminate workspace51ws.terminate()525354