3 # A shell script to build the VPP VM image or NFVbench+TRex VM image using diskinage-builder
5 # The following packages must be installed prior to using this script:
6 # sudo apt-get -y install python-virtualenv qemu-utils kpartx
9 echo "Usage: $0 [-l] [-g] [-v]"
10 echo " -l build NFVbench loop VM image"
11 echo " -g build NFVbench generator image"
12 echo " -v verify only (build but do not push to google storage)"
20 # ----------------------------------------------------------------------------
21 # Parse command line options and configure the script
22 # ----------------------------------------------------------------------------
24 while getopts ":hglv" opt; do
49 gs_url=artifacts.opnfv.org/nfvbench/images
51 # image version number
53 loopvm_image_name=nfvbenchvm_centos-$__version__
54 generator_image_name=nfvbenchvm_centos-generator-$__version__
56 function build_image {
57 # if image exists skip building
58 echo "Checking if image exists in google storage..."
59 if command -v gsutil >/dev/null; then
60 if gsutil -q stat gs://$gs_url/$1.qcow2; then
61 echo "Image already exists at http://$gs_url/$1.qcow2"
62 echo "Build is skipped"
65 echo "Image does not exist in google storage, starting build..."
68 echo "Cannot check image availability in OPNFV artifact repository (gsutil not available)"
71 # check if image is already built locally
72 if [ -f $1.qcow2 ]; then
73 echo "Image $1.qcow2 already exists locally"
76 # install diskimage-builder
77 if [ -d dib-venv ]; then
78 . dib-venv/bin/activate
81 . dib-venv/bin/activate
82 pip install diskimage-builder
85 # Add nfvbenchvm_centos elements directory to the DIB elements path
86 export ELEMENTS_PATH=`pwd`/elements
88 # canned user/password for direct login
89 export DIB_DEV_USER_USERNAME=nfvbench
90 export DIB_DEV_USER_PASSWORD=nfvbench
91 export DIB_DEV_USER_PWDLESS_SUDO=Y
93 # Set the data sources to have ConfigDrive only
94 export DIB_CLOUD_INIT_DATASOURCES="ConfigDrive"
97 export DIB_YUM_REPO_CONF=$ELEMENTS_PATH/nfvbenchvm/fdio-release.repo
99 # Use ELRepo to have latest kernel
100 # only for loop vm image
101 if [ $1 = $loopvm_image_name ]; then
102 export DIB_USE_ELREPO_KERNEL=True
103 export DIB_DEV_IMAGE=loopvm
105 export DIB_USE_ELREPO_KERNEL=False
106 export DIB_DEV_IMAGE=generator
107 # get current git branch to build image with current code
108 export GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
109 # retrieve TREX_VER from Dockerfile
110 export TREX_VER=$(awk '/ENV TREX_VER/ {print $3}' ../../docker/Dockerfile | sed 's/"//g' | sed 's/\r//g')
113 echo "Building $1.qcow2..."
114 time disk-image-create -o $1 centos7 nfvbenchvm
119 if [ $verify_only -eq 1 ]; then
120 echo "Image verification SUCCESS"
121 echo "NO upload to google storage (-v)"
123 if command -v gsutil >/dev/null; then
124 echo "Uploading $1.qcow2..."
125 gsutil cp $1.qcow2 gs://$gs_url/$1.qcow2
126 echo "You can access to image at http://$gs_url/$1.qcow2"
128 echo "Cannot upload new image to the OPNFV artifact repository (gsutil not available)"
135 if [ ! $generator_only -eq 1 ] && [ ! $loopvm_only -eq 1 ]; then
136 echo "Build loop VM image"
137 build_image $loopvm_image_name
138 echo "Build generator image"
139 build_image $generator_image_name
141 if [ $loopvm_only -eq 1 ]; then
142 echo "Build loop VM image"
143 build_image $loopvm_image_name
145 if [ $generator_only -eq 1 ]; then
146 echo "Build generator image"
147 build_image $generator_image_name