-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreserveSandbox.py
executable file
·60 lines (44 loc) · 1.94 KB
/
reserveSandbox.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
This script takes in a yml config file that states which sandbox to use
and the login credentials to the Tokalab controller.
The yml config file must have these parameters:
sdloControllerIp: 10.10.10.1
user: admin
password: admin
sandbox: gitlab-pytest
Requirements
- python 3.6+
- pip install requests PyYAML
- sdloAssistant.py
- sandbox yml config file
Usage:
python reserveSandbox.py -sandbox /path/sandbox.yml -reserve|-release
# -forceTakeOwnership: Include this parameter to force takeover the sandbox if sandbox is already reserve.
python reserveSandbox.py -sandbox /path/sandbox.yml -reserve -forceTakeOwnership
"""
import sys, os, traceback, yaml, argparse
import sdloAssistant
try:
parser = argparse.ArgumentParser()
parser.add_argument('-sandbox', help='The sandbox yml config file')
parser.add_argument('-reserve', action='store_true', help='Reserve the sandbox')
parser.add_argument('-release', action='store_true', help='Release the sandbox.')
parser.add_argument('-forceTakeOwnership', action='store_true', default=False,
help='For sandbox reservation only. Force take ownership of sandbox if it is reserved.')
args = parser.parse_args()
if not os.path.exists(args.sandbox):
raise Exception(f'No such config file found: {args.sandbox}')
with open(args.sandbox) as paramsObj:
params = yaml.safe_load(paramsObj)
print(f'\nconfigFile params: {params}')
sandboxObj = sdloAssistant.Controller(params['sdloControllerIp'], params['user'], params['password'])
# Set the sandbox name to use
sandboxObj.setSandbox(params['sandbox'])
if args.reserve:
sandboxObj.reserve(forceTakeOwnership=args.forceTakeOwnership)
if args.release:
sandboxObj.release()
sys.exit(0)
except Exception as errMsg:
print(f'\nreserveSandbox.py error: {errMsg}\n{traceback.format_exc()}\n')
sys.exit(1)