-
Notifications
You must be signed in to change notification settings - Fork 3
/
common.mk
169 lines (145 loc) · 4.42 KB
/
common.mk
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
# defaults
FORMAT?=qcow2
SIZE?=10
ROOT_PASSWORD:=$(shell dd if=/dev/urandom bs=1 count=64 2>/dev/null | base64 | awk "{printf \$$0}")
# Libvirt/virt-install variables
#LIBVIRT_URI?=qemu:///system
LIBVIRT_URI?=qemu:///session
# virt-install
VI?=virt-install \
--force \
--console pty \
--connect $(LIBVIRT_URI) \
--name="$(VI_NAME)" \
--ram=$(VI_RAM) \
--vcpus=$(VI_CPU) \
--wait=$(VI_TIMEOUT) \
--disk [email protected],format=raw,size=$(SIZE),cache=unsafe,sparse=true,bus=virtio \
--network=user,model=virtio \
--network=user,model=virtio \
--video=vga \
--noreboot
VI_NAME?=build-$(ON_PREFIX)
VI_CPU?=2
VI_RAM?=1536
VI_TIMEOUT?=45
# qemu-image
IMAGE?=$(CURDIR)/image
QI_QCOW_OPTS?=-c -o cluster_size=2M
QI_VMDK_OPTS?=
# ON ... OpenNebula image
ON_DS?=cerit-sc-ha-brno
ON_PUBLIC_DS?=cerit
ON_PREFIX?=$(OS)-$(OS_VERSION)
ON_NAME?=$(ON_PREFIX)-$(ON_VERSION)
ON_DESCRIPTION?=Generic OS image by CERIT Scientific Cloud
ON_VERSION:=$(shell date +%Y%m%d%H)
ON_SOURCE?=$(shell oneimage show $(ON_NAME) | awk -F'[ ]*:[ ]*' '$$1=="SOURCE" { print $$2 }')
ON_DEV_PREFIX?=vd
ON_PERSISTENT?=no
ON_OWNER?=cerit-sc-admin
ON_GROUP?=cerit-sc
# ON upload variables
SCP_PATH?=/home/cerit-sc-admin-api
# M4 templates
M4_OCCI_STORAGE?=../occi-storage.m4
M4_ONEIMAGE?=../oneimage.m4
###################################################
all: build upload clean
build: $(IMAGE).$(FORMAT)
cloud.tar: cloud/
tar -cvf $@ $?
# convert raw->qcow2
$(IMAGE).qcow2: $(IMAGE).raw
nice ionice -c 3 qemu-img convert $(QI_QCOW_OPTS) -O qcow2 $? $@
# convert raw->vmdk
$(IMAGE).vmdk: $(IMAGE).raw
nice ionice -c 3 qemu-img convert $(QI_VMDK_OPTS) -O vmdk $? $@
## upload image to default datastore through OCCI
#$(ON_NAME): $(IMAGE).$(FORMAT)
# if ! oneimage show $(ON_NAME); then \
# set -e; \
# DEF=`mktemp`; \
# m4 -D__NAME__="$(ON_NAME)" \
# -D__DESCRIPTION__="$(ON_DESCRIPTION)" \
# -D__URL__="file://$?" \
# $(M4_OCCI_STORAGE) | tee $$DEF; \
# occi-storage create $$DEF; \
# unlink $$DEF; \
# fi
# upload image to ON server
$(ON_NAME): $(IMAGE).$(FORMAT)
chmod o+r $?
scp -o 'Compression no' \
$? $(SCP_HOST):$(SCP_PATH)/$(ON_NAME).$(FORMAT)
## copy image from default to specified datastore
#$(ON_NAME)@%: $(ON_NAME)
# if ! oneimage show $@; then \
# set -e; \
# DEF=`mktemp`; \
# m4 -D__NAME__="$@" \
# -D__DESCRIPTION__="$(ON_DESCRIPTION)" \
# -D__PATH__="$(ON_SOURCE)" \
# -D__DRIVER__="$(ON_DRIVER)" \
# -D__DEV_PREFIX__="$(ON_DEV_PREFIX)" \
# -D__PERSISTENT__="$(ON_PERSISTENT)" \
# $(M4_ONEIMAGE) | tee $$DEF; \
# oneimage create $$DEF --datastore $*; \
# oneimage chgrp "$@" $(ON_GROUP) ; \
# oneimage chmod "$@" $(ON_MODE) ; \
# unlink $$DEF; \
# fi
#define oneimage
# oneimage create -v --name "$1" \
# --source="$(SCP_PATH)/$(ON_NAME).$(FORMAT)" \
# --prefix=vd --type=OS --driver=$(FORMAT) \
# --datastore="$2" --disk_type="BLOCK" \
# --size=$$(($(SIZE) * 1024)) \
# --description="$(ON_DESCRIPTION)"
# oneimage chown "$1" $(ON_OWNER)
# oneimage chgrp "$1" $(ON_GROUP)
# oneimage chmod "$1" $3
#endef
define oneimage
set -e; \
DEF=`mktemp`; \
m4 -D__NAME__="$1" \
-D__DESCRIPTION__="$(ON_DESCRIPTION)" \
-D__PATH__="$(SCP_PATH)/$(ON_NAME).$(FORMAT)" \
-D__DRIVER__="$(FORMAT)" \
-D__DEV_PREFIX__="$(ON_DEV_PREFIX)" \
-D__PERSISTENT__="$(ON_PERSISTENT)" \
$(M4_ONEIMAGE) | tee $$DEF; \
oneimage create $$DEF --datastore $2; \
oneimage chown "$1" $(ON_OWNER) ; \
oneimage chgrp "$1" $(ON_GROUP) ; \
oneimage chmod "$1" $3 ; \
unlink $$DEF
endef
#$(ON_NAME)@%: $(ON_NAME)
# oneimage create -v --name "$@" \
# --source="$(ON_PATH)/$(ON_NAME).$(FORMAT)" \
# --prefix=vd --type=OS --driver=$(FORMAT) \
# --datastore="$*" --disk_type="BLOCK" \
# --size=$$(($(SIZE) * 1024)) \
# --description="Generic OS image by CERIT Scientific Cloud"
# oneimage chown "$@" $(ON_OWNER)
# oneimage chgrp "$@" $(ON_GROUP)
# oneimage chmod "$@" $(ON_MODE)
$(ON_NAME)@%: $(ON_NAME)
$(call oneimage,$@,$*,600)
$(ON_NAME)@%.public: $(ON_NAME)
$(call oneimage,$(ON_NAME),$*,644)
upload: \
$(patsubst %, $(ON_NAME)@%.public, $(ON_PUBLIC_DS))
empty:
echo -n >empty
clean: empty
-virsh -q -c $(LIBVIRT_URI) destroy $(VI_NAME) 2>/dev/null
-virsh -q -c $(LIBVIRT_URI) undefine $(VI_NAME) 2>/dev/null
# -oneimage delete $(ON_NAME)
-scp -o 'Compression no' \
empty $(SCP_HOST):$(SCP_PATH)/$(ON_NAME).$(FORMAT)
rm -f $(IMAGE).raw $(IMAGE).raw.tmp $(IMAGE).$(FORMAT) \
$(IMAGE).qcow2 $(IMAGE).vmdk cloud.tar empty