Example #1
0
	def callback ():
		try:
			descriptions,command = extract_neighbors(line)
			peers = match_neighbors(reactor.peers,descriptions)
			if not peers:
				self.log_failure('no neighbor matching the command : %s' % command)
				reactor.processes.answer(service,'error')
				yield True
				return

			changes = self.api_route(command)
			if not changes:
				self.log_failure('command could not parse route in : %s' % command)
				reactor.processes.answer(service,'error')
				yield True
				return

			for change in changes:
				if not ParseStaticRoute.check(change):
					self.log_message('invalid route for %s : %s' % (', '.join(peers) if peers else 'all peers',change.extensive()))
					continue
				change.nlri.action = OUT.ANNOUNCE
				reactor.configuration.inject_change(peers,change)
				self.log_message('route added to %s : %s' % (', '.join(peers) if peers else 'all peers',change.extensive()))
				yield False

			reactor.processes.answer_done(service)
		except ValueError:
			self.log_failure('issue parsing the route')
			reactor.processes.answer(service,'error')
			yield True
		except IndexError:
			self.log_failure('issue parsing the route')
			reactor.processes.answer(service,'error')
			yield True
Example #2
0
    def callback():
        try:
            descriptions, command = self.parser.extract_neighbors(line)
            peers = reactor.match_neighbors(descriptions)
            if not peers:
                self.log_failure(
                    'no neighbor matching the command : %s' % command,
                    'warning')
                reactor.answer(service, 'error')
                yield True
                return

            changes = self.parser.api_route(command)
            if not changes:
                self.log_failure(
                    'command could not parse route in : %s' % command,
                    'warning')
                reactor.answer(service, 'error')
                yield True
                return

            for change in changes:
                # Change the action to withdraw before checking the route
                change.nlri.action = OUT.WITHDRAW
                # NextHop is a mandatory field (but we do not require in)
                if change.nlri.nexthop is NoNextHop:
                    change.nlri.nexthop = NextHop('0.0.0.0')

                if not ParseStaticRoute.check(change):
                    self.log_message(
                        'invalid route for %s : %s' %
                        (', '.join(peers) if peers else 'all peers',
                         change.extensive()))
                    continue
                if reactor.configuration.inject_change(peers, change):
                    self.log_message(
                        'route removed from %s : %s' %
                        (', '.join(peers) if peers else 'all peers',
                         change.extensive()))
                    yield False
                else:
                    self.log_failure(
                        'route not found on %s : %s' %
                        (', '.join(peers) if peers else 'all peers',
                         change.extensive()))
                    yield False

            reactor.route_update = True
            reactor.answer(service, 'done')
        except ValueError:
            self.log_failure('issue parsing the route')
            reactor.answer(service, 'error')
            yield True
        except IndexError:
            self.log_failure('issue parsing the route')
            reactor.answer(service, 'error')
            yield True
Example #3
0
    def callback():
        try:
            descriptions, command = self.parser.extract_neighbors(line)
            peers = reactor.match_neighbors(descriptions)
            if not peers:
                self.log_failure("no neighbor matching the command : %s" % command, "warning")
                reactor.answer(service, "error")
                yield True
                return

            changes = self.parser.api_route(command)
            if not changes:
                self.log_failure("command could not parse route in : %s" % command, "warning")
                reactor.answer(service, "error")
                yield True
                return

            for change in changes:
                # Change the action to withdraw before checking the route
                change.nlri.action = OUT.WITHDRAW
                # NextHop is a mandatory field (but we do not require in)
                if change.nlri.nexthop is NoNextHop or change.nlri.afi != AFI.ipv4:
                    change.nlri.nexthop = NextHop("0.0.0.0")

                if not ParseStaticRoute.check(change):
                    self.log_message(
                        "invalid route for %s : %s" % (", ".join(peers) if peers else "all peers", change.extensive())
                    )
                    continue
                if reactor.configuration.inject_change(peers, change):
                    self.log_message(
                        "route removed from %s : %s" % (", ".join(peers) if peers else "all peers", change.extensive())
                    )
                    yield False
                else:
                    self.log_failure(
                        "route not found on %s : %s" % (", ".join(peers) if peers else "all peers", change.extensive())
                    )
                    yield False

            reactor.route_update = True
            reactor.answer(service, "done")
        except ValueError:
            self.log_failure("issue parsing the route")
            yield True
        except IndexError:
            self.log_failure("issue parsing the route")
            yield True
