Merge "enginefacade: 'host_mapping'"
This commit is contained in:
commit
5e52d3bec0
@ -40,8 +40,7 @@ class HostMapping(base.NovaTimestampObject, base.NovaObject,
|
||||
}
|
||||
|
||||
def _get_cell_mapping(self):
|
||||
session = db_api.get_api_session()
|
||||
with session.begin():
|
||||
with db_api.api_context_manager.reader.using(self._context) as session:
|
||||
cell_map = (session.query(api_models.CellMapping)
|
||||
.join(api_models.HostMapping)
|
||||
.filter(api_models.HostMapping.host == self.host)
|
||||
@ -76,19 +75,17 @@ class HostMapping(base.NovaTimestampObject, base.NovaObject,
|
||||
return host_mapping
|
||||
|
||||
@staticmethod
|
||||
@db_api.api_context_manager.reader
|
||||
def _get_by_host_from_db(context, host):
|
||||
session = db_api.get_api_session()
|
||||
|
||||
with session.begin():
|
||||
db_mapping = (session.query(api_models.HostMapping)
|
||||
.join(api_models.CellMapping)
|
||||
.with_entities(api_models.HostMapping,
|
||||
api_models.CellMapping)
|
||||
.filter(api_models.HostMapping.host == host)).first()
|
||||
if not db_mapping:
|
||||
raise exception.HostMappingNotFound(name=host)
|
||||
host_mapping = db_mapping[0]
|
||||
host_mapping["cell_mapping"] = db_mapping[1]
|
||||
db_mapping = (context.session.query(api_models.HostMapping)
|
||||
.join(api_models.CellMapping)
|
||||
.with_entities(api_models.HostMapping,
|
||||
api_models.CellMapping)
|
||||
.filter(api_models.HostMapping.host == host)).first()
|
||||
if not db_mapping:
|
||||
raise exception.HostMappingNotFound(name=host)
|
||||
host_mapping = db_mapping[0]
|
||||
host_mapping["cell_mapping"] = db_mapping[1]
|
||||
return host_mapping
|
||||
|
||||
@base.remotable_classmethod
|
||||
@ -97,11 +94,11 @@ class HostMapping(base.NovaTimestampObject, base.NovaObject,
|
||||
return cls._from_db_object(context, cls(), db_mapping)
|
||||
|
||||
@staticmethod
|
||||
@db_api.api_context_manager.writer
|
||||
def _create_in_db(context, updates):
|
||||
session = db_api.get_api_session()
|
||||
db_mapping = api_models.HostMapping()
|
||||
db_mapping.update(updates)
|
||||
db_mapping.save(session)
|
||||
db_mapping.save(context.session)
|
||||
return db_mapping
|
||||
|
||||
@base.remotable
|
||||
@ -113,16 +110,14 @@ class HostMapping(base.NovaTimestampObject, base.NovaObject,
|
||||
self._from_db_object(self._context, self, db_mapping)
|
||||
|
||||
@staticmethod
|
||||
@db_api.api_context_manager.writer
|
||||
def _save_in_db(context, obj, updates):
|
||||
session = db_api.get_api_session()
|
||||
with session.begin():
|
||||
db_mapping = session.query(
|
||||
api_models.HostMapping).filter_by(
|
||||
id=obj.id).first()
|
||||
if not db_mapping:
|
||||
raise exception.HostMappingNotFound(name=obj.host)
|
||||
db_mapping = context.session.query(api_models.HostMapping).filter_by(
|
||||
id=obj.id).first()
|
||||
if not db_mapping:
|
||||
raise exception.HostMappingNotFound(name=obj.host)
|
||||
|
||||
db_mapping.update(updates)
|
||||
db_mapping.update(updates)
|
||||
return db_mapping
|
||||
|
||||
@base.remotable
|
||||
@ -135,14 +130,12 @@ class HostMapping(base.NovaTimestampObject, base.NovaObject,
|
||||
self.obj_reset_changes()
|
||||
|
||||
@staticmethod
|
||||
@db_api.api_context_manager.writer
|
||||
def _destroy_in_db(context, host):
|
||||
session = db_api.get_api_session()
|
||||
|
||||
with session.begin():
|
||||
result = session.query(api_models.HostMapping).filter_by(
|
||||
host=host).delete()
|
||||
if not result:
|
||||
raise exception.HostMappingNotFound(name=host)
|
||||
result = context.session.query(api_models.HostMapping).filter_by(
|
||||
host=host).delete()
|
||||
if not result:
|
||||
raise exception.HostMappingNotFound(name=host)
|
||||
|
||||
@base.remotable
|
||||
def destroy(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user