forked from openstack/devstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdib
More file actions
133 lines (107 loc) · 3.7 KB
/
dib
File metadata and controls
133 lines (107 loc) · 3.7 KB
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
# lib/dib
# Install and build images with **diskimage-builder**
# Dependencies:
#
# - functions
# - DEST, DATA_DIR must be defined
# stack.sh
# ---------
# - install_dib
# Save trace setting
XTRACE=$(set +o | grep xtrace)
set +o xtrace
# Defaults
# --------
# set up default directories
DIB_DIR=$DEST/diskimage-builder
TIE_DIR=$DEST/tripleo-image-elements
DIB_IMAGE_CACHE=$DATA_DIR/diskimage-builder/image-create
DIB_PIP_REPO=$DATA_DIR/diskimage-builder/pip-repo
DIB_PIP_REPO_PORT=${DIB_PIP_REPO_PORT:-8899}
OCC_DIR=$DEST/os-collect-config
ORC_DIR=$DEST/os-refresh-config
OAC_DIR=$DEST/os-apply-config
# Functions
# ---------
# install_dib() - Collect source and prepare
function install_dib {
git_clone $DIB_REPO $DIB_DIR $DIB_BRANCH
pushd $DIB_DIR
pip_install ./
popd
git_clone $TIE_REPO $TIE_DIR $TIE_BRANCH
git_clone $OCC_REPO $OCC_DIR $OCC_BRANCH
git_clone $ORC_REPO $ORC_DIR $ORC_BRANCH
git_clone $OAC_REPO $OAC_DIR $OAC_BRANCH
mkdir -p $DIB_IMAGE_CACHE
}
# build_dib_pip_repo() - Builds a local pip repo from local projects
function build_dib_pip_repo {
local project_dirs=$1
local projpath proj package
rm -rf $DIB_PIP_REPO
mkdir -p $DIB_PIP_REPO
echo "<html><body>" > $DIB_PIP_REPO/index.html
for projpath in $project_dirs; do
proj=$(basename $projpath)
mkdir -p $DIB_PIP_REPO/$proj
pushd $projpath
rm -rf dist
python setup.py sdist
pushd dist
package=$(ls *)
mv $package $DIB_PIP_REPO/$proj/$package
popd
echo "<html><body><a href=\"$package\">$package</a></body></html>" > $DIB_PIP_REPO/$proj/index.html
echo "<a href=\"$proj\">$proj</a><br/>" >> $DIB_PIP_REPO/index.html
popd
done
echo "</body></html>" >> $DIB_PIP_REPO/index.html
local dib_pip_repo_apache_conf=$(apache_site_config_for dib_pip_repo)
sudo cp $FILES/apache-dib-pip-repo.template $dib_pip_repo_apache_conf
sudo sed -e "
s|%DIB_PIP_REPO%|$DIB_PIP_REPO|g;
s|%DIB_PIP_REPO_PORT%|$DIB_PIP_REPO_PORT|g;
s|%APACHE_NAME%|$APACHE_NAME|g;
" -i $dib_pip_repo_apache_conf
enable_apache_site dib_pip_repo
}
# disk_image_create_upload() - Creates and uploads a diskimage-builder built image
function disk_image_create_upload {
local image_name=$1
local image_elements=$2
local elements_path=$3
local image_path=$TOP_DIR/files/$image_name.qcow2
# Set the local pip repo as the primary index mirror so the
# image is built with local packages
local pypi_mirror_url=http://$SERVICE_HOST:$DIB_PIP_REPO_PORT/
local pypi_mirror_url_1
if [ -a $HOME/.pip/pip.conf ]; then
# Add the current pip.conf index-url as an extra-index-url
# in the image build
pypi_mirror_url_1=$(iniget $HOME/.pip/pip.conf global index-url)
else
# If no pip.conf, set upstream pypi as an extra mirror
# (this also sets the .pydistutils.cfg index-url)
pypi_mirror_url_1=http://pypi.python.org/simple
fi
# The disk-image-create command to run
ELEMENTS_PATH=$elements_path \
PYPI_MIRROR_URL=$pypi_mirror_url \
PYPI_MIRROR_URL_1=$pypi_mirror_url_1 \
disk-image-create -a amd64 $image_elements \
--image-cache $DIB_IMAGE_CACHE \
-o $image_path
local token=$(keystone token-get | grep ' id ' | get_field 2)
die_if_not_set $LINENO token "Keystone fail to get token"
glance --os-auth-token $token --os-image-url http://$GLANCE_HOSTPORT \
image-create --name $image_name --is-public True \
--container-format=bare --disk-format qcow2 \
< $image_path
}
# Restore xtrace
$XTRACE
# Tell emacs to use shell-script-mode
## Local variables:
## mode: shell-script
## End: