-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupload-image
executable file
·112 lines (92 loc) · 2.95 KB
/
upload-image
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
#!/bin/bash
install-openstack-client() {
if command -v openstack &>/dev/null; then
return
fi
pip install python-openstackclient
}
upload() {
install-openstack-client
eval openstack image create \
--container-format bare \
--progress \
--public $@
}
image-general() {
local name="${1}"
local os_type="${2}"
local os_admin_user="${3}"
local os_distro="${4}"
local os_version="${5}"
local hw_disk_bus="${6}"
local upload_options="\
--property architecture=x86_64 \
--property hw_disk_bus='${hw_disk_bus}' \
--property hw_scsi_model=virtio-scsi \
--property hw_vif_multiqueue_enabled=true \
--property hw_qemu_guest_agent=yes \
--property os_require_quiesce=yes \
--property os_type='${os_type}' \
--property os_admin_user='${os_admin_user}' \
--property os_distro='${os_distro}' \
--property os_version='${os_version}'"
local id_file="${name}.id.txt"
if [ -f "${id_file}" ]; then
upload_options="${upload_options} --id '$(cat ${id_file})'"
fi
local desc_file="${name}.desc.txt"
if [ -f "${desc_file}" ]; then
upload_options="${upload_options} --property description='$(cat ${desc_file})'"
fi
local img_file="${name}.qcow2"
if [ -f "${img_file}" ]; then
upload_options="${upload_options} --disk-format qcow2"
else
img_file="${name}.img"
if [ -f "${img_file}" ]; then
upload_options="${upload_options} --disk-format raw"
fi
fi
upload ${upload_options} --file "${img_file}" "${name}"
}
image-data() {
local name="${1}"
local upload_options=""
local id_file="${name}.id.txt"
if [ -f "${id_file}" ]; then
upload_options="${upload_options} --id '$(cat ${id_file})'"
fi
local img_file="${name}.qcow2"
if [ -f "${img_file}" ]; then
upload_options="${upload_options} --disk-format qcow2"
else
img_file="${name}.img"
if [ -f "${img_file}" ]; then
upload_options="${upload_options} --disk-format raw"
fi
fi
upload ${upload_options} --file "${img_file}" "${name}"
}
image-linux() {
local name="$1"
local os_distro="${2:-ubuntu}"
local os_version="${3:-22.04}"
local hw_disk_bus="${4:-scsi}"
image-general "${name}" "linux" "root" "${os_distro}" "${os_version}" "${hw_disk_bus}"
}
image-ubuntu() {
image-linux "$1" "ubuntu" "$2" "$3"
}
image-centos() {
local os_version="${2:-7}"
image-linux "$1" "centos" "${os_version}" "$3"
}
image-windows() {
local name="$1"
local os_distro="${2:-Windows Server}"
# ref: https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions#Server_versions
# e.g. Windows Server 2022 version number is 21H2
local os_version="${3:-"21H2"}"
local hw_disk_bus="${4:-virtio}"
image-general "${name}" "windows" "Administrator" "${os_distro}" "${os_version}" "${hw_disk_bus}"
}