- add peer to roles
[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', 'peer']
33
34     accepts = [
35         Auth(),
36         Mixed(Peer.fields['peer_id'],
37               Peer.fields['peername']),
38         ]
39
40     # for RefreshPeer 
41     returns = {
42         'Sites-local': Parameter([dict], "List of local sites"),
43         'Sites-peer': Parameter([dict], "List of foreign sites"),
44         'Keys-local': Parameter([dict], "List of local keys"),
45         'Keys-peer':  Parameter([dict], "List of foreign keys"),
46         'Nodes-local':  Parameter([dict], "List of local nodes"),
47         'Nodes-peer':  Parameter([dict], "List of foreign nodes"),
48         'Persons-local':  Parameter([dict], "List of local users"),
49         'Persons-peer':  Parameter([dict], "List of foreign users"),
50         'SliceAttibuteTypes-local':  Parameter([dict], "List of local slice attribute types"),
51         'SliceAttibuteTypes-peer':  Parameter([dict], "List of foreign slice attribute types"),
52         'Slices-local':  Parameter([dict], "List of local slices"),
53         'Slices-peer':  Parameter([dict], "List of foreign slices"),
54         'SliceAttributes-local':  Parameter([dict], "List of local slice attributes"),
55         'SliceAttributes-peer':  Parameter([dict], "List of foreign slice attributes"),
56         }
57
58     def call (self, auth, peer_id_or_peername):
59
60         # checking the argument
61         try:
62             peer_id = Peers(self.api,[peer_id_or_peername])[0]['peer_id']
63         except:
64             raise PLCInvalidArgument,'GetPeerData: no such peer %r'%peer_id_or_peername
65         
66         t_start = time.time()
67         result = {
68             'Sites-local' : Sites (self.api,{'peer_id':None}),
69             'Sites-peer' : Sites (self.api,{'peer_id':peer_id}),
70             'Keys-local' : Keys (self.api,{'peer_id':None}),
71             'Keys-peer' : Keys (self.api,{'peer_id':peer_id}),
72             'Nodes-local' : Nodes (self.api,{'peer_id':None}),
73             'Nodes-peer' : Nodes (self.api,{'peer_id':peer_id}),
74             'Persons-local' : Persons (self.api,{'peer_id':None}),
75             'Persons-peer' : Persons (self.api,{'peer_id':peer_id}),
76             'SliceAttibuteTypes-local' : SliceAttributeTypes (self.api,{'peer_id':None}),
77             'SliceAttibuteTypes-peer' : SliceAttributeTypes (self.api,{'peer_id':peer_id}),
78             'Slices-local' : Slices (self.api,{'peer_id':None}),
79             'Slices-peer' : Slices (self.api,{'peer_id':peer_id}),
80             'SliceAttributes-local': SliceAttributes (self.api,{'peer_id':None}),
81             'SliceAttributes-peer': SliceAttributes (self.api,{'peer_id':peer_id}),
82             }
83         t_end = time.time()
84         result['ellapsed'] = t_end-t_start
85         return result
86