Merge branch 'master' into senslab2
[sfa.git] / sfa / util / xrn.py
index a21b10c..ac394f7 100644 (file)
@@ -32,8 +32,8 @@ def urn_to_hrn(urn): xrn=Xrn(urn); return (xrn.hrn, xrn.type)
 def hrn_to_urn(hrn,type): return Xrn(hrn, type=type).urn
 def hrn_authfor_hrn(parenthrn, hrn): return Xrn.hrn_is_auth_for_hrn(parenthrn, hrn)
 
-def urn_to_sliver_id(urn, slice_id, node_id, index=0):
-    return Xrn(urn).get_sliver_id(slice_id, node_id, index)
+def urn_to_sliver_id(urn, slice_id, node_id, index=0, authority=None):
+    return Xrn(urn).get_sliver_id(slice_id, node_id, index, authority)
 
 class Xrn:
 
@@ -168,9 +168,17 @@ class Xrn:
         self._normalize()
         return ':'.join( [Xrn.unescape(x) for x in self.authority] )
    
-    def get_sliver_id(self, slice_id, node_id, index=0):
+    def get_sliver_id(self, slice_id, node_id, index=0, authority=None):
         self._normalize()
-        return ":".join(map(str, [self.get_urn(), slice_id, node_id, index])) 
+        urn = self.get_urn()
+        if authority:
+            authority_hrn = self.get_authority_hrn()
+            if not authority_hrn.startswith(authority):
+                hrn = ".".join([authority,self.get_authority_hrn(), self.get_leaf()])
+            else:
+                hrn = ".".join([self.get_authority_hrn(), self.get_leaf()])
+            urn = Xrn(hrn, self.get_type()).get_urn()
+        return ":".join(map(str, [urn, slice_id, node_id, index])) 
  
     def urn_to_hrn(self):
         """