# Copyright 2015 OpenStack Foundation
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from oslo_config import cfg

default_opts = [
    cfg.StrOpt("scheduler_topic",
        default="scheduler",
        deprecated_for_removal=True,
        deprecated_since="15.0.0",
        deprecated_reason="""
There is no need to let users choose the RPC topic for all services - there
is little gain from this. Furthermore, it makes it really easy to break Nova
by using this option.
""",
        help="""
Scheduler message queue topic.

This is the message queue topic that the scheduler 'listens' on. It is used
when the scheduler service is started up to configure the queue, and whenever
an RPC call to the scheduler is made. There is almost never any reason to ever
change this value.

Possible values:

* A valid AMQP topic name
"""),
]

scheduler_group = cfg.OptGroup(name="scheduler",
                               title="Scheduler configuration")

scheduler_opts = [
    cfg.StrOpt("host_manager",
        default="host_manager",
        choices=("host_manager", "ironic_host_manager"),
        deprecated_name="scheduler_host_manager",
        deprecated_group="DEFAULT",
        help="""
The scheduler host manager to use.

The host manager manages the in-memory picture of the hosts that the scheduler
uses. The options values are chosen from the entry points under the namespace
'nova.scheduler.host_manager' in 'setup.cfg'.
"""),
    cfg.StrOpt("driver",
        default="filter_scheduler",
        choices=("filter_scheduler", "caching_scheduler",
                 "chance_scheduler", "fake_scheduler"),
        deprecated_name="scheduler_driver",
        deprecated_group="DEFAULT",
        help="""
The class of the driver used by the scheduler.

The options are chosen from the entry points under the namespace
'nova.scheduler.driver' in 'setup.cfg'.

Possible values:

* A string, where the string corresponds to the class name of a scheduler
  driver. There are a number of options available:
** 'caching_scheduler', which aggressively caches the system state for better
   individual scheduler performance at the risk of more retries when running
   multiple schedulers
** 'chance_scheduler', which simply picks a host at random
** 'fake_scheduler', which is used for testing
** A custom scheduler driver. In this case, you will be responsible for
   creating and maintaining the entry point in your 'setup.cfg' file
"""),
    cfg.IntOpt("periodic_task_interval",
        default=60,
        deprecated_name="scheduler_driver_task_period",
        deprecated_group="DEFAULT",
        help="""
Periodic task interval.

This value controls how often (in seconds) to run periodic tasks in the
scheduler. The specific tasks that are run for each period are determined by
the particular scheduler being used.

If this is larger than the nova-service 'service_down_time' setting, Nova may
report the scheduler service as down. This is because the scheduler driver is
responsible for sending a heartbeat and it will only do that as often as this
option allows. As each scheduler can work a little differently than the others,
be sure to test this with your selected scheduler.

Possible values:

* An integer, where the integer corresponds to periodic task interval in
  seconds. 0 uses the default interval (60 seconds). A negative value disables
  periodic tasks.

Related options:

* ``nova-service service_down_time``
"""),
    cfg.IntOpt("max_attempts",
        default=3,
        min=1,
        deprecated_name="scheduler_max_attempts",
        deprecated_group="DEFAULT",
        help="""
Maximum number of schedule attempts for a chosen host.

This is the maximum number of attempts that will be made to schedule an
instance before it is assumed that the failures aren't due to normal occasional
race conflicts, but rather some other problem. When this is reached a
MaxRetriesExceeded exception is raised, and the instance is set to an error
state.

Possible values:

* A positive integer, where the integer corresponds to the max number of
  attempts that can be made when scheduling an instance.
""")]

filter_scheduler_group = cfg.OptGroup(name="filter_scheduler",
                           title="Filter scheduler options")

