~gandelman-a/charms/precise/nova-compute/unused_func

« back to all changes in this revision

Viewing changes to hooks/lib/nova/grizzly

  • Committer: James Page
  • Date: 2013-10-15 12:04:13 UTC
  • mfrom: (46.1.83 nova-compute)
  • Revision ID: james.page@canonical.com-20131015120413-grclbw2ot5gbgp5r
Update of all Havana / Saucy / python-redux work:

* Full python rewrite using new OpenStack charm-helpers.

* Test coverage

* Havana support

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash -e
2
 
 
3
 
# Folsom-specific functions
4
 
 
5
 
nova_set_or_update() {
6
 
  # TODO: This needs to be shared among folsom, grizzly and beyond.
7
 
  # Set a config option in nova.conf or api-paste.ini, depending
8
 
  # Defaults to updating nova.conf
9
 
  local key="$1"
10
 
  local value="$2"
11
 
  local conf_file="$3"
12
 
  local section="${4:-DEFAULT}"
13
 
 
14
 
  local nova_conf=${NOVA_CONF:-/etc/nova/nova.conf}
15
 
  local api_conf=${API_CONF:-/etc/nova/api-paste.ini}
16
 
  local quantum_conf=${QUANTUM_CONF:-/etc/quantum/quantum.conf}
17
 
  local quantum_api_conf=${QUANTUM_API_CONF:-/etc/quantum/api-paste.ini}
18
 
  local quantum_plugin_conf=${QUANTUM_PLUGIN_CONF:-/etc/quantum/plugins/openvswitch/ovs_quantum_plugin.ini}
19
 
  local libvirtd_conf=${LIBVIRTD_CONF:-/etc/libvirt/libvirtd.conf}
20
 
 
21
 
  [[ -z $key ]] && juju-log "$CHARM: set_or_update: value $value missing key" && exit 1
22
 
  [[ -z $value ]] && juju-log "$CHARM: set_or_update: key $key missing value" && exit 1
23
 
 
24
 
  [[ -z "$conf_file" ]] && conf_file=$nova_conf
25
 
 
26
 
  local pattern=""
27
 
  case "$conf_file" in
28
 
    "$nova_conf") match="^$key="
29
 
                  pattern="$key="
30
 
                  out=$pattern
31
 
                  ;;
32
 
    "$api_conf"|"$quantum_conf"|"$quantum_api_conf"|"$quantum_plugin_conf"| \
33
 
    "$libvirtd_conf")
34
 
                 match="^$key = "
35
 
                 pattern="$match"
36
 
                 out="$key = "
37
 
                 ;;
38
 
    *) juju-log "$CHARM ERROR: set_or_update: Invalid conf_file ($conf_file)"
39
 
  esac
40
 
 
41
 
  cat $conf_file | grep "$match$value" >/dev/null &&
42
 
    juju-log "$CHARM: $key=$value already in set in $conf_file" \
43
 
      && return 0
44
 
 
45
 
  case $conf_file in
46
 
    "$quantum_conf"|"$quantum_api_conf"|"$quantum_plugin_conf")
47
 
        python -c "
48
 
import ConfigParser
49
 
config = ConfigParser.RawConfigParser()
50
 
config.read('$conf_file')
51
 
config.set('$section','$key','$value')
52
 
with open('$conf_file', 'wb') as configfile:
53
 
    config.write(configfile)
54
 
"
55
 
      ;;
56
 
    *)
57
 
      if cat $conf_file | grep "$match" >/dev/null ; then
58
 
        juju-log "$CHARM: Updating $conf_file, $key=$value"
59
 
        sed -i "s|\($pattern\).*|\1$value|" $conf_file
60
 
      else
61
 
        juju-log "$CHARM: Setting new option $key=$value in $conf_file"
62
 
        echo "$out$value" >>$conf_file
63
 
      fi
64
 
      ;;
65
 
  esac
66
 
  CONFIG_CHANGED="True"
67
 
}
68
 
 
69
 
# Upgrade Helpers
70
 
nova_pre_upgrade() {
71
 
  # Pre-upgrade helper.  Caller should pass the version of OpenStack we are
72
 
  # upgrading from.
73
 
  return 0 # Nothing to do here, yet.
74
 
}
75
 
 
76
 
nova_post_upgrade() {
77
 
  # Post-upgrade helper.  Caller should pass the version of OpenStack we are
78
 
  # upgrading from.
79
 
  local upgrade_from="$1"
80
 
  juju-log "$CHARM: Running post-upgrade hook: $upgrade_from -> grizzly."
81
 
  # We only support folsom -> grizzly, currently.
82
 
  [[ "$upgrade_from" != "folsom" ]] &&
83
 
    error_out "Unsupported upgrade: $upgrade_from -> grizzly"
84
 
 
85
 
  # This may be dangerous, if we are upgrading a number of units at once
86
 
  # and they all begin the same migration concurrently.  Migrate only from
87
 
  # the cloud controller(s).
88
 
  if [[ "$CHARM" == "nova-cloud-controller" ]] ; then
89
 
    juju-log "$CHARM: Migrating nova database."
90
 
    /usr/bin/nova-manage db sync
91
 
 
92
 
    # Trigger a service restart on all other nova nodes.
93
 
    trigger_remote_service_restarts
94
 
  fi
95
 
 
96
 
  juju-log "$CHARM: Post-upgrade hook complete: $upgrade_from -> grizzly."
97
 
}