"Fossies" - the Fresh Open Source Software Archive

Member "cloudkitty-13.0.0/cloudkitty/rating/pyscripts/db/api.py" (14 Oct 2020, 2954 Bytes) of package /linux/misc/openstack/cloudkitty-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 "api.py" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 12.1.0_vs_13.0.0.

    1 # -*- coding: utf-8 -*-
    2 # Copyright 2015 Objectif Libre
    3 #
    4 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    5 #    not use this file except in compliance with the License. You may obtain
    6 #    a copy of the License at
    7 #
    8 #         http://www.apache.org/licenses/LICENSE-2.0
    9 #
   10 #    Unless required by applicable law or agreed to in writing, software
   11 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   12 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   13 #    License for the specific language governing permissions and limitations
   14 #    under the License.
   15 #
   16 import abc
   17 
   18 from oslo_config import cfg
   19 from oslo_db import api as db_api
   20 import six
   21 
   22 from cloudkitty.i18n import _
   23 
   24 _BACKEND_MAPPING = {
   25     'sqlalchemy': 'cloudkitty.rating.pyscripts.db.sqlalchemy.api'}
   26 IMPL = db_api.DBAPI.from_config(cfg.CONF,
   27                                 backend_mapping=_BACKEND_MAPPING,
   28                                 lazy=True)
   29 
   30 
   31 def get_instance():
   32     """Return a DB API instance."""
   33     return IMPL
   34 
   35 
   36 class NoSuchScript(Exception):
   37     """Raised when the script doesn't exist."""
   38 
   39     def __init__(self, name=None, uuid=None):
   40         super(NoSuchScript, self).__init__(
   41             _("No such script: %(name)s (UUID: %(uuid)s)") % {'name': name,
   42                                                               'uuid': uuid})
   43         self.name = name
   44         self.uuid = uuid
   45 
   46 
   47 class ScriptAlreadyExists(Exception):
   48     """Raised when the script already exists."""
   49 
   50     def __init__(self, name, uuid):
   51         super(ScriptAlreadyExists, self).__init__(
   52             _("Script %(name)s already exists (UUID: %(uuid)s)") %
   53             {'name': name, 'uuid': uuid})
   54         self.name = name
   55         self.uuid = uuid
   56 
   57 
   58 @six.add_metaclass(abc.ABCMeta)
   59 class PyScripts(object):
   60     """Base class for pyscripts configuration."""
   61 
   62     @abc.abstractmethod
   63     def get_migration(self):
   64         """Return a migrate manager.
   65 
   66         """
   67 
   68     @abc.abstractmethod
   69     def get_script(self, name=None, uuid=None):
   70         """Return a script object.
   71 
   72         :param name: Filter on a script name.
   73         :param uuid: The uuid of the script to get.
   74         """
   75 
   76     @abc.abstractmethod
   77     def list_scripts(self):
   78         """Return a UUID list of every scripts available.
   79 
   80         """
   81 
   82     @abc.abstractmethod
   83     def create_script(self, name, data):
   84         """Create a new script.
   85 
   86         :param name: Name of the script to create.
   87         :param data: Content of the python script.
   88         """
   89 
   90     @abc.abstractmethod
   91     def update_script(self, uuid, **kwargs):
   92         """Update a script.
   93 
   94         :param uuid UUID of the script to modify.
   95         :param data: Script data.
   96         """
   97 
   98     @abc.abstractmethod
   99     def delete_script(self, name=None, uuid=None):
  100         """Delete a list.
  101 
  102         :param name: Name of the script to delete.
  103         :param uuid: UUID of the script to delete.
  104         """