~james-page/charms/trusty/nova-compute/disable-neutron-security-option

« back to all changes in this revision

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

  • 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
 
# Common utility functions used across all nova charms.
4
 
 
5
 
CONFIG_CHANGED=False
6
 
HOOKS_DIR="$CHARM_DIR/hooks"
7
 
 
8
 
# Load the common OpenStack helper library.
9
 
if [[ -e $HOOKS_DIR/lib/openstack-common ]] ; then
10
 
  . $HOOKS_DIR/lib/openstack-common
11
 
else
12
 
  juju-log "Couldn't load $HOOKS_DIR/lib/opentack-common." && exit 1
13
 
fi
14
 
 
15
 
set_or_update() {
16
 
  # Update config flags in nova.conf or api-paste.ini.
17
 
  # Config layout changed in Folsom, so this is now OpenStack release specific.
18
 
  local rel=$(get_os_codename_package "nova-common")
19
 
  . $HOOKS_DIR/lib/nova/$rel
20
 
  nova_set_or_update $@
21
 
}
22
 
 
23
 
function set_config_flags() {
24
 
  # Set user-defined nova.conf flags from deployment config
25
 
  juju-log "$CHARM: Processing config-flags."
26
 
  flags=$(config-get config-flags)
27
 
  if [[ "$flags" != "None" && -n "$flags" ]] ; then
28
 
    for f in $(echo $flags | sed -e 's/,/ /g') ; do
29
 
      k=$(echo $f | cut -d= -f1)
30
 
      v=$(echo $f | cut -d= -f2)
31
 
      set_or_update "$k" "$v"
32
 
    done
33
 
  fi
34
 
}
35
 
 
36
 
configure_volume_service() {
37
 
  local svc="$1"
38
 
  local cur_vers="$(get_os_codename_package "nova-common")"
39
 
  case "$svc" in
40
 
    "cinder")
41
 
      set_or_update "volume_api_class" "nova.volume.cinder.API" ;;
42
 
    "nova-volume")
43
 
      # nova-volume only supported before grizzly.
44
 
      [[ "$cur_vers" == "essex" ]] || [[ "$cur_vers" == "folsom" ]] &&
45
 
        set_or_update "volume_api_class" "nova.volume.api.API"
46
 
      ;;
47
 
    *) juju-log "$CHARM ERROR - configure_volume_service: Invalid service $svc"
48
 
       return 1 ;;
49
 
  esac
50
 
}
51
 
 
52
 
function configure_network_manager {
53
 
  local manager="$1"
54
 
  echo "$CHARM: configuring $manager network manager"
55
 
  case $1 in
56
 
    "FlatManager")
57
 
      set_or_update "network_manager" "nova.network.manager.FlatManager"
58
 
      ;;
59
 
    "FlatDHCPManager")
60
 
      set_or_update "network_manager" "nova.network.manager.FlatDHCPManager"
61
 
 
62
 
      if [[ "$CHARM" == "nova-compute" ]] ; then
63
 
        local flat_interface=$(config-get flat-interface)
64
 
        local ec2_host=$(relation-get ec2_host)
65
 
        set_or_update flat_inteface "$flat_interface"
66
 
        set_or_update ec2_dmz_host "$ec2_host"
67
 
 
68
 
        # Ensure flat_interface has link.
69
 
        if ip link show $flat_interface >/dev/null 2>&1 ; then
70
 
          ip link set $flat_interface up
71
 
        fi
72
 
 
73
 
        # work around (LP: #1035172)
74
 
        if [[ -e /dev/vhost-net ]] ; then
75
 
          iptables -A POSTROUTING -t mangle -p udp --dport 68 -j CHECKSUM \
76
 
            --checksum-fill
77
 
        fi
78
 
      fi
79
 
 
80
 
      ;;
81
 
    "Quantum")
82
 
      local local_ip=$(get_ip `unit-get private-address`)
83
 
      [[ -n $local_ip ]] || {
84
 
        juju-log "Unable to resolve local IP address"
85
 
        exit 1
86
 
      }
87
 
      set_or_update "network_api_class" "nova.network.quantumv2.api.API"
88
 
      set_or_update "quantum_auth_strategy" "keystone"
89
 
      set_or_update "core_plugin" "$QUANTUM_CORE_PLUGIN" "$QUANTUM_CONF"
90
 
      set_or_update "bind_host" "0.0.0.0" "$QUANTUM_CONF"
91
 
      if [ "$QUANTUM_PLUGIN" == "ovs" ]; then
92
 
          set_or_update "tenant_network_type" "gre" $QUANTUM_PLUGIN_CONF "OVS"
93
 
          set_or_update "enable_tunneling" "True" $QUANTUM_PLUGIN_CONF "OVS"
94
 
          set_or_update "tunnel_id_ranges" "1:1000" $QUANTUM_PLUGIN_CONF "OVS"
95
 
          set_or_update "local_ip" "$local_ip" $QUANTUM_PLUGIN_CONF "OVS"
96
 
      fi
97
 
      ;;
98
 
    *) juju-log "ERROR: Invalid network manager $1" && exit 1 ;;
99
 
  esac
100
 
}
101
 
 
102
 
function trigger_remote_service_restarts() {
103
 
  # Trigger a service restart on all other nova nodes that have a relation
104
 
  # via the cloud-controller interface.
105
 
 
106
 
  # possible relations to other nova services.
107
 
  local relations="cloud-compute nova-volume-service"
108
 
 
109
 
  for rel in $relations; do
110
 
    local r_ids=$(relation-ids $rel)
111
 
    for r_id in $r_ids ; do
112
 
      juju-log "$CHARM: Triggering a service restart on relation $r_id."
113
 
      relation-set -r $r_id restart-trigger=$(uuid)
114
 
    done
115
 
  done
116
 
}
117
 
 
118
 
do_openstack_upgrade() {
119
 
  # update openstack components to those provided by a new installation source
120
 
  # it is assumed the calling hook has confirmed that the upgrade is sane.
121
 
  local rel="$1"
122
 
  shift
123
 
  local packages=$@
124
 
 
125
 
  orig_os_rel=$(get_os_codename_package "nova-common")
126
 
  new_rel=$(get_os_codename_install_source "$rel")
127
 
 
128
 
  # Backup the config directory.
129
 
  local stamp=$(date +"%Y%m%d%M%S")
130
 
  tar -pcf /var/lib/juju/$CHARM-backup-$stamp.tar $CONF_DIR
131
 
 
132
 
  # load the release helper library for pre/post upgrade hooks specific to the
133
 
  # release we are upgrading to.
134
 
  . $HOOKS_DIR/lib/nova/$new_rel
135
 
 
136
 
  # new release specific pre-upgrade hook
137
 
  nova_pre_upgrade "$orig_os_rel"
138
 
 
139
 
  # Setup apt repository access and kick off the actual package upgrade.
140
 
  configure_install_source "$rel"
141
 
  apt-get update
142
 
  DEBIAN_FRONTEND=noninteractive apt-get --option Dpkg::Options::=--force-confold -y \
143
 
     install --no-install-recommends $packages
144
 
 
145
 
  # new release sepcific post-upgrade hook
146
 
  nova_post_upgrade "$orig_os_rel"
147
 
 
148
 
}