projects
/
osm
/
MON.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Modifies MON to create database if using mysql URI
[osm/MON.git]
/
osm_mon
/
core
/
database.py
diff --git
a/osm_mon/core/database.py
b/osm_mon/core/database.py
index
4cbd75f
..
939abc6
100644
(file)
--- a/
osm_mon/core/database.py
+++ b/
osm_mon/core/database.py
@@
-23,12
+23,15
@@
##
import logging
##
import logging
+import os
import uuid
from peewee import CharField, TextField, FloatField, Model, AutoField, Proxy
import uuid
from peewee import CharField, TextField, FloatField, Model, AutoField, Proxy
+from peewee_migrate import Router
from playhouse.db_url import connect
from playhouse.db_url import connect
-from osm_mon.core.settings import Config
+from osm_mon import migrations
+from osm_mon.core.config import Config
log = logging.getLogger(__name__)
log = logging.getLogger(__name__)
@@
-50,7
+53,7
@@
class VimCredentials(BaseModel):
user = CharField()
password = CharField()
tenant_name = CharField()
user = CharField()
password = CharField()
tenant_name = CharField()
- config = TextField(
default='{}'
)
+ config = TextField()
class Alarm(BaseModel):
class Alarm(BaseModel):
@@
-67,14
+70,13
@@
class Alarm(BaseModel):
class DatabaseManager:
class DatabaseManager:
- def __init__(self):
- cfg = Config.instance()
- cfg.read_environ()
- db.initialize(connect(cfg.DATABASE))
+ def __init__(self, config: Config):
+ db.initialize(connect(config.get('sql', 'database_uri')))
def create_tables(self) -> None:
with db.atomic():
def create_tables(self) -> None:
with db.atomic():
- db.create_tables([VimCredentials, Alarm])
+ router = Router(db, os.path.dirname(migrations.__file__))
+ router.run()
def get_credentials(self, vim_uuid: str = None) -> VimCredentials:
with db.atomic():
def get_credentials(self, vim_uuid: str = None) -> VimCredentials:
with db.atomic():