~heut2008/charms/precise/nova-compute/fix-rbd-option

« back to all changes in this revision

Viewing changes to hooks/lib/nova/nova-common

  • 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
# Common utility functions used across all nova charms.
 
4
 
 
5
# Load the common OpenStack helper library.
 
6
if [[ -e $CHARM_DIR/lib/openstack-common ]] ; then
 
7
  . $CHARM_DIR/lib/openstack-common
 
8
else
 
9
  juju-log "Couldn't load $CHARM_DIR/lib/opentack-common." && exit 1
 
10
fi
 
11
 
 
12
set_or_update() {
 
13
  # Update config flags in nova.conf or api-paste.ini.
 
14
  # Config layout changed in Folsom, so this is now OpenStack release specific.
 
15
  local rel=$(get_os_codename_package "nova-common")
 
16
  . $CHARM_DIR/lib/nova/$rel
 
17
  nova_set_or_update $@
 
18
}
 
19
 
 
20
function set_config_flags() {
 
21
  # Set user-defined nova.conf flags from deployment config
 
22
  juju-log "$CHARM: Processing config-flags."
 
23
  flags=$(config-get config-flags)
 
24
  if [[ "$flags" != "None" && -n "$flags" ]] ; then
 
25
    for f in $(echo $flags | sed -e 's/,/ /g') ; do
 
26
      k=$(echo $f | cut -d= -f1)
 
27
      v=$(echo $f | cut -d= -f2)
 
28
      set_or_update "$k" "$v"
 
29
    done
 
30
  fi
 
31
}
 
32
 
 
33
configure_volume_service() {
 
34
  local svc="$1"
 
35
  case "$svc" in
 
36
    "cinder") set_or_update "volume_api_class" "nova.volume.cinder.API" ;;
 
37
    "nova-volume") set_or_update "volume_api_class" "nova.volume.api.API" ;;
 
38
    *) juju-log "$CHARM ERROR - configure_volume_service: Invalid service $svc"
 
39
       return 1 ;;
 
40
  esac
 
41
}
 
42
 
 
43
function configure_network_manager {
 
44
  local manager="$1"
 
45
  echo "$CHARM: configuring $manager network manager"
 
46
  case $1 in
 
47
    "FlatManager")
 
48
      set_or_update "network_manager" "nova.network.manager.FlatManager"
 
49
      ;;
 
50
    "FlatDHCPManager")
 
51
      set_or_update "network_manager" "nova.network.manager.FlatDHCPManager"
 
52
      ;;
 
53
    *) echo "ERROR: Invalid network manager $1" && exit 1 ;;
 
54
  esac
 
55
}
 
56
 
 
57
function trigger_remote_service_restarts() {
 
58
  # Trigger a service restart on all other nova nodes that have a relation
 
59
  # via the cloud-controller interface.
 
60
 
 
61
  # possible relations to other nova services.
 
62
  local relations="cloud-compute nova-volume-service"
 
63
 
 
64
  for rel in $relations; do
 
65
    local r_ids=$(relation-ids $rel)
 
66
    for r_id in $r_ids ; do
 
67
      juju-log "$CHARM: Triggering a service restart on relation $r_id."
 
68
      relation-set -r $r_id restart-trigger=$(uuid)
 
69
    done
 
70
  done
 
71
}
 
72
 
 
73
do_openstack_upgrade() {
 
74
  # update openstack components to those provided by a new installation source
 
75
  # it is assumed the calling hook has confirmed that the upgrade is sane.
 
76
  local rel="$1"
 
77
  shift
 
78
  local packages=$@
 
79
 
 
80
  orig_os_rel=$(get_os_codename_package "nova-common")
 
81
  new_rel=$(get_os_codename_install_source "$rel")
 
82
 
 
83
  # Backup the config directory.
 
84
  local stamp=$(date +"%Y%m%d%M%S")
 
85
  tar -pcf /var/lib/juju/$CHARM-backup-$stamp.tar $CONF_DIR
 
86
 
 
87
  # load the release helper library for pre/post upgrade hooks specific to the
 
88
  # release we are upgrading to.
 
89
  . $CHARM_DIR/lib/nova/$new_rel
 
90
 
 
91
  # new release specific pre-upgrade hook
 
92
  nova_pre_upgrade "$orig_os_rel"
 
93
 
 
94
  # Setup apt repository access and kick off the actual package upgrade.
 
95
  configure_install_source "$rel"
 
96
  apt-get update
 
97
  DEBIAN_FRONTEND=noninteractive apt-get --option Dpkg::Options::=--force-confold -y \
 
98
     install --no-install-recommends $packages
 
99
 
 
100
  # new release sepcific post-upgrade hook
 
101
  nova_post_upgrade "$orig_os_rel"
 
102
 
 
103
}