X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Futil%2Fplxrn.py;h=5976f3ecdc49f04722b20bcc52e686cf56cb08a8;hb=f3121bd4ab559117a3c62253e955a3695837b8c6;hp=3e608b6196039e7912c042f0c5f68e1b08f36576;hpb=db03eb2324ae3cc66232f7bedccf3f3f204349c7;p=sfa.git diff --git a/sfa/util/plxrn.py b/sfa/util/plxrn.py index 3e608b61..5976f3ec 100644 --- a/sfa/util/plxrn.py +++ b/sfa/util/plxrn.py @@ -1,9 +1,12 @@ # specialized Xrn class for PlanetLab +import re from sfa.util.xrn import Xrn # temporary helper functions to use this module instead of namespace def hostname_to_hrn (auth, login_base, hostname): return PlXrn(auth=auth+'.'+login_base,hostname=hostname).get_hrn() +def hostname_to_urn(auth, login_base, hostname): + return PlXrn(auth=auth+'.'+login_base,hostname=hostname).get_urn() def slicename_to_hrn (auth_hrn, slicename): return PlXrn(auth=auth_hrn,slicename=slicename).get_hrn() def email_to_hrn (auth_hrn, email): @@ -14,20 +17,23 @@ def hrn_to_pl_login_base (hrn): return PlXrn(xrn=hrn,type='slice').pl_login_base() def hrn_to_pl_authname (hrn): return PlXrn(xrn=hrn,type='any').pl_authname() - +def xrn_to_hostname(hrn): + return Xrn.unescape(PlXrn(xrn=hrn, type='node').get_leaf()) class PlXrn (Xrn): @staticmethod def site_hrn (auth, login_base): - return '.'.join(auth,login_base) + return '.'.join([auth,login_base]) - def __init__ (self, auth=None, hostname=None, slicename=None, email=None, **kwargs): + def __init__ (self, auth=None, hostname=None, slicename=None, email=None, interface=None, **kwargs): #def hostname_to_hrn(auth_hrn, login_base, hostname): if hostname is not None: self.type='node' # keep only the first part of the DNS name - self.hrn='.'.join( [auth,hostname.split(".")[0] ] ) + #self.hrn='.'.join( [auth,hostname.split(".")[0] ] ) + # escape the '.' in the hostname + self.hrn='.'.join( [auth,Xrn.escape(hostname)] ) self.hrn_to_urn() #def slicename_to_hrn(auth_hrn, slicename): elif slicename is not None: @@ -42,13 +48,19 @@ class PlXrn (Xrn): # keep only the part before '@' and replace special chars into _ self.hrn='.'.join([auth,email.split('@')[0].replace(".", "_").replace("+", "_")]) self.hrn_to_urn() + elif interface is not None: + self.type = 'interface' + self.hrn = auth + '.' + interface + self.hrn_to_urn() else: Xrn.__init__ (self,**kwargs) #def hrn_to_pl_slicename(hrn): def pl_slicename (self): self._normalize() - return self.authority[-1] + '_' + self.leaf + leaf = self.leaf + leaf = re.sub('[^a-zA-Z0-9_]', '', leaf) + return self.pl_login_base() + '_' + leaf #def hrn_to_pl_authname(hrn): def pl_authname (self): @@ -58,4 +70,13 @@ class PlXrn (Xrn): #def hrn_to_pl_login_base(hrn): def pl_login_base (self): self._normalize() - return self.authority[-1] + base = self.authority[-1] + + # Fix up names of GENI Federates + base = base.lower() + base = re.sub('\\\[^a-zA-Z0-9]', '', base) + + if len(base) > 20: + base = base[len(base)-20:] + + return base