-
Notifications
You must be signed in to change notification settings - Fork 0
/
warden.py
executable file
·78 lines (71 loc) · 2.32 KB
/
warden.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/python3
import sys
import argparse
import os
import yaml
import pydebootstrap
import pynspawn
def readYaml(profile):
with open(profile, 'r') as ydata_file:
try:
ydata = yaml.safe_load(ydata_file)
return ydata
except yaml.YAMLError as e:
print(e)
def main():
parser = argparse.ArgumentParser('Create and Manage SystemD Jails')
parser.add_argument('-n',
'--name',
help='Name of the chroot jail'
)
parser.add_argument('-c',
'--create',
action='store_true',
help='Create a new Jail'
)
parser.add_argument('-p',
'--profile',
help='vars file containing details about the chroot env'
)
parser.add_argument('-r',
'--release',
action='store_true',
help='Release jail'
)
parser.add_argument('-D',
'--daemonize',
action='store_true',
help='Run container as systemd unit'
)
parser.add_argument('-o',
'--order',
help='Send comand or script to jail'
)
parser.add_argument('-l',
'--list',
action='store_true',
help='List jails in the configured jailhouse'
)
args = parser.parse_args()
if args.list:
pydebootstrap.list()
sys.exit(0)
elif args.release and args.name:
pydebootstrap.release(args.name)
sys.exit(0)
elif args.order and args.name:
pynspawn.order(args.name, args.order)
sys.exit(0)
elif args.daemonize and args.name:
pynspawn.daemonize(args.name)
sys.exit(0)
elif args.create and args.profile:
profile = readYaml(args.profile)
pydebootstrap.create(profile['conf'])
if args.daemonize:
pynspawn.daemonize(profile['conf']['name'])
else:
print("no actionable argument passed.")
sys.exit(0)
if __name__ == "__main__":
main()