merging lp:~gandelman-a/charms/precise/glance/cfgparser
This commit is contained in:
commit
807adaf5e0
|
@ -17,72 +17,27 @@ else
|
|||
juju-log "ERROR: Couldn't load $CHARM_DIR/lib/openstack-common." && exit 1
|
||||
fi
|
||||
|
||||
function set_paste_deploy_flavor {
|
||||
local flavor="$1"
|
||||
local config="$2"
|
||||
case $config in
|
||||
"api") local conf=$GLANCE_API_CONF ;;
|
||||
"registry") local conf=$GLANCE_REGISTRY_CONF ;;
|
||||
*) juju-log "ERROR: set_paste_deploy: invalid config=$config" && exit 1 ;;
|
||||
esac
|
||||
if ! grep -q "\[paste_deploy\]" "$conf" ; then
|
||||
juju-log "Updating $conf: Setting new paste_deploy flavor = $flavor"
|
||||
echo -e "\n[paste_deploy]\nflavor = keystone\n" >>$conf && return 0
|
||||
juju-log "ERROR: Could not update paste_deploy flavor in $conf" && return 1
|
||||
fi
|
||||
juju-log "Updating $conf: Setting paste_deploy flavor = $flavor"
|
||||
local tag="[paste_deploy]"
|
||||
sed -i "/$tag/, +1 s/\(flavor = \).*/\1$flavor/g" $conf && return 0
|
||||
juju-log "ERROR: Could not update paste_deploy flavor in $conf" && return 1
|
||||
}
|
||||
|
||||
function update_pipeline {
|
||||
# updates pipeline middleware definitions in api-paste.ini
|
||||
local pipeline="$1"
|
||||
local new="$2"
|
||||
local config="$3"
|
||||
|
||||
case $config in
|
||||
"api") local api_conf=$GLANCE_API_CONF ;;
|
||||
"registry") local api_conf=$GLANCE_REGISTRY_CONF ;;
|
||||
*) juju-log "ERROR: update_pipeline: invalid config=$config" && exit 1 ;;
|
||||
esac
|
||||
|
||||
local tag="\[pipeline:$pipeline\]"
|
||||
if ! grep -q "$tag" $api_conf ; then
|
||||
juju-log "ERROR: update_pipeline: pipeline not found: $pipeline"
|
||||
return 1
|
||||
fi
|
||||
juju-log "Updating pipeline:$pipeline in $api_conf"
|
||||
sed -i "/$tag/, +1 s/\(pipeline = \).*/\1$new/g" $api_conf
|
||||
}
|
||||
|
||||
function set_or_update {
|
||||
# This handles configuration of both api and registry server
|
||||
# until LP #806241 is resolved. Until then, $3 is either
|
||||
# 'api' or 'registry' to specify which
|
||||
# set or update a key=value config option in glance.conf
|
||||
KEY=$1
|
||||
VALUE=$2
|
||||
case "$3" in
|
||||
"api") CONF=$GLANCE_API_CONF ;;
|
||||
"api-paste") CONF=$GLANCE_API_PASTE_INI ;;
|
||||
"registry") CONF=$GLANCE_REGISTRY_CONF ;;
|
||||
"registry-paste") CONF=$GLANCE_REGISTRY_PASTE_INI ;;
|
||||
local key="$1"
|
||||
local value="$2"
|
||||
local file="$3"
|
||||
local section="$4"
|
||||
local conf=""
|
||||
[[ -z $key ]] && juju-log "ERROR: set_or_update(): value $value missing key" \
|
||||
&& exit 1
|
||||
[[ -z $value ]] && juju-log "ERROR: set_or_update(): key $key missing value" \
|
||||
&& exit 1
|
||||
case "$file" in
|
||||
"api") conf=$GLANCE_API_CONF ;;
|
||||
"api-paste") conf=$GLANCE_API_PASTE_INI ;;
|
||||
"registry") conf=$GLANCE_REGISTRY_CONF ;;
|
||||
"registry-paste") conf=$GLANCE_REGISTRY_PASTE_INI ;;
|
||||
*) juju-log "ERROR: set_or_update(): Invalid or no config file specified." \
|
||||
&& exit 1 ;;
|
||||
esac
|
||||
[[ -z $KEY ]] && juju-log "ERROR: set_or_update(): value $VALUE missing key" \
|
||||
[[ ! -e $conf ]] && juju-log "ERROR: set_or_update(): File not found $conf" \
|
||||
&& exit 1
|
||||
[[ -z $VALUE ]] && juju-log "ERROR: set_or_update(): key $KEY missing value" \
|
||||
&& exit 1
|
||||
cat $CONF | grep "$KEY = $VALUE" >/dev/null \
|
||||
&& juju-log "glance: $KEY = $VALUE already set" exit 0
|
||||
if cat $CONF | grep "$KEY =" >/dev/null ; then
|
||||
sed -i "s|\($KEY = \).*|\1$VALUE|" $CONF
|
||||
else
|
||||
echo "$KEY = $VALUE" >>$CONF
|
||||
fi
|
||||
cfg_set_or_update "$key" "$value" "$conf" "$section"
|
||||
}
|
||||
|
||||
do_openstack_upgrade() {
|
||||
|
|
|
@ -222,19 +222,20 @@ function keystone_changed {
|
|||
unset JUJU_REMOTE_UNIT JUJU_RELATION JUJU_RELATION_ID
|
||||
fi
|
||||
|
||||
set_paste_deploy_flavor "keystone" "api" || exit 1
|
||||
set_paste_deploy_flavor "keystone" "registry" || exit 1
|
||||
set_or_update "flavor" "keystone" "api" "paste_deploy"
|
||||
set_or_update "flavor" "keystone" "registry" "paste_deploy"
|
||||
|
||||
local sect="filter:authtoken"
|
||||
for i in api-paste registry-paste ; do
|
||||
set_or_update "service_host" "$keystone_host" $i
|
||||
set_or_update "service_port" "$service_port" $i
|
||||
set_or_update "auth_host" "$keystone_host" $i
|
||||
set_or_update "auth_port" "$auth_port" $i
|
||||
set_or_update "auth_uri" "http://$keystone_host:$service_port/" $i
|
||||
set_or_update "admin_token" "$token" $i
|
||||
set_or_update "admin_tenant_name" "$service_tenant" $i
|
||||
set_or_update "admin_user" "$service_username" $i
|
||||
set_or_update "admin_password" "$service_password" $i
|
||||
set_or_update "service_host" "$keystone_host" $i $sect
|
||||
set_or_update "service_port" "$service_port" $i $sect
|
||||
set_or_update "auth_host" "$keystone_host" $i $sect
|
||||
set_or_update "auth_port" "$auth_port" $i $sect
|
||||
set_or_update "auth_uri" "http://$keystone_host:$service_port/" $i $sect
|
||||
set_or_update "admin_token" "$token" $i $sect
|
||||
set_or_update "admin_tenant_name" "$service_tenant" $i $sect
|
||||
set_or_update "admin_user" "$service_username" $i $sect
|
||||
set_or_update "admin_password" "$service_password" $i $sect
|
||||
done
|
||||
service_ctl all restart
|
||||
|
||||
|
|
|
@ -314,3 +314,29 @@ function get_block_device() {
|
|||
echo "$found"
|
||||
return 0
|
||||
}
|
||||
|
||||
function cfg_set_or_update() {
|
||||
local key="$1"
|
||||
local value="$2"
|
||||
local file="$3"
|
||||
local section="$4"
|
||||
[[ -z "$section" ]] && section="DEFAULT"
|
||||
[[ -z $key ]] && juju-log "ERROR: cfg_set_or_update(): value $value missing key" \
|
||||
&& exit 1
|
||||
[[ -z $value ]] && juju-log "ERROR: cfg_set_or_update(): key $key missing value" \
|
||||
&& exit 1
|
||||
[[ ! -e $file ]] && juju-log "ERROR: cfg_set_or_update(): File not found $file" \
|
||||
&& exit 1
|
||||
|
||||
python -c "
|
||||
import ConfigParser
|
||||
config = ConfigParser.RawConfigParser()
|
||||
config.read('$file')
|
||||
if '$section' != 'DEFAULT' and not config.has_section('$section'):
|
||||
config.add_section('$section')
|
||||
config.set('$section', '$key', '$value')
|
||||
with open('$file', 'wb') as conf_out:
|
||||
config.write(conf_out)
|
||||
"
|
||||
juju-log "Updated config $file, $key = $value in section $section."
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue