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