Ejemplo n.º 1
0
 def delete(self, session=None):
     """Delete this object."""
     self.deleted = True
     self.deleted_at = timeutils.utcnow()
     if not session:
         session = sql_session.get_session()
     session.delete(self)
     session.flush()
Ejemplo n.º 2
0
def taskdetail_destroy(td_id):
    """Deletes the TaskDetail model with matching td_id"""
    # Get a session for interaction with the database
    session = sql_session.get_session()
    with session.begin():
        # Get the TaskDetail model to delete
        td = _taskdetail_get_model(td_id, session=session)
        # Delete the TaskDetail model from the database
        td.delete(session=session)
Ejemplo n.º 3
0
def logbook_destroy(lb_id):
    """Deletes the LogBook model with matching lb_id"""
    # Get the session to interact with the database
    session = sql_session.get_session()
    with session.begin():
        # Get the LogBook model
        lb = _logbook_get_model(lb_id, session=session)
        # Delete the LogBook model from the database
        lb.delete(session=session)
Ejemplo n.º 4
0
def flowdetail_destroy(fd_id):
    """Deletes the FlowDetail model with matching fd_id"""
    # Get a session for interaction with the database
    session = sql_session.get_session()
    with session.begin():
        # Get the FlowDetail model
        fd = _flowdetail_get_model(fd_id, session=session)
        # Delete the FlowDetail from the database
        fd.delete(session=session)
Ejemplo n.º 5
0
def flowdetail_remove_taskdetail(fd_id, td_id):
    """Removes a TaskDetail with id td_id from a FlowDetail with id fd_id"""
    # Get a session for interaction with the database
    session = sql_session.get_session()
    with session.begin():
        # Get the FlowDetail model
        fd = _flowdetail_get_model(fd_id, session=session)
        # Remove the TaskDetail from the FlowDetail model
        fd.taskdetails = [td for td in fd.taskdetails
                          if td.taskdetail_id != td_id]
Ejemplo n.º 6
0
def logbook_remove_flowdetail(lb_id, fd_id):
    """Removes a FlowDetail with id fd_id from a LogBook with id lb_id"""
    # Get a session to interact with the database
    session = sql_session.get_session()
    with session.begin():
        # Get the LogBook model
        lb = _logbook_get_model(lb_id, session=session)
        # Remove the FlowDetail model from the LogBook model
        lb.flowdetails = [fd for fd in lb.flowdetails
                          if fd.flowdetail_id != fd_id]
Ejemplo n.º 7
0
def flowdetail_add_task_detail(fd_id, td_id):
    """Adds a TaskDetail with id td_id to a Flowdetail with id fd_id"""
    # Get a session for interaction with the database
    session = sql_session.get_session()
    with session.begin():
        # Get the FlowDetail model
        fd = _flowdetail_get_model(fd_id, session=session)
        # Get the TaskDetail model
        td = _taskdetail_get_model(td_id, session=session)
        # Add the TaskDetail model to the FlowDetail model
        fd.taskdetails.append(td)
Ejemplo n.º 8
0
def logbook_add_flow_detail(lb_id, fd_id):
    """Adds a FlowDetail with id fd_id to a LogBook with id lb_id"""
    # Get a session to interact with the database
    session = sql_session.get_session()
    with session.begin():
        # Get the LogBook model from the database
        lb = _logbook_get_model(lb_id, session=session)
        # Get the FlowDetail model from the database
        fd = _flowdetail_get_model(fd_id, session=session)
        # Add the FlowDetail model to the LogBook model
        lb.flowdetails.append(fd)
Ejemplo n.º 9
0
 def save(self, session=None):
     """Save this object."""
     if not session:
         session = sql_session.get_session()
     session.add(self)
     try:
         session.flush()
     except IntegrityError, e:
         if str(e).endswith("is not unique"):
             raise exception.Duplicate(str(e))
         else:
             raise
