def delete_routes(self): if self.route_objects: logger.info("Generating XML config") device = np.Device() flow = np.Flow() for route_object in self.route_objects: route_obj = route_object route = np.Route() flow.routes.append(route) route.name = route_obj.name route.operation = 'delete' device.routing_options.append(flow) device = device.export(netconf_config=True) return ET.tostring(device) else: return False
def to_xml(self, operation=None): logger.info("Operation: %s" % operation) if self.route_object: try: settings.PORTRANGE_LIMIT except: settings.PORTRANGE_LIMIT = 100 logger.info("Generating XML config") route_obj = self.route_object device = np.Device() flow = np.Flow() route = np.Route() flow.routes.append(route) device.routing_options.append(flow) route.name = route_obj.name if operation == "delete": logger.info("Requesting a delete operation") route.operation = operation device = device.export(netconf_config=True) return ET.tostring(device) if route_obj.source: route.match['source'].append(route_obj.source) if route_obj.destination: route.match['destination'].append(route_obj.destination) try: if route_obj.protocol: for protocol in route_obj.protocol.all(): route.match['protocol'].append(protocol.protocol) except: pass try: ports = [] if route_obj.port: portrange = str(route_obj.port) for port in portrange.split(","): route.match['port'].append(port) except: pass try: ports = [] if route_obj.destinationport: portrange = str(route_obj.destinationport) for port in portrange.split(","): route.match['destination-port'].append(port) except: pass try: if route_obj.sourceport: portrange = str(route_obj.sourceport) for port in portrange.split(","): route.match['source-port'].append(port) except: pass if route_obj.icmpcode: route.match['icmp-code'].append(route_obj.icmpcode) if route_obj.icmptype: route.match['icmp-type'].append(route_obj.icmptype) if route_obj.tcpflag: route.match['tcp-flags'].append(route_obj.tcpflag) try: if route_obj.dscp: for dscp in route_obj.dscp.all(): route.match['dscp'].append(dscp.dscp) except: pass try: if route_obj.fragmenttype: for frag in route_obj.fragmenttype.all(): route.match['fragment'].append(frag.fragmenttype) except: pass for thenaction in route_obj.then.all(): if thenaction.action_value: route.then[thenaction.action] = thenaction.action_value else: route.then[thenaction.action] = True if operation == "replace": logger.info("Requesting a replace operation") route.operation = operation device = device.export(netconf_config=True) logger.debug(ET.tostring(device)) return ET.tostring(device) else: return False