Correct errors about freezer-api supporting for V1 and V2 api

At present, the codes as follows:
db/elastic/driver.py:
Def get_engine (self):
    If not self._engine:
        Self._engine = db_session.ElasticSearchEngineV2(self.backend)
    Return self._engine
There is that freezer-api can't support support v1.
Actually, there is enable_v1_api ,but it is not used correctly.
The documents will be modified in other patches.

For example:
1)freezer-api v1:
  /etc/freezer/freezer-api.conf:
      [DEFAULT]
          enable_v1_api = True
	  [storage]
          driver = elasticsearch
          backend = elasticsearch
	  [elasticsearch]
          hosts = http://172.16.1.200:9200
          number_of_replicas = 0
          index = freezer

  /etc/freezer/scheduler.conf:
      [DEFAULT]
          enable_v1_api = True

   command: freezer --os-backup-api-version 1  job-list

2)freezer-api v2:
  /etc/freezer/freezer-api.conf:
      [DEFAULT]
          enable_v1_api = False
		  or
		  # enable_v1_api = False
	  [storage]
          driver = elasticsearch
          backend = elasticsearch
	  [elasticsearch]
          hosts = http://172.16.1.200:9200
          number_of_replicas = 0
          index = freezer

  /etc/freezer/scheduler.conf:
      [DEFAULT]
         enable_v1_api = False
		 or
		 # enable_v1_api = False

   command: freezer job-list

Change-Id: Iccee3a7cde986d0ba2aaf018fafa6bca411c34bf
This commit is contained in:
gengchc2 2018-10-31 21:07:58 -07:00
parent b09705d812
commit d1a5e93b25
5 changed files with 58 additions and 67 deletions

View File

@ -12,36 +12,26 @@
# Maximum value: 65535
#bind_port = 9090
# Deploy the v1 OpenStack Freezer API.
# When this option is set to ``True``, Freezer-api service will respond to
# requests on registered endpoints conforming to the v1 OpenStack Freezer API.
# NOTES:
# * Multi-tenancy is not supported under this api version.
# * Everything is user based.
# * Freezer api v1 doesn't support Oslo.db.
# * Use elasticsearch db with v1 api version
# Deploy the OpenStack Freezer API.
# Default is the v2 Freezer API.
# When this option is set
# to ``True``, Freezer-api service will respond
# to requests on registered endpoints conforming
# to the v1 OpenStack Freezer api.
# The v1 OpenStack Freezer API:
# * Multi-tenancy is not supported under this
# api version.
# * Everything is user based.
# * Freezer api v1 doesn't support Oslo.db.
# * Use elasticsearch db with v1 api version
# The v2 OpenStack Freezer API:
# * Multi-tenancy is supported under this api version.
# * Freezer api v2 supports Oslo.db.
# * Recommended to use oslo.db with api v2
# Possible values:
# * True
# * False
# Related options:
# * enable_v2_api
# (boolean value)
#enable_v1_api = false
# Deploy the v2 OpenStack Freezer API.
# When this option is set to ``True``, Freezer-api service will respond to
# requests on registered endpoints conforming to the v2 OpenStack Freezer api.
# NOTES:
# * Multi-tenancy is supported under this api version.
# * Freezer api v2 supports Oslo.db.
# * Recommended to use oslo.db with api v2
# Possible values:
# * True
# * False
# Related options:
# * enable_v1_api
# (boolean value)
#enable_v2_api = true
# * True
# * False
#enable_v1_api = False
#
# From oslo.log

View File

@ -51,7 +51,8 @@ def api_versions(conf=None):
class Resource(object):
def _build_versions(self, host_url):
allowed_versions = {'v1': CONF.enable_v1_api, 'v2': CONF.enable_v2_api}
allowed_versions = {'v1': CONF.enable_v1_api,
'v2': False if CONF.enable_v1_api else True}
updated_versions = {'versions': []}
for version in VERSIONS['versions']:

View File

@ -61,35 +61,27 @@ def api_common_opts():
),
cfg.BoolOpt('enable_v1_api',
default=False,
help="""Deploy the v1 OpenStack Freezer API.
When this option is set to ``True``, Freezer-api service will respond to
requests on registered endpoints conforming to the v1 OpenStack Freezer API.
NOTES:
* Multi-tenancy is not supported under this api version.
* Everything is user based.
* Freezer api v1 doesn't support Oslo.db.
* Use elasticsearch db with v1 api version
Possible values:
* True
* False
Related options:
* enable_v2_api
"""),
cfg.BoolOpt('enable_v2_api',
default=True,
help="""Deploy the v2 OpenStack Freezer API.
When this option is set to ``True``, Freezer-api service will respond to
requests on registered endpoints conforming to the v2 OpenStack Freezer api.
NOTES:
* Multi-tenancy is supported under this api version.
* Freezer api v2 supports Oslo.db.
* Recommended to use oslo.db with api v2
Possible values:
* True
* False
Related options:
* enable_v1_api
""")
help="""Default False, That is the v2 Freezer API
will be deployed. When this option is set
to ``True``, Freezer-api service will respond
to requests on registered endpoints conforming
to the v1 OpenStack Freezer api.
The v1 OpenStack Freezer API functions
as follows:
* Multi-tenancy is not supported under this
api version.
* Everything is user based.
* Freezer api v1 doesn't support Oslo.db.
* Use elasticsearch db with v1 api version
The v2 OpenStack Freezer API functions
as follows:
* Multi-tenancy is supported under this api version.
* Freezer api v2 supports Oslo.db.
* Recommended to use oslo.db with api v2
Possible values:
* True
* False
""")
]
return _COMMON

View File

@ -19,8 +19,8 @@ from oslo_log import log
from freezer_api.common import db_mappings
from freezer_api.db import base as db_base
from freezer_api.db.elasticsearch import es_manager
from freezer_api.storage import elasticv2 as db_session
from freezer_api.storage import elastic as db_session_v1
from freezer_api.storage import elasticv2 as db_session_v2
CONF = cfg.CONF
LOG = log.getLogger(__name__)
@ -89,7 +89,12 @@ class ElasticSearchDB(db_base.DBDriver):
def get_engine(self):
if not self._engine:
self._engine = db_session.ElasticSearchEngineV2(self.backend)
if CONF.enable_v1_api:
self._engine = db_session_v1.\
ElasticSearchEngine(self.backend)
else:
self._engine = db_session_v2.\
ElasticSearchEngineV2(self.backend)
return self._engine
def get_api(self):

View File

@ -33,13 +33,16 @@ FALCON_MINVERSION_MIDDLEWARE = pkg_resources.parse_version('0.2.0b1')
def root_app_factory(loader, global_conf, **local_conf):
"""Allows freezer to launch multiple applications at a time.
It will allow freezer to manage multiple versions.
"""Freezer can manage multiple versions, but
only launch one version at a time, Otherwise it is
easy to cause confusion. If there is a demand in the future
for a single freezer-api instance to support both v1 and v2 at a time,
you need to add a new patch to implement it.
"""
if not CONF.enable_v1_api and '/v1' in local_conf:
del local_conf['/v1']
if not CONF.enable_v2_api and '/v2' in local_conf:
if CONF.enable_v1_api and '/v1' in local_conf:
del local_conf['/v2']
else:
del local_conf['/v1']
return urlmap.urlmap_factory(loader, global_conf, **local_conf)