コード例 #1
0
ファイル: jobs.py プロジェクト: Anonymike/quark
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)}
コード例 #2
0
ファイル: jobs.py プロジェクト: MultipleCrashes/quark
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)}
コード例 #3
0
ファイル: jobs.py プロジェクト: Anonymike/quark
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)
コード例 #4
0
ファイル: jobs.py プロジェクト: MultipleCrashes/quark
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)
コード例 #5
0
ファイル: jobs.py プロジェクト: roaet/quark
def create_job(context, body):
    LOG.info("create_job for tenant %s" % context.tenant_id)

    if not context.is_admin:
        raise n_exc.NotAuthorized()
    job = body.get('job')
    if not job:
        raise n_exc.BadRequest(resource="job", msg="Invalid request body.")
    with context.session.begin():
        new_job = db_api.async_transaction_create(context, **job)
    return v._make_job_dict(new_job)
コード例 #6
0
ファイル: jobs.py プロジェクト: MultipleCrashes/quark
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)
コード例 #7
0
ファイル: jobs.py プロジェクト: Anonymike/quark
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)
コード例 #8
0
ファイル: jobs.py プロジェクト: MultipleCrashes/quark
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)
コード例 #9
0
ファイル: jobs.py プロジェクト: Anonymike/quark
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)
コード例 #10
0
ファイル: jobs.py プロジェクト: MultipleCrashes/quark
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]
コード例 #11
0
ファイル: jobs.py プロジェクト: Anonymike/quark
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]