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 create_flow(flow_id, flow, correlation_id): try: 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) payload = {'payload': flow, 'clazz': MT_FLOW_RESPONSE} message_utils.send_info_message(payload, correlation_id) except Exception as e: logger.exception('Can not create flow: %s', flow_id) message_utils.send_error_message(correlation_id, "CREATION_FAILURE", e.message, flow_id) raise return True
def create_flow(flow_id, flow, correlation_id, tx, propagate=True, from_nb=False): """ :param propagate: If true, send to switch :param from_nb: If true, send response to NORTHBOUND API; otherwise to FLOW_TOPOLOGY :return: """ try: 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, tx) logger.info('Flow was stored: correlation_id=%s, flow_id=%s', correlation_id, flow_id) if propagate: message_utils.send_install_commands(rules, correlation_id) logger.info('Flow rules INSTALLED: correlation_id=%s, flow_id=%s', correlation_id, flow_id) if not from_nb: message_utils.send_info_message({'payload': flow, 'clazz': MT_FLOW_RESPONSE}, correlation_id) else: # The request is sent from Northbound .. send response back logger.info('Flow rules NOT PROPAGATED: correlation_id=%s, flow_id=%s', correlation_id, flow_id) data = {"payload":{"flowid": flow_id,"status": "UP"}, "clazz": message_utils.MT_INFO_FLOW_STATUS} message_utils.send_to_topic( payload=data, correlation_id=correlation_id, message_type=message_utils.MT_INFO, destination="NORTHBOUND", topic=config.KAFKA_NORTHBOUND_TOPIC ) except Exception as e: logger.exception('Can not create flow: %s', flow_id) if not from_nb: # Propagate is the normal scenario, so send response back to FLOW message_utils.send_error_message(correlation_id, "CREATION_FAILURE", e.message, flow_id) else: # This means we tried a PUSH, send response back to NORTHBOUND message_utils.send_error_message(correlation_id, "PUSH_FAILURE", e.message, flow_id, destination="NORTHBOUND", topic=config.KAFKA_NORTHBOUND_TOPIC) 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