Commit 3707aa73 authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Add new config_url os parameter

This url points to a json file that contains the value for other
OS parameters. Using this file we can pass parameters to snf-image
without writting them in Ganeti's config.data. This is
useful, for 2 reasons:
* Privacy: We don't want the password to appear in the Ganeti config
* Speed: Some parameters like IMG_PERSONALITY can be quite large (a few
KB) and since ganeti shares the instance configuration among different
nodes, the overall system will start getting slower if many instances
with IMG_PERSONALITY exist.
parent eafa1728
......@@ -12,7 +12,7 @@ variantsdir=${sysconfdir}/ganeti/snf-image/variants
dist_os_SCRIPTS = ${srcdir}/create ${srcdir}/import ${srcdir}/export \
${srcdir}/rename ${srcdir}/verify ${srcdir}/pithcat \
${srcdir}/copy-monitor.py ${srcdir}/helper-monitor.py \
${srcdir}/host-monitor.py
${srcdir}/host-monitor.py ${srcdir}/decode-config.py
dist_os_DATA = ${srcdir}/ganeti_api_version ${srcdir}/parameters.list \
${srcdir}/variants.list
......
......@@ -144,28 +144,25 @@ get_api10_arguments() {
get_api20_arguments() {
get_api10_arguments
if [ -z "$OSP_IMG_ID" ]; then
log_error "Missing OS API Parameter: OSP_IMG_ID"
exit 1
fi
if [ -z "$OSP_IMG_FORMAT" ]; then
log_error "Missing OS API Parameter: OSP_IMG_FORMAT"
exit 1
fi
if [ -z "$OSP_IMG_PASSWD" ]; then
log_error "Missing OS API Parameter: OSP_IMG_PASSWD"
exit 1
fi
IMG_ID=$OSP_IMG_ID
IMG_FORMAT=$OSP_IMG_FORMAT
IMG_PASSWD=$OSP_IMG_PASSWD
if [ -n "$OSP_IMG_PROPERTIES" ]; then
IMG_PROPERTIES="$OSP_IMG_PROPERTIES"
fi
if [ -n "$OSP_IMG_PERSONALITY" ]; then
IMG_PERSONALITY="$OSP_IMG_PERSONALITY"
local required_osparams="IMG_ID IMG_FORMAT IMG_PASSWD"
local osparams="$required_osparams IMG_PROPERTIES IMG_PERSONALITY CONFIG_URL"
# Store OSP_VAR in VAR
for param in $osparams; do
eval $param=\"\$OSP_$param\"
done
if [ -n "$CONFIG_URL" ]; then
source <($CURL -f "$CONFIG_URL" | ./decode-config.py $osparams)
fi
for var in $required_osparams; do
if [ -z "${!var}" ]; then
log_error "Missing OS API Parameter: ${var}"
exit 1
fi
done
}
map_disk0() {
......
#!/usr/bin/env python
# Copyright (C) 2012 GRNET S.A.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
"""Decode a json encoded string with properties
This program decodes a json encoded properties string and outputs it in a
bash sourcable way. The properties are passed to the program through a JSON
string either read from a file or from standard input and are outputed to a
target file.
"""
import sys
import os
import subprocess
import json
import random
import string
from StringIO import StringIO
def main():
options = sys.argv[1:]
prefix = ''.join(random.choice(string.ascii_uppercase) for x in range(8))
config = json.load(sys.stdin)
for key, value in config.items():
if str(key).upper() in options:
os.environ[prefix + str(key).upper()] = value
p = subprocess.Popen(['bash', '-c', 'set'], stdout=subprocess.PIPE)
output = StringIO(p.communicate()[0])
for line in iter(output):
if line.startswith(prefix):
print line[len(prefix):]
return 0
if __name__ == "__main__":
sys.exit(main())
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :
......@@ -3,3 +3,4 @@ img_format The format of the image to be installed
img_passwd The root password which will be injected into the image
img_properties The image properties that are used to customize the image (json.dumps format)
img_personality The files to be injected into the image (base64 encoded in a json.dumps format)
config_url The url to download configuration data from
......@@ -22,36 +22,29 @@ set -e
. common.sh
if [ -z "$OSP_IMG_ID" ]; then
log_error "Missing OS API Parameter: OSP_IMG_ID"
exit 1
fi
if [ -z "$OSP_IMG_FORMAT" ]; then
log_error "Missing OS API Parameter: OSP_IMG_FORMAT"
exit 1
fi
if [ -z "$OSP_IMG_PASSWD" ]; then
log_error "Missing OS API Parameter: OSP_IMG_PASSWD"
exit 1
fi
check_required() {
local required_params="IMG_ID IMG_FORMAT IMG_PASSWD"
local osparams="$required_params IMG_PROPERTIES IMG_PERSONALITY CONFIG_URL"
IMG_ID=$OSP_IMG_ID
IMG_FORMAT=$OSP_IMG_FORMAT
IMG_PASSWD=$OSP_IMG_PASSWD
if [ -n "$OSP_IMG_PROPERTIES" ]; then
IMG_PROPERTIES="$OSP_IMG_PROPERTIES"
fi
if [ -n "$OSP_IMG_PERSONALITY" ]; then
IMG_PERSONALITY="$OSP_IMG_PERSONALITY"
fi
# Store OSP_VAR in VAR
for param in $osparams; do
eval $param=\"\$OSP_$param\"
done
for var in $required_params; do
if [ -z "${!var}" ]; then
log_error "Missing OS API Parameter: ${var}"
exit 1
fi
done
case $IMG_FORMAT in
extdump|ntfsdump)
case $IMG_FORMAT in
extdump|ntfsdump)
;;
diskdump)
diskdump)
if [ -z "$IMG_PROPERTIES" ]; then
log_error "\`img_properties' parameter must be present when using \`diskdump' format."
log_error "\`img_properties' parameter must be present when"
log_error "using \`diskdump' format."
exit 1
fi
;;
......@@ -60,5 +53,12 @@ case $IMG_FORMAT in
exit 1
;;
esac
}
if [ -z "$OSP_CONFIG_URL" ]; then
check_required
fi
exit 0
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment