Esempio n. 1
0
def add_job_to_context(context, job_id):
    """Adds job to neutron context for use later."""
    db_job = db_api.async_transaction_find(
        context, id=job_id, scope=db_api.ONE)
    if not db_job:
        return
    context.async_job = {"job": v._make_job_dict(db_job)}
Esempio n. 2
0
def add_job_to_context(context, job_id):
    """Adds job to neutron context for use later."""
    db_job = db_api.async_transaction_find(context,
                                           id=job_id,
                                           scope=db_api.ONE)
    if not db_job:
        return
    context.async_job = {"job": v._make_job_dict(db_job)}
Esempio n. 3
0
def get_job(context, id):
    LOG.info("get_job %s for tenant %s" % (id, context.tenant_id))
    filters = {}
    job = db_api.async_transaction_find(context, id=id, scope=db_api.ONE,
                                        **filters)
    if not job:
        raise q_exc.JobNotFound(job_id=id)
    return v._make_job_dict(job)
Esempio n. 4
0
def get_job(context, id):
    LOG.info("get_job %s for tenant %s" % (id, context.tenant_id))
    filters = {}
    job = db_api.async_transaction_find(context,
                                        id=id,
                                        scope=db_api.ONE,
                                        **filters)
    if not job:
        raise q_exc.JobNotFound(job_id=id)
    return v._make_job_dict(job)
Esempio n. 5
0
def update_job(context, id, body):
    LOG.info("update_job %s for tenant %s" % (id, context.tenant_id))

    if not context.is_admin:
        raise n_exc.NotAuthorized()
    job_update = body.get('job')
    if not job_update:
        raise n_exc.BadRequest(resource="job", msg="Invalid request body.")
    job = db_api.async_transaction_find(context, id=id, scope=db_api.ONE)
    if not job:
        raise q_exc.JobNotFound(job_id=id)
    job_mod = db_api.async_transaction_update(context, job, **job_update)
    return v._make_job_dict(job_mod)
Esempio n. 6
0
def update_job(context, id, body):
    LOG.info("update_job %s for tenant %s" % (id, context.tenant_id))

    if not context.is_admin:
        raise n_exc.NotAuthorized()
    job_update = body.get('job')
    if not job_update:
        raise n_exc.BadRequest(resource="job", msg="Invalid request body.")
    job = db_api.async_transaction_find(context, id=id, scope=db_api.ONE)
    if not job:
        raise q_exc.JobNotFound(job_id=id)
    job_mod = db_api.async_transaction_update(context, job, **job_update)
    return v._make_job_dict(job_mod)
Esempio n. 7
0
def delete_job(context, id, **filters):
    """Delete an ip address.

    : param context: neutron api request context
    : param id: UUID representing the ip address to delete.
    """
    LOG.info("delete_ip_address %s for tenant %s" % (id, context.tenant_id))

    if not context.is_admin:
        raise n_exc.NotAuthorized()
    with context.session.begin():
        job = db_api.async_transaction_find(context, id=id, scope=db_api.ONE,
                                            **filters)
        if not job:
            raise q_exc.JobNotFound(job_id=id)
        db_api.async_transaction_delete(context, job)
Esempio n. 8
0
def delete_job(context, id, **filters):
    """Delete an ip address.

    : param context: neutron api request context
    : param id: UUID representing the ip address to delete.
    """
    LOG.info("delete_ip_address %s for tenant %s" % (id, context.tenant_id))

    if not context.is_admin:
        raise n_exc.NotAuthorized()
    with context.session.begin():
        job = db_api.async_transaction_find(context,
                                            id=id,
                                            scope=db_api.ONE,
                                            **filters)
        if not job:
            raise q_exc.JobNotFound(job_id=id)
        db_api.async_transaction_delete(context, job)
Esempio n. 9
0
def create_job(context, body):
    """Creates a job with support for subjobs.

    If parent_id is not in the body:
    * the job is considered a parent job
    * it will have a NULL transaction id
    * its transaction id == its id
    * all subjobs will use its transaction id as theirs

    Else:
    * the job is a sub job
    * the parent id is the id passed in
    * the transaction id is the root of the job tree
    """
    LOG.info("create_job for tenant %s" % context.tenant_id)

    if not context.is_admin:
        raise n_exc.NotAuthorized()
    job = body.get('job')
    if 'parent_id' in job:
        parent_id = job['parent_id']
        if not parent_id:
            raise q_exc.JobNotFound(job_id=parent_id)
        parent_job = db_api.async_transaction_find(context,
                                                   id=parent_id,
                                                   scope=db_api.ONE)
        if not parent_job:
            raise q_exc.JobNotFound(job_id=parent_id)
        tid = parent_id
        if parent_job.get('transaction_id'):
            tid = parent_job.get('transaction_id')
        job['transaction_id'] = tid

    if not job:
        raise n_exc.BadRequest(resource="job", msg="Invalid request body.")
    with context.session.begin(subtransactions=True):
        new_job = db_api.async_transaction_create(context, **job)
    return v._make_job_dict(new_job)
Esempio n. 10
0
def create_job(context, body):
    """Creates a job with support for subjobs.

    If parent_id is not in the body:
    * the job is considered a parent job
    * it will have a NULL transaction id
    * its transaction id == its id
    * all subjobs will use its transaction id as theirs

    Else:
    * the job is a sub job
    * the parent id is the id passed in
    * the transaction id is the root of the job tree
    """
    LOG.info("create_job for tenant %s" % context.tenant_id)

    if not context.is_admin:
        raise n_exc.NotAuthorized()
    job = body.get('job')
    if 'parent_id' in job:
        parent_id = job['parent_id']
        if not parent_id:
            raise q_exc.JobNotFound(job_id=parent_id)
        parent_job = db_api.async_transaction_find(
            context, id=parent_id, scope=db_api.ONE)
        if not parent_job:
            raise q_exc.JobNotFound(job_id=parent_id)
        tid = parent_id
        if parent_job.get('transaction_id'):
            tid = parent_job.get('transaction_id')
        job['transaction_id'] = tid

    if not job:
        raise n_exc.BadRequest(resource="job", msg="Invalid request body.")
    with context.session.begin(subtransactions=True):
        new_job = db_api.async_transaction_create(context, **job)
    return v._make_job_dict(new_job)
Esempio n. 11
0
def get_jobs(context, **filters):
    LOG.info("get_jobs for tenant %s" % context.tenant_id)
    if not filters:
        filters = {}
    jobs = db_api.async_transaction_find(context, scope=db_api.ALL, **filters)
    return [v._make_job_dict(ip) for ip in jobs]
Esempio n. 12
0
def get_jobs(context, **filters):
    LOG.info("get_jobs for tenant %s" % context.tenant_id)
    if not filters:
        filters = {}
    jobs = db_api.async_transaction_find(context, scope=db_api.ALL, **filters)
    return [v._make_job_dict(ip) for ip in jobs]