Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 1 | # lib/nova |
| 2 | # Functions to control the configuration and operation of the XXXX service |
| 3 | |
| 4 | # Dependencies: |
| 5 | # ``functions`` file |
| 6 | # ``DEST``, ``DATA_DIR`` must be defined |
| 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 | |
| 42 | # Support entry points installation of console scripts |
| 43 | if [[ -d $NOVA_DIR/bin ]]; then |
| 44 | NOVA_BIN_DIR=$NOVA_DIR/bin |
| 45 | else |
| 46 | NOVA_BIN_DIR=/usr/local/bin |
| 47 | fi |
| 48 | |
| 49 | # Set the paths of certain binaries |
Vincent Untz | 856a11e | 2012-11-21 16:04:12 +0100 | [diff] [blame] | 50 | NOVA_ROOTWRAP=$(get_rootwrap_location nova) |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 51 | |
| 52 | # Allow rate limiting to be turned off for testing, like for Tempest |
| 53 | # NOTE: Set API_RATE_LIMIT="False" to turn OFF rate limiting |
| 54 | API_RATE_LIMIT=${API_RATE_LIMIT:-"True"} |
| 55 | |
| 56 | # Nova supports pluggable schedulers. The default ``FilterScheduler`` |
| 57 | # should work in most cases. |
| 58 | SCHEDULER=${SCHEDULER:-nova.scheduler.filter_scheduler.FilterScheduler} |
| 59 | |
| 60 | QEMU_CONF=/etc/libvirt/qemu.conf |
| 61 | |
| 62 | |
| 63 | # Entry Points |
| 64 | # ------------ |
| 65 | |
| 66 | function add_nova_opt { |
| 67 | echo "$1" >>$NOVA_CONF |
| 68 | } |
| 69 | |
| 70 | # Helper to clean iptables rules |
| 71 | function clean_iptables() { |
| 72 | # Delete rules |
| 73 | 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 |
| 74 | # Delete nat rules |
| 75 | 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 |
| 76 | # Delete chains |
| 77 | 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 |
| 78 | # Delete nat chains |
| 79 | 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 |
| 80 | } |
| 81 | |
| 82 | # cleanup_nova() - Remove residual data files, anything left over from previous |
| 83 | # runs that a clean run would need to clean up |
| 84 | function cleanup_nova() { |
| 85 | if is_service_enabled n-cpu; then |
| 86 | # Clean iptables from previous runs |
| 87 | clean_iptables |
| 88 | |
| 89 | # Destroy old instances |
| 90 | instances=`sudo virsh list --all | grep $INSTANCE_NAME_PREFIX | sed "s/.*\($INSTANCE_NAME_PREFIX[0-9a-fA-F]*\).*/\1/g"` |
| 91 | if [ ! "$instances" = "" ]; then |
| 92 | echo $instances | xargs -n1 sudo virsh destroy || true |
| 93 | echo $instances | xargs -n1 sudo virsh undefine || true |
| 94 | fi |
| 95 | |
| 96 | # Logout and delete iscsi sessions |
| 97 | sudo iscsiadm --mode node | grep $VOLUME_NAME_PREFIX | cut -d " " -f2 | xargs sudo iscsiadm --mode node --logout || true |
| 98 | sudo iscsiadm --mode node | grep $VOLUME_NAME_PREFIX | cut -d " " -f2 | sudo iscsiadm --mode node --op delete || true |
| 99 | |
| 100 | # Clean out the instances directory. |
| 101 | sudo rm -rf $NOVA_INSTANCES_PATH/* |
| 102 | fi |
| 103 | } |
| 104 | |
| 105 | # configure_novaclient() - Set config files, create data dirs, etc |
| 106 | function configure_novaclient() { |
| 107 | setup_develop $NOVACLIENT_DIR |
| 108 | } |
| 109 | |
| 110 | # configure_nova_rootwrap() - configure Nova's rootwrap |
| 111 | function configure_nova_rootwrap() { |
| 112 | # Deploy new rootwrap filters files (owned by root). |
| 113 | # Wipe any existing rootwrap.d files first |
| 114 | if [[ -d $NOVA_CONF_DIR/rootwrap.d ]]; then |
| 115 | sudo rm -rf $NOVA_CONF_DIR/rootwrap.d |
| 116 | fi |
| 117 | # Deploy filters to /etc/nova/rootwrap.d |
| 118 | sudo mkdir -m 755 $NOVA_CONF_DIR/rootwrap.d |
| 119 | sudo cp $NOVA_DIR/etc/nova/rootwrap.d/*.filters $NOVA_CONF_DIR/rootwrap.d |
| 120 | sudo chown -R root:root $NOVA_CONF_DIR/rootwrap.d |
| 121 | sudo chmod 644 $NOVA_CONF_DIR/rootwrap.d/* |
| 122 | # Set up rootwrap.conf, pointing to /etc/nova/rootwrap.d |
| 123 | sudo cp $NOVA_DIR/etc/nova/rootwrap.conf $NOVA_CONF_DIR/ |
| 124 | sudo sed -e "s:^filters_path=.*$:filters_path=$NOVA_CONF_DIR/rootwrap.d:" -i $NOVA_CONF_DIR/rootwrap.conf |
| 125 | sudo chown root:root $NOVA_CONF_DIR/rootwrap.conf |
| 126 | sudo chmod 0644 $NOVA_CONF_DIR/rootwrap.conf |
| 127 | # Specify rootwrap.conf as first parameter to nova-rootwrap |
| 128 | ROOTWRAP_SUDOER_CMD="$NOVA_ROOTWRAP $NOVA_CONF_DIR/rootwrap.conf *" |
| 129 | |
| 130 | # Set up the rootwrap sudoers for nova |
| 131 | TEMPFILE=`mktemp` |
| 132 | echo "$USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE |
| 133 | chmod 0440 $TEMPFILE |
| 134 | sudo chown root:root $TEMPFILE |
| 135 | sudo mv $TEMPFILE /etc/sudoers.d/nova-rootwrap |
| 136 | } |
| 137 | |
| 138 | # configure_nova() - Set config files, create data dirs, etc |
| 139 | function configure_nova() { |
| 140 | setup_develop $NOVA_DIR |
| 141 | |
| 142 | # Put config files in ``/etc/nova`` for everyone to find |
| 143 | if [[ ! -d $NOVA_CONF_DIR ]]; then |
| 144 | sudo mkdir -p $NOVA_CONF_DIR |
| 145 | fi |
| 146 | sudo chown `whoami` $NOVA_CONF_DIR |
| 147 | |
| 148 | cp -p $NOVA_DIR/etc/nova/policy.json $NOVA_CONF_DIR |
| 149 | |
| 150 | configure_nova_rootwrap |
| 151 | |
| 152 | if is_service_enabled n-api; then |
| 153 | # Use the sample http middleware configuration supplied in the |
| 154 | # Nova sources. This paste config adds the configuration required |
| 155 | # for Nova to validate Keystone tokens. |
| 156 | |
| 157 | # Remove legacy paste config if present |
| 158 | rm -f $NOVA_DIR/bin/nova-api-paste.ini |
| 159 | |
| 160 | # Get the sample configuration file in place |
| 161 | cp $NOVA_DIR/etc/nova/api-paste.ini $NOVA_CONF_DIR |
| 162 | |
| 163 | # Rewrite the authtoken configuration for our Keystone service. |
| 164 | # This is a bit defensive to allow the sample file some variance. |
| 165 | sed -e " |
| 166 | /^admin_token/i admin_tenant_name = $SERVICE_TENANT_NAME |
| 167 | /admin_tenant_name/s/^.*$/admin_tenant_name = $SERVICE_TENANT_NAME/; |
| 168 | /admin_user/s/^.*$/admin_user = nova/; |
| 169 | /admin_password/s/^.*$/admin_password = $SERVICE_PASSWORD/; |
| 170 | s,%SERVICE_TENANT_NAME%,$SERVICE_TENANT_NAME,g; |
| 171 | s,%SERVICE_TOKEN%,$SERVICE_TOKEN,g; |
| 172 | " -i $NOVA_API_PASTE_INI |
| 173 | fi |
| 174 | |
Akihiro MOTOKI | 5e3deb6 | 2012-12-11 17:09:02 +0900 | [diff] [blame] | 175 | 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] | 176 | |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 177 | if is_service_enabled n-cpu; then |
| 178 | # Force IP forwarding on, just on case |
| 179 | sudo sysctl -w net.ipv4.ip_forward=1 |
| 180 | |
| 181 | # Attempt to load modules: network block device - used to manage qcow images |
| 182 | sudo modprobe nbd || true |
| 183 | |
| 184 | # Check for kvm (hardware based virtualization). If unable to initialize |
| 185 | # kvm, we drop back to the slower emulation mode (qemu). Note: many systems |
| 186 | # come with hardware virtualization disabled in BIOS. |
| 187 | if [[ "$LIBVIRT_TYPE" == "kvm" ]]; then |
| 188 | sudo modprobe kvm || true |
| 189 | if [ ! -e /dev/kvm ]; then |
| 190 | echo "WARNING: Switching to QEMU" |
| 191 | LIBVIRT_TYPE=qemu |
| 192 | if which selinuxenabled 2>&1 > /dev/null && selinuxenabled; then |
| 193 | # https://bugzilla.redhat.com/show_bug.cgi?id=753589 |
| 194 | sudo setsebool virt_use_execmem on |
| 195 | fi |
| 196 | fi |
| 197 | fi |
| 198 | |
| 199 | # Install and configure **LXC** if specified. LXC is another approach to |
| 200 | # splitting a system into many smaller parts. LXC uses cgroups and chroot |
| 201 | # to simulate multiple systems. |
| 202 | if [[ "$LIBVIRT_TYPE" == "lxc" ]]; then |
Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 203 | if is_ubuntu; then |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 204 | if [[ ! "$DISTRO" > natty ]]; then |
| 205 | cgline="none /cgroup cgroup cpuacct,memory,devices,cpu,freezer,blkio 0 0" |
| 206 | sudo mkdir -p /cgroup |
| 207 | if ! grep -q cgroup /etc/fstab; then |
| 208 | echo "$cgline" | sudo tee -a /etc/fstab |
| 209 | fi |
| 210 | if ! mount -n | grep -q cgroup; then |
| 211 | sudo mount /cgroup |
| 212 | fi |
| 213 | fi |
| 214 | fi |
| 215 | fi |
| 216 | |
Yoshihiro Kaneko | 602cf9b | 2012-07-23 06:27:36 +0000 | [diff] [blame] | 217 | if is_service_enabled quantum && is_quantum_ovs_base_plugin "$Q_PLUGIN" && ! sudo grep -q '^cgroup_device_acl' $QEMU_CONF ; then |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 218 | # Add /dev/net/tun to cgroup_device_acls, needed for type=ethernet interfaces |
| 219 | cat <<EOF | sudo tee -a $QEMU_CONF |
| 220 | cgroup_device_acl = [ |
| 221 | "/dev/null", "/dev/full", "/dev/zero", |
| 222 | "/dev/random", "/dev/urandom", |
| 223 | "/dev/ptmx", "/dev/kvm", "/dev/kqemu", |
| 224 | "/dev/rtc", "/dev/hpet","/dev/net/tun", |
| 225 | ] |
| 226 | EOF |
| 227 | fi |
| 228 | |
Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 229 | if is_ubuntu; then |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 230 | LIBVIRT_DAEMON=libvirt-bin |
| 231 | else |
Vincent Untz | f1c094c | 2012-12-05 17:59:04 +0100 | [diff] [blame] | 232 | LIBVIRT_DAEMON=libvirtd |
| 233 | fi |
| 234 | |
| 235 | # For distributions using polkit to authorize access to libvirt, |
| 236 | # configure polkit accordingly. |
| 237 | # Based on http://wiki.libvirt.org/page/SSHPolicyKitSetup |
| 238 | if is_fedora; then |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 239 | sudo bash -c 'cat <<EOF >/etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla |
| 240 | [libvirt Management Access] |
| 241 | Identity=unix-group:libvirtd |
| 242 | Action=org.libvirt.unix.manage |
| 243 | ResultAny=yes |
| 244 | ResultInactive=yes |
| 245 | ResultActive=yes |
| 246 | EOF' |
Vincent Untz | f1c094c | 2012-12-05 17:59:04 +0100 | [diff] [blame] | 247 | elif is_suse; then |
| 248 | # Work around the fact that polkit-default-privs overrules pklas |
| 249 | # with 'unix-group:$group'. |
| 250 | sudo bash -c "cat <<EOF >/etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla |
| 251 | [libvirt Management Access] |
| 252 | Identity=unix-user:$USER |
| 253 | Action=org.libvirt.unix.manage |
| 254 | ResultAny=yes |
| 255 | ResultInactive=yes |
| 256 | ResultActive=yes |
| 257 | EOF" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 258 | fi |
| 259 | |
| 260 | # The user that nova runs as needs to be member of **libvirtd** group otherwise |
| 261 | # nova-compute will be unable to use libvirt. |
Vincent Untz | f1c094c | 2012-12-05 17:59:04 +0100 | [diff] [blame] | 262 | if ! getent group libvirtd >/dev/null; then |
| 263 | sudo groupadd libvirtd |
| 264 | fi |
Vincent Untz | 856a11e | 2012-11-21 16:04:12 +0100 | [diff] [blame] | 265 | add_user_to_group `whoami` libvirtd |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 266 | |
| 267 | # libvirt detects various settings on startup, as we potentially changed |
| 268 | # the system configuration (modules, filesystems), we need to restart |
| 269 | # libvirt to detect those changes. |
| 270 | restart_service $LIBVIRT_DAEMON |
| 271 | |
| 272 | |
| 273 | # Instance Storage |
| 274 | # ---------------- |
| 275 | |
| 276 | # Nova stores each instance in its own directory. |
| 277 | mkdir -p $NOVA_INSTANCES_PATH |
| 278 | |
| 279 | # You can specify a different disk to be mounted and used for backing the |
| 280 | # virtual machines. If there is a partition labeled nova-instances we |
| 281 | # mount it (ext filesystems can be labeled via e2label). |
| 282 | if [ -L /dev/disk/by-label/nova-instances ]; then |
| 283 | if ! mount -n | grep -q $NOVA_INSTANCES_PATH; then |
| 284 | sudo mount -L nova-instances $NOVA_INSTANCES_PATH |
| 285 | sudo chown -R `whoami` $NOVA_INSTANCES_PATH |
| 286 | fi |
| 287 | fi |
| 288 | |
| 289 | # Clean up old instances |
| 290 | cleanup_nova |
| 291 | fi |
| 292 | } |
| 293 | |
Dean Troyer | a0dce26 | 2012-12-11 16:52:37 -0600 | [diff] [blame] | 294 | # create_nova_accounts() - Set up common required nova accounts |
| 295 | |
| 296 | # Tenant User Roles |
| 297 | # ------------------------------------------------------------------ |
| 298 | # service nova admin, [ResellerAdmin (swift only)] |
| 299 | |
| 300 | # Migrated from keystone_data.sh |
| 301 | create_nova_accounts() { |
| 302 | |
| 303 | SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }") |
| 304 | ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }") |
| 305 | |
| 306 | # Nova |
| 307 | if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then |
| 308 | NOVA_USER=$(keystone user-create \ |
| 309 | --name=nova \ |
| 310 | --pass="$SERVICE_PASSWORD" \ |
| 311 | --tenant_id $SERVICE_TENANT \ |
| 312 | --email=nova@example.com \ |
| 313 | | grep " id " | get_field 2) |
| 314 | keystone user-role-add \ |
| 315 | --tenant_id $SERVICE_TENANT \ |
| 316 | --user_id $NOVA_USER \ |
| 317 | --role_id $ADMIN_ROLE |
| 318 | if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then |
| 319 | NOVA_SERVICE=$(keystone service-create \ |
| 320 | --name=nova \ |
| 321 | --type=compute \ |
| 322 | --description="Nova Compute Service" \ |
| 323 | | grep " id " | get_field 2) |
| 324 | keystone endpoint-create \ |
| 325 | --region RegionOne \ |
| 326 | --service_id $NOVA_SERVICE \ |
| 327 | --publicurl "http://$SERVICE_HOST:\$(compute_port)s/v2/\$(tenant_id)s" \ |
| 328 | --adminurl "http://$SERVICE_HOST:\$(compute_port)s/v2/\$(tenant_id)s" \ |
| 329 | --internalurl "http://$SERVICE_HOST:\$(compute_port)s/v2/\$(tenant_id)s" |
| 330 | fi |
| 331 | fi |
| 332 | } |
| 333 | |
Dean Troyer | da7b809 | 2012-10-08 18:12:14 -0500 | [diff] [blame] | 334 | # create_nova_conf() - Create a new nova.conf file |
| 335 | function create_nova_conf() { |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 336 | # Remove legacy ``nova.conf`` |
| 337 | rm -f $NOVA_DIR/bin/nova.conf |
| 338 | |
| 339 | # (Re)create ``nova.conf`` |
Dean Troyer | 3cf1ffb | 2012-10-02 11:51:27 -0500 | [diff] [blame] | 340 | rm -f $NOVA_CONF |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 341 | add_nova_opt "[DEFAULT]" |
| 342 | add_nova_opt "verbose=True" |
| 343 | add_nova_opt "auth_strategy=keystone" |
| 344 | add_nova_opt "allow_resize_to_same_host=True" |
| 345 | add_nova_opt "api_paste_config=$NOVA_API_PASTE_INI" |
| 346 | add_nova_opt "rootwrap_config=$NOVA_CONF_DIR/rootwrap.conf" |
| 347 | add_nova_opt "compute_scheduler_driver=$SCHEDULER" |
Dean Troyer | 3cf1ffb | 2012-10-02 11:51:27 -0500 | [diff] [blame] | 348 | add_nova_opt "dhcpbridge_flagfile=$NOVA_CONF" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 349 | add_nova_opt "force_dhcp_release=True" |
| 350 | add_nova_opt "fixed_range=$FIXED_RANGE" |
| 351 | add_nova_opt "s3_host=$SERVICE_HOST" |
| 352 | add_nova_opt "s3_port=$S3_SERVICE_PORT" |
| 353 | add_nova_opt "osapi_compute_extension=nova.api.openstack.compute.contrib.standard_extensions" |
| 354 | add_nova_opt "my_ip=$HOST_IP" |
Terry Wilson | 428af5a | 2012-11-01 16:12:39 -0400 | [diff] [blame] | 355 | local dburl |
| 356 | database_connection_url dburl nova |
| 357 | add_nova_opt "sql_connection=$dburl" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 358 | add_nova_opt "libvirt_type=$LIBVIRT_TYPE" |
| 359 | add_nova_opt "libvirt_cpu_mode=none" |
| 360 | add_nova_opt "instance_name_template=${INSTANCE_NAME_PREFIX}%08x" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 361 | |
| 362 | if is_service_enabled n-api; then |
| 363 | add_nova_opt "enabled_apis=$NOVA_ENABLED_APIS" |
| 364 | fi |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 365 | if is_service_enabled cinder; then |
| 366 | add_nova_opt "volume_api_class=nova.volume.cinder.API" |
| 367 | fi |
| 368 | if [ -n "$NOVA_STATE_PATH" ]; then |
| 369 | add_nova_opt "state_path=$NOVA_STATE_PATH" |
Dean Troyer | 1331445 | 2012-10-23 15:09:50 -0500 | [diff] [blame] | 370 | add_nova_opt "lock_path=$NOVA_STATE_PATH" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 371 | fi |
| 372 | if [ -n "$NOVA_INSTANCES_PATH" ]; then |
| 373 | add_nova_opt "instances_path=$NOVA_INSTANCES_PATH" |
| 374 | fi |
| 375 | if [ "$MULTI_HOST" != "False" ]; then |
| 376 | add_nova_opt "multi_host=True" |
| 377 | add_nova_opt "send_arp_for_ha=True" |
| 378 | fi |
| 379 | if [ "$SYSLOG" != "False" ]; then |
| 380 | add_nova_opt "use_syslog=True" |
| 381 | fi |
| 382 | if [ "$API_RATE_LIMIT" != "True" ]; then |
| 383 | add_nova_opt "api_rate_limit=False" |
| 384 | fi |
| 385 | if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then |
| 386 | # Add color to logging output |
| 387 | add_nova_opt "logging_context_format_string=%(asctime)s %(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" |
| 388 | add_nova_opt "logging_default_format_string=%(asctime)s %(color)s%(levelname)s %(name)s [[00;36m-%(color)s] [01;35m%(instance)s%(color)s%(message)s[00m" |
| 389 | add_nova_opt "logging_debug_format_suffix=[00;33mfrom (pid=%(process)d) %(funcName)s %(pathname)s:%(lineno)d[00m" |
| 390 | add_nova_opt "logging_exception_prefix=%(color)s%(asctime)s TRACE %(name)s [01;35m%(instance)s[00m" |
| 391 | else |
| 392 | # Show user_name and project_name instead of user_id and project_id |
| 393 | add_nova_opt "logging_context_format_string=%(asctime)s %(levelname)s %(name)s [%(request_id)s %(user_name)s %(project_name)s] %(instance)s%(message)s" |
| 394 | fi |
Eoghan Glynn | 1fcc6a1 | 2012-10-25 14:57:14 +0000 | [diff] [blame] | 395 | if is_service_enabled ceilometer; then |
| 396 | add_nova_opt "instance_usage_audit=True" |
| 397 | add_nova_opt "instance_usage_audit_period=hour" |
| 398 | add_nova_opt "notification_driver=nova.openstack.common.notifier.rabbit_notifier" |
| 399 | add_nova_opt "notification_driver=ceilometer.compute.nova_notifier" |
| 400 | fi |
| 401 | |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 402 | |
| 403 | # Provide some transition from ``EXTRA_FLAGS`` to ``EXTRA_OPTS`` |
| 404 | if [[ -z "$EXTRA_OPTS" && -n "$EXTRA_FLAGS" ]]; then |
| 405 | EXTRA_OPTS=$EXTRA_FLAGS |
| 406 | fi |
| 407 | |
| 408 | # Define extra nova conf flags by defining the array ``EXTRA_OPTS``. |
| 409 | # For Example: ``EXTRA_OPTS=(foo=true bar=2)`` |
| 410 | for I in "${EXTRA_OPTS[@]}"; do |
| 411 | # Attempt to convert flags to options |
| 412 | add_nova_opt ${I//--} |
| 413 | done |
Dean Troyer | da7b809 | 2012-10-08 18:12:14 -0500 | [diff] [blame] | 414 | } |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 415 | |
Dean Troyer | da7b809 | 2012-10-08 18:12:14 -0500 | [diff] [blame] | 416 | # init_nova() - Initialize databases, etc. |
| 417 | function init_nova() { |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 418 | # Nova Database |
| 419 | # ------------- |
| 420 | |
| 421 | # All nova components talk to a central database. We will need to do this step |
| 422 | # only once for an entire cluster. |
| 423 | |
Terry Wilson | 428af5a | 2012-11-01 16:12:39 -0400 | [diff] [blame] | 424 | if is_service_enabled $DATABASE_BACKENDS && is_service_enabled nova; then |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 425 | # (Re)create nova database |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 426 | # Explicitly use latin1: to avoid lp#829209, nova expects the database to |
| 427 | # use latin1 by default, and then upgrades the database to utf8 (see the |
| 428 | # 082_essex.py in nova) |
Terry Wilson | 428af5a | 2012-11-01 16:12:39 -0400 | [diff] [blame] | 429 | recreate_database nova latin1 |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 430 | |
| 431 | # (Re)create nova database |
| 432 | $NOVA_BIN_DIR/nova-manage db sync |
| 433 | fi |
| 434 | |
Akihiro MOTOKI | 5e3deb6 | 2012-12-11 17:09:02 +0900 | [diff] [blame] | 435 | # Create cache dir |
| 436 | sudo mkdir -p $NOVA_AUTH_CACHE_DIR |
| 437 | sudo chown `whoami` $NOVA_AUTH_CACHE_DIR |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | # install_novaclient() - Collect source and prepare |
| 441 | function install_novaclient() { |
| 442 | git_clone $NOVACLIENT_REPO $NOVACLIENT_DIR $NOVACLIENT_BRANCH |
| 443 | } |
| 444 | |
| 445 | # install_nova() - Collect source and prepare |
| 446 | function install_nova() { |
| 447 | if is_service_enabled n-cpu; then |
Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 448 | if is_ubuntu; then |
Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 449 | install_package libvirt-bin |
| 450 | elif is_fedora || is_suse; then |
| 451 | install_package libvirt |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 452 | else |
Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 453 | exit_distro_not_supported "libvirt installation" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 454 | fi |
Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 455 | |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 456 | # Install and configure **LXC** if specified. LXC is another approach to |
| 457 | # splitting a system into many smaller parts. LXC uses cgroups and chroot |
| 458 | # to simulate multiple systems. |
| 459 | if [[ "$LIBVIRT_TYPE" == "lxc" ]]; then |
Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 460 | if is_ubuntu; then |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 461 | if [[ "$DISTRO" > natty ]]; then |
| 462 | install_package cgroup-lite |
| 463 | fi |
| 464 | else |
| 465 | ### FIXME(dtroyer): figure this out |
| 466 | echo "RPM-based cgroup not implemented yet" |
| 467 | yum_install libcgroup-tools |
| 468 | fi |
| 469 | fi |
| 470 | fi |
| 471 | |
| 472 | git_clone $NOVA_REPO $NOVA_DIR $NOVA_BRANCH |
| 473 | } |
| 474 | |
| 475 | # start_nova() - Start running processes, including screen |
| 476 | function start_nova() { |
| 477 | # The group **libvirtd** is added to the current user in this script. |
| 478 | # Use 'sg' to execute nova-compute as a member of the **libvirtd** group. |
| 479 | # ``screen_it`` checks ``is_service_enabled``, it is not needed here |
Russell Bryant | ff7f308 | 2012-11-29 22:00:51 -0500 | [diff] [blame] | 480 | screen_it n-cond "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-conductor" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 481 | screen_it n-cpu "cd $NOVA_DIR && sg libvirtd $NOVA_BIN_DIR/nova-compute" |
| 482 | screen_it n-crt "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-cert" |
| 483 | screen_it n-net "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-network" |
| 484 | screen_it n-sch "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-scheduler" |
Dean Troyer | 3cf1ffb | 2012-10-02 11:51:27 -0500 | [diff] [blame] | 485 | screen_it n-novnc "cd $NOVNC_DIR && ./utils/nova-novncproxy --config-file $NOVA_CONF --web ." |
Monty Taylor | 0edfd6f | 2012-11-23 15:00:38 -0800 | [diff] [blame] | 486 | screen_it n-xvnc "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-xvpvncproxy --config-file $NOVA_CONF" |
| 487 | screen_it n-cauth "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-consoleauth" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | # stop_nova() - Stop running processes (non-screen) |
| 491 | function stop_nova() { |
| 492 | # Kill the nova screen windows |
Dan Smith | d57ccf0 | 2012-11-15 10:09:33 -0800 | [diff] [blame] | 493 | for serv in n-api n-cpu n-crt n-net n-sch n-novnc n-xvnc n-cauth n-cond; do |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 494 | screen -S $SCREEN_NAME -p $serv -X kill |
| 495 | done |
| 496 | } |
| 497 | |
| 498 | # Restore xtrace |
| 499 | $XTRACE |