Example #1
0
def contract_destroy(contract_id, context):
    if context.is_admin:
        contract_ref = contract_get(contract_id, context)
        if contract_ref:
            get_session().query(
                models.Contract).filter_by(contract_id=contract_id).delete()
        else:
            raise exception.ResourceNotFound(resource_type="Contract",
                                             resource_uuid=contract_id)
    else:
        raise exception.ResourceNoPermission(resource_type="Contract",
                                             resource_uuid=contract_id)
Example #2
0
def offer_update(offer_id, values, context):
    offer_ref = get_session().query(
        models.Offer).filter_by(offer_id=offer_id).one_or_none()

    if offer_ref:
        if offer_ref.project_id != context.project_id and not context.is_admin:
            raise exception.ResourceNoPermission(resource_type="Offer",
                                                 resource_uuid=offer_id)
        values.pop('offer_id', None)
        offer_ref.update(values)
        offer_ref.save(get_session())
        return offer_ref
    else:
        raise exception.ResourceNotFound(resource_type="Offer",
                                         resource_uuid=offer_id)
Example #3
0
def contract_update(contract_id, values, context):

    if context.is_admin:
        contract_ref = get_session().query(
            models.Contract).filter_by(contract_id=contract_id).one_or_none()
        if contract_ref:
            values.pop('contract_id', None)
            contract_ref.update(values)
            contract_ref.save(get_session())
            return contract_ref
        else:
            raise exception.ResourceNotFound(resource_type="Contract",
                                             resource_uuid=contract_id)
    else:
        raise exception.ResourceNoPermission(resource_type="Contract",
                                             resource_uuid=contract_id)
Example #4
0
def offer_destroy(offer_id, context):
    offer_ref = get_session().query(
        models.Offer).filter_by(offer_id=offer_id).one_or_none()

    if offer_ref:
        if offer_ref.project_id != context.project_id and not context.is_admin:
            raise exception.ResourceNoPermission(resource_type="Offer",
                                                 resource_uuid=offer_id)

        if context.is_admin:
            get_session().query(
                models.Offer).filter_by(offer_id=offer_id).delete()
        else:
            get_session().query(models.Offer).filter_by(
                offer_id=offer_id, project_id=context.project_id).delete()
    else:
        raise exception.ResourceNotFound(resource_type="Offer",
                                         resource_uuid=offer_id)
Example #5
0
def bid_update(bid_id, values, context):
    if context.is_admin:
        bid_ref = get_session().query(
            models.Bid).filter_by(bid_id=bid_id).one_or_none()
    else:
        bid_ref = get_session().query(
            models.Bid).filter_by(bid_id=bid_id).one_or_none()

    if bid_ref:
        if bid_ref.project_id != context.project_id and not context.is_admin:
            raise exception.ResourceNoPermission(resource_type="Bid",
                                                 resource_uuid=bid_id)

        values.pop('bid_id', None)
        bid_ref.update(values)
        bid_ref.save(get_session())
        return bid_ref
    else:
        raise exception.ResourceNotFound(resource_type="Bid",
                                         resource_uuid=bid_id)
Example #6
0
def bid_destroy(bid_id, context):
    if context.is_admin:
        bid_ref = get_session().query(
            models.Bid).filter_by(bid_id=bid_id).one_or_none()
    else:
        bid_ref = get_session().query(
            models.Bid).filter_by(bid_id=bid_id).one_or_none()

    if bid_ref:
        if bid_ref.project_id != context.project_id and not context.is_admin:
            raise exception.ResourceNoPermission(resource_type="Bid",
                                                 resource_uuid=bid_id)

        if context.is_admin:
            get_session().query(models.Bid).filter_by(bid_id=bid_id).delete()
        else:
            get_session().query(models.Bid).filter_by(
                bid_id=bid_id, project_id=context.project_id).delete()
    else:
        raise exception.ResourceNotFound(resource_type="Bid",
                                         resource_uuid=bid_id)
Example #7
0
def offer_create(values, context):
    resource_id = values['resource_id']
    resource_type = values.get('resource_type', resource_types.IRONIC_NODE)
    resource = ro_factory.ResourceObjectFactory.get_resource_object(
        resource_type, resource_id)

    if not resource.is_resource_admin(context.project_id):
        raise exception.ResourceNoPermission(resource_type=resource_type,
                                             resource_id=resource_id)

    if len(
            offer_get_all_by_resource_id(context, resource_id,
                                         statuses.AVAILABLE)) > 0:
        raise ValueError(
            "%resource_type %resource_id already has an available offer",
            resource_type, resource_id)

    values['offer_id'] = uuidutils.generate_uuid()
    values['project_id'] = context.project_id
    offer_ref = models.Offer()
    offer_ref.update(values)
    offer_ref.save(get_session())
    return offer_ref