~clark-laughlin/charms/trusty/nova-compute/arm64-support

« back to all changes in this revision

Viewing changes to hooks/lib/nova/essex

  • Committer: Adam Gandelman
  • Date: 2012-10-25 15:55:14 UTC
  • mfrom: (36.1.17 nova-compute)
  • Revision ID: adamg@canonical.com-20121025155514-rchue8w4az6tpouu
Add ceph integration, upgrade support, common code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash -e
 
2
 
 
3
# Essex-specific functions
 
4
 
 
5
nova_set_or_update() {
 
6
  # Set a config option in nova.conf or api-paste.ini, depending
 
7
  # Defaults to updating nova.conf
 
8
  local key=$1
 
9
  local value=$2
 
10
  local conf_file=$3
 
11
  local pattern=""
 
12
 
 
13
  local nova_conf=${NOVA_CONF:-/etc/nova/nova.conf}
 
14
  local api_conf=${API_CONF:-/etc/nova/api-paste.ini}
 
15
 
 
16
  [[ -z $key ]] && juju-log "$CHARM set_or_update: value $value missing key" && exit 1
 
17
  [[ -z $value ]] && juju-log "$CHARM set_or_update: key $key missing value" && exit 1
 
18
  [[ -z "$conf_file" ]] && conf_file=$nova_conf
 
19
 
 
20
  case "$conf_file" in
 
21
    "$nova_conf") match="\-\-$key="
 
22
                  pattern="--$key="
 
23
                  out=$pattern
 
24
                  ;;
 
25
    "$api_conf") match="^$key = "
 
26
                 pattern="$match"
 
27
                 out="$key = "
 
28
                 ;;
 
29
    *) error_out "ERROR: set_or_update: Invalid conf_file ($conf_file)"
 
30
  esac
 
31
 
 
32
  cat $conf_file | grep "$match$value" >/dev/null &&
 
33
    juju-log "$CHARM: $key=$value already in set in $conf_file" \
 
34
      && return 0
 
35
  if cat $conf_file | grep "$match" >/dev/null ; then
 
36
    juju-log "$CHARM: Updating $conf_file, $key=$value"
 
37
    sed -i "s|\($pattern\).*|\1$value|" $conf_file
 
38
  else
 
39
    juju-log "$CHARM: Setting new option $key=$value in $conf_file"
 
40
    echo "$out$value" >>$conf_file
 
41
  fi
 
42
}