Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 1 | # lib/nova |
Dean Troyer | 6d04fd7 | 2012-12-21 11:03:37 -0600 | [diff] [blame] | 2 | # Functions to control the configuration and operation of the **Nova** service |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 3 | |
| 4 | # Dependencies: |
| 5 | # ``functions`` file |
Attila Fazekas | 91b8d13 | 2013-01-06 22:40:09 +0100 | [diff] [blame] | 6 | # ``DEST``, ``DATA_DIR``, ``STACK_USER`` must be defined |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 7 | # ``SERVICE_{TENANT_NAME|PASSWORD}`` must be defined |
| 8 | # ``LIBVIRT_TYPE`` must be defined |
| 9 | # ``INSTANCE_NAME_PREFIX``, ``VOLUME_NAME_PREFIX`` must be defined |
Dean Troyer | bc071bc | 2012-10-01 14:06:44 -0500 | [diff] [blame] | 10 | # ``KEYSTONE_TOKEN_FORMAT`` must be defined |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 11 | |
| 12 | # ``stack.sh`` calls the entry points in this order: |
| 13 | # |
| 14 | # install_nova |
| 15 | # configure_nova |
Dean Troyer | da7b809 | 2012-10-08 18:12:14 -0500 | [diff] [blame] | 16 | # create_nova_conf |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 17 | # init_nova |
| 18 | # start_nova |
| 19 | # stop_nova |
| 20 | # cleanup_nova |
| 21 | |
| 22 | # Save trace setting |
| 23 | XTRACE=$(set +o | grep xtrace) |
| 24 | set +o xtrace |
| 25 | |
| 26 | |
| 27 | # Defaults |
| 28 | # -------- |
| 29 | |
| 30 | # Set up default directories |
| 31 | NOVA_DIR=$DEST/nova |
| 32 | NOVACLIENT_DIR=$DEST/python-novaclient |
| 33 | NOVA_STATE_PATH=${NOVA_STATE_PATH:=$DATA_DIR/nova} |
| 34 | # INSTANCES_PATH is the previous name for this |
| 35 | NOVA_INSTANCES_PATH=${NOVA_INSTANCES_PATH:=${INSTANCES_PATH:=$NOVA_STATE_PATH/instances}} |
Dean Troyer | bc071bc | 2012-10-01 14:06:44 -0500 | [diff] [blame] | 36 | NOVA_AUTH_CACHE_DIR=${NOVA_AUTH_CACHE_DIR:-/var/cache/nova} |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 37 | |
| 38 | NOVA_CONF_DIR=/etc/nova |
| 39 | NOVA_CONF=$NOVA_CONF_DIR/nova.conf |
Kieran Spear | fb2a3ae | 2013-03-11 23:55:49 +0000 | [diff] [blame] | 40 | NOVA_CELLS_CONF=$NOVA_CONF_DIR/nova-cells.conf |
| 41 | NOVA_CELLS_DB=${NOVA_CELLS_DB:-nova_cell} |
| 42 | |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 43 | NOVA_API_PASTE_INI=${NOVA_API_PASTE_INI:-$NOVA_CONF_DIR/api-paste.ini} |
| 44 | |
Dean Troyer | 3a3a2ba | 2012-12-11 15:26:24 -0600 | [diff] [blame] | 45 | # Public facing bits |
| 46 | NOVA_SERVICE_HOST=${NOVA_SERVICE_HOST:-$SERVICE_HOST} |
| 47 | NOVA_SERVICE_PORT=${NOVA_SERVICE_PORT:-8774} |
| 48 | NOVA_SERVICE_PORT_INT=${NOVA_SERVICE_PORT_INT:-18774} |
| 49 | NOVA_SERVICE_PROTOCOL=${NOVA_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL} |
| 50 | |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 51 | # Support entry points installation of console scripts |
| 52 | if [[ -d $NOVA_DIR/bin ]]; then |
| 53 | NOVA_BIN_DIR=$NOVA_DIR/bin |
| 54 | else |
Jakub Ruzicka | 4196d55 | 2013-01-30 15:35:54 +0100 | [diff] [blame] | 55 | NOVA_BIN_DIR=$(get_python_exec_prefix) |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 56 | fi |
| 57 | |
| 58 | # Set the paths of certain binaries |
Vincent Untz | 856a11e | 2012-11-21 16:04:12 +0100 | [diff] [blame] | 59 | NOVA_ROOTWRAP=$(get_rootwrap_location nova) |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 60 | |
| 61 | # Allow rate limiting to be turned off for testing, like for Tempest |
| 62 | # NOTE: Set API_RATE_LIMIT="False" to turn OFF rate limiting |
| 63 | API_RATE_LIMIT=${API_RATE_LIMIT:-"True"} |
| 64 | |
| 65 | # Nova supports pluggable schedulers. The default ``FilterScheduler`` |
| 66 | # should work in most cases. |
| 67 | SCHEDULER=${SCHEDULER:-nova.scheduler.filter_scheduler.FilterScheduler} |
| 68 | |
| 69 | QEMU_CONF=/etc/libvirt/qemu.conf |
| 70 | |
Dean Troyer | b7490da | 2013-03-18 16:07:56 -0500 | [diff] [blame] | 71 | NOVNC_DIR=$DEST/noVNC |
| 72 | SPICE_DIR=$DEST/spice-html5 |
| 73 | |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 74 | |
Dean Troyer | b323691 | 2013-03-17 15:17:05 -0500 | [diff] [blame] | 75 | # Nova Network Configuration |
| 76 | # -------------------------- |
| 77 | |
| 78 | # Set defaults according to the virt driver |
| 79 | if [ "$VIRT_DRIVER" = 'xenserver' ]; then |
| 80 | PUBLIC_INTERFACE_DEFAULT=eth3 |
| 81 | GUEST_INTERFACE_DEFAULT=eth1 |
| 82 | # Allow ``build_domU.sh`` to specify the flat network bridge via kernel args |
Mate Lakat | f652e0f | 2013-05-21 18:12:48 +0100 | [diff] [blame] | 83 | FLAT_NETWORK_BRIDGE_DEFAULT=$(sed -e 's/.* flat_network_bridge=\([[:alnum:]]*\).*$/\1/g' /proc/cmdline) |
| 84 | if is_service_enabled quantum; then |
| 85 | XEN_INTEGRATION_BRIDGE=$(sed -e 's/.* xen_integration_bridge=\([[:alnum:]]*\).*$/\1/g' /proc/cmdline) |
| 86 | fi |
Dean Troyer | b323691 | 2013-03-17 15:17:05 -0500 | [diff] [blame] | 87 | elif [ "$VIRT_DRIVER" = 'baremetal' ]; then |
| 88 | NETWORK_MANAGER=${NETWORK_MANAGER:-FlatManager} |
| 89 | PUBLIC_INTERFACE_DEFAULT=eth0 |
| 90 | FLAT_INTERFACE=${FLAT_INTERFACE:-eth0} |
| 91 | FLAT_NETWORK_BRIDGE_DEFAULT=br100 |
| 92 | STUB_NETWORK=${STUB_NETWORK:-False} |
| 93 | else |
| 94 | PUBLIC_INTERFACE_DEFAULT=br100 |
| 95 | GUEST_INTERFACE_DEFAULT=eth0 |
| 96 | FLAT_NETWORK_BRIDGE_DEFAULT=br100 |
| 97 | fi |
| 98 | |
| 99 | NETWORK_MANAGER=${NETWORK_MANAGER:-${NET_MAN:-FlatDHCPManager}} |
| 100 | PUBLIC_INTERFACE=${PUBLIC_INTERFACE:-$PUBLIC_INTERFACE_DEFAULT} |
| 101 | VLAN_INTERFACE=${VLAN_INTERFACE:-$GUEST_INTERFACE_DEFAULT} |
| 102 | FLAT_NETWORK_BRIDGE=${FLAT_NETWORK_BRIDGE:-$FLAT_NETWORK_BRIDGE_DEFAULT} |
| 103 | EC2_DMZ_HOST=${EC2_DMZ_HOST:-$SERVICE_HOST} |
| 104 | |
| 105 | # If you are using the FlatDHCP network mode on multiple hosts, set the |
| 106 | # ``FLAT_INTERFACE`` variable but make sure that the interface doesn't already |
| 107 | # have an IP or you risk breaking things. |
| 108 | # |
| 109 | # **DHCP Warning**: If your flat interface device uses DHCP, there will be a |
| 110 | # hiccup while the network is moved from the flat interface to the flat network |
| 111 | # bridge. This will happen when you launch your first instance. Upon launch |
| 112 | # you will lose all connectivity to the node, and the VM launch will probably |
| 113 | # fail. |
| 114 | # |
| 115 | # If you are running on a single node and don't need to access the VMs from |
| 116 | # devices other than that node, you can set ``FLAT_INTERFACE=`` |
| 117 | # This will stop nova from bridging any interfaces into ``FLAT_NETWORK_BRIDGE``. |
Davanum Srinivas | b93b74c | 2013-03-21 21:25:05 -0400 | [diff] [blame] | 118 | FLAT_INTERFACE=${FLAT_INTERFACE:-$GUEST_INTERFACE_DEFAULT} |
Dean Troyer | b323691 | 2013-03-17 15:17:05 -0500 | [diff] [blame] | 119 | |
| 120 | # ``MULTI_HOST`` is a mode where each compute node runs its own network node. This |
| 121 | # allows network operations and routing for a VM to occur on the server that is |
| 122 | # running the VM - removing a SPOF and bandwidth bottleneck. |
| 123 | MULTI_HOST=`trueorfalse False $MULTI_HOST` |
| 124 | |
| 125 | # Test floating pool and range are used for testing. They are defined |
| 126 | # here until the admin APIs can replace nova-manage |
| 127 | TEST_FLOATING_POOL=${TEST_FLOATING_POOL:-test} |
| 128 | TEST_FLOATING_RANGE=${TEST_FLOATING_RANGE:-192.168.253.0/29} |
| 129 | |
| 130 | |
Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 131 | # Functions |
| 132 | # --------- |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 133 | |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 134 | # Helper to clean iptables rules |
| 135 | function clean_iptables() { |
| 136 | # Delete rules |
| 137 | sudo iptables -S -v | sed "s/-c [0-9]* [0-9]* //g" | grep "nova" | grep "\-A" | sed "s/-A/-D/g" | awk '{print "sudo iptables",$0}' | bash |
| 138 | # Delete nat rules |
| 139 | sudo iptables -S -v -t nat | sed "s/-c [0-9]* [0-9]* //g" | grep "nova" | grep "\-A" | sed "s/-A/-D/g" | awk '{print "sudo iptables -t nat",$0}' | bash |
| 140 | # Delete chains |
| 141 | sudo iptables -S -v | sed "s/-c [0-9]* [0-9]* //g" | grep "nova" | grep "\-N" | sed "s/-N/-X/g" | awk '{print "sudo iptables",$0}' | bash |
| 142 | # Delete nat chains |
| 143 | sudo iptables -S -v -t nat | sed "s/-c [0-9]* [0-9]* //g" | grep "nova" | grep "\-N" | sed "s/-N/-X/g" | awk '{print "sudo iptables -t nat",$0}' | bash |
| 144 | } |
| 145 | |
| 146 | # cleanup_nova() - Remove residual data files, anything left over from previous |
| 147 | # runs that a clean run would need to clean up |
| 148 | function cleanup_nova() { |
| 149 | if is_service_enabled n-cpu; then |
| 150 | # Clean iptables from previous runs |
| 151 | clean_iptables |
| 152 | |
| 153 | # Destroy old instances |
| 154 | instances=`sudo virsh list --all | grep $INSTANCE_NAME_PREFIX | sed "s/.*\($INSTANCE_NAME_PREFIX[0-9a-fA-F]*\).*/\1/g"` |
| 155 | if [ ! "$instances" = "" ]; then |
| 156 | echo $instances | xargs -n1 sudo virsh destroy || true |
Daniel P. Berrange | d52008a | 2013-05-20 15:03:43 +0100 | [diff] [blame] | 157 | echo $instances | xargs -n1 sudo virsh undefine --managed-save || true |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 158 | fi |
| 159 | |
| 160 | # Logout and delete iscsi sessions |
Dan Smith | c0fad2b | 2013-03-28 12:22:25 -0700 | [diff] [blame] | 161 | tgts=$(sudo iscsiadm --mode node | grep $VOLUME_NAME_PREFIX | cut -d ' ' -f2) |
| 162 | for target in $tgts; do |
| 163 | sudo iscsiadm --mode node -T $target --logout || true |
| 164 | done |
| 165 | sudo iscsiadm --mode node --op delete || true |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 166 | |
| 167 | # Clean out the instances directory. |
| 168 | sudo rm -rf $NOVA_INSTANCES_PATH/* |
| 169 | fi |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 170 | |
| 171 | sudo rm -rf $NOVA_STATE_PATH $NOVA_AUTH_CACHE_DIR |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 172 | } |
| 173 | |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 174 | # configure_nova_rootwrap() - configure Nova's rootwrap |
| 175 | function configure_nova_rootwrap() { |
| 176 | # Deploy new rootwrap filters files (owned by root). |
| 177 | # Wipe any existing rootwrap.d files first |
| 178 | if [[ -d $NOVA_CONF_DIR/rootwrap.d ]]; then |
| 179 | sudo rm -rf $NOVA_CONF_DIR/rootwrap.d |
| 180 | fi |
| 181 | # Deploy filters to /etc/nova/rootwrap.d |
| 182 | sudo mkdir -m 755 $NOVA_CONF_DIR/rootwrap.d |
| 183 | sudo cp $NOVA_DIR/etc/nova/rootwrap.d/*.filters $NOVA_CONF_DIR/rootwrap.d |
| 184 | sudo chown -R root:root $NOVA_CONF_DIR/rootwrap.d |
| 185 | sudo chmod 644 $NOVA_CONF_DIR/rootwrap.d/* |
| 186 | # Set up rootwrap.conf, pointing to /etc/nova/rootwrap.d |
| 187 | sudo cp $NOVA_DIR/etc/nova/rootwrap.conf $NOVA_CONF_DIR/ |
| 188 | sudo sed -e "s:^filters_path=.*$:filters_path=$NOVA_CONF_DIR/rootwrap.d:" -i $NOVA_CONF_DIR/rootwrap.conf |
| 189 | sudo chown root:root $NOVA_CONF_DIR/rootwrap.conf |
| 190 | sudo chmod 0644 $NOVA_CONF_DIR/rootwrap.conf |
| 191 | # Specify rootwrap.conf as first parameter to nova-rootwrap |
| 192 | ROOTWRAP_SUDOER_CMD="$NOVA_ROOTWRAP $NOVA_CONF_DIR/rootwrap.conf *" |
| 193 | |
| 194 | # Set up the rootwrap sudoers for nova |
| 195 | TEMPFILE=`mktemp` |
| 196 | echo "$USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE |
| 197 | chmod 0440 $TEMPFILE |
| 198 | sudo chown root:root $TEMPFILE |
| 199 | sudo mv $TEMPFILE /etc/sudoers.d/nova-rootwrap |
| 200 | } |
| 201 | |
| 202 | # configure_nova() - Set config files, create data dirs, etc |
| 203 | function configure_nova() { |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 204 | # Put config files in ``/etc/nova`` for everyone to find |
| 205 | if [[ ! -d $NOVA_CONF_DIR ]]; then |
| 206 | sudo mkdir -p $NOVA_CONF_DIR |
| 207 | fi |
Attila Fazekas | 91b8d13 | 2013-01-06 22:40:09 +0100 | [diff] [blame] | 208 | sudo chown $STACK_USER $NOVA_CONF_DIR |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 209 | |
| 210 | cp -p $NOVA_DIR/etc/nova/policy.json $NOVA_CONF_DIR |
| 211 | |
| 212 | configure_nova_rootwrap |
| 213 | |
| 214 | if is_service_enabled n-api; then |
| 215 | # Use the sample http middleware configuration supplied in the |
| 216 | # Nova sources. This paste config adds the configuration required |
| 217 | # for Nova to validate Keystone tokens. |
| 218 | |
| 219 | # Remove legacy paste config if present |
| 220 | rm -f $NOVA_DIR/bin/nova-api-paste.ini |
| 221 | |
| 222 | # Get the sample configuration file in place |
| 223 | cp $NOVA_DIR/etc/nova/api-paste.ini $NOVA_CONF_DIR |
| 224 | |
Mate Lakat | a6601a5 | 2013-03-13 13:35:47 +0000 | [diff] [blame] | 225 | iniset $NOVA_API_PASTE_INI filter:authtoken auth_host $KEYSTONE_AUTH_HOST |
Dean Troyer | 3a3a2ba | 2012-12-11 15:26:24 -0600 | [diff] [blame] | 226 | if is_service_enabled tls-proxy; then |
Mate Lakat | a6601a5 | 2013-03-13 13:35:47 +0000 | [diff] [blame] | 227 | iniset $NOVA_API_PASTE_INI filter:authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL |
Dean Troyer | 3a3a2ba | 2012-12-11 15:26:24 -0600 | [diff] [blame] | 228 | fi |
Dean Troyer | b205cc8 | 2013-02-11 17:34:39 -0600 | [diff] [blame] | 229 | iniset $NOVA_API_PASTE_INI filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME |
| 230 | iniset $NOVA_API_PASTE_INI filter:authtoken admin_user nova |
| 231 | iniset $NOVA_API_PASTE_INI filter:authtoken admin_password $SERVICE_PASSWORD |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 232 | fi |
| 233 | |
Akihiro MOTOKI | 5e3deb6 | 2012-12-11 17:09:02 +0900 | [diff] [blame] | 234 | iniset $NOVA_API_PASTE_INI filter:authtoken signing_dir $NOVA_AUTH_CACHE_DIR |
Dean Troyer | bc071bc | 2012-10-01 14:06:44 -0500 | [diff] [blame] | 235 | |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 236 | if is_service_enabled n-cpu; then |
| 237 | # Force IP forwarding on, just on case |
| 238 | sudo sysctl -w net.ipv4.ip_forward=1 |
| 239 | |
| 240 | # Attempt to load modules: network block device - used to manage qcow images |
| 241 | sudo modprobe nbd || true |
| 242 | |
| 243 | # Check for kvm (hardware based virtualization). If unable to initialize |
| 244 | # kvm, we drop back to the slower emulation mode (qemu). Note: many systems |
| 245 | # come with hardware virtualization disabled in BIOS. |
| 246 | if [[ "$LIBVIRT_TYPE" == "kvm" ]]; then |
| 247 | sudo modprobe kvm || true |
| 248 | if [ ! -e /dev/kvm ]; then |
| 249 | echo "WARNING: Switching to QEMU" |
| 250 | LIBVIRT_TYPE=qemu |
| 251 | if which selinuxenabled 2>&1 > /dev/null && selinuxenabled; then |
| 252 | # https://bugzilla.redhat.com/show_bug.cgi?id=753589 |
| 253 | sudo setsebool virt_use_execmem on |
| 254 | fi |
| 255 | fi |
| 256 | fi |
| 257 | |
| 258 | # Install and configure **LXC** if specified. LXC is another approach to |
| 259 | # splitting a system into many smaller parts. LXC uses cgroups and chroot |
| 260 | # to simulate multiple systems. |
| 261 | if [[ "$LIBVIRT_TYPE" == "lxc" ]]; then |
Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 262 | if is_ubuntu; then |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 263 | if [[ ! "$DISTRO" > natty ]]; then |
| 264 | cgline="none /cgroup cgroup cpuacct,memory,devices,cpu,freezer,blkio 0 0" |
| 265 | sudo mkdir -p /cgroup |
| 266 | if ! grep -q cgroup /etc/fstab; then |
| 267 | echo "$cgline" | sudo tee -a /etc/fstab |
| 268 | fi |
| 269 | if ! mount -n | grep -q cgroup; then |
| 270 | sudo mount /cgroup |
| 271 | fi |
| 272 | fi |
| 273 | fi |
| 274 | fi |
| 275 | |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 276 | # Prepare directories and packages for baremetal driver |
| 277 | if is_baremetal; then |
| 278 | configure_baremetal_nova_dirs |
| 279 | fi |
| 280 | |
Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 281 | if is_service_enabled quantum && is_quantum_ovs_base_plugin && ! sudo grep -q '^cgroup_device_acl' $QEMU_CONF; then |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 282 | # Add /dev/net/tun to cgroup_device_acls, needed for type=ethernet interfaces |
| 283 | cat <<EOF | sudo tee -a $QEMU_CONF |
| 284 | cgroup_device_acl = [ |
| 285 | "/dev/null", "/dev/full", "/dev/zero", |
| 286 | "/dev/random", "/dev/urandom", |
| 287 | "/dev/ptmx", "/dev/kvm", "/dev/kqemu", |
| 288 | "/dev/rtc", "/dev/hpet","/dev/net/tun", |
| 289 | ] |
| 290 | EOF |
| 291 | fi |
| 292 | |
Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 293 | if is_ubuntu; then |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 294 | LIBVIRT_DAEMON=libvirt-bin |
| 295 | else |
Vincent Untz | f1c094c | 2012-12-05 17:59:04 +0100 | [diff] [blame] | 296 | LIBVIRT_DAEMON=libvirtd |
| 297 | fi |
| 298 | |
Sunil Thaha | a534e0b | 2013-01-21 17:00:50 +1000 | [diff] [blame] | 299 | |
| 300 | |
Ralf Haferkamp | 76ca9a9 | 2013-04-12 12:39:58 +0200 | [diff] [blame] | 301 | if is_fedora || is_suse; then |
Ian Wienand | b85f9d7 | 2013-05-02 12:02:22 +1000 | [diff] [blame] | 302 | if is_fedora && [[ $DISTRO =~ (rhel6) || "$os_RELEASE" -le "17" ]]; then |
Émilien Macchi | b2ef890 | 2013-05-04 00:48:20 +0200 | [diff] [blame] | 303 | sudo bash -c "cat <<EOF >/etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla |
Ralf Haferkamp | 76ca9a9 | 2013-04-12 12:39:58 +0200 | [diff] [blame] | 304 | [libvirt Management Access] |
Émilien Macchi | b2ef890 | 2013-05-04 00:48:20 +0200 | [diff] [blame] | 305 | Identity=unix-group:$LIBVIRT_GROUP |
Ralf Haferkamp | 76ca9a9 | 2013-04-12 12:39:58 +0200 | [diff] [blame] | 306 | Action=org.libvirt.unix.manage |
| 307 | ResultAny=yes |
| 308 | ResultInactive=yes |
| 309 | ResultActive=yes |
Émilien Macchi | b2ef890 | 2013-05-04 00:48:20 +0200 | [diff] [blame] | 310 | EOF" |
Ralf Haferkamp | 76ca9a9 | 2013-04-12 12:39:58 +0200 | [diff] [blame] | 311 | elif is_suse && [[ $os_RELEASE = 12.2 || "$os_VENDOR" = "SUSE LINUX" ]]; then |
| 312 | # openSUSE < 12.3 or SLE |
| 313 | # Work around the fact that polkit-default-privs overrules pklas |
| 314 | # with 'unix-group:$group'. |
| 315 | sudo bash -c "cat <<EOF >/etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla |
| 316 | [libvirt Management Access] |
| 317 | Identity=unix-user:$USER |
| 318 | Action=org.libvirt.unix.manage |
| 319 | ResultAny=yes |
| 320 | ResultInactive=yes |
| 321 | ResultActive=yes |
| 322 | EOF" |
| 323 | else |
| 324 | # Starting with fedora 18 and opensuse-12.3 enable stack-user to |
| 325 | # virsh -c qemu:///system by creating a policy-kit rule for |
| 326 | # stack-user using the new Javascript syntax |
Sunil Thaha | a534e0b | 2013-01-21 17:00:50 +1000 | [diff] [blame] | 327 | rules_dir=/etc/polkit-1/rules.d |
| 328 | sudo mkdir -p $rules_dir |
| 329 | sudo bash -c "cat <<EOF > $rules_dir/50-libvirt-$STACK_USER.rules |
| 330 | polkit.addRule(function(action, subject) { |
| 331 | if (action.id == 'org.libvirt.unix.manage' && |
| 332 | subject.user == '"$STACK_USER"') { |
| 333 | return polkit.Result.YES; |
| 334 | } |
| 335 | }); |
| 336 | EOF" |
| 337 | unset rules_dir |
Sunil Thaha | a534e0b | 2013-01-21 17:00:50 +1000 | [diff] [blame] | 338 | fi |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 339 | fi |
| 340 | |
| 341 | # The user that nova runs as needs to be member of **libvirtd** group otherwise |
| 342 | # nova-compute will be unable to use libvirt. |
Émilien Macchi | b2ef890 | 2013-05-04 00:48:20 +0200 | [diff] [blame] | 343 | if ! getent group $LIBVIRT_GROUP >/dev/null; then |
| 344 | sudo groupadd $LIBVIRT_GROUP |
Vincent Untz | f1c094c | 2012-12-05 17:59:04 +0100 | [diff] [blame] | 345 | fi |
Émilien Macchi | b2ef890 | 2013-05-04 00:48:20 +0200 | [diff] [blame] | 346 | add_user_to_group $STACK_USER $LIBVIRT_GROUP |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 347 | |
| 348 | # libvirt detects various settings on startup, as we potentially changed |
| 349 | # the system configuration (modules, filesystems), we need to restart |
| 350 | # libvirt to detect those changes. |
| 351 | restart_service $LIBVIRT_DAEMON |
| 352 | |
| 353 | |
| 354 | # Instance Storage |
| 355 | # ---------------- |
| 356 | |
| 357 | # Nova stores each instance in its own directory. |
Doug Hellmann | cf9eef8 | 2013-03-25 19:34:48 -0400 | [diff] [blame] | 358 | sudo mkdir -p $NOVA_INSTANCES_PATH |
| 359 | sudo chown -R $STACK_USER $NOVA_INSTANCES_PATH |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 360 | |
| 361 | # You can specify a different disk to be mounted and used for backing the |
| 362 | # virtual machines. If there is a partition labeled nova-instances we |
| 363 | # mount it (ext filesystems can be labeled via e2label). |
| 364 | if [ -L /dev/disk/by-label/nova-instances ]; then |
| 365 | if ! mount -n | grep -q $NOVA_INSTANCES_PATH; then |
| 366 | sudo mount -L nova-instances $NOVA_INSTANCES_PATH |
Attila Fazekas | 91b8d13 | 2013-01-06 22:40:09 +0100 | [diff] [blame] | 367 | sudo chown -R $STACK_USER $NOVA_INSTANCES_PATH |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 368 | fi |
| 369 | fi |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 370 | fi |
| 371 | } |
| 372 | |
Dean Troyer | a0dce26 | 2012-12-11 16:52:37 -0600 | [diff] [blame] | 373 | # create_nova_accounts() - Set up common required nova accounts |
| 374 | |
| 375 | # Tenant User Roles |
| 376 | # ------------------------------------------------------------------ |
| 377 | # service nova admin, [ResellerAdmin (swift only)] |
| 378 | |
| 379 | # Migrated from keystone_data.sh |
| 380 | create_nova_accounts() { |
| 381 | |
| 382 | SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }") |
| 383 | ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }") |
| 384 | |
| 385 | # Nova |
| 386 | if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then |
| 387 | NOVA_USER=$(keystone user-create \ |
| 388 | --name=nova \ |
| 389 | --pass="$SERVICE_PASSWORD" \ |
| 390 | --tenant_id $SERVICE_TENANT \ |
| 391 | --email=nova@example.com \ |
| 392 | | grep " id " | get_field 2) |
| 393 | keystone user-role-add \ |
| 394 | --tenant_id $SERVICE_TENANT \ |
| 395 | --user_id $NOVA_USER \ |
| 396 | --role_id $ADMIN_ROLE |
| 397 | if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then |
| 398 | NOVA_SERVICE=$(keystone service-create \ |
| 399 | --name=nova \ |
| 400 | --type=compute \ |
| 401 | --description="Nova Compute Service" \ |
| 402 | | grep " id " | get_field 2) |
| 403 | keystone endpoint-create \ |
| 404 | --region RegionOne \ |
| 405 | --service_id $NOVA_SERVICE \ |
Dean Troyer | 3a3a2ba | 2012-12-11 15:26:24 -0600 | [diff] [blame] | 406 | --publicurl "$NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT/v2/\$(tenant_id)s" \ |
| 407 | --adminurl "$NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT/v2/\$(tenant_id)s" \ |
| 408 | --internalurl "$NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT/v2/\$(tenant_id)s" |
Dean Troyer | a0dce26 | 2012-12-11 16:52:37 -0600 | [diff] [blame] | 409 | fi |
| 410 | fi |
| 411 | } |
| 412 | |
Dean Troyer | da7b809 | 2012-10-08 18:12:14 -0500 | [diff] [blame] | 413 | # create_nova_conf() - Create a new nova.conf file |
| 414 | function create_nova_conf() { |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 415 | # Remove legacy ``nova.conf`` |
| 416 | rm -f $NOVA_DIR/bin/nova.conf |
| 417 | |
| 418 | # (Re)create ``nova.conf`` |
Dean Troyer | 3cf1ffb | 2012-10-02 11:51:27 -0500 | [diff] [blame] | 419 | rm -f $NOVA_CONF |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame] | 420 | iniset $NOVA_CONF DEFAULT verbose "True" |
Joe Gordon | 8750b3d | 2013-01-17 23:49:50 -0500 | [diff] [blame] | 421 | iniset $NOVA_CONF DEFAULT debug "True" |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame] | 422 | iniset $NOVA_CONF DEFAULT auth_strategy "keystone" |
| 423 | iniset $NOVA_CONF DEFAULT allow_resize_to_same_host "True" |
| 424 | iniset $NOVA_CONF DEFAULT api_paste_config "$NOVA_API_PASTE_INI" |
| 425 | iniset $NOVA_CONF DEFAULT rootwrap_config "$NOVA_CONF_DIR/rootwrap.conf" |
| 426 | iniset $NOVA_CONF DEFAULT compute_scheduler_driver "$SCHEDULER" |
| 427 | iniset $NOVA_CONF DEFAULT dhcpbridge_flagfile "$NOVA_CONF" |
| 428 | iniset $NOVA_CONF DEFAULT force_dhcp_release "True" |
mathrock | 27c0695 | 2013-03-13 00:23:18 -0400 | [diff] [blame] | 429 | iniset $NOVA_CONF DEFAULT fixed_range "" |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame] | 430 | iniset $NOVA_CONF DEFAULT default_floating_pool "$PUBLIC_NETWORK_NAME" |
| 431 | iniset $NOVA_CONF DEFAULT s3_host "$SERVICE_HOST" |
| 432 | iniset $NOVA_CONF DEFAULT s3_port "$S3_SERVICE_PORT" |
| 433 | iniset $NOVA_CONF DEFAULT osapi_compute_extension "nova.api.openstack.compute.contrib.standard_extensions" |
| 434 | iniset $NOVA_CONF DEFAULT my_ip "$HOST_IP" |
Attila Fazekas | 7e79d91 | 2013-03-03 12:23:04 +0100 | [diff] [blame] | 435 | iniset $NOVA_CONF DEFAULT sql_connection `database_connection_url nova` |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 436 | if is_baremetal; then |
Attila Fazekas | 7e79d91 | 2013-03-03 12:23:04 +0100 | [diff] [blame] | 437 | iniset $NOVA_CONF baremetal sql_connection `database_connection_url nova_bm` |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 438 | fi |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame] | 439 | iniset $NOVA_CONF DEFAULT libvirt_type "$LIBVIRT_TYPE" |
| 440 | iniset $NOVA_CONF DEFAULT libvirt_cpu_mode "none" |
| 441 | iniset $NOVA_CONF DEFAULT instance_name_template "${INSTANCE_NAME_PREFIX}%08x" |
Chris Yeoh | 1b4d91b | 2013-06-03 16:23:01 +0930 | [diff] [blame^] | 442 | iniset $NOVA_CONF osapi_v3 enabled "True" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 443 | |
| 444 | if is_service_enabled n-api; then |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame] | 445 | iniset $NOVA_CONF DEFAULT enabled_apis "$NOVA_ENABLED_APIS" |
Dean Troyer | 3a3a2ba | 2012-12-11 15:26:24 -0600 | [diff] [blame] | 446 | if is_service_enabled tls-proxy; then |
| 447 | # Set the service port for a proxy to take the original |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame] | 448 | iniset $NOVA_CONF DEFAULT osapi_compute_listen_port "$NOVA_SERVICE_PORT_INT" |
Dean Troyer | 3a3a2ba | 2012-12-11 15:26:24 -0600 | [diff] [blame] | 449 | fi |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 450 | fi |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 451 | if is_service_enabled cinder; then |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame] | 452 | iniset $NOVA_CONF DEFAULT volume_api_class "nova.volume.cinder.API" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 453 | fi |
| 454 | if [ -n "$NOVA_STATE_PATH" ]; then |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame] | 455 | iniset $NOVA_CONF DEFAULT state_path "$NOVA_STATE_PATH" |
| 456 | iniset $NOVA_CONF DEFAULT lock_path "$NOVA_STATE_PATH" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 457 | fi |
| 458 | if [ -n "$NOVA_INSTANCES_PATH" ]; then |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame] | 459 | iniset $NOVA_CONF DEFAULT instances_path "$NOVA_INSTANCES_PATH" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 460 | fi |
| 461 | if [ "$MULTI_HOST" != "False" ]; then |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame] | 462 | iniset $NOVA_CONF DEFAULT multi_host "True" |
| 463 | iniset $NOVA_CONF DEFAULT send_arp_for_ha "True" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 464 | fi |
| 465 | if [ "$SYSLOG" != "False" ]; then |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame] | 466 | iniset $NOVA_CONF DEFAULT use_syslog "True" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 467 | fi |
| 468 | if [ "$API_RATE_LIMIT" != "True" ]; then |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame] | 469 | iniset $NOVA_CONF DEFAULT api_rate_limit "False" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 470 | fi |
| 471 | if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then |
| 472 | # Add color to logging output |
Joe Gordon | 07db713 | 2013-01-30 13:07:25 -0800 | [diff] [blame] | 473 | iniset $NOVA_CONF DEFAULT logging_context_format_string "%(asctime)s.%(msecs)03d %(color)s%(levelname)s %(name)s [[01;36m%(request_id)s [00;36m%(user_name)s %(project_name)s%(color)s] [01;35m%(instance)s%(color)s%(message)s[00m" |
| 474 | iniset $NOVA_CONF DEFAULT logging_default_format_string "%(asctime)s.%(msecs)03d %(color)s%(levelname)s %(name)s [[00;36m-%(color)s] [01;35m%(instance)s%(color)s%(message)s[00m" |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame] | 475 | iniset $NOVA_CONF DEFAULT logging_debug_format_suffix "[00;33mfrom (pid=%(process)d) %(funcName)s %(pathname)s:%(lineno)d[00m" |
Joe Gordon | 07db713 | 2013-01-30 13:07:25 -0800 | [diff] [blame] | 476 | iniset $NOVA_CONF DEFAULT logging_exception_prefix "%(color)s%(asctime)s.%(msecs)03d TRACE %(name)s [01;35m%(instance)s[00m" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 477 | else |
| 478 | # Show user_name and project_name instead of user_id and project_id |
Joe Gordon | 07db713 | 2013-01-30 13:07:25 -0800 | [diff] [blame] | 479 | iniset $NOVA_CONF DEFAULT logging_context_format_string "%(asctime)s.%(msecs)03d %(levelname)s %(name)s [%(request_id)s %(user_name)s %(project_name)s] %(instance)s%(message)s" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 480 | fi |
Eoghan Glynn | 1fcc6a1 | 2012-10-25 14:57:14 +0000 | [diff] [blame] | 481 | if is_service_enabled ceilometer; then |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame] | 482 | iniset $NOVA_CONF DEFAULT instance_usage_audit "True" |
| 483 | iniset $NOVA_CONF DEFAULT instance_usage_audit_period "hour" |
Lianhao Lu | 239f324 | 2013-03-01 15:54:02 +0800 | [diff] [blame] | 484 | iniset_multiline $NOVA_CONF DEFAULT notification_driver "nova.openstack.common.notifier.rpc_notifier" "ceilometer.compute.nova_notifier" |
Eoghan Glynn | 1fcc6a1 | 2012-10-25 14:57:14 +0000 | [diff] [blame] | 485 | fi |
| 486 | |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 487 | |
| 488 | # Provide some transition from ``EXTRA_FLAGS`` to ``EXTRA_OPTS`` |
| 489 | if [[ -z "$EXTRA_OPTS" && -n "$EXTRA_FLAGS" ]]; then |
| 490 | EXTRA_OPTS=$EXTRA_FLAGS |
| 491 | fi |
| 492 | |
| 493 | # Define extra nova conf flags by defining the array ``EXTRA_OPTS``. |
| 494 | # For Example: ``EXTRA_OPTS=(foo=true bar=2)`` |
| 495 | for I in "${EXTRA_OPTS[@]}"; do |
Dean Troyer | dff9512 | 2013-01-10 20:51:28 -0600 | [diff] [blame] | 496 | # Replace the first '=' with ' ' for iniset syntax |
| 497 | iniset $NOVA_CONF DEFAULT ${I/=/ } |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 498 | done |
Dean Troyer | b323691 | 2013-03-17 15:17:05 -0500 | [diff] [blame] | 499 | |
| 500 | # All nova-compute workers need to know the vnc configuration options |
| 501 | # These settings don't hurt anything if n-xvnc and n-novnc are disabled |
| 502 | if is_service_enabled n-cpu; then |
| 503 | NOVNCPROXY_URL=${NOVNCPROXY_URL:-"http://$SERVICE_HOST:6080/vnc_auto.html"} |
| 504 | iniset $NOVA_CONF DEFAULT novncproxy_base_url "$NOVNCPROXY_URL" |
| 505 | XVPVNCPROXY_URL=${XVPVNCPROXY_URL:-"http://$SERVICE_HOST:6081/console"} |
| 506 | iniset $NOVA_CONF DEFAULT xvpvncproxy_base_url "$XVPVNCPROXY_URL" |
| 507 | SPICEHTML5PROXY_URL=${SPICEHTML5PROXY_URL:-"http://$SERVICE_HOST:6082/spice_auto.html"} |
| 508 | iniset $NOVA_CONF spice html5proxy_base_url "$SPICEHTML5PROXY_URL" |
| 509 | fi |
| 510 | if [ "$VIRT_DRIVER" = 'xenserver' ]; then |
| 511 | VNCSERVER_PROXYCLIENT_ADDRESS=${VNCSERVER_PROXYCLIENT_ADDRESS=169.254.0.1} |
| 512 | else |
| 513 | VNCSERVER_PROXYCLIENT_ADDRESS=${VNCSERVER_PROXYCLIENT_ADDRESS=127.0.0.1} |
| 514 | fi |
| 515 | |
Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 516 | if is_service_enabled n-novnc || is_service_enabled n-xvnc; then |
Dean Troyer | b323691 | 2013-03-17 15:17:05 -0500 | [diff] [blame] | 517 | # Address on which instance vncservers will listen on compute hosts. |
| 518 | # For multi-host, this should be the management ip of the compute host. |
| 519 | VNCSERVER_LISTEN=${VNCSERVER_LISTEN=127.0.0.1} |
| 520 | iniset $NOVA_CONF DEFAULT vnc_enabled true |
| 521 | iniset $NOVA_CONF DEFAULT vncserver_listen "$VNCSERVER_LISTEN" |
| 522 | iniset $NOVA_CONF DEFAULT vncserver_proxyclient_address "$VNCSERVER_PROXYCLIENT_ADDRESS" |
| 523 | else |
| 524 | iniset $NOVA_CONF DEFAULT vnc_enabled false |
| 525 | fi |
| 526 | |
| 527 | if is_service_enabled n-spice; then |
| 528 | # Address on which instance spiceservers will listen on compute hosts. |
| 529 | # For multi-host, this should be the management ip of the compute host. |
| 530 | SPICESERVER_PROXYCLIENT_ADDRESS=${SPICESERVER_PROXYCLIENT_ADDRESS=127.0.0.1} |
| 531 | SPICESERVER_LISTEN=${SPICESERVER_LISTEN=127.0.0.1} |
| 532 | iniset $NOVA_CONF spice enabled true |
| 533 | iniset $NOVA_CONF spice server_listen "$SPICESERVER_LISTEN" |
| 534 | iniset $NOVA_CONF spice server_proxyclient_address "$SPICESERVER_PROXYCLIENT_ADDRESS" |
| 535 | else |
| 536 | iniset $NOVA_CONF spice enabled false |
| 537 | fi |
| 538 | |
| 539 | iniset $NOVA_CONF DEFAULT ec2_dmz_host "$EC2_DMZ_HOST" |
| 540 | iniset_rpc_backend nova $NOVA_CONF DEFAULT |
| 541 | iniset $NOVA_CONF DEFAULT glance_api_servers "$GLANCE_HOSTPORT" |
Dean Troyer | da7b809 | 2012-10-08 18:12:14 -0500 | [diff] [blame] | 542 | } |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 543 | |
Kieran Spear | fb2a3ae | 2013-03-11 23:55:49 +0000 | [diff] [blame] | 544 | function init_nova_cells() { |
| 545 | if is_service_enabled n-cell; then |
| 546 | cp $NOVA_CONF $NOVA_CELLS_CONF |
| 547 | iniset $NOVA_CELLS_CONF DEFAULT sql_connection `database_connection_url $NOVA_CELLS_DB` |
| 548 | iniset $NOVA_CELLS_CONF DEFAULT rabbit_virtual_host child_cell |
| 549 | iniset $NOVA_CELLS_CONF DEFAULT dhcpbridge_flagfile $NOVA_CELLS_CONF |
| 550 | iniset $NOVA_CELLS_CONF cells enable True |
| 551 | iniset $NOVA_CELLS_CONF cells name child |
| 552 | |
| 553 | iniset $NOVA_CONF DEFAULT scheduler_topic cells |
| 554 | iniset $NOVA_CONF DEFAULT compute_api_class nova.compute.cells_api.ComputeCellsAPI |
| 555 | iniset $NOVA_CONF cells enable True |
| 556 | iniset $NOVA_CONF cells name region |
| 557 | |
| 558 | if is_service_enabled n-api-meta; then |
| 559 | NOVA_ENABLED_APIS=$(echo $NOVA_ENABLED_APIS | sed "s/,metadata//") |
| 560 | iniset $NOVA_CONF DEFAULT enabled_apis $NOVA_ENABLED_APIS |
| 561 | iniset $NOVA_CELLS_CONF DEFAULT enabled_apis metadata |
| 562 | fi |
| 563 | |
| 564 | $NOVA_BIN_DIR/nova-manage --config-file $NOVA_CELLS_CONF db sync |
| 565 | $NOVA_BIN_DIR/nova-manage --config-file $NOVA_CELLS_CONF cell create --name=region --cell_type=parent --username=guest --hostname=$RABBIT_HOST --port=5672 --password=$RABBIT_PASSWORD --virtual_host=/ --woffset=0 --wscale=1 |
| 566 | $NOVA_BIN_DIR/nova-manage cell create --name=child --cell_type=child --username=guest --hostname=$RABBIT_HOST --port=5672 --password=$RABBIT_PASSWORD --virtual_host=child_cell --woffset=0 --wscale=1 |
| 567 | fi |
| 568 | } |
| 569 | |
Dean Troyer | f03bafe | 2013-02-12 10:58:28 -0600 | [diff] [blame] | 570 | # create_nova_cache_dir() - Part of the init_nova() process |
| 571 | function create_nova_cache_dir() { |
| 572 | # Create cache dir |
| 573 | sudo mkdir -p $NOVA_AUTH_CACHE_DIR |
| 574 | sudo chown $STACK_USER $NOVA_AUTH_CACHE_DIR |
| 575 | rm -f $NOVA_AUTH_CACHE_DIR/* |
| 576 | } |
| 577 | |
Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 578 | function create_nova_conf_nova_network() { |
Dean Troyer | b323691 | 2013-03-17 15:17:05 -0500 | [diff] [blame] | 579 | iniset $NOVA_CONF DEFAULT network_manager "nova.network.manager.$NETWORK_MANAGER" |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame] | 580 | iniset $NOVA_CONF DEFAULT public_interface "$PUBLIC_INTERFACE" |
| 581 | iniset $NOVA_CONF DEFAULT vlan_interface "$VLAN_INTERFACE" |
| 582 | iniset $NOVA_CONF DEFAULT flat_network_bridge "$FLAT_NETWORK_BRIDGE" |
Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 583 | if [ -n "$FLAT_INTERFACE" ]; then |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame] | 584 | iniset $NOVA_CONF DEFAULT flat_interface "$FLAT_INTERFACE" |
Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 585 | fi |
| 586 | } |
| 587 | |
Dean Troyer | f03bafe | 2013-02-12 10:58:28 -0600 | [diff] [blame] | 588 | # create_nova_keys_dir() - Part of the init_nova() process |
| 589 | function create_nova_keys_dir() { |
| 590 | # Create keys dir |
| 591 | sudo mkdir -p ${NOVA_STATE_PATH}/keys |
| 592 | sudo chown -R $STACK_USER ${NOVA_STATE_PATH} |
| 593 | } |
| 594 | |
Dean Troyer | da7b809 | 2012-10-08 18:12:14 -0500 | [diff] [blame] | 595 | # init_nova() - Initialize databases, etc. |
| 596 | function init_nova() { |
Dean Troyer | f03bafe | 2013-02-12 10:58:28 -0600 | [diff] [blame] | 597 | # All nova components talk to a central database. |
| 598 | # Only do this step once on the API node for an entire cluster. |
Bob Melander | c439b5d | 2012-12-19 14:49:34 +0100 | [diff] [blame] | 599 | if is_service_enabled $DATABASE_BACKENDS && is_service_enabled n-api; then |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 600 | # (Re)create nova database |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 601 | # Explicitly use latin1: to avoid lp#829209, nova expects the database to |
| 602 | # use latin1 by default, and then upgrades the database to utf8 (see the |
| 603 | # 082_essex.py in nova) |
Terry Wilson | 428af5a | 2012-11-01 16:12:39 -0400 | [diff] [blame] | 604 | recreate_database nova latin1 |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 605 | |
Dean Troyer | f03bafe | 2013-02-12 10:58:28 -0600 | [diff] [blame] | 606 | # Migrate nova database |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 607 | $NOVA_BIN_DIR/nova-manage db sync |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 608 | |
Kieran Spear | fb2a3ae | 2013-03-11 23:55:49 +0000 | [diff] [blame] | 609 | if is_service_enabled n-cell; then |
| 610 | recreate_database $NOVA_CELLS_DB latin1 |
| 611 | fi |
| 612 | |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 613 | # (Re)create nova baremetal database |
| 614 | if is_baremetal; then |
| 615 | recreate_database nova_bm latin1 |
| 616 | $NOVA_BIN_DIR/nova-baremetal-manage db sync |
| 617 | fi |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 618 | fi |
| 619 | |
Dean Troyer | f03bafe | 2013-02-12 10:58:28 -0600 | [diff] [blame] | 620 | create_nova_cache_dir |
| 621 | create_nova_keys_dir |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | # install_novaclient() - Collect source and prepare |
| 625 | function install_novaclient() { |
| 626 | git_clone $NOVACLIENT_REPO $NOVACLIENT_DIR $NOVACLIENT_BRANCH |
Dean Troyer | 253a1a3 | 2013-04-01 18:23:22 -0500 | [diff] [blame] | 627 | setup_develop $NOVACLIENT_DIR |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | # install_nova() - Collect source and prepare |
| 631 | function install_nova() { |
| 632 | if is_service_enabled n-cpu; then |
Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 633 | if is_ubuntu; then |
Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 634 | install_package libvirt-bin |
| 635 | elif is_fedora || is_suse; then |
| 636 | install_package libvirt |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 637 | else |
Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 638 | exit_distro_not_supported "libvirt installation" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 639 | fi |
Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 640 | |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 641 | # Install and configure **LXC** if specified. LXC is another approach to |
| 642 | # splitting a system into many smaller parts. LXC uses cgroups and chroot |
| 643 | # to simulate multiple systems. |
| 644 | if [[ "$LIBVIRT_TYPE" == "lxc" ]]; then |
Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 645 | if is_ubuntu; then |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 646 | if [[ "$DISTRO" > natty ]]; then |
| 647 | install_package cgroup-lite |
| 648 | fi |
| 649 | else |
| 650 | ### FIXME(dtroyer): figure this out |
| 651 | echo "RPM-based cgroup not implemented yet" |
| 652 | yum_install libcgroup-tools |
| 653 | fi |
| 654 | fi |
| 655 | fi |
| 656 | |
| 657 | git_clone $NOVA_REPO $NOVA_DIR $NOVA_BRANCH |
Dean Troyer | 253a1a3 | 2013-04-01 18:23:22 -0500 | [diff] [blame] | 658 | setup_develop $NOVA_DIR |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 659 | } |
| 660 | |
Dean Troyer | 3a3a2ba | 2012-12-11 15:26:24 -0600 | [diff] [blame] | 661 | # start_nova_api() - Start the API process ahead of other things |
| 662 | function start_nova_api() { |
| 663 | # Get right service port for testing |
| 664 | local service_port=$NOVA_SERVICE_PORT |
| 665 | if is_service_enabled tls-proxy; then |
| 666 | service_port=$NOVA_SERVICE_PORT_INT |
| 667 | fi |
| 668 | |
| 669 | screen_it n-api "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-api" |
| 670 | echo "Waiting for nova-api to start..." |
| 671 | if ! wait_for_service $SERVICE_TIMEOUT http://$SERVICE_HOST:$service_port; then |
Nachi Ueno | 07115eb | 2013-02-26 12:38:18 -0800 | [diff] [blame] | 672 | die $LINENO "nova-api did not start" |
Dean Troyer | 3a3a2ba | 2012-12-11 15:26:24 -0600 | [diff] [blame] | 673 | fi |
| 674 | |
| 675 | # Start proxies if enabled |
| 676 | if is_service_enabled tls-proxy; then |
| 677 | start_tls_proxy '*' $NOVA_SERVICE_PORT $NOVA_SERVICE_HOST $NOVA_SERVICE_PORT_INT & |
| 678 | fi |
| 679 | } |
| 680 | |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 681 | # start_nova() - Start running processes, including screen |
| 682 | function start_nova() { |
Kieran Spear | fb2a3ae | 2013-03-11 23:55:49 +0000 | [diff] [blame] | 683 | NOVA_CONF_BOTTOM=$NOVA_CONF |
| 684 | |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 685 | # ``screen_it`` checks ``is_service_enabled``, it is not needed here |
Russell Bryant | ff7f308 | 2012-11-29 22:00:51 -0500 | [diff] [blame] | 686 | screen_it n-cond "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-conductor" |
Kieran Spear | fb2a3ae | 2013-03-11 23:55:49 +0000 | [diff] [blame] | 687 | |
| 688 | if is_service_enabled n-cell; then |
| 689 | NOVA_CONF_BOTTOM=$NOVA_CELLS_CONF |
| 690 | screen_it n-cond "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-conductor --config-file $NOVA_CELLS_CONF" |
| 691 | screen_it n-cell "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-cells --config-file $NOVA_CONF" |
| 692 | screen_it n-cell "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-cells --config-file $NOVA_CELLS_CONF" |
| 693 | fi |
| 694 | |
| 695 | # The group **$LIBVIRT_GROUP** is added to the current user in this script. |
| 696 | # Use 'sg' to execute nova-compute as a member of the **$LIBVIRT_GROUP** group. |
Ben Nemec | 2fce0a9 | 2013-05-22 21:13:11 +0000 | [diff] [blame] | 697 | screen_it n-cpu "cd $NOVA_DIR && sg $LIBVIRT_GROUP '$NOVA_BIN_DIR/nova-compute --config-file $NOVA_CONF_BOTTOM'" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 698 | screen_it n-crt "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-cert" |
Kieran Spear | fb2a3ae | 2013-03-11 23:55:49 +0000 | [diff] [blame] | 699 | screen_it n-net "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-network --config-file $NOVA_CONF_BOTTOM" |
| 700 | screen_it n-sch "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-scheduler --config-file $NOVA_CONF_BOTTOM" |
| 701 | screen_it n-api-meta "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-api-metadata --config-file $NOVA_CONF_BOTTOM" |
| 702 | |
Daniel P. Berrange | 3edddd1 | 2013-01-03 12:06:47 +0000 | [diff] [blame] | 703 | screen_it n-novnc "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-novncproxy --config-file $NOVA_CONF --web $NOVNC_DIR" |
Monty Taylor | 0edfd6f | 2012-11-23 15:00:38 -0800 | [diff] [blame] | 704 | screen_it n-xvnc "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-xvpvncproxy --config-file $NOVA_CONF" |
Daniel P. Berrange | d10e12f | 2013-01-03 11:51:42 +0000 | [diff] [blame] | 705 | screen_it n-spice "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-spicehtml5proxy --config-file $NOVA_CONF --web $SPICE_DIR" |
Monty Taylor | 0edfd6f | 2012-11-23 15:00:38 -0800 | [diff] [blame] | 706 | screen_it n-cauth "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-consoleauth" |
Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 707 | |
| 708 | # Starting the nova-objectstore only if swift3 service is not enabled. |
| 709 | # Swift will act as s3 objectstore. |
| 710 | is_service_enabled swift3 || \ |
| 711 | screen_it n-obj "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-objectstore" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | # stop_nova() - Stop running processes (non-screen) |
| 715 | function stop_nova() { |
| 716 | # Kill the nova screen windows |
Kieran Spear | fb2a3ae | 2013-03-11 23:55:49 +0000 | [diff] [blame] | 717 | # Some services are listed here twice since more than one instance |
| 718 | # of a service may be running in certain configs. |
| 719 | for serv in n-api n-cpu n-crt n-net n-sch n-novnc n-xvnc n-cauth n-spice n-cond n-cond n-cell n-cell n-api-meta; do |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 720 | screen -S $SCREEN_NAME -p $serv -X kill |
| 721 | done |
| 722 | } |
| 723 | |
Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 724 | |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 725 | # Restore xtrace |
| 726 | $XTRACE |
Sean Dague | 584d90e | 2013-03-29 14:34:53 -0400 | [diff] [blame] | 727 | |
| 728 | # Local variables: |
| 729 | # mode: shell-script |
| 730 | # End: |