summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--moonv4/moon_db/Changelog5
-rw-r--r--moonv4/moon_db/moon_db/__init__.py2
-rw-r--r--moonv4/moon_db/moon_db/api/keystone.py18
-rw-r--r--moonv4/moon_db/moon_db/api/managers.py2
-rw-r--r--moonv4/moon_db/moon_db/api/model.py11
-rw-r--r--moonv4/moon_db/moon_db/api/pdp.py12
-rw-r--r--moonv4/moon_db/moon_db/api/policy.py12
-rw-r--r--moonv4/moon_db/moon_db/api/tenants.py2
-rw-r--r--moonv4/moon_db/moon_db/backends/memory.py2
-rw-r--r--moonv4/moon_db/moon_db/backends/sql.py15
-rw-r--r--moonv4/moon_db/moon_db/core.py16
-rw-r--r--moonv4/moon_db/moon_db/db_manager.py53
12 files changed, 70 insertions, 80 deletions
diff --git a/moonv4/moon_db/Changelog b/moonv4/moon_db/Changelog
index 9295c0de..16452f6e 100644
--- a/moonv4/moon_db/Changelog
+++ b/moonv4/moon_db/Changelog
@@ -23,3 +23,8 @@ CHANGES
-----
- Test PyPi upload
+1.0.3
+-----
+- Fix a bug in core.py
+- Update db_manager
+
diff --git a/moonv4/moon_db/moon_db/__init__.py b/moonv4/moon_db/moon_db/__init__.py
index bfca6ef9..d42cdbdf 100644
--- a/moonv4/moon_db/moon_db/__init__.py
+++ b/moonv4/moon_db/moon_db/__init__.py
@@ -3,5 +3,5 @@
# license which can be found in the file 'LICENSE' in this package distribution
# or at 'http://www.apache.org/licenses/LICENSE-2.0'.
-__version__ = "1.0.2"
+__version__ = "1.0.3"
diff --git a/moonv4/moon_db/moon_db/api/keystone.py b/moonv4/moon_db/moon_db/api/keystone.py
index b5d7e3a6..b570918c 100644
--- a/moonv4/moon_db/moon_db/api/keystone.py
+++ b/moonv4/moon_db/moon_db/api/keystone.py
@@ -8,13 +8,11 @@ import requests
import json
from uuid import uuid4
from oslo_log import log as logging
-from oslo_config import cfg
-from moon_utilities import exceptions
+from moon_utilities import exceptions, configuration
from moon_db.api.managers import Managers
from moon_utilities.security_functions import filter_input, login, logout
-LOG = logging.getLogger(__name__)
-CONF = cfg.CONF
+LOG = logging.getLogger("moon.db.api.keystone")
class KeystoneManager(Managers):
@@ -22,11 +20,13 @@ class KeystoneManager(Managers):
def __init__(self, connector=None):
self.driver = connector.driver
Managers.KeystoneManager = self
- self.__url = CONF.keystone.url
- self.__user = CONF.keystone.user
- self.__password = CONF.keystone.password
- self.__domain = CONF.keystone.domain
- self.__project = CONF.keystone.project
+ conf = configuration.get_configuration("openstack/keystone")['openstack/keystone']
+
+ self.__url = conf['url']
+ self.__user = conf['user']
+ self.__password = conf['password']
+ self.__domain = conf['domain']
+ self.__project = conf['project']
try:
os.environ.pop("http_proxy")
os.environ.pop("https_proxy")
diff --git a/moonv4/moon_db/moon_db/api/managers.py b/moonv4/moon_db/moon_db/api/managers.py
index 48ac9ce1..602e0f11 100644
--- a/moonv4/moon_db/moon_db/api/managers.py
+++ b/moonv4/moon_db/moon_db/api/managers.py
@@ -4,7 +4,7 @@
# or at 'http://www.apache.org/licenses/LICENSE-2.0'.
from oslo_log import log as logging
-LOG = logging.getLogger(__name__)
+LOG = logging.getLogger("moon.db.api.managers")
class Managers(object):
diff --git a/moonv4/moon_db/moon_db/api/model.py b/moonv4/moon_db/moon_db/api/model.py
index 22a5a834..f648295e 100644
--- a/moonv4/moon_db/moon_db/api/model.py
+++ b/moonv4/moon_db/moon_db/api/model.py
@@ -3,23 +3,14 @@
# license which can be found in the file 'LICENSE' in this package distribution
# or at 'http://www.apache.org/licenses/LICENSE-2.0'.
-import os
-import re
-import types
-import json
-import copy
from uuid import uuid4
-from oslo_config import cfg
from oslo_log import log as logging
-import requests
from moon_utilities import exceptions
from moon_utilities.security_functions import filter_input, enforce
-# from moon_db.api import algorithms
from moon_db.api.managers import Managers
-LOG = logging.getLogger(__name__)
-CONF = cfg.CONF
+LOG = logging.getLogger("moon.db.api.model")
class ModelManager(Managers):
diff --git a/moonv4/moon_db/moon_db/api/pdp.py b/moonv4/moon_db/moon_db/api/pdp.py
index f84c7a85..05eb163f 100644
--- a/moonv4/moon_db/moon_db/api/pdp.py
+++ b/moonv4/moon_db/moon_db/api/pdp.py
@@ -3,23 +3,13 @@
# license which can be found in the file 'LICENSE' in this package distribution
# or at 'http://www.apache.org/licenses/LICENSE-2.0'.
-import os
-import re
-import types
-import json
-import copy
from uuid import uuid4
-from oslo_config import cfg
from oslo_log import log as logging
-import requests
-from moon_utilities import exceptions
from moon_utilities.security_functions import filter_input, enforce
-# from moon_db.api import algorithms
from moon_db.api.managers import Managers
-LOG = logging.getLogger(__name__)
-CONF = cfg.CONF
+LOG = logging.getLogger("moon.db.api.pdp")
class PDPManager(Managers):
diff --git a/moonv4/moon_db/moon_db/api/policy.py b/moonv4/moon_db/moon_db/api/policy.py
index 0beaf78f..e0413bdc 100644
--- a/moonv4/moon_db/moon_db/api/policy.py
+++ b/moonv4/moon_db/moon_db/api/policy.py
@@ -3,23 +3,13 @@
# license which can be found in the file 'LICENSE' in this package distribution
# or at 'http://www.apache.org/licenses/LICENSE-2.0'.
-import os
-import re
-import types
-import json
-import copy
from uuid import uuid4
-from oslo_config import cfg
from oslo_log import log as logging
-import requests
-from moon_utilities import exceptions
from moon_utilities.security_functions import filter_input, enforce
-# from moon_db.api import algorithms
from moon_db.api.managers import Managers
-LOG = logging.getLogger(__name__)
-CONF = cfg.CONF
+LOG = logging.getLogger("moon.db.api.policy")
class PolicyManager(Managers):
diff --git a/moonv4/moon_db/moon_db/api/tenants.py b/moonv4/moon_db/moon_db/api/tenants.py
index dd7c4ec5..527e6712 100644
--- a/moonv4/moon_db/moon_db/api/tenants.py
+++ b/moonv4/moon_db/moon_db/api/tenants.py
@@ -9,7 +9,7 @@ from moon_db.api.managers import Managers
from moon_utilities.security_functions import filter_input, enforce
from oslo_log import log as logging
-LOG = logging.getLogger(__name__)
+LOG = logging.getLogger("moon.db.api.tenants")
class TenantManager(Managers):
diff --git a/moonv4/moon_db/moon_db/backends/memory.py b/moonv4/moon_db/moon_db/backends/memory.py
index 06de99eb..5762b183 100644
--- a/moonv4/moon_db/moon_db/backends/memory.py
+++ b/moonv4/moon_db/moon_db/backends/memory.py
@@ -11,7 +11,7 @@ from glob import glob
from oslo_config import cfg
from moon_db.core import ConfigurationDriver
-LOG = logging.getLogger(__name__)
+LOG = logging.getLogger("moon.db.driver.memory")
CONF = cfg.CONF
diff --git a/moonv4/moon_db/moon_db/backends/sql.py b/moonv4/moon_db/moon_db/backends/sql.py
index d6becbbe..78de468f 100644
--- a/moonv4/moon_db/moon_db/backends/sql.py
+++ b/moonv4/moon_db/moon_db/backends/sql.py
@@ -6,7 +6,7 @@
import copy
import json
from uuid import uuid4
-from moon_db.exception import *
+from moon_utilities.exceptions import *
from moon_db.core import PDPDriver, PolicyDriver, ModelDriver
import sqlalchemy as sql
import logging
@@ -15,15 +15,12 @@ from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine
from contextlib import contextmanager
from sqlalchemy import types as sql_types
-from oslo_config import cfg
-# from moon_utilities.exceptions import IntraExtensionUnknown
+from moon_utilities import configuration
-# from sqlalchemy.orm.exc import UnmappedInstanceError
-# from keystone.contrib.moon import InterExtensionDriver
-CONF = cfg.CONF
-LOG = logging.getLogger(__name__)
+LOG = logging.getLogger("moon.db.driver.sql")
Base = declarative_base()
+DEBUG = True if configuration.get_configuration("logging")['logging']['loggers']['moon']['level'] == "DEBUG" else False
class DictBase:
@@ -342,7 +339,7 @@ class Rule(Base, DictBase):
def session_scope(engine):
"""Provide a transactional scope around a series of operations."""
if type(engine) is str:
- echo = True if CONF.debug else False
+ echo = DEBUG
engine = create_engine(engine, echo=echo)
session = sessionmaker(bind=engine)()
try:
@@ -360,7 +357,7 @@ class BaseConnector(object):
engine = ""
def __init__(self, engine_name):
- echo = True if CONF.debug else False
+ echo = DEBUG
self.engine = create_engine(engine_name, echo=echo)
def init_db(self):
diff --git a/moonv4/moon_db/moon_db/core.py b/moonv4/moon_db/moon_db/core.py
index cf233ab2..069f2533 100644
--- a/moonv4/moon_db/moon_db/core.py
+++ b/moonv4/moon_db/moon_db/core.py
@@ -3,15 +3,14 @@
# license which can be found in the file 'LICENSE' in this package distribution
# or at 'http://www.apache.org/licenses/LICENSE-2.0'.
-from moon_db.exception import *
from oslo_log import log as logging
from oslo_config import cfg
from stevedore.driver import DriverManager
-from moon_utilities import options # noqa
+from moon_utilities import configuration
from moon_db.api import model, policy, pdp, keystone
CONF = cfg.CONF
-LOG = logging.getLogger(__name__)
+LOG = logging.getLogger("moon.db")
class Driver(DriverManager):
@@ -212,22 +211,21 @@ class KeystoneDriver(Driver):
super(KeystoneDriver, self).__init__(driver_name, engine_name)
-# TODO (asteroide): we may use an other driver like the SQL driver
-# so we can change the driver to directly interrogate the Keystone database.
+conf = configuration.get_configuration("database")['database']
KeystoneManager = keystone.KeystoneManager(
- KeystoneDriver(CONF.database.driver, CONF.database.url)
+ KeystoneDriver(conf['driver'], conf['url'])
)
ModelManager = model.ModelManager(
- ModelDriver(CONF.database.driver, CONF.database.url)
+ ModelDriver(conf['driver'], conf['url'])
)
PolicyManager = policy.PolicyManager(
- PolicyDriver(CONF.database.driver, CONF.database.url)
+ PolicyDriver(conf['driver'], conf['url'])
)
PDPManager = pdp.PDPManager(
- PDPDriver(CONF.database.driver, CONF.database.url)
+ PDPDriver(conf['driver'], conf['url'])
)
diff --git a/moonv4/moon_db/moon_db/db_manager.py b/moonv4/moon_db/moon_db/db_manager.py
index 1c10aa22..81e6fe77 100644
--- a/moonv4/moon_db/moon_db/db_manager.py
+++ b/moonv4/moon_db/moon_db/db_manager.py
@@ -8,21 +8,40 @@
import os
import glob
import importlib
-from oslo_config import cfg
-from oslo_log import log as logging
+import argparse
+import logging
from sqlalchemy import create_engine
from moon_db.migrate_repo import versions
+from moon_utilities import configuration
-# Note (asteroide): The next line must be called before the next import
-# aka before registering all the options
-cfg.CONF.register_cli_opt(cfg.StrOpt('command', positional=True,
- help="The command to execute (upgrade, downgrade)"))
-from moon_utilities import options # noqa
+parser = argparse.ArgumentParser()
+parser.add_argument('command', help='command (upgrade or downgrade)', nargs=1)
+parser.add_argument("--verbose", "-v", action='store_true', help="verbose mode")
+parser.add_argument("--debug", "-d", action='store_true', help="debug mode")
+args = parser.parse_args()
-LOG = logging.getLogger(__name__)
-CONF = cfg.CONF
+FORMAT = '%(asctime)-15s %(levelname)s %(message)s'
+if args.debug:
+ logging.basicConfig(
+ format=FORMAT,
+ level=logging.DEBUG)
+elif args.verbose:
+ logging.basicConfig(
+ format=FORMAT,
+ level=logging.INFO)
+else:
+ logging.basicConfig(
+ format=FORMAT,
+ level=logging.WARNING)
-engine = create_engine(CONF.database.url)
+requests_log = logging.getLogger("requests.packages.urllib3")
+requests_log.setLevel(logging.WARNING)
+requests_log.propagate = True
+
+logger = logging.getLogger("moon.db.manager")
+
+db_conf = configuration.get_configuration("database")["database"]
+engine = create_engine(db_conf['url'])
def format_data(ext):
@@ -31,15 +50,15 @@ def format_data(ext):
def run():
files = glob.glob(versions.__path__[0] + "/[0-9][0-9][0-9]*.py")
- # args = set_options()
for filename in files:
filename = os.path.basename(filename).replace(".py", "")
o = importlib.import_module("moon_db.migrate_repo.versions.{}".format(filename))
- LOG.info("Command is {}".format(CONF.command))
- if CONF.command in ("upgrade", "u", "up"):
- LOG.info("upgrading moon_db.migrate_repo.versions.{}".format(filename))
+ logger.info("Command is {}".format(args.command[0]))
+ if args.command[0] in ("upgrade", "u", "up"):
+ logger.info("upgrading moon_db.migrate_repo.versions.{}".format(filename))
o.upgrade(engine)
- elif CONF.command in ("downgrade", "d", "down"):
- LOG.info("downgrading moon_db.migrate_repo.versions.{}".format(filename))
+ elif args.command[0] in ("downgrade", "d", "down"):
+ logger.info("downgrading moon_db.migrate_repo.versions.{}".format(filename))
o.downgrade(engine)
- LOG.info("Done!")
+ else:
+ logger.critical("Cannot understand the command!")