4
PACKAGES="nova-compute python-keystone genisoimage"
5
SERVICES="nova-compute"
7
NOVA_CONF=$(config-get nova-config)
8
API_CONF="/etc/nova/api-paste.ini"
9
QUANTUM_CONF="/etc/quantum/quantum.conf"
10
LIBVIRTD_CONF="/etc/libvirt/libvirtd.conf"
11
HOOKS_DIR="$CHARM_DIR/hooks"
12
MULTI_HOST=$(config-get multi-host)
14
if [ -f /etc/nova/nm.conf ]; then
15
NET_MANAGER=$(cat /etc/nova/nm.conf)
19
QUANTUM_PLUGIN=$(cat /etc/nova/quantum_plugin.conf)
20
case $QUANTUM_PLUGIN in
22
SERVICES="$SERVICES quantum-plugin-openvswitch-agent"
23
QUANTUM_PLUGIN_CONF="/etc/quantum/plugins/openvswitch/ovs_quantum_plugin.ini"
26
QUANTUM_PLUGIN_CONF="/etc/quantum/plugins/nicira/nvp.ini"
29
juju-log "Unrecognised plugin for quantum: $QUANTUM_PLUGIN" && exit 1
33
"FlatManager"|"FlatDHCPManager")
34
if [[ "$MULTI_HOST" == "yes" ]] ; then
35
SERVICES="$SERVICES nova-api nova-network"
40
if [[ -e $HOOKS_DIR/lib/nova/nova-common ]] ; then
41
. $HOOKS_DIR/lib/nova/nova-common
43
juju-log "$CHARM: Couldn't load $HOOKS_DIR/lib/nova-common" && exit 1
46
determine_compute_package() {
47
# determines the appropriate nova-compute package to install
48
# for the configured virt-type.
52
"kvm") compute_pkg="nova-compute-kvm";;
53
"qemu") compute_pkg="nova-compute-qemu";;
54
"xen") compute_pkg="nova-compute-xen";;
55
"uml") compute_pkg="nova-compute-uml";;
56
"lxc") compute_pkg="nova-compute-lxc";;
57
*) error_out "ERROR: Unsupported virt_type=$virt_type";;
62
function setup_bridge {
63
# XXX This is required by nova-network and will likely move somewhere else
64
# once we can split these services up into seperate formulas.
68
[[ -z $br ]] && br="br100"
69
[[ -z $ip ]] && ip="11.0.0.1"
70
[[ -z $netmask ]] && netmask="255.255.255.0"
72
apt-get -y install bridge-utils augeas-lenses augeas-tools
73
echo "Configuring bridge $br ($ip $netmask)"
74
context="/files/etc/network/interfaces"
76
set $context/auto[child::1 = "$br"]/1 $br
77
set $context/iface[. = '$br'] $br
78
set $context/iface[. = '$br']/family inet
79
set $context/iface[. = '$br']/method static
80
set $context/iface[. = '$br']/address $ip
81
set $context/iface[. = '$br']/netmask $netmask
82
set $context/iface[. = '$br']/bridge_ports none
88
function configure_network_manager {
89
# needed by the nova-network bits
90
# to be expanded later to cover flatDhcp and VLAN
91
echo "$0: configuring $1 network manager"
93
local quantum_plugin=$2
94
local network_bridge=$(config-get bridge-interface)
95
local private_address=$(get_ip `unit-get private-address`)
96
# Check to ensure we can actually resolve
97
# the local unit IP address
98
[[ -n $private_address ]] || {
99
juju-log "Unable to resolve local IP address"
104
"FlatManager"|"FlatDHCPManager")
105
if [[ "$MULTI_HOST" == "yes" ]] ; then
106
apt-get -y install nova-api nova-network
107
SERVICES="$SERVICES nova-api nova-network"
109
[[ -n $net_manager ]] && echo $net_manager > /etc/nova/nm.conf
112
local bridge_ip=$(config-get bridge-ip)
113
local bridge_netmask=$(config-get bridge-netmask)
114
setup_bridge $network_bridge $bridge_ip $bridge_netmask
115
set_or_update network_manager nova.network.manager.FlatManager
116
set_or_update flat_network_bridge $network_bridge
119
local flat_interface=$(config-get flat-interface)
120
local ec2_host=$(relation-get ec2_host)
121
[[ -z $ec2_host ]] && juju-log "nova-compute: Missing ec2_host" \
123
set_or_update network_manager nova.network.manager.FlatDHCPManager
124
# the interface on which bridge is built
125
set_or_update flat_interface $flat_interface
126
# address of API server to forward requests
127
set_or_update ec2_dmz_host $ec2_host
130
local keystone_host="$(relation-get keystone_host)"
131
local auth_port="$(relation-get auth_port)"
132
local quantum_url="$(relation-get quantum_url)"
133
local quantum_admin_tenant_name="$(relation-get service_tenant)"
134
local quantum_admin_username="$(relation-get service_username)"
135
local quantum_admin_password="$(relation-get service_password)"
136
local quantum_security_groups="$(relation-get quantum_security_groups)"
138
# might end up here before nova-c-c has processed keystone hooks
139
[[ -z "$keystone_host" ]] ||
140
[[ -z "$auth_port" ]] ||
141
[[ -z "$quantum_url" ]] ||
142
[[ -z "$quantum_admin_tenant_name" ]] ||
143
[[ -z "$quantum_admin_username" ]] ||
144
[[ -z "$quantum_admin_password" ]] &&
145
juju-log "nova-compute: Missing required data for Quantum config." &&
148
local cur=$(get_os_codename_package "nova-common")
149
local vers=$(get_os_version_codename $cur)
151
[[ "$quantum_security_groups" == "yes" ]] &&
152
dpkg --compare-versions $vers lt '2013.1' &&
153
juju-log "Unable to use quantum security groups with < grizzly" &&
156
set_or_update "network_api_class" "nova.network.quantumv2.api.API"
157
set_or_update "quantum_auth_strategy" "keystone"
158
set_or_update "quantum_url" "$quantum_url"
159
set_or_update "quantum_admin_tenant_name" "$quantum_admin_tenant_name"
160
set_or_update "quantum_admin_username" "$quantum_admin_username"
161
set_or_update "quantum_admin_password" "$quantum_admin_password"
162
set_or_update "quantum_admin_auth_url" \
163
"http://$keystone_host:$auth_port/v2.0"
165
if dpkg --compare-versions $vers gt '2012.2'; then
166
# Grizzly onwards supports metadata proxy so forcing use of config
167
# drive is not required.
168
set_or_update "force_config_drive" "False"
170
set_or_update "force_config_drive" "True"
172
case $quantum_plugin in
174
apt-get -y install openvswitch-datapath-dkms
175
apt-get -y install quantum-plugin-openvswitch-agent
176
local quantum_plugin_conf="/etc/quantum/plugins/openvswitch/ovs_quantum_plugin.ini"
177
set_or_update "core_plugin" "quantum.plugins.openvswitch.ovs_quantum_plugin.OVSQuantumPluginV2" "$QUANTUM_CONF"
178
if dpkg --compare-versions $vers gt '2012.2'; then
179
set_or_update "libvirt_vif_driver" "nova.virt.libvirt.vif.LibvirtGenericVIFDriver"
181
set_or_update "libvirt_vif_driver" "nova.virt.libvirt.vif.LibvirtHybridOVSBridgeDriver"
183
set_or_update "libvirt_use_virtio_for_bridges" "True"
184
set_or_update "tenant_network_type" "gre" $quantum_plugin_conf "OVS"
185
set_or_update "enable_tunneling" "True" $quantum_plugin_conf "OVS"
186
set_or_update "tunnel_id_ranges" "1:1000" $quantum_plugin_conf "OVS"
187
set_or_update "local_ip" "$private_address" $quantum_plugin_conf "OVS"
188
if [ "$quantum_security_groups" == "yes" ]; then
189
set_or_update "security_group_api" "quantum"
190
set_or_update "firewall_driver" "nova.virt.firewall.NoopFirewallDriver"
191
set_or_update "firewall_driver" \
192
"quantum.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver" \
193
$quantum_plugin_conf "SECURITYGROUP"
195
SERVICES="$SERVICES quantum-plugin-openvswitch-agent"
198
set_or_update "bind_host" "0.0.0.0" "$QUANTUM_CONF"
199
[[ -n $net_manager ]] && echo $net_manager > /etc/nova/nm.conf
200
[[ -n $quantum_plugin ]] && echo $quantum_plugin > /etc/nova/quantum_plugin.conf
202
*) echo "ERROR: Invalid network manager $1" && exit 1 ;;
208
function configure_quantum_bridge {
209
if ! ovs-vsctl show | grep -q "Bridge $BR_INT"; then
210
ovs-vsctl add-br $BR_INT
214
function initialize_ssh_keys {
215
# generate ssh keypair for root if one does not exist or
216
# the pari is not complete.
217
local pub="/root/.ssh/id_rsa"
218
local priv="/root/.ssh/id_rsa.pub"
220
[[ -e $priv ]] ; then
221
juju-log "$CHARM: SSH credentials already exist for root."
224
juju-log "$CHARM: Initializing new SSH key pair for live migration."
225
[[ -e $pub ]] && mv $pub $pub.$(date +"%s")
226
[[ -e $priv ]] && mv $priv $priv.$(date +"%s")
227
local keyname=$(echo $JUJU_UNIT_NAME | sed -e 's,/,-,g')
228
echo -e "\n" | ssh-keygen -C "$keyname" -N ""
231
function libvirt_tcp_listening {
232
# toggle libvirtd's tcp listening in both /etc/default/libvirt-bin
233
# and /etc/libvirt/libvirtd.conf.
235
juju-log "$CHARM: Configuring libvirt tcp listening: $toggle."
236
local cur_opts=$(grep "^libvirtd_opts" /etc/default/libvirt-bin |
237
cut -d= -f2 | sed -e 's/\"//g')
240
if [[ "$toggle" == "on" ]] ; then
241
if [[ -z "$cur_opts" ]] ; then
242
echo "libvirtd_opts=\"-d -l\"" >>/etc/default/libvirt-bin
243
elif ! echo "$cur_opts" | grep -q "\-l" ; then
244
new_opts="$cur_opts -l"
245
sed -i "s|\(libvirtd_opts=\).*|\1\"$new_opts\"|" /etc/default/libvirt-bin
247
set_or_update "listen_tcp" 1 $LIBVIRTD_CONF
248
elif [[ "$toggle" == "off" ]] ; then
249
if echo "$cur_opts" | grep -q "\-l" ; then
250
new_opts=$(echo $cur_opts | sed -e 's/\-l//g')
252
set_or_update "listen_tcp" 0 $LIBVIRTD_CONF
255
[[ -n "$new_opts" ]] &&
256
sed -i "s|\(libvirtd_opts=\).*|\1\"$new_opts\"|" /etc/default/libvirt-bin
262
function configure_migration {
263
local enable_migration=$(config-get enable-live-migration)
265
if [[ "$enable_migration" != "True" ]] &&
266
[[ "$enable_migraiton" != "true" ]] ; then
267
libvirt_tcp_listening "off"
271
libvirt_tcp_listening "on"
273
case "$(config-get migration-auth-type)" in
275
set_or_update "listen_tls" 0 $LIBVIRTD_CONF
276
set_or_update "auth_tcp" "\"none\"" $LIBVIRTD_CONF
279
set_or_update "listen_tls" 0 $LIBVIRTD_CONF
280
set_or_update "live_migration_uri" "qemu+ssh://%s/system" $NOVA_CONF
282
# check in with nova-c-c and register our new key.
283
for id in $(relation-ids cloud-compute) ; do
286
service_ctl nova-compute restart ;;
291
function configure_libvirt {
292
cat > /etc/libvirt/qemu.conf << EOF
293
# File installed by Juju nova-compute charm
294
cgroup_device_acl = [
295
"/dev/null", "/dev/full", "/dev/zero",
296
"/dev/random", "/dev/urandom",
297
"/dev/ptmx", "/dev/kvm", "/dev/kqemu",
298
"/dev/rtc", "/dev/hpet", "/dev/net/tun",
302
service libvirt-bin restart
305
function migration_enabled {
306
local migration="$(config-get enable-live-migration)"
307
[[ "$migration" == "true" ]] || [[ "$migration" == "True" ]] && return 0