Revision 3707aa73

b/snf-image-host/Makefile.am
12 12
dist_os_SCRIPTS = ${srcdir}/create ${srcdir}/import ${srcdir}/export \
13 13
	${srcdir}/rename ${srcdir}/verify ${srcdir}/pithcat \
14 14
	${srcdir}/copy-monitor.py ${srcdir}/helper-monitor.py \
15
	${srcdir}/host-monitor.py
15
	${srcdir}/host-monitor.py ${srcdir}/decode-config.py
16 16

  
17 17
dist_os_DATA = ${srcdir}/ganeti_api_version ${srcdir}/parameters.list \
18 18
               ${srcdir}/variants.list
b/snf-image-host/common.sh.in
144 144

  
145 145
get_api20_arguments() {
146 146
    get_api10_arguments
147
    if [ -z "$OSP_IMG_ID" ]; then
148
        log_error "Missing OS API Parameter: OSP_IMG_ID"
149
        exit 1
150
    fi
151
    if [ -z "$OSP_IMG_FORMAT" ]; then
152
        log_error "Missing OS API Parameter: OSP_IMG_FORMAT"
153
        exit 1
154
    fi
155
    if [ -z "$OSP_IMG_PASSWD" ]; then
156
        log_error "Missing OS API Parameter: OSP_IMG_PASSWD"
157
        exit 1
158
    fi
159 147

  
160
    IMG_ID=$OSP_IMG_ID
161
    IMG_FORMAT=$OSP_IMG_FORMAT
162
    IMG_PASSWD=$OSP_IMG_PASSWD
163
    if [ -n "$OSP_IMG_PROPERTIES" ]; then
164
        IMG_PROPERTIES="$OSP_IMG_PROPERTIES"
165
    fi
166
    if [ -n "$OSP_IMG_PERSONALITY" ]; then
167
        IMG_PERSONALITY="$OSP_IMG_PERSONALITY"
148
    local required_osparams="IMG_ID IMG_FORMAT IMG_PASSWD"
149
    local osparams="$required_osparams IMG_PROPERTIES IMG_PERSONALITY CONFIG_URL"
150

  
151
    # Store OSP_VAR in VAR
152
    for param in $osparams; do
153
        eval $param=\"\$OSP_$param\"
154
    done
155

  
156
    if [ -n "$CONFIG_URL" ]; then
157
	source <($CURL -f "$CONFIG_URL" | ./decode-config.py $osparams)
168 158
    fi
159

  
160
    for var in $required_osparams; do
161
        if [ -z "${!var}" ]; then
162
             log_error "Missing OS API Parameter: ${var}"
163
             exit 1
164
        fi
165
    done
169 166
}
170 167

  
171 168
map_disk0() {
b/snf-image-host/decode-config.py
1
#!/usr/bin/env python
2

  
3
# Copyright (C) 2012 GRNET S.A.
4
#
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
9
#
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
# General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18
# 02110-1301, USA.
19

  
20
"""Decode a json encoded string with properties
21

  
22
This program decodes a json encoded properties string and outputs it in a
23
bash sourcable way. The properties are passed to the program through a JSON
24
string either read from a file or from standard input and are outputed to a
25
target file.
26
"""
27

  
28
import sys
29
import os
30
import subprocess
31
import json
32
import random
33
import string
34
from StringIO import StringIO
35

  
36

  
37
def main():
38
    options = sys.argv[1:]
39

  
40
    prefix = ''.join(random.choice(string.ascii_uppercase) for x in range(8))
41

  
42
    config = json.load(sys.stdin)
43

  
44
    for key, value in config.items():
45
        if str(key).upper() in options:
46
            os.environ[prefix + str(key).upper()] = value
47

  
48
    p = subprocess.Popen(['bash', '-c', 'set'], stdout=subprocess.PIPE)
49
    output = StringIO(p.communicate()[0])
50
    for line in iter(output):
51
        if line.startswith(prefix):
52
            print line[len(prefix):]
53

  
54
    return 0
55

  
56

  
57
if __name__ == "__main__":
58
    sys.exit(main())
59

  
60
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :
b/snf-image-host/parameters.list
3 3
img_passwd The root password which will be injected into the image
4 4
img_properties The image properties that are used to customize the image (json.dumps format)
5 5
img_personality The files to be injected into the image (base64 encoded in a json.dumps format)
6
config_url The url to download configuration data from
b/snf-image-host/verify
22 22
. common.sh
23 23

  
24 24

  
25
if [ -z "$OSP_IMG_ID" ]; then
26
    log_error "Missing OS API Parameter: OSP_IMG_ID"
27
    exit 1
28
fi
29
if [ -z "$OSP_IMG_FORMAT" ]; then
30
    log_error "Missing OS API Parameter: OSP_IMG_FORMAT"
31
    exit 1
32
fi
33
if [ -z "$OSP_IMG_PASSWD" ]; then
34
    log_error "Missing OS API Parameter: OSP_IMG_PASSWD"
35
    exit 1
36
fi
25
check_required() {
26
    local required_params="IMG_ID IMG_FORMAT IMG_PASSWD"
27
    local osparams="$required_params IMG_PROPERTIES IMG_PERSONALITY CONFIG_URL"
37 28

  
38
IMG_ID=$OSP_IMG_ID
39
IMG_FORMAT=$OSP_IMG_FORMAT
40
IMG_PASSWD=$OSP_IMG_PASSWD
41
if [ -n "$OSP_IMG_PROPERTIES" ]; then
42
    IMG_PROPERTIES="$OSP_IMG_PROPERTIES"
43
fi
44
if [ -n "$OSP_IMG_PERSONALITY" ]; then
45
    IMG_PERSONALITY="$OSP_IMG_PERSONALITY"
46
fi
29
    # Store OSP_VAR in VAR
30
    for param in $osparams; do
31
        eval $param=\"\$OSP_$param\"
32
    done
47 33

  
34
    for var in $required_params; do
35
        if [ -z "${!var}" ]; then
36
             log_error "Missing OS API Parameter: ${var}"
37
             exit 1
38
        fi
39
    done
48 40

  
49
case $IMG_FORMAT in
50
    extdump|ntfsdump)
41
    case $IMG_FORMAT in
42
        extdump|ntfsdump)
51 43
        ;;
52
    diskdump)
44
	diskdump)
53 45
        if [ -z "$IMG_PROPERTIES" ]; then
54
            log_error "\`img_properties' parameter must be present when using \`diskdump' format."
46
            log_error "\`img_properties' parameter must be present when"
47
            log_error "using \`diskdump' format."
55 48
            exit 1
56 49
        fi
57 50
        ;;
......
60 53
        exit 1
61 54
        ;;
62 55
esac
56
}
57

  
58
if [ -z "$OSP_CONFIG_URL" ]; then
59
    check_required
60
fi
63 61

  
64 62
exit 0
63

  
64
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :

Also available in: Unified diff