-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeros
executable file
·141 lines (114 loc) · 3.23 KB
/
meros
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/python3
import mos.helper as helper
import mos.kernel_build as kernel_build
import mos.target_manage as target_manage
import mos.libvirt_manage as libvirt_manage
import mos.ssh_communication as ssh_communication
import subprocess
import logging
import getopt
import sys
def main():
h = helper.Helper
mos_path = h.mos_path
logging.basicConfig(
filename = mos_path + '/LOG',
format = '%(asctime)s::MerOS::%(levelname)s::%(message)s',
datefmt = '%H:%M:%S',
encoding = 'utf-8',
level = logging.INFO)
try:
opts, args = getopt.getopt(sys.argv[1:], "hic:v", [
"help",
"kernel-build",
"get", "bootstrap", "build",
"init","shutdown", "shutdown-all",
"connect","push", "pull", "run",
"info", "log",
"output="
])
except getopt.GetoptError as err:
print(err)
h.display_help()
sys.exit(2)
output = None
verbose = False
for o, a in opts:
if o == "-v":
verbose = True
elif o in ("--log"):
h.display_log()
sys.exit()
elif o in ("-h", "--help"):
h.display_help()
sys.exit()
elif o in ("--kernel-build"):
kb = kernel_build.KernelBuild()
kb.kernel_clone()
kb.kernel_build()
sys.exit()
## When building, we will be chrooting in the newly created rootfs
## configuring local ( build-time ) packages-
## thus needing elevated ( root ) privileges
## ( See: mos/target_manage.py:104 )
elif o in ("--build"):
target_fam = sys.argv[2]
h.elevate_privs()
tm = target_manage.TargetManage(target_fam)
tm.main()
sys.exit()
## When initializing/ halting, we will be accessing the libvirt daemon resources
## As well as nftables ( kernel ) access
## thus needing elevated ( root ) privileges
## ( See: mos/libvirt_manage.py:40,72,98 )
elif o in ("-i", "--init"):
h.elevate_privs()
if sys.argv[2] == 'target':
target_id = sys.argv[3]
lm = libvirt_manage.LibvirtManage(target_id)
lm.dom_init()
else:
target_fam_id = sys.argv[2]
lm = libvirt_manage.LibvirtManage(target_fam_id)
lm.nets_init()
lm.doms_init()
lm.hooks_init()
## Haltign ( See above )
elif o in ("--shutdown"):
TargetID = sys.argv[2]
h.elevate_privs()
lm = libvirt_manage.LibvirtExtra()
lm.shutdown_target(TargetID)
elif o in ("--shutdown-all"):
h.elevate_privs()
lm = libvirt_manage.LibvirtExtra()
lm.shutdown_all()
elif o in ("-c", "--connect"):
target_full_id = sys.argv[2]
tc = ssh_communication.SSHCommunication(target_full_id)
## tc.target_run("konsole")
## tc.interactive_shell_paramiko()
tc.interactive_shell_native()
elif o in ("--run"):
target_full_id = sys.argv[2]
run_args = sys.argv[3]
tc = ssh_communication.SSHCommunication(target_full_id)
tc.target_run(run_args)
elif o in ("--push"):
target_full_id = sys.argv[2]
file = sys.argv[3]
ts = ssh_communication.SSHCommunication(target_full_id)
ts.target_push(file)
elif o in ("--pull"):
target_full_id = sys.argv[2]
ts = ssh_communication.SSHCommunication(target_full_id)
ts.target_pull()
elif o in ("--info"):
h.elevate_privs()
lm = libvirt_manage.LibvirtExtra()
lm.libvirt_info()
else:
print("Error")
assert False, "unhandled option"
if __name__ == "__main__":
main()