(*) Peer has new fields person_ids and site_ids
[plcapi.git] / PLC / Methods / GetPeerData.py
index 4b0f068..d6ef1e3 100644 (file)
@@ -2,6 +2,8 @@
 # Thierry Parmentelat - INRIA
 # 
 
+import time
+
 from PLC.Faults import *
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
@@ -30,24 +32,43 @@ class GetPeerData (Method):
     roles = ['admin']
 
     accepts = [Auth(),
-               Parameter (int, "Peer id"),
+               Mixed (Parameter (Peer.fields['peer_id']),
+                      Parameter (Peer.fields['peername'])),
                ]
     # for RefreshPeer 
-    returns = Parameter (dict,"Sites, Keys, Nodes, Persons, Slices")
-    event_type = 'Get'
-    object_type = 'Peer'
+    returns = Parameter (dict,
+                         "Sites-local Sites-peer Keys-local Keys-peer "
+                         "Nodes-local Nodes-peer Persons-local Persons-peer "
+                         "SliceAttibuteTypes-local SliceAttibuteTypes-peer "
+                         "Slices-local Slices-peer "
+                         "SliceAttributes-local SliceAttributes-peer")
+
+    def call (self, auth, peer_id_or_peername):
 
-    def call (self, auth, peer_id):
-        # xxx a peer cannot yet compute it's peer_id under another plc
-        # so we return evrything by now
+        # checking the argument
+        try:
+            peer_id = Peers(self.api,[peer_id_or_peername])[0]['peer_id']
+        except:
+            raise PLCInvalidArgument,'GetPeerData: no such peer %r'%peer_id_or_peername
         
-        return {
-            'Sites' : Sites (self.api),
-            'Keys' : Keys (self.api),
-            'Nodes' : Nodes (self.api),
-            'Persons' : Persons (self.api),
-            'SliceAttibuteTypes' : SliceAttributeTypes (self.api),
-            'Slices' : Slices (self.api),
-            'SliceAttributes': SliceAttributes (self.api)
+        t_start = time.time()
+        result = {
+            'Sites-local' : Sites (self.api,{'peer_id':None}),
+            'Sites-peer' : Sites (self.api,{'peer_id':peer_id}),
+            'Keys-local' : Keys (self.api,{'peer_id':None}),
+            'Keys-peer' : Keys (self.api,{'peer_id':peer_id}),
+            'Nodes-local' : Nodes (self.api,{'peer_id':None}),
+            'Nodes-peer' : Nodes (self.api,{'peer_id':peer_id}),
+            'Persons-local' : Persons (self.api,{'peer_id':None}),
+            'Persons-peer' : Persons (self.api,{'peer_id':peer_id}),
+            'SliceAttibuteTypes-local' : SliceAttributeTypes (self.api,{'peer_id':None}),
+            'SliceAttibuteTypes-peer' : SliceAttributeTypes (self.api,{'peer_id':peer_id}),
+            'Slices-local' : Slices (self.api,{'peer_id':None}),
+            'Slices-peer' : Slices (self.api,{'peer_id':peer_id}),
+            'SliceAttributes-local': SliceAttributes (self.api,{'peer_id':None}),
+            'SliceAttributes-peer': SliceAttributes (self.api,{'peer_id':peer_id}),
             }
+        t_end = time.time()
+        result['ellapsed'] = t_end-t_start
+        return result