4
0
Quellcode durchsuchen

BatcaveClient: rename find_node to find_node_by_name and add _by_mac

Helge Jung vor 9 Jahren
Ursprung
Commit
f77b4748f1
1 geänderte Dateien mit 16 neuen und 2 gelöschten Zeilen
  1. 16 2
      modules/batcave/client.py

+ 16 - 2
modules/batcave/client.py

@@ -35,11 +35,25 @@ class BatcaveClient(object):
         url = 'node/{0}.json'.format(nodeid)
         return self.__load_response(url, 'node \'' + nodeid + '\'')
 
-    def find_node(self, name, fuzzymatch=True, single_match_only=True):
+    def find_node_by_name(self, name, fuzzymatch=True, single_match_only=True):
         """Tries to find a node by given name."""
 
         url = 'find?name=' + name + '&fuzzy=' + ('1' if fuzzymatch else '0')
-        matches = self.__load_response(url, 'find=' + name)
+        matches = self.__load_response(url, 'find_name=' + name)
+
+        if single_match_only:
+            if len(matches) == 1:
+                return matches[0]
+            else:
+                return None
+
+        return matches
+
+    def find_node_by_mac(self, mac, single_match_only=True):
+        """Tries to find a node by given MAC address."""
+
+        url = 'find?mac=' + mac
+        matches = self.__load_response(url, 'find_mac=' + mac)
 
         if single_match_only:
             if len(matches) == 1: