Merge branch 'master' into eucalyptus-devel
[sfa.git] / sfa / util / plxrn.py
index 3e608b6..7049df6 100644 (file)
@@ -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):
@@ -27,7 +30,9 @@ class PlXrn (Xrn):
         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:
@@ -48,7 +53,9 @@ class PlXrn (Xrn):
     #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 +65,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