614ea1202a7ade38e5516b60a314f5aee5866b21
[sfa.git] / geni / util / misc.py
1 from excep import *
2
3 def get_leaf(hrn):
4     parts = hrn.split(".")
5     return ".".join(parts[-1:])
6
7 def get_authority(hrn):
8     
9     parts = hrn.split(".")
10     return ".".join(parts[:-1])
11
12 def get_auth_type(type):
13     if (type=="slice") or (type=="user") or (type=="sa"):
14         return "sa"
15     elif (type=="component") or (type=="ma"):
16         return "ma"
17     else:
18         raise UnknownGeniType(type)
19
20 def hrn_to_pl_slicename(hrn):
21     parts = hrn.split(".")
22     return parts[-2] + "_" + parts[-1]
23
24 # assuming hrn is the hrn of an authority, return the plc authority name
25 def hrn_to_pl_authname(hrn):
26     parts = hrn.split(".")
27     return parts[-1]
28
29 # assuming hrn is the hrn of an authority, return the plc login_base
30 def hrn_to_pl_login_base(hrn):
31     return hrn_to_pl_authname(hrn)
32
33 def hostname_to_hrn(auth_hrn, login_base, hostname):
34     """
35     Convert hrn to plantelab name.
36     """
37     genihostname = "_".join(hostname.split("."))
38     return ".".join([auth_hrn, login_base, genihostname])
39
40 def slicename_to_hrn(auth_hrn, slicename):
41     """
42     Convert hrn to planetlab name.
43     """
44     parts = slicename.split("_")
45     slice_hrn = ".".join([auth_hrn, parts[0]]) + "." + "_".join(parts[1:])
46
47     return slice_hrn
48