Browse Source

Merge "Change access column type for instance"

tags/14.0.0.0rc1
Zuul 1 week ago
committed by Gerrit Code Review
parent
commit
38977368be
3 changed files with 15 additions and 8 deletions
  1. +0
    -6
      trove/db/sqlalchemy/migrate_repo/schema.py
  2. +2
    -2
      trove/db/sqlalchemy/migrate_repo/versions/046_add_access_to_instance.py
  3. +13
    -0
      trove/instance/models.py

+ 0
- 6
trove/db/sqlalchemy/migrate_repo/schema.py View File

@@ -18,7 +18,6 @@
from oslo_log import log as logging
import sqlalchemy.types


logger = logging.getLogger('trove.db.sqlalchemy.migrate_repo.schema')


@@ -63,11 +62,6 @@ class Float(sqlalchemy.types.Float):
super(Float, self).__init__(*args, **kwargs)


class Json(sqlalchemy.types.JSON):
def __init__(self, *args, **kwargs):
super(Json, self).__init__(*args, **kwargs)


def create_tables(tables):
for table in tables:
logger.info("creating table %(table)s", {'table': table})


+ 2
- 2
trove/db/sqlalchemy/migrate_repo/versions/046_add_access_to_instance.py View File

@@ -16,8 +16,8 @@
from sqlalchemy.schema import Column
from sqlalchemy.schema import MetaData

from trove.db.sqlalchemy.migrate_repo.schema import Json
from trove.db.sqlalchemy.migrate_repo.schema import Table
from trove.db.sqlalchemy.migrate_repo.schema import Text


def upgrade(migrate_engine):
@@ -25,4 +25,4 @@ def upgrade(migrate_engine):
meta.bind = migrate_engine

instances = Table('instances', meta, autoload=True)
instances.create_column(Column('access', Json(), nullable=True))
instances.create_column(Column('access', Text(), nullable=True))

+ 13
- 0
trove/instance/models.py View File

@@ -17,6 +17,7 @@
"""Model classes that form the core of instances functionality."""
from datetime import datetime
from datetime import timedelta
import json
import os.path
import re

@@ -492,6 +493,8 @@ class SimpleInstance(object):
@property
def access(self):
if hasattr(self.db_info, 'access'):
if type(self.db_info.access) == str:
return json.loads(self.db_info.access)
return self.db_info.access
else:
return None
@@ -885,6 +888,10 @@ class BaseInstance(SimpleInstance):

def update_db(self, **values):
self.db_info = DBInstance.find_by(id=self.id, deleted=False)

if 'access' in values and type(values['access'] != str):
values['access'] = json.dumps(values['access'])

for key in values:
setattr(self.db_info, key, values[key])
self.db_info.save()
@@ -1884,6 +1891,12 @@ class DBInstance(dbmodels.DatabaseModelBase):
return cu.decrypt_data(cu.decode_data(self.encrypted_key),
CONF.inst_rpc_key_encr_key)

@classmethod
def create(cls, **values):
if 'access' in values and type(values['access'] != str):
values['access'] = json.dumps(values['access'])
return super(DBInstance, cls).create(**values)

def _validate(self, errors):
if InstanceTask.from_code(self.task_id) is None:
errors['task_id'] = "Not valid."


Loading…
Cancel
Save