removed another bunch of references to geni
[sfa.git] / sfa / util / misc.py
1 ### $Id$
2 ### $URL$
3
4 from sfa.util.faults import *
5
6 def get_leaf(hrn):
7     parts = hrn.split(".")
8     return ".".join(parts[-1:])
9
10 def get_authority(hrn):
11     parts = hrn.split(".")
12     return ".".join(parts[:-1])
13
14 def hrn_to_pl_slicename(hrn):
15     parts = hrn.split(".")
16     return parts[-2] + "_" + parts[-1]
17
18 # assuming hrn is the hrn of an authority, return the plc authority name
19 def hrn_to_pl_authname(hrn):
20     parts = hrn.split(".")
21     return parts[-1]
22
23 # assuming hrn is the hrn of an authority, return the plc login_base
24 def hrn_to_pl_login_base(hrn):
25     return hrn_to_pl_authname(hrn)
26
27 def hostname_to_hrn(auth_hrn, login_base, hostname):
28     """
29     Convert hrn to plantelab name.
30     """
31     sfa_hostname = ".".join([auth_hrn, login_base, hostname.split(".")[0]])
32     return sfa_hostname
33
34 def slicename_to_hrn(auth_hrn, slicename):
35     """
36     Convert hrn to planetlab name.
37     """
38     parts = slicename.split("_")
39     slice_hrn = ".".join([auth_hrn, parts[0]]) + "." + "_".join(parts[1:])
40
41     return slice_hrn
42
43 def email_to_hrn(auth_hrn, email):
44     parts = email.split("@")
45     username = parts[0]
46     username = username.replace(".", "_") 
47     person_hrn = ".".join([auth_hrn, username])
48     
49     return person_hrn