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

« back to all changes in this revision

Viewing changes to hooks/lib/nova/folsom

  • 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
# Folsom-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
 
 
12
  local nova_conf=${NOVA_CONF:-/etc/nova/nova.conf}
 
13
  local api_conf=${API_CONF:-/etc/nova/api-paste.ini}
 
14
 
 
15
  [[ -z $key ]] && juju-log "$CHARM: set_or_update: value $value missing key" && exit 1
 
16
  [[ -z $value ]] && juju-log "$CHARM: set_or_update: key $key missing value" && exit 1
 
17
 
 
18
  [[ -z "$conf_file" ]] && conf_file=$nova_conf
 
19
 
 
20
  local pattern=""
 
21
  case "$conf_file" in
 
22
    "$nova_conf") match="^$key="
 
23
                  pattern="$key="
 
24
                  out=$pattern
 
25
                  ;;
 
26
    "$api_conf") match="^$key = "
 
27
                 pattern="$match"
 
28
                 out="$key = "
 
29
                 ;;
 
30
    *) juju-log "$CHARM ERROR: set_or_update: Invalid conf_file ($conf_file)"
 
31
  esac
 
32
 
 
33
  cat $conf_file | grep "$match$value" >/dev/null &&
 
34
    juju-log "$CHARM: $key=$value already in set in $conf_file" \
 
35
      && return 0
 
36
  if cat $conf_file | grep "$match" >/dev/null ; then
 
37
    juju-log "$CHARM: Updating $conf_file, $key=$value"
 
38
    sed -i "s|\($pattern\).*|\1$value|" $conf_file
 
39
  else
 
40
    juju-log "$CHARM: Setting new option $key=$value in $conf_file"
 
41
    echo "$out$value" >>$conf_file
 
42
  fi
 
43
}
 
44
 
 
45
# Upgrade Helpers
 
46
nova_pre_upgrade() {
 
47
  # Pre-upgrade helper.  Caller should pass the version of OpenStack we are
 
48
  # upgrading from.
 
49
  return 0 # Nothing to do here, yet.
 
50
}
 
51
 
 
52
nova_post_upgrade() {
 
53
  # Post-upgrade helper.  Caller should pass the version of OpenStack we are
 
54
  # upgrading from.
 
55
  local upgrade_from="$1"
 
56
  juju-log "$CHARM: Running post-upgrade hook: $upgrade_from -> folsom."
 
57
  # We only support essex -> folsom, currently.
 
58
  [[ "$upgrade_from" != "essex" ]] &&
 
59
    error_out "Unsupported upgrade: $upgrade_from -> folsom"
 
60
 
 
61
  # This may be dangerous, if we are upgrading a number of units at once
 
62
  # and they all begin the same migration concurrently.  Migrate only from
 
63
  # the cloud controller(s).
 
64
  if [[ "$CHARM" == "nova-cloud-controller" ]] ; then
 
65
    juju-log "$CHARM: Migrating nova database."
 
66
    /usr/bin/nova-manage db sync
 
67
 
 
68
    # Trigger a service restart on all other nova nodes.
 
69
    trigger_remote_service_restarts
 
70
  fi
 
71
 
 
72
  # Packaging currently takes care of converting the Essex gflags format
 
73
  # to .ini, but we need to update the api-paste.ini manually.  It can be
 
74
  # updated directly from keystone, via the identity-service relation,
 
75
  # if it exists.  Only services that require keystone credentials will
 
76
  # have modified api-paste.ini, and only those services will have a .dpkg-dist
 
77
  # version present.
 
78
  local r_id=$(relation-ids identity-service)
 
79
  if [[ -n "$r_id" ]] && [[ -e "$CONF_DIR/api-paste.ini.dpkg-dist" ]] ; then
 
80
    # Backup the last api config, update the stock packaged version
 
81
    # with our current Keystone info.
 
82
    mv $API_CONF $CONF_DIR/api-paste.ini.juju-last
 
83
    mv $CONF_DIR/api-paste.ini.dpkg-dist $CONF_DIR/api-paste.ini
 
84
 
 
85
    unit=$(relation-list -r $r_id | head -n1)
 
86
    # Note, this should never be called from an relation hook, only config-changed.
 
87
    export JUJU_REMOTE_UNIT=$unit
 
88
    service_port=$(relation-get -r $r_id service_port)
 
89
    auth_port=$(relation-get -r $r_id auth_port)
 
90
    service_username=$(relation-get -r $r_id service_username)
 
91
    service_password=$(relation-get -r $r_id service_password)
 
92
    service_tenant=$(relation-get -r $r_id service_tenant)
 
93
    keystone_host=$(relation-get -r $r_id  private-address)
 
94
    unset JUJU_REMOTE_UNIT
 
95
 
 
96
    juju-log "$CHARM: Updating new api-paste.ini with keystone data from $unit:$r_id"
 
97
    set_or_update "service_host" "$keystone_host" "$API_CONF"
 
98
    set_or_update "service_port" "$service_port" "$API_CONF"
 
99
    set_or_update "auth_host" "$keystone_host" "$API_CONF"
 
100
    set_or_update "auth_port" "$auth_port" "$API_CONF"
 
101
    set_or_update "auth_uri" "http://$keystone_host:$service_port/" "$API_CONF"
 
102
    set_or_update "admin_tenant_name" "$service_tenant" "$API_CONF"
 
103
    set_or_update "admin_user" "$service_username" "$API_CONF"
 
104
    set_or_update "admin_password" "$service_password" "$API_CONF"
 
105
  fi
 
106
 
 
107
  # TEMPORARY
 
108
  # RC3 packaging in cloud archive doesn't have this in postinst.  Do it here
 
109
  sed -e "s,^root_helper=.\+,rootwrap_config=/etc/nova/rootwrap.conf," -i /etc/nova/nova.conf
 
110
 
 
111
  juju-log "$CHARM: Post-upgrade hook complete: $upgrade_from -> folsom."
 
112
}