remove all refrences to self, this is not a class
[sfa.git] / sfa / plc / peers.py
1 from sfa.util.misc import *
2
3 def get_peer(api, hrn):
4     # Becaues of myplc federation,  we first need to determine if this
5     # slice belongs to out local plc or a myplc peer. We will assume it
6     # is a local site, unless we find out otherwise
7     peer = None
8
9     # get this slice's authority (site)
10     slice_authority = get_authority(hrn)
11
12     # get this site's authority (sfa root authority or sub authority)
13     site_authority = get_authority(slice_authority).lower()
14     # check if we are already peered with this site_authority, if so
15     peers = api.plshell.GetPeers(api.plauth, {}, \
16                     ['peer_id', 'peername', 'shortname', 'hrn_root'])
17     for peer_record in peers:
18         names = [name.lower() for name in peer_record.values() if isinstance(name, StringTypes)]
19         if site_authority in names:
20             peer = peer_record['shortname']
21
22     return peer
23
24
25 def get_sfa_peer(api, hrn):
26     # return the authority for this hrn or None if we are the authority
27     sfa_peer = None
28     slice_authority = get_authority(hrn)
29     site_authority = get_authority(slice_authority)
30
31     if site_authority != api.hrn:
32         sfa_peer = site_authority
33
34     return sfa_peer
35