'Second pass to deal with connections between steps.
Create workflow connection objects using externally specified ids
using during creation or update.'

def __connect_workflow_steps(self, steps, steps_by_external_id):

    for step in steps:
        for (input_name, conn_list) in step.temp_input_connections.iteritems():
            if (not conn_list):
                continue
            if (not isinstance(conn_list, list)):
                conn_list = [conn_list]
            for conn_dict in conn_list:
                if (('output_name' not in conn_dict) or ('id' not in conn_dict)):
                    template = 'Invalid    connection    [%s]    -    must    be    dict    with    output_name    and    id    fields.'
                    message = (template % conn_dict)
                    raise exceptions.MessageException(message)
                conn = model.WorkflowStepConnection()
                conn.input_step = step
                conn.input_name = input_name
                conn.output_name = conn_dict['output_name']
                conn.output_step = steps_by_external_id[conn_dict['id']]
                input_subworkflow_step_index = conn_dict.get('input_subworkflow_step_id', None)
                if (input_subworkflow_step_index is not None):
                    conn.input_subworkflow_step = step.subworkflow.step_by_index(input_subworkflow_step_index)
        del step.temp_input_connections
