returns ellapsed time
[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                Parameter (int, "Peer id"),
36                ]
37     # for RefreshPeer 
38     returns = Parameter (dict,"Sites, Keys, Nodes, Persons, Slices")
39
40     def call (self, auth, peer_id):
41         # xxx a peer cannot yet compute it's peer_id under another plc
42         # so we return all foreign objects by now
43         
44         t_start = time.time()
45         result = {
46             'Sites-local' : Sites (self.api,{'peer_id':None}),
47             'Sites-peer' : Sites (self.api,{'~peer_id':None}),
48             'Keys-local' : Keys (self.api,{'peer_id':None}),
49             'Keys-peer' : Keys (self.api,{'~peer_id':None}),
50             'Nodes-local' : Nodes (self.api,{'peer_id':None}),
51             'Nodes-peer' : Nodes (self.api,{'~peer_id':None}),
52             'Persons-local' : Persons (self.api,{'peer_id':None}),
53             'Persons-peer' : Persons (self.api,{'~peer_id':None}),
54             'SliceAttibuteTypes-local' : SliceAttributeTypes (self.api,{'peer_id':None}),
55             'SliceAttibuteTypes-peer' : SliceAttributeTypes (self.api,{'~peer_id':None}),
56             'Slices-local' : Slices (self.api,{'peer_id':None}),
57             'Slices-peer' : Slices (self.api,{'~peer_id':None}),
58             'SliceAttributes-local': SliceAttributes (self.api,{'peer_id':None}),
59             'SliceAttributes-peer': SliceAttributes (self.api,{'~peer_id':None}),
60             }
61         t_end = time.time()
62         result['ellapsed'] = t_end-t_start
63         return result
64