Merge "enginefacade: 'certificate' and 'pci_device'"

This commit is contained in:
Jenkins 2015-11-16 17:18:13 +00:00 committed by Gerrit Code Review
commit 8665c9c654

View File

@ -679,26 +679,30 @@ def compute_node_statistics(context):
################### ###################
@main_context_manager.writer
def certificate_create(context, values): def certificate_create(context, values):
certificate_ref = models.Certificate() certificate_ref = models.Certificate()
for (key, value) in values.items(): for (key, value) in values.items():
certificate_ref[key] = value certificate_ref[key] = value
certificate_ref.save() certificate_ref.save(context.session)
return certificate_ref return certificate_ref
@main_context_manager.reader
def certificate_get_all_by_project(context, project_id): def certificate_get_all_by_project(context, project_id):
return model_query(context, models.Certificate, read_deleted="no").\ return model_query(context, models.Certificate, read_deleted="no").\
filter_by(project_id=project_id).\ filter_by(project_id=project_id).\
all() all()
@main_context_manager.reader
def certificate_get_all_by_user(context, user_id): def certificate_get_all_by_user(context, user_id):
return model_query(context, models.Certificate, read_deleted="no").\ return model_query(context, models.Certificate, read_deleted="no").\
filter_by(user_id=user_id).\ filter_by(user_id=user_id).\
all() all()
@main_context_manager.reader
def certificate_get_all_by_user_and_project(context, user_id, project_id): def certificate_get_all_by_user_and_project(context, user_id, project_id):
return model_query(context, models.Certificate, read_deleted="no").\ return model_query(context, models.Certificate, read_deleted="no").\
filter_by(user_id=user_id).\ filter_by(user_id=user_id).\
@ -6354,6 +6358,7 @@ def _instance_group_policies_add(context, id, policies, set_delete=False,
#################### ####################
@main_context_manager.reader
def pci_device_get_by_addr(context, node_id, dev_addr): def pci_device_get_by_addr(context, node_id, dev_addr):
pci_dev_ref = model_query(context, models.PciDevice).\ pci_dev_ref = model_query(context, models.PciDevice).\
filter_by(compute_node_id=node_id).\ filter_by(compute_node_id=node_id).\
@ -6364,6 +6369,7 @@ def pci_device_get_by_addr(context, node_id, dev_addr):
return pci_dev_ref return pci_dev_ref
@main_context_manager.reader
def pci_device_get_by_id(context, id): def pci_device_get_by_id(context, id):
pci_dev_ref = model_query(context, models.PciDevice).\ pci_dev_ref = model_query(context, models.PciDevice).\
filter_by(id=id).\ filter_by(id=id).\
@ -6373,6 +6379,7 @@ def pci_device_get_by_id(context, id):
return pci_dev_ref return pci_dev_ref
@main_context_manager.reader
def pci_device_get_all_by_node(context, node_id): def pci_device_get_all_by_node(context, node_id):
return model_query(context, models.PciDevice).\ return model_query(context, models.PciDevice).\
filter_by(compute_node_id=node_id).\ filter_by(compute_node_id=node_id).\
@ -6380,6 +6387,7 @@ def pci_device_get_all_by_node(context, node_id):
@require_context @require_context
@main_context_manager.reader
def pci_device_get_all_by_instance_uuid(context, instance_uuid): def pci_device_get_all_by_instance_uuid(context, instance_uuid):
return model_query(context, models.PciDevice).\ return model_query(context, models.PciDevice).\
filter_by(status='allocated').\ filter_by(status='allocated').\
@ -6387,12 +6395,14 @@ def pci_device_get_all_by_instance_uuid(context, instance_uuid):
all() all()
def _instance_pcidevs_get_multi(context, instance_uuids, session=None): @main_context_manager.reader
return model_query(context, models.PciDevice, session=session).\ def _instance_pcidevs_get_multi(context, instance_uuids):
return model_query(context, models.PciDevice).\
filter_by(status='allocated').\ filter_by(status='allocated').\
filter(models.PciDevice.instance_uuid.in_(instance_uuids)) filter(models.PciDevice.instance_uuid.in_(instance_uuids))
@main_context_manager.writer
def pci_device_destroy(context, node_id, address): def pci_device_destroy(context, node_id, address):
result = model_query(context, models.PciDevice).\ result = model_query(context, models.PciDevice).\
filter_by(compute_node_id=node_id).\ filter_by(compute_node_id=node_id).\
@ -6402,17 +6412,15 @@ def pci_device_destroy(context, node_id, address):
raise exception.PciDeviceNotFound(node_id=node_id, address=address) raise exception.PciDeviceNotFound(node_id=node_id, address=address)
@main_context_manager.writer
def pci_device_update(context, node_id, address, values): def pci_device_update(context, node_id, address, values):
session = get_session() query = model_query(context, models.PciDevice, read_deleted="no").\
with session.begin():
query = model_query(context, models.PciDevice, session=session,
read_deleted="no").\
filter_by(compute_node_id=node_id).\ filter_by(compute_node_id=node_id).\
filter_by(address=address) filter_by(address=address)
if query.update(values) == 0: if query.update(values) == 0:
device = models.PciDevice() device = models.PciDevice()
device.update(values) device.update(values)
session.add(device) context.session.add(device)
return query.one() return query.one()