Merge branch 'master' into senslab2
authorSandrine Avakian <sandrine.avakian@inria.fr>
Thu, 26 Apr 2012 08:52:40 +0000 (10:52 +0200)
committerSandrine Avakian <sandrine.avakian@inria.fr>
Thu, 26 Apr 2012 08:52:40 +0000 (10:52 +0200)
1  2 
sfa/client/sfi.py
sfa/util/xrn.py

diff --combined sfa/client/sfi.py
@@@ -147,10 -147,10 +147,10 @@@ def save_records_to_file(filename, reco
          print "unknown output format", format
  
  def save_record_to_file(filename, record_dict):
-     rec_record = Record(dict=record_dict)
-     str = record.save_to_string()
+     record = Record(dict=record_dict)
+     xml = record.save_as_xml()
      f=codecs.open(filename, encoding='utf-8',mode="w")
-     f.write(str)
+     f.write(xml)
      f.close()
      return
  
@@@ -904,7 -904,6 +904,7 @@@ or with an slice hrn, shows currently p
                  rspec.filter({'component_manager_id': server_version['urn']})
                  rspec = RSpecConverter.to_pg_rspec(rspec.toxml(), content_type='request')
              else:
 +                print >>sys.stderr, "\r\n \r\n \r\n WOOOOOO"
                  users = sfa_users_arg(user_records, slice_record)
  
          # do not append users, keys, or slice tags. Anything
          api_options = {}
          api_options ['append'] = False
          api_options ['call_id'] = unique_call_id()
          result = server.CreateSliver(slice_urn, creds, rspec, users, *self.ois(server, api_options))
          value = ReturnValue.get_value(result)
          if self.options.raw:
diff --combined sfa/util/xrn.py
@@@ -22,7 -22,7 +22,7 @@@
  #----------------------------------------------------------------------
  
  import re
 -
 +import sys
  from sfa.util.faults import SfaAPIError
  
  # for convenience and smoother translation - we should get rid of these functions eventually 
@@@ -32,8 -32,8 +32,8 @@@ def urn_to_hrn(urn): xrn=Xrn(urn); retu
  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:
  
      # provide either urn, or (hrn + type)
      def __init__ (self, xrn, type=None):
          if not xrn: xrn = ""
 +       
          # user has specified xrn : guess if urn or hrn
          if xrn.startswith(Xrn.URN_PREFIX):
              self.hrn=None
              self.urn=xrn
              self.urn_to_hrn()
 +            #print>>sys.stderr, " \r\n \r\n \t XRN.PY init  xrn.startswith(Xrn.URN_PREFIX) hrn %s urn %s type %s" %(  self.hrn,  self.urn, self.type)
          else:
              self.urn=None
              self.hrn=xrn
              self.type=type
              self.hrn_to_urn()
 +            #print>>sys.stderr, " \r\n \r\n \t XRN.PY init ELSE hrn %s urn %s type %s" %(  self.hrn,  self.urn, self.type)
  # happens all the time ..
  #        if not type:
  #            debug_logger.debug("type-less Xrn's are not safe")
      def get_hrn_type(self): return (self.hrn, self.type)
  
      def _normalize(self):
 +        #print>>sys.stderr, " \r\n \r\n \t XRN.PY _normalize self.hrn %s ",self.hrn
          if self.hrn is None: raise SfaAPIError, "Xrn._normalize"
          if not hasattr(self,'leaf'): 
              self.leaf=Xrn.hrn_split(self.hrn)[-1]
          # self.authority keeps a list
          if not hasattr(self,'authority'): 
              self.authority=Xrn.hrn_auth_list(self.hrn)
 -
 +        #print>>sys.stderr, " \r\n \r\n \t XRN.PY _normalize self.hrn %s leaf %s authority %s"%(self.hrn, self.leaf,  self.authority)
 +       
 +       
      def get_leaf(self):
          self._normalize()
          return self.leaf
          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):
          """