(*) Peer has new fields person_ids and site_ids
[plcapi.git] / PLC / Methods / GetPeerData.py
1 #
2 # Thierry Parmentelat - INRIA
3
4
5 import time
6
7 from PLC.Faults import *
8 from PLC.Method import Method
9 from PLC.Parameter import Parameter, Mixed
10 from PLC.Auth import Auth
11
12 from PLC.Peers import Peer, Peers
13
14 from PLC.Sites import Site, Sites
15 from PLC.Keys import Key, Keys
16 from PLC.Nodes import Node, Nodes
17 from PLC.Persons import Person, Persons
18 from PLC.SliceAttributeTypes import SliceAttributeType, SliceAttributeTypes
19 from PLC.Slices import Slice, Slices
20 from PLC.SliceAttributes import SliceAttribute, SliceAttributes
21
22 class GetPeerData (Method):
23     """
24     Gather all data needed by RefreshPeer in a single xmlrpc request
25
26     Expects a peer id or peer name, that identifies the requesting peer
27     
28     Returns a dict containing, for the various types of cached entities,
29     the local objects as well as the ones attached to that peer
30     """
31
32     roles = ['admin']
33
34     accepts = [Auth(),
35                Mixed (Parameter (Peer.fields['peer_id']),
36                       Parameter (Peer.fields['peername'])),
37                ]
38     # for RefreshPeer 
39     returns = Parameter (dict,
40                          "Sites-local Sites-peer Keys-local Keys-peer "
41                          "Nodes-local Nodes-peer Persons-local Persons-peer "
42                          "SliceAttibuteTypes-local SliceAttibuteTypes-peer "
43                          "Slices-local Slices-peer "
44                          "SliceAttributes-local SliceAttributes-peer")
45
46     def call (self, auth, peer_id_or_peername):
47
48         # checking the argument
49         try:
50             peer_id = Peers(self.api,[peer_id_or_peername])[0]['peer_id']
51         except:
52             raise PLCInvalidArgument,'GetPeerData: no such peer %r'%peer_id_or_peername
53         
54         t_start = time.time()
55         result = {
56             'Sites-local' : Sites (self.api,{'peer_id':None}),
57             'Sites-peer' : Sites (self.api,{'peer_id':peer_id}),
58             'Keys-local' : Keys (self.api,{'peer_id':None}),
59             'Keys-peer' : Keys (self.api,{'peer_id':peer_id}),
60             'Nodes-local' : Nodes (self.api,{'peer_id':None}),
61             'Nodes-peer' : Nodes (self.api,{'peer_id':peer_id}),
62             'Persons-local' : Persons (self.api,{'peer_id':None}),
63             'Persons-peer' : Persons (self.api,{'peer_id':peer_id}),
64             'SliceAttibuteTypes-local' : SliceAttributeTypes (self.api,{'peer_id':None}),
65             'SliceAttibuteTypes-peer' : SliceAttributeTypes (self.api,{'peer_id':peer_id}),
66             'Slices-local' : Slices (self.api,{'peer_id':None}),
67             'Slices-peer' : Slices (self.api,{'peer_id':peer_id}),
68             'SliceAttributes-local': SliceAttributes (self.api,{'peer_id':None}),
69             'SliceAttributes-peer': SliceAttributes (self.api,{'peer_id':peer_id}),
70             }
71         t_end = time.time()
72         result['ellapsed'] = t_end-t_start
73         return result
74