4 URN_PREFIX = "urn:publicid:IDN"
8 return ".".join(parts[-1:])
10 def get_authority(hrn):
11 parts = hrn.split(".")
12 return ".".join(parts[:-1])
14 def hrn_to_pl_slicename(hrn):
15 parts = hrn.split(".")
16 return parts[-2] + "_" + parts[-1]
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(".")
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)
27 def hostname_to_hrn(auth_hrn, login_base, hostname):
29 Convert hrn to plantelab name.
31 sfa_hostname = ".".join([auth_hrn, login_base, hostname.split(".")[0]])
34 def slicename_to_hrn(auth_hrn, slicename):
36 Convert hrn to planetlab name.
38 parts = slicename.split("_")
39 slice_hrn = ".".join([auth_hrn, parts[0]]) + "." + "_".join(parts[1:])
43 def email_to_hrn(auth_hrn, email):
44 parts = email.split("@")
46 username = username.replace(".", "_")
47 person_hrn = ".".join([auth_hrn, username])
54 return a tuple (hrn, type)
57 # if this is already a hrn dont do anything
58 if not urn or not urn.startswith(URN_PREFIX):
61 name = urn[len(URN_PREFIX):]
62 hrn_parts = name.split("+")
64 # type is always the second to last element in the list
65 type = hrn_parts.pop(-2)
67 # convert hrn_parts (list) into hrn (str) by doing the following
68 # remove blank elements
69 # replace ':' with '.'
70 # join list elements using '.'
71 hrn = '.'.join([part.replace(':', '.') for part in hrn_parts if part])
73 return str(hrn), str(type)
76 def hrn_to_urn(hrn, type=None):
78 convert an hrn and type to a urn string
80 # if this is already a urn dont do anything
81 if not hrn or hrn.startswith(URN_PREFIX):
84 authority = get_authority(hrn)
86 urn = "+".join([unicode(part).replace('.', ':') \
87 for part in ['',authority,type,name]])
89 return URN_PREFIX + urn