~openstack-ubuntu-testing/charms/precise/glance/trunk

« back to all changes in this revision

Viewing changes to hooks/glance-common

  • Committer: Adam Gandelman
  • Date: 2013-10-17 21:39:32 UTC
  • mfrom: (13.18.7 glance)
  • Revision ID: adamg@canonical.com-20131017213932-07uwux3uu2ndxmzn
MergeĀ upstreamĀ charm.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
2
 
 
3
 
CHARM="glance"
4
 
 
5
 
SERVICES="glance-api glance-registry"
6
 
PACKAGES="glance python-mysqldb python-swift python-keystone uuid haproxy"
7
 
 
8
 
GLANCE_REGISTRY_CONF="/etc/glance/glance-registry.conf"
9
 
GLANCE_REGISTRY_PASTE_INI="/etc/glance/glance-registry-paste.ini"
10
 
GLANCE_API_CONF="/etc/glance/glance-api.conf"
11
 
GLANCE_API_PASTE_INI="/etc/glance/glance-api-paste.ini"
12
 
CONF_DIR="/etc/glance"
13
 
HOOKS_DIR="$CHARM_DIR/hooks"
14
 
 
15
 
# Flag used to track config changes.
16
 
CONFIG_CHANGED="False"
17
 
if [[ -e "$HOOKS_DIR/lib/openstack-common" ]] ; then
18
 
  . $HOOKS_DIR/lib/openstack-common
19
 
else
20
 
  juju-log "ERROR: Couldn't load $HOOKS_DIR/lib/openstack-common." && exit 1
21
 
fi
22
 
 
23
 
function set_or_update {
24
 
  local key="$1"
25
 
  local value="$2"
26
 
  local file="$3"
27
 
  local section="$4"
28
 
  local conf=""
29
 
  [[ -z $key ]] && juju-log "ERROR: set_or_update(): value $value missing key" \
30
 
        && exit 1
31
 
  [[ -z $value ]] && juju-log "ERROR: set_or_update(): key $key missing value" \
32
 
        && exit 1
33
 
 
34
 
  case "$file" in
35
 
    "api") conf=$GLANCE_API_CONF ;;
36
 
    "api-paste") conf=$GLANCE_API_PASTE_INI ;;
37
 
    "registry") conf=$GLANCE_REGISTRY_CONF ;;
38
 
    "registry-paste") conf=$GLANCE_REGISTRY_PASTE_INI ;;
39
 
    *) juju-log "ERROR: set_or_update(): Invalid or no config file specified." \
40
 
        && exit 1 ;;
41
 
  esac
42
 
 
43
 
  [[ ! -e $conf ]] && juju-log "ERROR: set_or_update(): File not found $conf" \
44
 
        && exit 1
45
 
 
46
 
  if [[ "$(local_config_get "$conf" "$key" "$section")" == "$value" ]] ; then
47
 
    juju-log "$CHARM: set_or_update(): $key=$value already set in $conf."
48
 
    return 0
49
 
  fi
50
 
 
51
 
  cfg_set_or_update "$key" "$value" "$conf" "$section"
52
 
  CONFIG_CHANGED="True"
53
 
}
54
 
 
55
 
do_openstack_upgrade() {
56
 
  # update openstack components to those provided by a new installation source
57
 
  # it is assumed the calling hook has confirmed that the upgrade is sane.
58
 
  local rel="$1"
59
 
  shift
60
 
  local packages=$@
61
 
  orig_os_rel=$(get_os_codename_package "glance-common")
62
 
  new_rel=$(get_os_codename_install_source "$rel")
63
 
 
64
 
  # Backup the config directory.
65
 
  local stamp=$(date +"%Y%m%d%M%S")
66
 
  tar -pcf /var/lib/juju/$CHARM-backup-$stamp.tar $CONF_DIR
67
 
 
68
 
  # Setup apt repository access and kick off the actual package upgrade.
69
 
  configure_install_source "$rel"
70
 
  apt-get update
71
 
  DEBIAN_FRONTEND=noninteractive apt-get --option Dpkg::Options::=--force-confnew -y \
72
 
     install --no-install-recommends $packages
73
 
 
74
 
  # Update the new config files for existing relations.
75
 
  local r_id=""
76
 
 
77
 
  r_id=$(relation-ids shared-db)
78
 
  if [[ -n "$r_id" ]] ; then
79
 
    juju-log "$CHARM: Configuring database after upgrade to $rel."
80
 
    db_changed $r_id
81
 
  fi
82
 
 
83
 
  r_id=$(relation-ids identity-service)
84
 
  if [[ -n "$r_id" ]] ; then
85
 
    juju-log "$CHARM: Configuring identity service after upgrade to $rel."
86
 
    keystone_changed $r_id
87
 
  fi
88
 
 
89
 
  local ceph_ids="$(relation-ids ceph)"
90
 
  [[ -n "$ceph_ids" ]] && apt-get -y install ceph-common python-ceph
91
 
  for r_id in $ceph_ids ; do
92
 
    for unit in $(relation-list -r $r_id) ; do
93
 
      ceph_changed "$r_id" "$unit"
94
 
    done
95
 
  done
96
 
 
97
 
  [[ -n "$(relation-ids object-store)" ]] && object-store_joined
98
 
}
99
 
 
100
 
configure_https() {
101
 
  # request openstack-common setup reverse proxy mapping for API and registry
102
 
  # servers
103
 
  service_ctl glance-api stop
104
 
  if [[ -n "$(peer_units)" ]] || is_clustered ; then
105
 
    # haproxy may already be configured. need to push it back in the request
106
 
    # pipeline in preparation for a change from:
107
 
    #  from:  haproxy (9292) -> glance_api (9282)
108
 
    #  to:    ssl (9292) -> haproxy (9291) -> glance_api (9272)
109
 
    local next_server=$(determine_haproxy_port 9292)
110
 
    local api_port=$(determine_api_port 9292)
111
 
    configure_haproxy "glance_api:$next_server:$api_port"
112
 
  else
113
 
    # if not clustered, the glance-api is next in the pipeline.
114
 
    local api_port=$(determine_api_port 9292)
115
 
    local next_server=$api_port
116
 
  fi
117
 
 
118
 
  # setup https to point to either haproxy or directly to api server, depending.
119
 
  setup_https 9292:$next_server
120
 
 
121
 
  # configure servers to listen on new ports accordingly.
122
 
  set_or_update bind_port "$api_port" "api"
123
 
  service_ctl all start
124
 
 
125
 
  local r_id=""
126
 
  # (re)configure ks endpoint accordingly in ks and nova.
127
 
  for r_id in $(relation-ids identity-service) ; do
128
 
    keystone_joined "$r_id"
129
 
  done
130
 
  for r_id in $(relation-ids image-service) ; do
131
 
    image-service_joined "$r_id"
132
 
  done
133
 
}