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 | |
Dean Troyer | bc071bc | 2012-10-01 14:06:44 -0500 | [diff] [blame] | 175 | if [[ "$KEYSTONE_TOKEN_FORMAT" == "PKI" ]]; then |
| 176 | iniset $NOVA_API_PASTE_INI filter:authtoken signing_dir $NOVA_AUTH_CACHE_DIR |
| 177 | fi |
| 178 | |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 179 | if is_service_enabled n-cpu; then |
| 180 | # Force IP forwarding on, just on case |
| 181 | sudo sysctl -w net.ipv4.ip_forward=1 |
| 182 | |
| 183 | # Attempt to load modules: network block device - used to manage qcow images |
| 184 | sudo modprobe nbd || true |
| 185 | |
| 186 | # Check for kvm (hardware based virtualization). If unable to initialize |
| 187 | # kvm, we drop back to the slower emulation mode (qemu). Note: many systems |
| 188 | # come with hardware virtualization disabled in BIOS. |
| 189 | if [[ "$LIBVIRT_TYPE" == "kvm" ]]; then |
| 190 | sudo modprobe kvm || true |
| 191 | if [ ! -e /dev/kvm ]; then |
| 192 | echo "WARNING: Switching to QEMU" |
| 193 | LIBVIRT_TYPE=qemu |
| 194 | if which selinuxenabled 2>&1 > /dev/null && selinuxenabled; then |
| 195 | # https://bugzilla.redhat.com/show_bug.cgi?id=753589 |
| 196 | sudo setsebool virt_use_execmem on |
| 197 | fi |
| 198 | fi |
| 199 | fi |
| 200 | |
| 201 | # Install and configure **LXC** if specified. LXC is another approach to |
| 202 | # splitting a system into many smaller parts. LXC uses cgroups and chroot |
| 203 | # to simulate multiple systems. |
| 204 | if [[ "$LIBVIRT_TYPE" == "lxc" ]]; then |
Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame^] | 205 | if is_ubuntu; then |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 206 | if [[ ! "$DISTRO" > natty ]]; then |
| 207 | cgline="none /cgroup cgroup cpuacct,memory,devices,cpu,freezer,blkio 0 0" |
| 208 | sudo mkdir -p /cgroup |
| 209 | if ! grep -q cgroup /etc/fstab; then |
| 210 | echo "$cgline" | sudo tee -a /etc/fstab |
| 211 | fi |
| 212 | if ! mount -n | grep -q cgroup; then |
| 213 | sudo mount /cgroup |
| 214 | fi |
| 215 | fi |
| 216 | fi |
| 217 | fi |
| 218 | |
Yoshihiro Kaneko | 602cf9b | 2012-07-23 06:27:36 +0000 | [diff] [blame] | 219 | 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] | 220 | # Add /dev/net/tun to cgroup_device_acls, needed for type=ethernet interfaces |
| 221 | cat <<EOF | sudo tee -a $QEMU_CONF |
| 222 | cgroup_device_acl = [ |
| 223 | "/dev/null", "/dev/full", "/dev/zero", |
| 224 | "/dev/random", "/dev/urandom", |
| 225 | "/dev/ptmx", "/dev/kvm", "/dev/kqemu", |
| 226 | "/dev/rtc", "/dev/hpet","/dev/net/tun", |
| 227 | ] |
| 228 | EOF |
| 229 | fi |
| 230 | |
Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame^] | 231 | if is_ubuntu; then |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 232 | LIBVIRT_DAEMON=libvirt-bin |
| 233 | else |
| 234 | # http://wiki.libvirt.org/page/SSHPolicyKitSetup |
| 235 | if ! grep ^libvirtd: /etc/group >/dev/null; then |
| 236 | sudo groupadd libvirtd |
| 237 | fi |
| 238 | sudo bash -c 'cat <<EOF >/etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla |
| 239 | [libvirt Management Access] |
| 240 | Identity=unix-group:libvirtd |
| 241 | Action=org.libvirt.unix.manage |
| 242 | ResultAny=yes |
| 243 | ResultInactive=yes |
| 244 | ResultActive=yes |
| 245 | EOF' |
| 246 | LIBVIRT_DAEMON=libvirtd |
| 247 | fi |
| 248 | |
| 249 | # The user that nova runs as needs to be member of **libvirtd** group otherwise |
| 250 | # nova-compute will be unable to use libvirt. |
Vincent Untz | 856a11e | 2012-11-21 16:04:12 +0100 | [diff] [blame] | 251 | add_user_to_group `whoami` libvirtd |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 252 | |
| 253 | # libvirt detects various settings on startup, as we potentially changed |
| 254 | # the system configuration (modules, filesystems), we need to restart |
| 255 | # libvirt to detect those changes. |
| 256 | restart_service $LIBVIRT_DAEMON |
| 257 | |
| 258 | |
| 259 | # Instance Storage |
| 260 | # ---------------- |
| 261 | |
| 262 | # Nova stores each instance in its own directory. |
| 263 | mkdir -p $NOVA_INSTANCES_PATH |
| 264 | |
| 265 | # You can specify a different disk to be mounted and used for backing the |
| 266 | # virtual machines. If there is a partition labeled nova-instances we |
| 267 | # mount it (ext filesystems can be labeled via e2label). |
| 268 | if [ -L /dev/disk/by-label/nova-instances ]; then |
| 269 | if ! mount -n | grep -q $NOVA_INSTANCES_PATH; then |
| 270 | sudo mount -L nova-instances $NOVA_INSTANCES_PATH |
| 271 | sudo chown -R `whoami` $NOVA_INSTANCES_PATH |
| 272 | fi |
| 273 | fi |
| 274 | |
| 275 | # Clean up old instances |
| 276 | cleanup_nova |
| 277 | fi |
| 278 | } |
| 279 | |
Dean Troyer | da7b809 | 2012-10-08 18:12:14 -0500 | [diff] [blame] | 280 | # create_nova_conf() - Create a new nova.conf file |
| 281 | function create_nova_conf() { |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 282 | # Remove legacy ``nova.conf`` |
| 283 | rm -f $NOVA_DIR/bin/nova.conf |
| 284 | |
| 285 | # (Re)create ``nova.conf`` |
Dean Troyer | 3cf1ffb | 2012-10-02 11:51:27 -0500 | [diff] [blame] | 286 | rm -f $NOVA_CONF |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 287 | add_nova_opt "[DEFAULT]" |
| 288 | add_nova_opt "verbose=True" |
| 289 | add_nova_opt "auth_strategy=keystone" |
| 290 | add_nova_opt "allow_resize_to_same_host=True" |
| 291 | add_nova_opt "api_paste_config=$NOVA_API_PASTE_INI" |
| 292 | add_nova_opt "rootwrap_config=$NOVA_CONF_DIR/rootwrap.conf" |
| 293 | add_nova_opt "compute_scheduler_driver=$SCHEDULER" |
Dean Troyer | 3cf1ffb | 2012-10-02 11:51:27 -0500 | [diff] [blame] | 294 | add_nova_opt "dhcpbridge_flagfile=$NOVA_CONF" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 295 | add_nova_opt "force_dhcp_release=True" |
| 296 | add_nova_opt "fixed_range=$FIXED_RANGE" |
| 297 | add_nova_opt "s3_host=$SERVICE_HOST" |
| 298 | add_nova_opt "s3_port=$S3_SERVICE_PORT" |
| 299 | add_nova_opt "osapi_compute_extension=nova.api.openstack.compute.contrib.standard_extensions" |
| 300 | add_nova_opt "my_ip=$HOST_IP" |
Terry Wilson | 428af5a | 2012-11-01 16:12:39 -0400 | [diff] [blame] | 301 | local dburl |
| 302 | database_connection_url dburl nova |
| 303 | add_nova_opt "sql_connection=$dburl" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 304 | add_nova_opt "libvirt_type=$LIBVIRT_TYPE" |
| 305 | add_nova_opt "libvirt_cpu_mode=none" |
| 306 | add_nova_opt "instance_name_template=${INSTANCE_NAME_PREFIX}%08x" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 307 | |
| 308 | if is_service_enabled n-api; then |
| 309 | add_nova_opt "enabled_apis=$NOVA_ENABLED_APIS" |
| 310 | fi |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 311 | if is_service_enabled cinder; then |
| 312 | add_nova_opt "volume_api_class=nova.volume.cinder.API" |
| 313 | fi |
| 314 | if [ -n "$NOVA_STATE_PATH" ]; then |
| 315 | add_nova_opt "state_path=$NOVA_STATE_PATH" |
Dean Troyer | 1331445 | 2012-10-23 15:09:50 -0500 | [diff] [blame] | 316 | add_nova_opt "lock_path=$NOVA_STATE_PATH" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 317 | fi |
| 318 | if [ -n "$NOVA_INSTANCES_PATH" ]; then |
| 319 | add_nova_opt "instances_path=$NOVA_INSTANCES_PATH" |
| 320 | fi |
| 321 | if [ "$MULTI_HOST" != "False" ]; then |
| 322 | add_nova_opt "multi_host=True" |
| 323 | add_nova_opt "send_arp_for_ha=True" |
| 324 | fi |
| 325 | if [ "$SYSLOG" != "False" ]; then |
| 326 | add_nova_opt "use_syslog=True" |
| 327 | fi |
| 328 | if [ "$API_RATE_LIMIT" != "True" ]; then |
| 329 | add_nova_opt "api_rate_limit=False" |
| 330 | fi |
| 331 | if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then |
| 332 | # Add color to logging output |
| 333 | 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" |
| 334 | 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" |
| 335 | add_nova_opt "logging_debug_format_suffix=[00;33mfrom (pid=%(process)d) %(funcName)s %(pathname)s:%(lineno)d[00m" |
| 336 | add_nova_opt "logging_exception_prefix=%(color)s%(asctime)s TRACE %(name)s [01;35m%(instance)s[00m" |
| 337 | else |
| 338 | # Show user_name and project_name instead of user_id and project_id |
| 339 | 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" |
| 340 | fi |
Eoghan Glynn | 1fcc6a1 | 2012-10-25 14:57:14 +0000 | [diff] [blame] | 341 | if is_service_enabled ceilometer; then |
| 342 | add_nova_opt "instance_usage_audit=True" |
| 343 | add_nova_opt "instance_usage_audit_period=hour" |
| 344 | add_nova_opt "notification_driver=nova.openstack.common.notifier.rabbit_notifier" |
| 345 | add_nova_opt "notification_driver=ceilometer.compute.nova_notifier" |
| 346 | fi |
| 347 | |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 348 | |
| 349 | # Provide some transition from ``EXTRA_FLAGS`` to ``EXTRA_OPTS`` |
| 350 | if [[ -z "$EXTRA_OPTS" && -n "$EXTRA_FLAGS" ]]; then |
| 351 | EXTRA_OPTS=$EXTRA_FLAGS |
| 352 | fi |
| 353 | |
| 354 | # Define extra nova conf flags by defining the array ``EXTRA_OPTS``. |
| 355 | # For Example: ``EXTRA_OPTS=(foo=true bar=2)`` |
| 356 | for I in "${EXTRA_OPTS[@]}"; do |
| 357 | # Attempt to convert flags to options |
| 358 | add_nova_opt ${I//--} |
| 359 | done |
Dean Troyer | da7b809 | 2012-10-08 18:12:14 -0500 | [diff] [blame] | 360 | } |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 361 | |
Dean Troyer | da7b809 | 2012-10-08 18:12:14 -0500 | [diff] [blame] | 362 | # init_nova() - Initialize databases, etc. |
| 363 | function init_nova() { |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 364 | # Nova Database |
| 365 | # ------------- |
| 366 | |
| 367 | # All nova components talk to a central database. We will need to do this step |
| 368 | # only once for an entire cluster. |
| 369 | |
Terry Wilson | 428af5a | 2012-11-01 16:12:39 -0400 | [diff] [blame] | 370 | if is_service_enabled $DATABASE_BACKENDS && is_service_enabled nova; then |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 371 | # (Re)create nova database |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 372 | # Explicitly use latin1: to avoid lp#829209, nova expects the database to |
| 373 | # use latin1 by default, and then upgrades the database to utf8 (see the |
| 374 | # 082_essex.py in nova) |
Terry Wilson | 428af5a | 2012-11-01 16:12:39 -0400 | [diff] [blame] | 375 | recreate_database nova latin1 |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 376 | |
| 377 | # (Re)create nova database |
| 378 | $NOVA_BIN_DIR/nova-manage db sync |
| 379 | fi |
| 380 | |
Dean Troyer | bc071bc | 2012-10-01 14:06:44 -0500 | [diff] [blame] | 381 | if [[ "$KEYSTONE_TOKEN_FORMAT" == "PKI" ]]; then |
| 382 | # Create cache dir |
| 383 | sudo mkdir -p $NOVA_AUTH_CACHE_DIR |
| 384 | sudo chown `whoami` $NOVA_AUTH_CACHE_DIR |
| 385 | fi |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | # install_novaclient() - Collect source and prepare |
| 389 | function install_novaclient() { |
| 390 | git_clone $NOVACLIENT_REPO $NOVACLIENT_DIR $NOVACLIENT_BRANCH |
| 391 | } |
| 392 | |
| 393 | # install_nova() - Collect source and prepare |
| 394 | function install_nova() { |
| 395 | if is_service_enabled n-cpu; then |
Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame^] | 396 | if is_ubuntu; then |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 397 | LIBVIRT_PKG_NAME=libvirt-bin |
| 398 | else |
| 399 | LIBVIRT_PKG_NAME=libvirt |
| 400 | fi |
| 401 | install_package $LIBVIRT_PKG_NAME |
| 402 | # Install and configure **LXC** if specified. LXC is another approach to |
| 403 | # splitting a system into many smaller parts. LXC uses cgroups and chroot |
| 404 | # to simulate multiple systems. |
| 405 | if [[ "$LIBVIRT_TYPE" == "lxc" ]]; then |
Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame^] | 406 | if is_ubuntu; then |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 407 | if [[ "$DISTRO" > natty ]]; then |
| 408 | install_package cgroup-lite |
| 409 | fi |
| 410 | else |
| 411 | ### FIXME(dtroyer): figure this out |
| 412 | echo "RPM-based cgroup not implemented yet" |
| 413 | yum_install libcgroup-tools |
| 414 | fi |
| 415 | fi |
| 416 | fi |
| 417 | |
| 418 | git_clone $NOVA_REPO $NOVA_DIR $NOVA_BRANCH |
| 419 | } |
| 420 | |
| 421 | # start_nova() - Start running processes, including screen |
| 422 | function start_nova() { |
| 423 | # The group **libvirtd** is added to the current user in this script. |
| 424 | # Use 'sg' to execute nova-compute as a member of the **libvirtd** group. |
| 425 | # ``screen_it`` checks ``is_service_enabled``, it is not needed here |
Russell Bryant | ff7f308 | 2012-11-29 22:00:51 -0500 | [diff] [blame] | 426 | screen_it n-cond "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-conductor" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 427 | screen_it n-cpu "cd $NOVA_DIR && sg libvirtd $NOVA_BIN_DIR/nova-compute" |
| 428 | screen_it n-crt "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-cert" |
| 429 | screen_it n-net "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-network" |
| 430 | screen_it n-sch "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-scheduler" |
Dean Troyer | 3cf1ffb | 2012-10-02 11:51:27 -0500 | [diff] [blame] | 431 | 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] | 432 | screen_it n-xvnc "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-xvpvncproxy --config-file $NOVA_CONF" |
| 433 | screen_it n-cauth "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-consoleauth" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | # stop_nova() - Stop running processes (non-screen) |
| 437 | function stop_nova() { |
| 438 | # Kill the nova screen windows |
Dan Smith | d57ccf0 | 2012-11-15 10:09:33 -0800 | [diff] [blame] | 439 | 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] | 440 | screen -S $SCREEN_NAME -p $serv -X kill |
| 441 | done |
| 442 | } |
| 443 | |
| 444 | # Restore xtrace |
| 445 | $XTRACE |