~landscape/charms/trusty/openstack-dashboard/fix-for-1311234

« back to all changes in this revision

Viewing changes to hooks/horizon-common

  • Committer: Adam Gandelman
  • Date: 2013-10-16 18:27:02 UTC
  • mfrom: (17.1.54 openstack-dashboard)
  • Revision ID: adamg@canonical.com-20131016182702-mfeq1nulyj18q6j7
Merge of python-redux work for havana cycle

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
2
 
# vim: set ts=2:et
3
 
 
4
 
CHARM="openstack-dashboard"
5
 
 
6
 
PACKAGES="openstack-dashboard python-keystoneclient python-memcache memcached haproxy python-novaclient"
7
 
LOCAL_SETTINGS="/etc/openstack-dashboard/local_settings.py"
8
 
HOOKS_DIR="$CHARM_DIR/hooks"
9
 
 
10
 
if [[ -e "$HOOKS_DIR/lib/openstack-common" ]] ; then
11
 
  . $HOOKS_DIR/lib/openstack-common
12
 
else
13
 
  juju-log "ERROR: Couldn't load $HOOKS_DIR/lib/openstack-common." && exit 1
14
 
fi
15
 
 
16
 
set_or_update() {
17
 
  # set a key = value option in $LOCAL_SETTINGS
18
 
  local key=$1 value=$2
19
 
  [[ -z "$key" ]] || [[ -z "$value" ]] &&
20
 
    juju-log "$CHARM set_or_update: ERROR - missing parameters" && return 1
21
 
  if [ "$value" == "True" ] || [ "$value" == "False" ]; then
22
 
    grep -q "^$key = $value" "$LOCAL_SETTINGS" &&
23
 
      juju-log "$CHARM set_or_update: $key = $value already set" && return 0
24
 
  else
25
 
    grep -q "^$key = \"$value\"" "$LOCAL_SETTINGS" &&
26
 
      juju-log "$CHARM set_or_update: $key = $value already set" && return 0
27
 
  fi
28
 
  if grep -q "^$key = " "$LOCAL_SETTINGS" ; then
29
 
    juju-log "$CHARM set_or_update: Setting $key = $value"
30
 
    cp "$LOCAL_SETTINGS" /etc/openstack-dashboard/local_settings.last
31
 
    if [ "$value" == "True" ] || [ "$value" == "False" ]; then
32
 
      sed -i "s|\(^$key = \).*|\1$value|g" "$LOCAL_SETTINGS" || return 1
33
 
    else
34
 
      sed -i "s|\(^$key = \).*|\1\"$value\"|g" "$LOCAL_SETTINGS" || return 1
35
 
    fi
36
 
  else
37
 
    juju-log "$CHARM set_or_update: Adding $key = $value"
38
 
    if [ "$value" == "True" ] || [ "$value" == "False" ]; then
39
 
      echo "$key = $value" >>$LOCAL_SETTINGS || return 1
40
 
    else
41
 
      echo "$key = \"$value\"" >>$LOCAL_SETTINGS || return 1
42
 
    fi
43
 
  fi
44
 
  return 0
45
 
}
46
 
 
47
 
do_openstack_upgrade() {
48
 
  local rel="$1"
49
 
  shift
50
 
  local packages=$@
51
 
 
52
 
  # Setup apt repository access and kick off the actual package upgrade.
53
 
  configure_install_source "$rel"
54
 
  apt-get update
55
 
  DEBIAN_FRONTEND=noninteractive apt-get --option Dpkg::Options::=--force-confnew -y \
56
 
     install $packages
57
 
 
58
 
  # Configure new config files for access to keystone, if a relation exists.
59
 
  r_id=$(relation-ids identity-service | head -n1)
60
 
  if [[ -n "$r_id" ]] ; then
61
 
    export JUJU_REMOTE_UNIT=$(relation-list -r $r_id | head -n1)
62
 
    export JUJU_RELATION="identity-service"
63
 
    export JUJU_RELATION_ID="$r_id"
64
 
    local service_host=$(relation-get -r $r_id service_host)
65
 
    local service_port=$(relation-get -r $r_id service_port)
66
 
    if [[ -n "$service_host" ]] && [[ -n "$service_port" ]] ; then
67
 
      service_url="http://$service_host:$service_port/v2.0"
68
 
      set_or_update OPENSTACK_KEYSTONE_URL "$service_url"
69
 
    fi
70
 
  fi
71
 
}
72
 
 
73
 
configure_apache() {
74
 
  # Reconfigure to listen on provided port
75
 
  a2ensite default-ssl || :
76
 
  a2enmod ssl || :
77
 
  for ports in $@; do
78
 
    from_port=$(echo $ports | cut -d : -f 1)
79
 
    to_port=$(echo $ports | cut -d : -f 2)
80
 
    sed -i -e "s/$from_port/$to_port/g" /etc/apache2/ports.conf
81
 
    for site in $(ls -1 /etc/apache2/sites-available); do
82
 
      sed -i -e "s/$from_port/$to_port/g" \
83
 
        /etc/apache2/sites-available/$site
84
 
    done
85
 
  done
86
 
}
87
 
 
88
 
configure_apache_cert() {
89
 
  cert=$1
90
 
  key=$2
91
 
  echo $cert | base64 -di > /etc/ssl/certs/dashboard.cert
92
 
  echo $key | base64 -di > /etc/ssl/private/dashboard.key
93
 
  chmod 0600 /etc/ssl/private/dashboard.key
94
 
  sed -i -e "s|\(.*SSLCertificateFile\).*|\1 /etc/ssl/certs/dashboard.cert|g" \
95
 
         -e "s|\(.*SSLCertificateKeyFile\).*|\1 /etc/ssl/private/dashboard.key|g" \
96
 
          /etc/apache2/sites-available/default-ssl
97
 
}