def dump_network(self): correlation_id = self.correlation_id step = "Init" logger.info('Dump network request: timestamp=%s, correlation_id=%s', self.timestamp, correlation_id) try: step = "Switches" switches = self.get_switches() logger.debug("%s: %s", step, switches) step = "ISLs" isls = self.get_isls() logger.debug("%s: %s", step, isls) step = "Flows" flows = flow_utils.get_flows() logger.debug("%s: %s", step, flows) step = "Send" payload = { 'switches': switches, 'isls': isls, 'flows': flows, 'message_type': "network"} message_utils.send_message( payload, correlation_id, "INFO", "WFM_CACHE") except Exception as e: logger.exception('Can not dump network: %s', e.message) message_utils.send_error_message( correlation_id, "INTERNAL_ERROR", e.message, step, "WFM_CACHE") raise return True
def delete_flow(flow_id, flow, correlation_id): try: flow_path = flow['flowpath']['path'] logger.info('Flow path remove: %s', flow_path) flow_utils.remove_flow(flow, flow_path) logger.info('Flow was removed: correlation_id=%s, flow_id=%s', correlation_id, flow_id) message_utils.send_delete_commands( flow_path, flow_id, correlation_id, int(flow['cookie'])) logger.info('Flow rules removed: correlation_id=%s, flow_id=%s', correlation_id, flow_id) payload = {'payload': flow, 'message_type': "flow"} message_utils.send_message(payload, correlation_id, "INFO") except Exception as e: logger.exception('Can not delete flow: %s', e.message) message_utils.send_error_message( correlation_id, "DELETION_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, 'message_type': "flow"} message_utils.send_message(payload, correlation_id, "INFO") 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 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, 'message_type': "flow"} message_utils.send_message(payload, correlation_id, "INFO") 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 send_message(data): logger.info(data) message_utils.send_message(data, "topology_reader-{}".format(time.time()), "INFO", "WFM_CACHE")