fix bug in site_hrn()
[sfa.git] / sfa / util / plxrn.py
index 89efd4d..5580c44 100644 (file)
@@ -5,6 +5,8 @@ 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):
@@ -21,14 +23,16 @@ 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 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:
@@ -50,7 +54,7 @@ class PlXrn (Xrn):
     def pl_slicename (self):
         self._normalize()
         leaf = self.leaf
-        leaf = re.sub('[^a-zA-Z0-9]', '', leaf)
+        leaf = re.sub('[^a-zA-Z0-9_]', '', leaf)
         return self.pl_login_base() + '_' + leaf
 
     #def hrn_to_pl_authname(hrn):