Added root history to instance details. Still need to move the root history over to mysql/extensions, but the int tests work right now.
This commit is contained in:
parent
14d9d232db
commit
7ca1f7f159
@ -28,6 +28,8 @@ def map(engine, models):
|
||||
return
|
||||
|
||||
orm.mapper(models['instance'], Table('instances', meta, autoload=True))
|
||||
orm.mapper(models['root_enabled_history'],
|
||||
Table('root_enabled_history', meta, autoload=True))
|
||||
orm.mapper(models['service_image'],
|
||||
Table('service_images', meta, autoload=True))
|
||||
orm.mapper(models['service_statuses'],
|
||||
|
@ -20,11 +20,9 @@ from sqlalchemy.schema import Column
|
||||
from sqlalchemy.schema import MetaData
|
||||
from sqlalchemy.schema import UniqueConstraint
|
||||
|
||||
from reddwarf.db.sqlalchemy.migrate_repo.schema import Boolean
|
||||
from reddwarf.db.sqlalchemy.migrate_repo.schema import create_tables
|
||||
from reddwarf.db.sqlalchemy.migrate_repo.schema import DateTime
|
||||
from reddwarf.db.sqlalchemy.migrate_repo.schema import drop_tables
|
||||
from reddwarf.db.sqlalchemy.migrate_repo.schema import Integer
|
||||
from reddwarf.db.sqlalchemy.migrate_repo.schema import String
|
||||
from reddwarf.db.sqlalchemy.migrate_repo.schema import Table
|
||||
|
||||
@ -33,8 +31,7 @@ meta = MetaData()
|
||||
|
||||
root_enabled_history = Table('root_enabled_history', meta,
|
||||
Column('id', String(36), primary_key=True, nullable=False),
|
||||
Column('instance_id', String(36), nullable=False),
|
||||
Column('user_id', String(length=255)),
|
||||
Column('user', String(length=255)),
|
||||
Column('created', DateTime()),
|
||||
)
|
||||
|
||||
|
@ -106,24 +106,14 @@ class Root(object):
|
||||
return create_guest_client(context, instance_id).is_root_enabled()
|
||||
|
||||
@classmethod
|
||||
def create(cls, context, instance_id):
|
||||
def create(cls, context, instance_id, user):
|
||||
load_and_verify(context, instance_id)
|
||||
root = create_guest_client(context, instance_id).enable_root()
|
||||
root_user = guest_models.MySQLUser()
|
||||
root_user.deserialize(root)
|
||||
# Ledger
|
||||
root_history = base_models.RootHistory.create(context, instance_id, user)
|
||||
return root_user
|
||||
|
||||
class RootHistory(object):
|
||||
|
||||
@classmethod
|
||||
def load(cls, context, instance_id, user):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def create(cls, context, instance_id, user):
|
||||
pass
|
||||
|
||||
|
||||
class Users(object):
|
||||
|
||||
|
@ -74,7 +74,8 @@ class RootController(BaseController):
|
||||
LOG.info(_("Enabling root for instance '%s'") % instance_id)
|
||||
LOG.info(_("req : '%s'\n\n") % req)
|
||||
context = req.environ[wsgi.CONTEXT_KEY]
|
||||
root = models.Root.create(context, instance_id)
|
||||
user_name = req.headers.get('X-User', None)
|
||||
root = models.Root.create(context, instance_id, user_name)
|
||||
return wsgi.Result(views.RootCreatedView(root).data(), 200)
|
||||
|
||||
|
||||
|
@ -473,6 +473,7 @@ def persisted_models():
|
||||
'instance': DBInstance,
|
||||
'service_image': ServiceImage,
|
||||
'service_statuses': InstanceServiceStatus,
|
||||
'root_enabled_history': RootHistory,
|
||||
}
|
||||
|
||||
|
||||
@ -550,6 +551,37 @@ class ServiceStatus(object):
|
||||
return self._description
|
||||
|
||||
|
||||
class RootHistory(ModelBase):
|
||||
|
||||
_auto_generated_attrs = ['id']
|
||||
_data_fields = ['instance_id', 'user', 'created']
|
||||
_table_name = 'root_enabled_history'
|
||||
|
||||
def __init__(self, instance_id, user):
|
||||
self.id = instance_id
|
||||
self.user = user
|
||||
self.created = utils.utcnow()
|
||||
|
||||
def save(self):
|
||||
LOG.debug(_("Saving %s: %s") % (self.__class__.__name__, self.__dict__))
|
||||
return db.db_api.save(self)
|
||||
|
||||
@classmethod
|
||||
def load(cls, context, instance_id):
|
||||
history = db.db_api.find_by(cls, id=instance_id)
|
||||
return history
|
||||
|
||||
@classmethod
|
||||
def create(cls, context, instance_id, user):
|
||||
history = cls.load(context, instance_id)
|
||||
if history is not None:
|
||||
return history
|
||||
LOG.debug("Context right now is: %s" % str(context.to_dict()))
|
||||
history = RootHistory(instance_id, user)
|
||||
history.save()
|
||||
return history
|
||||
|
||||
|
||||
class ServiceStatuses(object):
|
||||
RUNNING = ServiceStatus(0x01, 'running', 'ACTIVE')
|
||||
BLOCKED = ServiceStatus(0x02, 'blocked', 'BLOCKED')
|
||||
|
@ -198,7 +198,9 @@ class InstanceController(BaseController):
|
||||
LOG.error(e)
|
||||
return wsgi.Result(str(e), 404)
|
||||
# TODO(cp16net): need to set the return code correctly
|
||||
return wsgi.Result(views.InstanceDetailView(server,
|
||||
# Adding the root history, if it exists.
|
||||
history = models.RootHistory.load(context=context, instance_id=id)
|
||||
return wsgi.Result(views.InstanceDetailView(server, roothistory=history,
|
||||
add_addresses=self.add_addresses).data(), 200)
|
||||
|
||||
def delete(self, req, tenant_id, id):
|
||||
|
@ -44,11 +44,18 @@ class InstanceView(object):
|
||||
|
||||
class InstanceDetailView(InstanceView):
|
||||
|
||||
def __init__(self, instance, add_addresses=False, roothistory=None):
|
||||
super(InstanceDetailView, self).__init__(instance, add_addresses)
|
||||
self.roothistory = roothistory
|
||||
|
||||
def data(self):
|
||||
result = super(InstanceDetailView, self).data()
|
||||
result['instance']['created'] = self.instance.created
|
||||
result['instance']['flavor'] = self.instance.flavor
|
||||
result['instance']['updated'] = self.instance.updated
|
||||
if self.roothistory:
|
||||
result['instance']['root_enabled_at'] = self.roothistory.created
|
||||
result['instance']['root_enabled_by'] = self.roothistory.user
|
||||
return result
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user