forked from google/netbsd-gce
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mkvm.py
65 lines (55 loc) · 1.35 KB
/
mkvm.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
#!/usr/bin/env python
# Copyright 2016 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
import anita
import ftplib
import sys
def find_latest_release(branch, arch):
"""Find the latest NetBSD-current release for the given arch.
Returns:
the full path to the release.
"""
conn = ftplib.FTP('nyftp.netbsd.org')
conn.login()
conn.cwd('/pub/NetBSD-daily/%s' % branch)
releases = conn.nlst()
releases.sort(reverse=True)
for r in releases:
archs = conn.nlst(r)
if not archs:
next
has_arch = [a for a in archs if a.endswith(arch)]
if has_arch:
return "https://nycdn.netbsd.org/pub/NetBSD-daily/%s/%s/" % (branch, has_arch[0])
arch = sys.argv[1]
branch = sys.argv[2]
commands = [
"""cat > /etc/ifconfig.vioif0 << EOF
!dhcpcd vioif0
mtu 1460
EOF""",
"dhcpcd",
"""ed /etc/fstab << EOF
H
%s/wd0/sd0/
wq
EOF""",
"sync; shutdown -hp now",
]
a = anita.Anita(
anita.URL(find_latest_release(branch, arch)),
workdir="work-%s-%s" % (branch, arch),
disk_size="4G",
memory_size = "1G",
persist=True)
child = a.boot()
anita.login(child)
for cmd in commands:
anita.shell_cmd(child, cmd, 1200)
# Sometimes, the halt command times out, even though it has completed
# successfully.
try:
a.halt()
except:
pass