def delete(self): context = api.request.context cdict = context.to_policy_values() policy.authorize('baremetal:allocation:delete', cdict, cdict) rpc_node = api_utils.get_rpc_node_with_suffix(self.parent_node_ident) allocations = objects.Allocation.list( api.request.context, filters={'node_uuid': rpc_node.uuid}) try: rpc_allocation = allocations[0] except IndexError: raise exception.AllocationNotFound( _("Allocation for node %s was not found") % self.parent_node_ident) notify.emit_start_notification(context, rpc_allocation, 'delete', node_uuid=rpc_node.uuid) with notify.handle_error_notification(context, rpc_allocation, 'delete', node_uuid=rpc_node.uuid): topic = api.request.rpcapi.get_random_topic() api.request.rpcapi.destroy_allocation(context, rpc_allocation, topic) notify.emit_end_notification(context, rpc_allocation, 'delete', node_uuid=rpc_node.uuid)
def get_all(self, fields=None): parent_node = self.parent_node_ident result = self.inner._get_allocations_collection( parent_node, fields=fields, parent_node=parent_node) try: return result['allocations'][0] except IndexError: raise exception.AllocationNotFound( _("Allocation for node %s was not found") % self.parent_node_ident)
def get_all(self, fields=None): api_utils.check_policy('baremetal:allocation:get') result = self.inner._get_allocations_collection(self.parent_node_ident, fields=fields) try: return result['allocations'][0] except IndexError: raise exception.AllocationNotFound( _("Allocation for node %s was not found") % self.parent_node_ident)
def get_all(self, fields=None): cdict = api.request.context.to_policy_values() policy.authorize('baremetal:allocation:get', cdict, cdict) result = self.inner._get_allocations_collection(self.parent_node_ident, fields=fields) try: return result.allocations[0] except IndexError: raise exception.AllocationNotFound( _("Allocation for node %s was not found") % self.parent_node_ident)
def delete(self): context = api.request.context rpc_node = api_utils.get_rpc_node_with_suffix(self.parent_node_ident) # Check the policy, and 404 if not authorized. api_utils.check_owner_policy('node', 'baremetal:node:get', rpc_node.owner, lessee=rpc_node.lessee, conceal_node=self.parent_node_ident) # A project ID is associated, thus we should filter # our search using it. filters = {'node_uuid': rpc_node.uuid} allocations = objects.Allocation.list(api.request.context, filters=filters) try: rpc_allocation = allocations[0] allocation_owner = allocations[0]['owner'] api_utils.check_owner_policy('allocation', 'baremetal:allocation:delete', allocation_owner) except IndexError: raise exception.AllocationNotFound( _("Allocation for node %s was not found") % self.parent_node_ident) notify.emit_start_notification(context, rpc_allocation, 'delete', node_uuid=rpc_node.uuid) with notify.handle_error_notification(context, rpc_allocation, 'delete', node_uuid=rpc_node.uuid): topic = api.request.rpcapi.get_random_topic() api.request.rpcapi.destroy_allocation(context, rpc_allocation, topic) notify.emit_end_notification(context, rpc_allocation, 'delete', node_uuid=rpc_node.uuid)