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