-
Notifications
You must be signed in to change notification settings - Fork 3
/
create-kvm-manifest
executable file
·151 lines (133 loc) · 2.44 KB
/
create-kvm-manifest
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
#!/usr/bin/env bash
#
# Copyright (c) 2017 Joyent Inc., All rights reserved.
#
set -euo pipefail
IFS=$'\n\t'
NOW=$(date -u +%Y-%m-%dT%TZ)
VM_UUID=$(uuid)
SUM=/usr/bin/sum
description=
disk_driver=
filename=
name=
nic_driver=
os=
image_size=
version=
homepage=
usage() {
cat <<USAGE
Usage: $0 -f <filename> -n <name> -s <size>
Options:
-d <image description> (optional, default: "<NAME> <VERSION> KVM Triton")
-D <disk driver> (optional, default: "virtio")
-f <filename of VM image> (required)
-n <name of VM image> (required)
-N <NIC driver> (optional, default: "virtio")
-o <OS name> (optional, default: other)
-s <size of virtual disk (as seen by VM, MiB)> (required)
-v <version of VM image> (optional, default: YYYMMDDHHMM)
-h <homepage link> (optional, default: https://docs.joyent.com/images/)
Example:
$0 -f ubuntu-14-20170207.zfs.gz -s 65566 -n Ubuntu -v 20170207
USAGE
exit 1
}
while getopts d:D:f:n:N:o:s:v:h:? OPTION; do
case $OPTION in
d)
description=${OPTARG}
;;
D)
disk_driver=${OPTARG}
;;
f)
filename=${OPTARG}
;;
n)
name=${OPTARG}
;;
N)
nic_driver=${OPTARG}
;;
o)
os=${OPTARG}
;;
s)
image_size=${OPTARG}
;;
v)
version=${OPTARG}
;;
h)
homepage=${OPTARG}
;;
\?)
usage
;;
esac
done
if [[ -z $filename || -z $name || -z $image_size ]]; then
echo "FATAL: All of -f, -n, and -s are required."
usage
fi
if [[ -z $description ]]; then
description="$name $version KVM Triton image"
fi
if [[ -z $os ]]; then
os=other
fi
if [[ ! -f $filename ]]; then
echo "FATAL: $filename does not exist."
usage
fi
if [[ -z $disk_driver ]]; then
disk_driver="virtio"
fi
if [[ -z $nic_driver ]]; then
nic_driver="virtio"
fi
if [[ -z $version ]]; then
version=$(date +%Y%m%d%H%M)
fi
if [[ -z $homepage ]]; then
homepage="https://docs.joyent.com/images/"
fi
shasum=$($SUM -x sha1 "$filename" | cut -d' ' -f1)
filesize=$(wc -c < "$filename")
cat <<EOF
{
"v": "2",
"name": "$name",
"version": "$version",
"type": "zvol",
"cpu_type": "host",
"description": "$description",
"homepage": "$homepage",
"published_at": "$NOW",
"os": "$os",
"image_size": "$image_size",
"files": [
{
"sha1": "$shasum",
"size": $filesize,
"compression": "gzip"
}
],
"requirements": {
"networks": [
{
"name": "net0",
"description": "public"
}
]
},
"disk_driver": "virtio",
"nic_driver": "virtio",
"uuid": "${VM_UUID}",
"public": false,
"owner": "00000000-0000-0000-0000-000000000000",
}
}
EOF