python3 - 2to3 + miscell obvious tweaks
[sfa.git] / sfa / planetlab / peers.py
1 from sfa.util.xrn import get_authority
2
3 from sfa.util.py23 import StringType
4
5
6 def get_peer(pldriver, hrn):
7     # Because of myplc native federation,  we first need to determine if this
8     # slice belongs to out local plc or a myplc peer. We will assume it
9     # is a local site, unless we find out otherwise
10     peer = None
11
12     # get this slice's authority (site)
13     slice_authority = get_authority(hrn)
14
15     # get this site's authority (sfa root authority or sub authority)
16     site_authority = get_authority(slice_authority).lower()
17     # check if we are already peered with this site_authority, if so
18     peers = pldriver.shell.GetPeers(
19         {}, ['peer_id', 'peername', 'shortname', 'hrn_root'])
20     for peer_record in peers:
21         names = [name.lower() for name in list(peer_record.values())
22                  if isinstance(name, StringType)]
23         if site_authority in names:
24             peer = peer_record['shortname']
25
26     return peer
27
28
29 # def get_sfa_peer(pldriver, hrn):
30 #    # return the authority for this hrn or None if we are the authority
31 #    sfa_peer = None
32 #    slice_authority = get_authority(hrn)
33 #    site_authority = get_authority(slice_authority)
34 #
35 #    if site_authority != pldriver.hrn:
36 #        sfa_peer = site_authority
37 #
38 #    return sfa_peer