filter_scheduler_opts = [
    cfg.IntOpt("host_subset_size",
        default=1,
        min=1,
        deprecated_name="scheduler_host_subset_size",
        deprecated_group="DEFAULT",
        help="""
Size of subset of best hosts selected by scheduler.

New instances will be scheduled on a host chosen randomly from a subset of the
N best hosts, where N is the value set by this option.

Setting this to a value greater than 1 will reduce the chance that multiple
scheduler processes handling similar requests will select the same host,
creating a potential race condition. By selecting a host randomly from the N
hosts that best fit the request, the chance of a conflict is reduced. However,
the higher you set this value, the less optimal the chosen host may be for a
given request.

This option is only used by the FilterScheduler and its subclasses; if you use
a different scheduler, this option has no effect.

Possible values:

* An integer, where the integer corresponds to the size of a host subset. Any
  integer is valid, although any value less than 1 will be treated as 1
"""),
    cfg.IntOpt("max_io_ops_per_host",
        default=8,
        deprecated_group="DEFAULT",
        help="""
The number of instances that can be actively performing IO on a host.

Instances performing IO includes those in the following states: build, resize,
snapshot, migrate, rescue, unshelve.

This option is only used by the FilterScheduler and its subclasses; if you use
a different scheduler, this option has no effect. Also note that this setting
only affects scheduling if the 'io_ops_filter' filter is enabled.

Possible values:

* An integer, where the integer corresponds to the max number of instances
  that can be actively performing IO on any given host.
"""),
    # TODO(sfinucan): Add 'min' parameter
    cfg.IntOpt("max_instances_per_host",
        default=50,
        deprecated_group="DEFAULT",
        help="""
Maximum number of instances that be active on a host.

If you need to limit the number of instances on any given host, set this option
to the maximum number of instances you want to allow. The num_instances_filter
will reject any host that has at least as many instances as this option's
value.

This option is only used by the FilterScheduler and its subclasses; if you use
a different scheduler, this option has no effect. Also note that this setting
only affects scheduling if the 'num_instances_filter' filter is enabled.

Possible values:

* An integer, where the integer corresponds to the max instances that can be
  scheduled on a host.
"""),
    cfg.BoolOpt("track_instance_changes",
        default=True,
        deprecated_name="scheduler_tracks_instance_changes",
        deprecated_group="DEFAULT",
        help="""
Enable querying of individual hosts for instance information.

The scheduler may need information about the instances on a host in order to
evaluate its filters and weighers. The most common need for this information is
for the (anti-)affinity filters, which need to choose a host based on the
instances already running on a host.

If the configured filters and weighers do not need this information, disabling
this option will improve performance. It may also be disabled when the tracking
overhead proves too heavy, although this will cause classes requiring host
usage data to query the database on each request instead.

This option is only used by the FilterScheduler and its subclasses; if you use
a different scheduler, this option has no effect.
"""),
    cfg.MultiStrOpt("available_filters",
        default=["nova.scheduler.filters.all_filters"],
        deprecated_name="scheduler_available_filters",
        deprecated_group="DEFAULT",
        help="""
Filters that the scheduler can use.

An unordered list of the filter classes the nova scheduler may apply.  Only the
filters specified in the 'scheduler_enabled_filters' option will be used, but
any filter appearing in that option must also be included in this list.

By default, this is set to all filters that are included with nova.

This option is only used by the FilterScheduler and its subclasses; if you use
a different scheduler, this option has no effect.

Possible values:

* A list of zero or more strings, where each string corresponds to the name of
  a filter that may be used for selecting a host

Related options:

* scheduler_enabled_filters
"""),
    cfg.ListOpt("enabled_filters",
        default=[
          "RetryFilter",
          "AvailabilityZoneFilter",
          "RamFilter",
          "DiskFilter",
          "ComputeFilter",
          "ComputeCapabilitiesFilter",
          "ImagePropertiesFilter",
          "ServerGroupAntiAffinityFilter",
          "ServerGroupAffinityFilter",
          ],
        deprecated_name="scheduler_default_filters",
        deprecated_group="DEFAULT",
        help="""
Filters that the scheduler will use.

An ordered list of filter class names that will be used for filtering
hosts. Ignore the word 'default' in the name of this option: these filters will
*always* be applied, and they will be applied in the order they are listed so
place your most restrictive filters first to make the filtering process more
efficient.

This option is only used by the FilterScheduler and its subclasses; if you use
a different scheduler, this option has no effect.

Possible values:

* A list of zero or more strings, where each string corresponds to the name of
  a filter to be used for selecting a host

Related options:

* All of the filters in this option *must* be present in the
  'scheduler_available_filters' option, or a SchedulerHostFilterNotFound
  exception will be raised.
"""),
    cfg.ListOpt("baremetal_enabled_filters",
        default=[
            "RetryFilter",
            "AvailabilityZoneFilter",
            "ComputeFilter",
            "ComputeCapabilitiesFilter",
            "ImagePropertiesFilter",
            "ExactRamFilter",
            "ExactDiskFilter",
            "ExactCoreFilter",
        ],
        deprecated_name="baremetal_scheduler_default_filters",
        deprecated_group="DEFAULT",
        help="""
Filters used for filtering baremetal hosts.

Filters are applied in order, so place your most restrictive filters first to
make the filtering process more efficient.

This option is only used by the FilterScheduler and its subclasses; if you use
a different scheduler, this option has no effect.

Possible values:

* A list of zero or more strings, where each string corresponds to the name of
  a filter to be used for selecting a baremetal host

Related options:

* If the 'scheduler_use_baremetal_filters' option is False, this option has
  no effect.
"""),
    cfg.BoolOpt("use_baremetal_filters",
        deprecated_name="scheduler_use_baremetal_filters",
        deprecated_group="DEFAULT",
        default=False,
        help="""
Enable baremetal filters.

Set this to True to tell the nova scheduler that it should use the filters
specified in the 'baremetal_scheduler_enabled_filters' option. If you are not
scheduling baremetal nodes, leave this at the default setting of False.

This option is only used by the FilterScheduler and its subclasses; if you use
a different scheduler, this option has no effect.

Related options:

* If this option is set to True, then the filters specified in the
  'baremetal_scheduler_enabled_filters' are used instead of the filters
  specified in 'scheduler_enabled_filters'.
"""),
    cfg.ListOpt("weight_classes",
        default=["nova.scheduler.weights.all_weighers"],
        deprecated_name="scheduler_weight_classes",
        deprecated_group="DEFAULT",
        help="""
Weighers that the scheduler will use.

Only hosts which pass the filters are weighed. The weight for any host starts
at 0, and the weighers order these hosts by adding to or subtracting from the
weight assigned by the previous weigher. Weights may become negative. An
instance will be scheduled to one of the N most-weighted hosts, where N is
'scheduler_host_subset_size'.

By default, this is set to all weighers that are included with Nova.

This option is only used by the FilterScheduler and its subclasses; if you use
a different scheduler, this option has no effect.

Possible values:

* A list of zero or more strings, where each string corresponds to the name of
  a weigher that will be used for selecting a host
"""),
    cfg.FloatOpt("ram_weight_multiplier",
        default=1.0,
        deprecated_group="DEFAULT",
        help="""
Ram weight multipler ratio.

This option determines how hosts with more or less available RAM are weighed. A
positive value will result in the scheduler preferring hosts with more
available RAM, and a negative number will result in the scheduler preferring
hosts with less available RAM. Another way to look at it is that positive
values for this option will tend to spread instances across many hosts, while
negative values will tend to fill up (stack) hosts as much as possible before
scheduling to a less-used host. The absolute value, whether positive or
negative, controls how strong the RAM weigher is relative to other weighers.

This option is only used by the FilterScheduler and its subclasses; if you use
a different scheduler, this option has no effect. Also note that this setting
only affects scheduling if the 'ram' weigher is enabled.

Possible values:

* An integer or float value, where the value corresponds to the multipler
  ratio for this weigher.
"""),
    cfg.FloatOpt("disk_weight_multiplier",
        default=1.0,
        deprecated_group="DEFAULT",