-
Notifications
You must be signed in to change notification settings - Fork 0
/
BelagosLib.py
executable file
·280 lines (268 loc) · 8.88 KB
/
BelagosLib.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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#!/usr/bin/env python3
import pexpect, os, sys
def boot_vm(command, glenda_pass="", disk_pass=""):
pexp = pexpect.spawn(command, timeout=None, encoding='utf-8')
pexp.logfile = sys.stdout
while True:
i = pexp.expect(['\w+# ', 'term% ', 'user\[glenda\]\: ', 'bootargs is \(.*\)\[.*\]', 'authid\:', 'Password\: '])
if i==0 or i==1:
break
if i==2:
pexp.sendline()
elif i==3: # Normal boot; disk encryption and super normal
if disk_pass:
pexp.sendline("!rc")
pexp.expect('% ')
pexp.sendline("disk/cryptsetup -i /dev/sd00/fsworm /dev/sd00/fscache /dev/sd00/other")
pexp.expect('Password: ')
pexp.sendline(disk_pass)
pexp.expect('% ')
pexp.sendline("exit")
pexp.expect('bootargs is ')
pexp.sendline()
else:
pexp.sendline()
elif i==4: # Booting a grid host with no vram
pexp.sendline('glenda')
pexp.expect('authdom\:')
pexp.sendline('localgrid')
pexp.expect('secstore key\:')
pexp.sendline(glenda_pass)
pexp.expect('password\:')
pexp.sendline(glenda_pass)
pexp.expect('confirm password\: ')
pexp.sendline(glenda_pass)
pexp.expect('enable legacy p9sk1\[no\]\: ')
pexp.sendline()
elif i==5: # Additional password prompt for the prev
pexp.sendline(glenda_pass)
pexp.expect('Confirm password\: ')
pexp.sendline(glenda_pass)
return(pexp)
def halt_vm(pexp):
pexp.sendline()
pexp.expect('\w+# ')
pexp.sendline('fshalt')
pexp.expect('done halting')
pexp.close()
return(0)
def grid_authserver_vm(command, glenda_pass):
pexp = boot_vm(command, glenda_pass, "") # only the main serve needs the disk password ever
pexp.sendline('auth/changeuser glenda')
pexp.expect('Password\:')
pexp.sendline(glenda_pass)
pexp.expect('Confirm password\:')
pexp.sendline(glenda_pass)
pexp.expect('assign.*POP.*\:')
pexp.sendline('n')
pexp.expect('Expiration.*\:')
pexp.sendline()
pexp.expect('Post.*\:')
pexp.sendline()
pexp.expect('.*name\:')
pexp.sendline()
pexp.expect('Department.*\:')
pexp.sendline()
pexp.expect('U.*email address\:')
pexp.sendline()
pexp.expect('Spon.*email address\:')
pexp.sendline()
pexp.expect('authserve# ')
pexp.sendline('fshalt')
pexp.expect(pexpect.EOF)
pexp.close()
return(0)
def grid_nvram_vm(command, glenda_pass):
pexp = boot_vm(command, glenda_pass, "") # Never need disk password for nvram
pexp.sendline('plan9Scripts/nvram.rc')
pexp.expect('\w+# ')
pexp.sendline('auth/wrkey')
pexp.expect('authid\:')
pexp.sendline('glenda')
pexp.expect('authdom\:')
pexp.sendline('localgrid')
pexp.expect('secstore key\:')
pexp.sendline(glenda_pass)
pexp.expect('password\:')
pexp.sendline(glenda_pass)
pexp.expect('confirm password\: ')
pexp.sendline(glenda_pass)
pexp.expect('enable legacy p9sk1\[no\]\: ')
pexp.sendline()
pexp.expect('\w+# ')
pexp.sendline('fshalt')
pexp.expect(pexpect.EOF)
pexp.close()
return(0)
def base_services_vm(command, scripts_iso, glenda_pass, installType, disk_pass=""):
# Enable CPU service
pexp = boot_vm(command, glenda_pass, disk_pass)
pexp.sendline('9fs 9fat; echo \'service=cpu\' >>/n/9fat/plan9.ini')
pexp.expect('term% ')
pexp.sendline('fshalt')
pexp.expect(pexpect.EOF)
pexp.close()
# Set a password for Glenda
pexp = boot_vm(command, glenda_pass, disk_pass)
pexp.sendline('fshalt')
pexp.expect(pexpect.EOF)
pexp.close()
# Turn on 9p/fs Serve
bootfs = '/dev/sd00/fscache'
if disk_pass:
bootfs = '/dev/fs/fscache'
pexp = pexpect.spawn(command, timeout=None, encoding='utf-8')
pexp.logfile = sys.stdout
if disk_pass:
pexp.expect('bootargs is \(.*\)\[.*\]')
pexp.sendline('!rc')
pexp.expect('% ')
pexp.sendline('disk/cryptsetup -i /dev/sd00/fsworm /dev/sd00/fscache /dev/sd00/other')
pexp.expect('Password\: ')
pexp.sendline(disk_pass)
pexp.expect('% ')
pexp.sendline('exit')
pexp.expect('bootargs is \(.*\)\[.*\]')
pexp.sendline('local!%s -c' % (bootfs))
pexp.expect('config\: ')
pexp.sendline('noauth')
pexp.expect('config\: ')
pexp.sendline('noauth')
pexp.expect('config\: ')
pexp.sendline('end')
pexp.expect('# ')
pexp.sendline('9fs 9fat; echo \'bootargs=local!%s -a tcp!*!564\' >>/n/9fat/plan9.ini' % (bootfs))
pexp.expect('# ')
pexp.sendline('fshalt')
pexp.expect(pexpect.EOF)
pexp.close()
# Copy post install scripts and execute
command_withIso = "%s -drive if=none,id=vd1,file=%s -device scsi-cd,drive=vd1," % (command, scripts_iso)
pexp = boot_vm(command_withIso, glenda_pass, disk_pass)
pexp.sendline('mkdir plan9Scripts')
pexp.expect('# ')
pexp.sendline('mount <{9660srv -s >[0=1]} /n/iso /dev/sd01/data')
pexp.expect('# ')
pexp.sendline('cp /n/iso/* plan9Scripts')
pexp.expect('# ')
pexp.sendline('chmod 755 plan9Scripts/*')
pexp.expect('# ')
if installType == 'grid':
pexp.sendline('plan9Scripts/pxe.rc')
else:
pexp.sendline('plan9Scripts/solo.rc')
pexp.expect('# ')
pexp.sendline('fshalt')
pexp.expect(pexpect.EOF)
pexp.close()
return(0)
# Plan 9 install: take all defaults and when you see >>>, type w \n q.
def base_install_vm(command, timezone, disk_pass=""):
pexp = pexpect.spawn(command, timeout=None, encoding='utf-8')
pexp.logfile = sys.stdout
pexp.expect('bootargs is \(tcp, tls, il, local!device\)\[local!/dev/sd01/data\]')
pexp.sendline()
pexp.expect('user\[glenda\]: ')
pexp.sendline()
pexp.expect('vgasize is \(text, 640x480x8, 1024x768x16, ...\) \[1024x768x16\] ')
pexp.sendline('text')
pexp.expect('term% ')
pexp.sendline('inst/start')
pexp.expect('Task to do \[.*\]\: ')
pexp.sendline()
pexp.expect('File system *:*')
pexp.sendline()
pexp.expect('Task to do \[.*\]\: ')
pexp.sendline()
pexp.expect('Disk to partition .*\: ')
pexp.sendline('sd00')
pexp.expect('Install mbr or gpt .*\: ')
pexp.sendline('mbr')
pexp.expect('>>>')
pexp.sendline('w')
pexp.expect('>>>')
pexp.sendline('q')
pexp.expect('Task to do \[.*\]\: ')
pexp.sendline()
pexp.expect('Plan 9 partition to subdivide .*\: ')
pexp.sendline()
pexp.expect('>>>')
pexp.sendline('w')
pexp.expect('>>>')
pexp.sendline('q')
# Disk Encyption Here
if disk_pass:
pexp.expect('Task to do \[.*\]\: ')
pexp.sendline('!rc')
pexp.expect('term% ')
pexp.sendline('disk/cryptsetup -f /dev/sd00/fsworm /dev/sd00/fscache /dev/sd00/other')
pexp.expect('Password\: ')
pexp.sendline(disk_pass)
pexp.expect('Confirm\: ')
pexp.sendline(disk_pass)
pexp.expect('term% ')
pexp.sendline('disk/cryptsetup -i /dev/sd00/fsworm /dev/sd00/fscache /dev/sd00/other')
pexp.expect('Password: ')
pexp.sendline(disk_pass)
pexp.expect('term% ')
pexp.sendline('exit')
pexp.expect('Task to do \[.*\]\: ')
pexp.sendline()
pexp.expect('Cwfs cache partition .*\: ')
pexp.sendline('/dev/fs/fscache')
pexp.expect('Cwfs worm partition .*\: ')
pexp.sendline('/dev/fs/fsworm')
pexp.expect('Cwfs other partition .*\: ')
pexp.sendline('/dev/fs/other')
else:
pexp.expect('Task to do \[.*\]\: ')
pexp.sendline()
pexp.expect('Cwfs cache partition .*\: ')
pexp.sendline()
pexp.expect('Cwfs worm partition .*\: ')
pexp.sendline()
pexp.expect('Cwfs other partition .*\: ')
pexp.sendline()
pexp.expect('Ream the filesystem?.*')
pexp.sendline()
pexp.expect('Task to do \[.*\]: ')
pexp.sendline()
pexp.expect('Configuration method .*\: ')
pexp.sendline('manual')
pexp.expect('ip address .*\: ')
pexp.sendline('192.168.9.3')
pexp.expect('network mask .*\: ')
pexp.sendline('255.255.255.0')
pexp.expect('gateway address .*\: ')
pexp.sendline('192.168.9.1')
pexp.expect('dns server .*\: ')
pexp.sendline('192.168.9.1')
pexp.expect('Task to do \[.*\]\: ')
pexp.sendline()
pexp.expect('Distribution disk .*\: ')
pexp.sendline('/dev/sd01/data')
pexp.expect('Location of archives .*\: ')
pexp.sendline()
pexp.expect('Task to do \[.*\]\: ')
pexp.sendline()
pexp.expect('Task to do \[.*\]\: ')
pexp.sendline()
pexp.expect('sysname .*\: ')
pexp.sendline()
pexp.expect('Task to do \[.*\]\: ')
pexp.sendline()
pexp.expect('Time Zone .*: ')
pexp.sendline(timezone)
pexp.expect('Task to do \[.*\]\: ')
pexp.sendline()
pexp.expect('Plan 9 FAT partition .*\: ')
pexp.sendline()
pexp.expect('Install the Plan 9 master boot record .*\: ')
pexp.sendline('yes')
pexp.expect('Mark the Plan 9 partition active .*\: ')
pexp.sendline('yes')
pexp.expect('Task to do \[.*\]\: ')
pexp.sendline()
pexp.expect(pexpect.EOF)
pexp.close()
return(0)