# Copyright (c) 2018 European Organization for Nuclear Research.
# 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


reaper_group = cfg.OptGroup(
    'reaper',
    title='Aardvark Service Options',
    help="Configuration options for Aardvark service")


reaper_opts = [
    cfg.StrOpt('reaper_driver',
               default='chance_driver',
               help="""
The driver that the reaper will use

Possible choices:

* strict_driver: The purpose of the preemptibles existence is to eliminate the
                 idling resources. This driver gets all the possible offers
                 from the relevant hosts and tries to find the best matching
                 for the requested resources. The best matching offer is the
                 combination of preemptible servers that leave the least
                 possible resources unused.

* chance_driver: A valid host is selected randomly and in a number of
                 preconfigured retries, the driver tries to find the instances
                 that have to be culled in order to have the requested
                 resources available.
"""
    ),
    cfg.IntOpt('alternatives',
               default=1,
               help="""
The number of alternative slots that the the reaper will try to free up for
each requested slot.
"""
    ),
    cfg.IntOpt('max_attempts',
               default=5,
               help="""
The number of alternative slots that the the reaper will try to free up for
each requested slot.
"""
    ),
    cfg.ListOpt('watched_aggregates',
               default=[],
               help="""
The list of aggregate names that the reaper will try to make space to

Each element of the list can be an aggregate or a combination of aggregates.
Combination of aggregates is a single string with a vertical-line-separated
aggregate names.

e.g. watched_aggregates={agg_name1},{agg_name2}|{agg_name3}',....

For each element in the list, a reaper thread will be spawned and the request
will be forwarded to the responsible worker.

If the provided list is empty, only one worker will be spawned, responsible for
the whole system.
"""
    ),
    cfg.StrOpt('job_backend',
               default='redis',
               choices=('redis', 'zookeeper'),
               help="""
The backend to use for distributed task management.

For this purpose the Reaper uses OpenStack Taskflow. The two supported
backends are redis and zookeper.
"""
    ),
    cfg.StrOpt('backend_host',
               default='localhost',
               help="""
Specifies the host where the job board backend can be found.
"""
    ),
]


def register_opts(conf):
    conf.register_group(reaper_group)
    conf.register_opts(reaper_opts, group=reaper_group)

[((708, 820), 'oslo_config.cfg.OptGroup', 'cfg.OptGroup', (['"""reaper"""'], {'title': '"""Aardvark Service Options"""', 'help': '"""Configuration options for Aardvark service"""'}), "('reaper', title='Aardvark Service Options', help=\n    'Configuration options for Aardvark service')\n", (720, 820), False, 'from oslo_config import cfg\n'), ((851, 1668), 'oslo_config.cfg.StrOpt', 'cfg.StrOpt', (['"""reaper_driver"""'], {'default': '"""chance_driver"""', 'help': '"""\nThe driver that the reaper will use\n\nPossible choices:\n\n* strict_driver: The purpose of the preemptibles existence is to eliminate the\n                 idling resources. This driver gets all the possible offers\n                 from the relevant hosts and tries to find the best matching\n                 for the requested resources. The best matching offer is the\n                 combination of preemptible servers that leave the least\n                 possible resources unused.\n\n* chance_driver: A valid host is selected randomly and in a number of\n                 preconfigured retries, the driver tries to find the instances\n                 that have to be culled in order to have the requested\n                 resources available.\n"""'}), '(\'reaper_driver\', default=\'chance_driver\', help=\n    """\nThe driver that the reaper will use\n\nPossible choices:\n\n* strict_driver: The purpose of the preemptibles existence is to eliminate the\n                 idling resources. This driver gets all the possible offers\n                 from the relevant hosts and tries to find the best matching\n                 for the requested resources. The best matching offer is the\n                 combination of preemptible servers that leave the least\n                 possible resources unused.\n\n* chance_driver: A valid host is selected randomly and in a number of\n                 preconfigured retries, the driver tries to find the instances\n                 that have to be culled in order to have the requested\n                 resources available.\n"""\n    )\n', (861, 1668), False, 'from oslo_config import cfg\n'), ((1699, 1857), 'oslo_config.cfg.IntOpt', 'cfg.IntOpt', (['"""alternatives"""'], {'default': '(1)', 'help': '"""\nThe number of alternative slots that the the reaper will try to free up for\neach requested slot.\n"""'}), '(\'alternatives\', default=1, help=\n    """\nThe number of alternative slots that the the reaper will try to free up for\neach requested slot.\n"""\n    )\n', (1709, 1857), False, 'from oslo_config import cfg\n'), ((1888, 2046), 'oslo_config.cfg.IntOpt', 'cfg.IntOpt', (['"""max_attempts"""'], {'default': '(5)', 'help': '"""\nThe number of alternative slots that the the reaper will try to free up for\neach requested slot.\n"""'}), '(\'max_attempts\', default=5, help=\n    """\nThe number of alternative slots that the the reaper will try to free up for\neach requested slot.\n"""\n    )\n', (1898, 2046), False, 'from oslo_config import cfg\n'), ((2077, 2677), 'oslo_config.cfg.ListOpt', 'cfg.ListOpt', (['"""watched_aggregates"""'], {'default': '[]', 'help': '"""\nThe list of aggregate names that the reaper will try to make space to\n\nEach element of the list can be an aggregate or a combination of aggregates.\nCombination of aggregates is a single string with a vertical-line-separated\naggregate names.\n\ne.g. watched_aggregates={agg_name1},{agg_name2}|{agg_name3}\',....\n\nFor each element in the list, a reaper thread will be spawned and the request\nwill be forwarded to the responsible worker.\n\nIf the provided list is empty, only one worker will be spawned, responsible for\nthe whole system.\n"""'}), '(\'watched_aggregates\', default=[], help=\n    """\nThe list of aggregate names that the reaper will try to make space to\n\nEach element of the list can be an aggregate or a combination of aggregates.\nCombination of aggregates is a single string with a vertical-line-separated\naggregate names.\n\ne.g. watched_aggregates={agg_name1},{agg_name2}|{agg_name3}\',....\n\nFor each element in the list, a reaper thread will be spawned and the request\nwill be forwarded to the responsible worker.\n\nIf the provided list is empty, only one worker will be spawned, responsible for\nthe whole system.\n"""\n    )\n', (2088, 2677), False, 'from oslo_config import cfg\n'), ((2708, 2967), 'oslo_config.cfg.StrOpt', 'cfg.StrOpt', (['"""job_backend"""'], {'default': '"""redis"""', 'choices': "('redis', 'zookeeper')", 'help': '"""\nThe backend to use for distributed task management.\n\nFor this purpose the Reaper uses OpenStack Taskflow. The two supported\nbackends are redis and zookeper.\n"""'}), '(\'job_backend\', default=\'redis\', choices=(\'redis\', \'zookeeper\'),\n    help=\n    """\nThe backend to use for distributed task management.\n\nFor this purpose the Reaper uses OpenStack Taskflow. The two supported\nbackends are redis and zookeper.\n"""\n    )\n', (2718, 2967), False, 'from oslo_config import cfg\n'), ((3009, 3136), 'oslo_config.cfg.StrOpt', 'cfg.StrOpt', (['"""backend_host"""'], {'default': '"""localhost"""', 'help': '"""\nSpecifies the host where the job board backend can be found.\n"""'}), '(\'backend_host\', default=\'localhost\', help=\n    """\nSpecifies the host where the job board backend can be found.\n""")\n', (3019, 3136), False, 'from oslo_config import cfg\n')]