"Fossies" - the Fresh Open Source Software Archive

Member "openstack-heat-13.0.0/heat/engine/clients/os/trove.py" (16 Oct 2019, 3516 Bytes) of package /linux/misc/openstack/openstack-heat-13.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "trove.py" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 12.0.0_vs_13.0.0.

    1 #
    2 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    3 #    not use this file except in compliance with the License. You may obtain
    4 #    a copy of the License at
    5 #
    6 #         http://www.apache.org/licenses/LICENSE-2.0
    7 #
    8 #    Unless required by applicable law or agreed to in writing, software
    9 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   10 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   11 #    License for the specific language governing permissions and limitations
   12 #    under the License.
   13 
   14 from oslo_config import cfg
   15 from troveclient import client as tc
   16 from troveclient import exceptions
   17 
   18 from heat.common import exception
   19 from heat.common.i18n import _
   20 from heat.engine.clients import client_plugin
   21 from heat.engine import constraints
   22 
   23 CLIENT_NAME = 'trove'
   24 
   25 
   26 class TroveClientPlugin(client_plugin.ClientPlugin):
   27 
   28     exceptions_module = exceptions
   29 
   30     service_types = [DATABASE] = ['database']
   31 
   32     def _create(self):
   33 
   34         con = self.context
   35         endpoint_type = self._get_client_option(CLIENT_NAME, 'endpoint_type')
   36         args = {
   37             'endpoint_type': endpoint_type,
   38             'service_type': self.DATABASE,
   39             'session': con.keystone_session,
   40             'connect_retries': cfg.CONF.client_retry_limit,
   41             'region_name': self._get_region_name()
   42         }
   43 
   44         client = tc.Client('1.0', **args)
   45         return client
   46 
   47     def validate_datastore(self, datastore_type, datastore_version,
   48                            ds_type_key, ds_version_key):
   49         if datastore_type:
   50             # get current active versions
   51             allowed_versions = self.client().datastore_versions.list(
   52                 datastore_type)
   53             allowed_version_names = [v.name for v in allowed_versions]
   54             if datastore_version:
   55                 if datastore_version not in allowed_version_names:
   56                     msg = _("Datastore version %(dsversion)s "
   57                             "for datastore type %(dstype)s is not valid. "
   58                             "Allowed versions are %(allowed)s.") % {
   59                                 'dstype': datastore_type,
   60                                 'dsversion': datastore_version,
   61                                 'allowed': ', '.join(allowed_version_names)}
   62                     raise exception.StackValidationFailed(message=msg)
   63         else:
   64             if datastore_version:
   65                 msg = _("Not allowed - %(dsver)s without %(dstype)s.") % {
   66                     'dsver': ds_version_key,
   67                     'dstype': ds_type_key}
   68                 raise exception.StackValidationFailed(message=msg)
   69 
   70     def is_not_found(self, ex):
   71         return isinstance(ex, exceptions.NotFound)
   72 
   73     def is_over_limit(self, ex):
   74         return isinstance(ex, exceptions.RequestEntityTooLarge)
   75 
   76     def is_conflict(self, ex):
   77         return isinstance(ex, exceptions.Conflict)
   78 
   79     def find_flavor_by_name_or_id(self, flavor):
   80         """Find the specified flavor by name or id.
   81 
   82         :param flavor: the name of the flavor to find
   83         :returns: the id of :flavor:
   84         """
   85         try:
   86             return self.client().flavors.get(flavor).id
   87         except exceptions.NotFound:
   88             return self.client().flavors.find(name=flavor).id
   89 
   90 
   91 class FlavorConstraint(constraints.BaseCustomConstraint):
   92 
   93     expected_exceptions = (exceptions.NotFound,)
   94 
   95     resource_client_name = CLIENT_NAME
   96     resource_getter_name = 'find_flavor_by_name_or_id'