location-query: Implement searching for an AS that matches a string
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 1 Feb 2018 14:18:15 +0000 (14:18 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 1 Feb 2018 14:18:15 +0000 (14:18 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/python/location-query.in

index 933024e..1f1d42a 100644 (file)
@@ -65,6 +65,13 @@ class CLI(object):
                get_as.add_argument("asn", nargs="+")
                get_as.set_defaults(func=self.handle_get_as)
 
+               # Search for AS
+               search_as = subparsers.add_parser("search-as",
+                       help=_("Search for Autonomous Systems that match the string"),
+               )
+               search_as.add_argument("query", nargs=1)
+               search_as.set_defaults(func=self.handle_search_as)
+
                return parser.parse_args()
 
        def run(self):
@@ -148,6 +155,12 @@ class CLI(object):
 
                return ret
 
+       def handle_search_as(self, ns):
+               for query in ns.query:
+                       # Print all matches ASes
+                       for a in self.db.search_as(query):
+                               print(a)
+
 def main():
        # Run the command line interface
        c = CLI()