# Copyright 2017 Huawei Technologies Co.,LTD.
# 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.

import os
import socket

from oslo_config import cfg

from cyborg.common.i18n import _


exc_log_opts = [
    cfg.BoolOpt('fatal_exception_format_errors',
                default=False,
                help=_('Used if there is a formatting error when generating '
                       'an exception message (a programming error). If True, '
                       'raise an exception; if False, use the unformatted '
                       'message.')),
]

service_opts = [
    cfg.HostAddressOpt('host',
                       default=socket.getfqdn(),
                       sample_default='localhost',
                       help=_('Name of this node. This can be an opaque '
                              'identifier. It is not necessarily a hostname, '
                              'FQDN, or IP address. However, the node name '
                              'must be valid within an AMQP key, and if using '
                              'ZeroMQ, a valid hostname, FQDN, or IP address.')
                       ),
    cfg.IntOpt('periodic_interval',
               default=60,
               help=_('Default interval (in seconds) for running periodic '
                      'tasks.')),
]

path_opts = [
    cfg.StrOpt('pybasedir',
               default=os.path.abspath(
                   os.path.join(os.path.dirname(__file__), '../')),
               sample_default='/usr/lib/python/site-packages/cyborg/cyborg',
               help=_('Directory where the cyborg python module is '
                      'installed.')),
    cfg.StrOpt('bindir',
               default='$pybasedir/bin',
               help=_('Directory where cyborg binaries are installed.')),
    cfg.StrOpt('state_path',
               default='$pybasedir',
               help=_("Top-level directory for maintaining cyborg's state.")),
]

PLACEMENT_CONF_SECTION = 'placement'

placement_opts = [
    cfg.StrOpt('region_name',
               help=_('Name of placement region to use. Useful if keystone '
                      'manages more than one region.')),
    cfg.StrOpt('endpoint_type',
               default='public',
               choices=['public', 'admin', 'internal'],
               help=_('Type of the placement endpoint to use.  This endpoint '
                      'will be looked up in the keystone catalog and should '
                      'be one of public, internal or admin.')),
    cfg.BoolOpt('insecure',
                default=False,
                help="""
                    If true, the vCenter server certificate is not verified.
                    If false, then the default CA truststore is used for
                    verification. Related options:
                    * ca_file: This option is ignored if "ca_file" is set.
                    """),
    cfg.StrOpt('cafile',
               default=None,
               help="""
                   Specifies the CA bundle file to be used in verifying the
                   vCenter server certificate.
                   """),
    cfg.StrOpt('certfile',
               default=None,
               help="""
                   Specifies the certificate file to be used in verifying
                   the vCenter server certificate.
                   """),
    cfg.StrOpt('keyfile',
               default=None,
               help="""
                   Specifies the key file to be used in verifying the vCenter
                   server certificate.
                   """),
    cfg.IntOpt('timeout',
               default=None,
               help=_('Timeout for inactive connections (in seconds)')),
    cfg.BoolOpt('split_loggers',
                default=False,
                help=_('Split the logging of requests across multiple loggers '
                       'instead of just one. Defaults to False.')),
    cfg.IntOpt('collect_timing',
               default=False,
               help=_('Whether or not to collect per-method timing information'
                      ' for each API call. (optional,defaults to False')),
]


def register_opts(conf):
    conf.register_opts(exc_log_opts)
    conf.register_opts(service_opts)
    conf.register_opts(path_opts)


def register_placement_opts(cfg=cfg.CONF):
    cfg.register_opts(placement_opts, group=PLACEMENT_CONF_SECTION)

@@ -689,16 +689,63 @@
 port cfg
+%0Afrom keystoneauth1 import loading as k_loading
 %0A%0Afrom c
@@ -3072,1629 +3072,8 @@
 )),%0A
-    cfg.BoolOpt('insecure',%0A                default=False,%0A                help=%22%22%22%0A                    If true, the vCenter server certificate is not verified.%0A                    If false, then the default CA truststore is used for%0A                    verification. Related options:%0A                    * ca_file: This option is ignored if %22ca_file%22 is set.%0A                    %22%22%22),%0A    cfg.StrOpt('cafile',%0A               default=None,%0A               help=%22%22%22%0A                   Specifies the CA bundle file to be used in verifying the%0A                   vCenter server certificate.%0A                   %22%22%22),%0A    cfg.StrOpt('certfile',%0A               default=None,%0A               help=%22%22%22%0A                   Specifies the certificate file to be used in verifying%0A                   the vCenter server certificate.%0A                   %22%22%22),%0A    cfg.StrOpt('keyfile',%0A               default=None,%0A               help=%22%22%22%0A                   Specifies the key file to be used in verifying the vCenter%0A                   server certificate.%0A                   %22%22%22),%0A    cfg.IntOpt('timeout',%0A               default=None,%0A               help=_('Timeout for inactive connections (in seconds)')),%0A    cfg.BoolOpt('split_loggers',%0A                default=False,%0A                help=_('Split the logging of requests across multiple loggers '%0A                       'instead of just one. Defaults to False.')),%0A    cfg.IntOpt('collect_timing',%0A               default=False,%0A               help=_('Whether or not to collect per-method timing information'%0A                      ' for each API call. (optional,defaults to False')),%0A
 %5D%0A%0A%0A
@@ -3250,16 +3250,128 @@
 .CONF):%0A
+    cfg.register_opts(k_loading.get_session_conf_options(),%0A                      group=PLACEMENT_CONF_SECTION)%0A
     cfg.

use config options from keystoneauth1 under placement