コード例 #1
0
ファイル: api.py プロジェクト: Kernelalive/kingbird
def resource_sync_list_by_job(context, job_id):
    parent_row = model_query(context, models.SyncJob).\
        filter_by(id=job_id, user_id=context.user,
                  project_id=context.project).first()
    if not parent_row:
        raise exception.JobNotFound()
    rows = model_query(context, models.ResourceSync).\
        filter_by(job_id=parent_row.id).all()
    output = list()
    if not rows:
        raise exception.JobNotFound()
    for row in rows:
        result = dict()
        result['target_region'] = row.target_region
        result['source_region'] = row.source_region
        result['resource'] = row.resource
        result['resource_type'] = row.resource_type
        result['sync_status'] = row.sync_status
        if row.updated_at:
            result['updated_at'] = row.updated_at.isoformat()
        else:
            result['updated_at'] = "None"
        result['created_at'] = row.created_at.isoformat()
        output.append(result)
    return output
コード例 #2
0
ファイル: api.py プロジェクト: Kernelalive/kingbird
def sync_job_delete(context, job_id):
    with write_session() as session:
        parent_job = model_query(context, models.SyncJob). \
            filter_by(id=job_id, user_id=context.user,
                      project_id=context.project).first()
        if parent_job:
            child_jobs = model_query(context, models.ResourceSync). \
                filter_by(job_id=parent_job.id).all()
            if not child_jobs:
                raise exception.JobNotFound()
            for child_job in child_jobs:
                session.delete(child_job)
            session.delete(parent_job)
        else:
            raise exception.JobNotFound()
コード例 #3
0
ファイル: api.py プロジェクト: Kernelalive/kingbird
def sync_job_status(context, job_id):
    row = model_query(context, models.SyncJob).\
        filter_by(id=job_id, user_id=context.user,
                  project_id=context.project).first()
    if not row:
        raise exception.JobNotFound()
    status = row.sync_status
    return status
コード例 #4
0
ファイル: api.py プロジェクト: Kernelalive/kingbird
def resource_sync_status(context, job_id):
    rows = model_query(context, models.ResourceSync).\
        filter_by(job_id=job_id).all()
    output = list()
    if not rows:
        raise exception.JobNotFound()
    for row in rows:
        output.append(row.sync_status)
    return output
コード例 #5
0
ファイル: api.py プロジェクト: Kernelalive/kingbird
def sync_job_update(context, job_id, status):
    with write_session() as session:
        sync_job_ref = session.query(models.SyncJob). \
            filter_by(id=job_id).first()
        if not sync_job_ref:
            raise exception.JobNotFound()
        values = dict()
        values['sync_status'] = status
        sync_job_ref.update(values)
コード例 #6
0
 def update_result_in_database(self, context, job_id, region, resource,
                               result):
     """Update result in database based on the sync operation."""
     job_result = consts.JOB_SUCCESS if result else consts.JOB_FAILURE
     try:
         db_api.resource_sync_update(context, job_id, region, resource,
                                     job_result)
     except exceptions.JobNotFound():
         raise
     pass
コード例 #7
0
ファイル: api.py プロジェクト: Kernelalive/kingbird
def resource_sync_update(context, job_id, region, resource, status):
    with write_session() as session:
        resource_sync_ref = session.query(models.ResourceSync).\
            filter_by(job_id=job_id, target_region=region, resource=resource).\
            first()
        if not resource_sync_ref:
            raise exception.JobNotFound()
        values = dict()
        values['sync_status'] = status
        resource_sync_ref.update(values)
        return resource_sync_ref
コード例 #8
0
ファイル: api.py プロジェクト: Kernelalive/kingbird
def resource_sync_create(context, job, region, source_region, resource,
                         resource_type):
    if not job:
        raise exception.JobNotFound()
    with write_session() as session:
        rsc = models.ResourceSync()
        rsc.sync_job = job
        rsc.resource = resource
        rsc.target_region = region
        rsc.source_region = source_region
        rsc.resource_type = resource_type
        session.add(rsc)
        return rsc
コード例 #9
0
 def create_resources(self, job_id, force, region, source_keypair,
                      session, context):
     """Create resources using threads."""
     target_nova_client = NovaClient(region, session)
     try:
         target_nova_client.create_keypairs(force, source_keypair)
         LOG.info('keypair %(keypair)s created in %(region)s'
                  % {'keypair': source_keypair.name, 'region': region})
         try:
             db_api.resource_sync_update(context, job_id, region,
                                         source_keypair.name,
                                         consts.JOB_SUCCESS)
         except exceptions.JobNotFound():
             raise
     except Exception as exc:
         LOG.error('Exception Occurred: %(msg)s in %(region)s'
                   % {'msg': exc.message, 'region': region})
         try:
             db_api.resource_sync_update(context, job_id, region,
                                         source_keypair.name,
                                         consts.JOB_FAILURE)
         except exceptions.JobNotFound():
             raise
         pass