def update_flow(flow_id, flow, correlation_id, tx): try: old_flow = flow_utils.get_old_flow(flow) # # Start the transaction to govern the create/delete # logger.info('Flow rules were built: correlation_id=%s, flow_id=%s', correlation_id, flow_id) rules = flow_utils.build_rules(flow) # TODO: add tx to store_flow flow_utils.store_flow(flow, tx) logger.info('Flow was stored: correlation_id=%s, flow_id=%s', correlation_id, flow_id) message_utils.send_install_commands(rules, correlation_id) MessageItem.delete_flow(old_flow['flowid'], old_flow, correlation_id, tx) payload = {'payload': flow, 'clazz': MT_FLOW_RESPONSE} message_utils.send_info_message(payload, correlation_id) except Exception as e: logger.exception('Can not update flow: %s', e.message) message_utils.send_error_message( correlation_id, "UPDATE_FAILURE", e.message, flow_id) raise return True
def update_flow(flow_id, flow, correlation_id): try: old_flow = flow_utils.get_old_flow(flow) old_flow_path = json.loads(old_flow['flowpath'])['path'] logger.info('Flow path remove: %s', old_flow_path) flow_utils.remove_flow(old_flow, old_flow_path) logger.info('Flow was removed: correlation_id=%s, flow_id=%s', correlation_id, flow_id) rules = flow_utils.build_rules(flow) logger.info('Flow rules were built: correlation_id=%s, flow_id=%s', correlation_id, flow_id) flow_utils.store_flow(flow) logger.info('Flow was stored: correlation_id=%s, flow_id=%s', correlation_id, flow_id) message_utils.send_install_commands(rules, correlation_id) logger.info('Flow rules installed: correlation_id=%s, flow_id=%s', correlation_id, flow_id) message_utils.send_delete_commands(old_flow_path, old_flow['flowid'], correlation_id, int(old_flow['cookie'])) logger.info('Flow rules removed: correlation_id=%s, flow_id=%s', correlation_id, flow_id) payload = {'payload': flow, 'clazz': MT_FLOW_RESPONSE} message_utils.send_info_message(payload, correlation_id) except Exception as e: logger.exception('Can not update flow: %s', e.message) message_utils.send_error_message(correlation_id, "UPDATE_FAILURE", e.message, flow_id) raise return True