Ejemplo n.º 10
0
def taskdetail_update(td_id, values):
    """Updates a TaskDetail with matching td_id"""
    # Get a session for interaction with the database
    session = sql_session.get_session()
    with session.begin():
        # Get the TaskDetail model
        td = _taskdetail_get_model(td_id, session=session)

        # Update the TaskDetail model with values
        td.update(values)
        # Write the TaskDetail model changes to the database
        td.save(session=session)
Ejemplo n.º 11
0
def logbook_delete(lb):
    """Deletes a LogBook from db based on a generic type"""
    # Get a session to interact with the database
    session = sql_session.get_session()
    with session.begin():
        # Get the LogBook model
        lb_model = _logbook_get_model(lb.uuid, session=session)

    # Raise an error if the LogBook model still has FlowDetails
    if lb_model.flowdetails:
        raise exception.Error("Logbook <%s> still has "
                              "dependents." % (lb.uuid,))
    # Destroy the model if it is safe
    else:
        logbook_destroy(lb.uuid)
Ejemplo n.º 12
0
def flowdetail_delete(fd):
    """Deletes a FlowDetail from db based on a generic type"""
    # Get a session to interact with the database
    session = sql_session.get_session()
    with session.begin():
        # Get the FlowDetail model
        fd_model = _flowdetail_get_model(fd.uuid, session=session)

    # Raise an error if the FlowDetail model still has TaskDetails
    if fd_model.taskdetails:
        raise exception.Error("FlowDetail <%s> still has "
                              "dependents." % (fd.uuid,))
    # If it is safe, destroy the FlowDetail model from the database
    else:
        flowdetail_destroy(fd.uuid)
Ejemplo n.º 13
0
def logbook_get(lb_id):
    """Gets a LogBook with matching lb_id, if it exists"""
    # Get a session to interact with the database
    session = sql_session.get_session()
    with session.begin():
        # Get the LogBook model from the database
        lb = _logbook_get_model(lb_id, session=session)

    # Create a generic LogBook to return
    retVal = logbook.LogBook(lb.name, lb.logbook_id)

    # Add the generic FlowDetails associated with this LogBook
    for fd in lb.flowdetails:
        retVal.add_flow_detail(flowdetail_get(fd.flowdetail_id))

    return retVal
Ejemplo n.º 14
0
def flowdetail_get(fd_id):
    """Gets a FlowDetail with matching fd_id, if it exists"""
    # Get a session for interaction with the database
    session = sql_session.get_session()
    with session.begin():
        # Get the FlowDetail model from the database
        fd = _flowdetail_get_model(fd_id, session=session)

    # Create a generic FlowDetail to return
    retVal = flowdetail.FlowDetail(fd.name, None, fd.flowdetail_id)

    # Update attributes to match
    retVal.updated_at = fd.updated_at

    # Add the TaskDetails belonging to this FlowDetail to itself
    for td in fd.taskdetails:
        retVal.add_task_detail(taskdetail_get(td.taskdetail_id))

    return retVal
Ejemplo n.º 15
0
def taskdetail_get(td_id):
    """Gets a TaskDetail with matching td_id, if it exists"""
    # Get a session for interaction with the database
    session = sql_session.get_session()
    with session.begin():
        # Get the TaskDetail model
        td = _taskdetail_get_model(td_id, session=session)

    # Create a generic type Task to return as part of the TaskDetail
    tsk = None

    # Create a generic type TaskDetail to return
    retVal = taskdetail.TaskDetail(td.name, tsk, td.taskdetail_id)
    # Update the TaskDetail to reflect the data in the database
    retVal.updated_at = td.updated_at
    retVal.state = td.state
    retVal.results = td.results
    retVal.exception = td.exception
    retVal.stacktrace = td.stacktrace
    retVal.meta = td.meta

    return retVal
Ejemplo n.º 16
0
def model_query(*args, **kwargs):
    session = kwargs.get('session') or sql_session.get_session()
    query = session.query(*args)

    return query