Example #4
0
File: text.py Project: doddt/exabgp
    def callback():
        try:
            descriptions, command = self.parser.extract_neighbors(line)
            peers = reactor.match_neighbors(descriptions)
            if not peers:
                self.log_failure(
                    'no neighbor matching the command : %s' % command,
                    'warning')
                reactor.answer(service, 'error')
                yield True
                return

            changes = self.parser.api_route(command)
            if not changes:
                self.log_failure(
                    'command could not parse route in : %s' % command,
                    'warning')
                reactor.answer(service, 'error')
                yield True
                return

            for change in changes:
                if not ParseStaticRoute.check(change):
                    self.log_message(
                        'invalid route for %s : %s' %
                        (', '.join(peers) if peers else 'all peers',
                         change.extensive()))
                    continue
                change.nlri.action = OUT.ANNOUNCE
                reactor.configuration.inject_change(peers, change)
                self.log_message('route added to %s : %s' %
                                 (', '.join(peers) if peers else 'all peers',
                                  change.extensive()))
                yield False

            reactor.route_update = True
            reactor.answer(service, 'done')
        except ValueError:
            self.log_failure('issue parsing the route')
            reactor.answer(service, 'error')
            yield True
        except IndexError:
            self.log_failure('issue parsing the route')
            reactor.answer(service, 'error')
            yield True
Example #5
0
	def callback ():
		try:
			descriptions,command = extract_neighbors(line)
			peers = match_neighbors(reactor.peers,descriptions)
			if not peers:
				self.log_failure('no neighbor matching the command : %s' % command)
				reactor.processes.answer(service,'error')
				yield True
				return

			changes = self.api_route(command)
			if not changes:
				self.log_failure('command could not parse route in : %s' % command)
				reactor.processes.answer(service,'error')
				yield True
				return

			for change in changes:
				# Change the action to withdraw before checking the route
				change.nlri.action = OUT.WITHDRAW
				# NextHop is a mandatory field (but we do not require in)
				if change.nlri.nexthop is NoNextHop:
					change.nlri.nexthop = NextHop('0.0.0.0')

				if not ParseStaticRoute.check(change):
					self.log_message('invalid route for %s : %s' % (', '.join(peers) if peers else 'all peers',change.extensive()))
					continue
				if reactor.configuration.inject_change(peers,change):
					self.log_message('route removed from %s : %s' % (', '.join(peers) if peers else 'all peers',change.extensive()))
					yield False
				else:
					self.log_failure('route not found on %s : %s' % (', '.join(peers) if peers else 'all peers',change.extensive()))
					yield False

			reactor.processes.answer_done(service)
		except ValueError:
			self.log_failure('issue parsing the route')
			reactor.processes.answer(service,'error')
			yield True
		except IndexError:
			self.log_failure('issue parsing the route')
			reactor.processes.answer(service,'error')
			yield True
Example #6
0
    def callback():
        try:
            descriptions, command = self.parser.extract_neighbors(line)
            peers = reactor.match_neighbors(descriptions)
            if not peers:
                self.log_failure("no neighbor matching the command : %s" % command, "warning")
                reactor.answer(service, "error")
                yield True
                return

            changes = self.parser.api_route(command)
            if not changes:
                self.log_failure("command could not parse route in : %s" % command, "warning")
                reactor.answer(service, "error")
                yield True
                return

            for change in changes:
                if not ParseStaticRoute.check(change):
                    self.log_message(
                        "invalid route for %s : %s" % (", ".join(peers) if peers else "all peers", change.extensive())
                    )
                    continue
                change.nlri.action = OUT.ANNOUNCE
                reactor.configuration.inject_change(peers, change)
                self.log_message(
                    "route added to %s : %s" % (", ".join(peers) if peers else "all peers", change.extensive())
                )
                yield False

            reactor.route_update = True
            reactor.answer(service, "done")
        except ValueError:
            self.log_failure("issue parsing the route")
            reactor.answer(service, "error")
            yield True
        except IndexError:
            self.log_failure("issue parsing the route")
            reactor.answer(service, "error")
            yield True
Example #7
0
	def callback ():
		try:
			descriptions,command = self.parser.extract_neighbors(line)
			peers = reactor.match_neighbors(descriptions)
			if not peers:
				self.log_failure('no neighbor matching the command : %s' % command,'warning')
				reactor.answer(service,'error')
				yield True
				return

			changes = self.parser.api_route(command)
			if not changes:
				self.log_failure('command could not parse route in : %s' % command,'warning')
				reactor.answer(service,'error')
				yield True
				return

			for change in changes:
				if not ParseStaticRoute.check(change):
					self.log_message('invalid route for %s : %s' % (', '.join(peers) if peers else 'all peers',change.extensive()))
					continue
				change.nlri.action = OUT.WITHDRAW
				if reactor.configuration.inject_change(peers,change):
					self.log_message('route removed from %s : %s' % (', '.join(peers) if peers else 'all peers',change.extensive()))
					yield False
				else:
					self.log_failure('route not found on %s : %s' % (', '.join(peers) if peers else 'all peers',change.extensive()))
					yield False

			reactor.route_update = True
			reactor.answer(service,'done')
		except ValueError:
			self.log_failure('issue parsing the route')
			yield True
		except IndexError:
			self.log_failure('issue parsing the route')
			yield True