~gandelman-a/charms/precise/glance/cfgparser

« back to all changes in this revision

Viewing changes to hooks/lib/openstack-common

  • Committer: Adam Gandelman
  • Date: 2013-02-27 19:22:55 UTC
  • Revision ID: adamg@canonical.com-20130227192255-z9re672o5c4u7h3m
Use standard ConfigParser for updating configs.

Use python standard ConfigParser for updating configs now that all
OS projects have standardized on a config format.  Replaces the
use of sed, which is hard to support across versions.  Use the same
set_or_update() to set keystone paste_deploy flavor now.

Drops a couple of unused functions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
314
314
  echo "$found"
315
315
  return 0
316
316
}
 
317
 
 
318
function cfg_set_or_update() {
 
319
  local key="$1"
 
320
  local value="$2"
 
321
  local file="$3"
 
322
  local section="$4"
 
323
  [[ -z "$section" ]] && section="DEFAULT"
 
324
  [[ -z $key ]] && juju-log "ERROR: cfg_set_or_update(): value $value missing key" \
 
325
        && exit 1
 
326
  [[ -z $value ]] && juju-log "ERROR: cfg_set_or_update(): key $key missing value" \
 
327
        && exit 1
 
328
  [[ ! -e $file ]] && juju-log "ERROR: cfg_set_or_update(): File not found $file" \
 
329
        && exit 1
 
330
 
 
331
  python -c "
 
332
import ConfigParser
 
333
config = ConfigParser.RawConfigParser()
 
334
config.read('$file')
 
335
if '$section' != 'DEFAULT' and not config.has_section('$section'):
 
336
    config.add_section('$section')
 
337
config.set('$section', '$key', '$value')
 
338
with open('$file', 'wb') as conf_out:
 
339
    config.write(conf_out)
 
340
"
 
341
  juju-log "Updated config $file, $key = $value in section $section."
 
342
}