checkpointing - in the middle of the move towards xrn vs namespace
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 14 Oct 2010 16:46:34 +0000 (18:46 +0200)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 14 Oct 2010 16:46:34 +0000 (18:46 +0200)
sfa/client/sfi.py
sfa/managers/aggregate_manager_eucalyptus.py
sfa/managers/aggregate_manager_max.py
sfa/managers/registry_manager_pl.py
sfa/methods/Remove.py
sfa/util/namespace.py
sfa/util/xrn.py

index bce85b6..f534d36 100755 (executable)
@@ -22,7 +22,7 @@ from sfa.trust.gid import GID
 from sfa.trust.credential import Credential
 from sfa.util.sfaticket import SfaTicket
 from sfa.util.record import SfaRecord, UserRecord, SliceRecord, NodeRecord, AuthorityRecord
-from sfa.util.namespace import get_leaf, get_authority, hrn_to_urn
+from sfa.util.xrn import Xrn, get_leaf, get_authority, hrn_to_urn
 from sfa.util.xmlrpcprotocol import ServerException
 import sfa.util.xmlrpcprotocol as xmlrpcprotocol
 from sfa.util.config import Config
@@ -335,7 +335,6 @@ class Sfi:
     
     def get_key_file(self):
        file = os.path.join(self.options.sfi_dir, self.user.replace(self.authority + '.', '') + ".pkey")
-       #file = os.path.join(self.options.sfi_dir, get_leaf(self.user) + ".pkey")
        if (os.path.isfile(file)):
           return file
        else:
@@ -345,7 +344,6 @@ class Sfi:
     
     def get_cert_file(self, key_file):
     
-       #file = os.path.join(self.options.sfi_dir, get_leaf(self.user) + ".cert")
        file = os.path.join(self.options.sfi_dir, self.user.replace(self.authority + '.', '') + ".cert")
        if (os.path.isfile(file)):
           return file
@@ -406,7 +404,6 @@ class Sfi:
         return None 
  
     def get_user_cred(self):
-        #file = os.path.join(self.options.sfi_dir, get_leaf(self.user) + ".cred")
         file = os.path.join(self.options.sfi_dir, self.user.replace(self.authority + '.', '') + ".cred")
         return self.get_cred(file, 'user', self.user)
 
@@ -414,9 +411,7 @@ class Sfi:
         if not self.authority:
             self.logger.critical("no authority specified. Use -a or set SF_AUTH")
             sys.exit(-1)
-        ### xxx get_leaf('authority') always returns 'authority'
-        # are we not meaning get_leaf(self.authority) instead ?
-        file = os.path.join(self.options.sfi_dir, get_leaf("authority") + ".cred")
+        file = os.path.join(self.options.sfi_dir, self.authority + ".cred")
         return self.get_cred(file, 'authority', self.authority)
 
     def get_slice_cred(self, name):
@@ -639,6 +634,9 @@ class Sfi:
     #   - have to first retrieve the record to be removed
     def remove(self, opts, args):
         auth_cred = self.get_auth_cred().save_to_string(save_parents=True)
+        if len(args)!=1:
+            self.parser.print_help()
+            sys.exit(1)
         hrn = args[0]
         type = opts.type 
         if type in ['all']:
@@ -648,6 +646,9 @@ class Sfi:
     # add named registry record
     def add(self, opts, args):
         auth_cred = self.get_auth_cred().save_to_string(save_parents=True)
+        if len(args)!=1:
+            self.parser.print_help()
+            sys.exit(1)
         record_filepath = args[0]
         rec_file = self.get_record_file(record_filepath)
         record = load_record_from_file(rec_file).as_dict()
@@ -656,6 +657,9 @@ class Sfi:
     # update named registry entry
     def update(self, opts, args):
         user_cred = self.get_user_cred()
+        if len(args)!=1:
+            self.parser.print_help()
+            sys.exit(1)
         rec_file = self.get_record_file(args[0])
         record = load_record_from_file(rec_file)
         if record['type'] == "user":
index 7b50d2a..3d2018b 100644 (file)
@@ -12,7 +12,7 @@ from lxml import etree as ET
 from sqlobject import *
 
 from sfa.util.faults import *
-from sfa.util.namespace import urn_to_hrn
+from sfa.util.xrn import urn_to_hrn
 from sfa.util.rspec import RSpec
 from sfa.server.registry import Registries
 
index 4467026..14b924d 100644 (file)
@@ -3,7 +3,8 @@
 from sfa.util.rspec import RSpec
 import sys
 import pdb
-from sfa.util.namespace import hrn_to_pl_slicename, urn_to_hrn, get_authority
+from sfa.util.namespace import hrn_to_pl_slicename
+from sfa.util.xrn import urn_to_hrn, get_authority
 from sfa.util.rspec import *
 from sfa.util.specdict import *
 from sfa.util.faults import *
index 944a997..ac5901c 100644 (file)
@@ -1,14 +1,16 @@
 import types
 import time 
+
+from sfa.util.faults import *
 from sfa.util.prefixTree import prefixTree
 from sfa.util.record import SfaRecord
 from sfa.util.table import SfaTable
 from sfa.util.record import SfaRecord
 from sfa.trust.gid import GID 
-from sfa.util.namespace import get_leaf, get_authority, hrn_to_urn, hrn_to_pl_login_base, urn_to_hrn
-from sfa.trust.credential import *
-from sfa.trust.certificate import *
-from sfa.util.faults import *
+from sfa.util.namespace import hrn_to_pl_login_base
+from sfa.util.xrn import Xrn, get_leaf, get_authority, hrn_to_urn, urn_to_hrn
+from sfa.trust.credential import Credential
+from sfa.trust.certificate import Certificate, Keypair
 from sfa.trust.gid import create_uuid
 
 def get_version(api):
@@ -366,12 +368,13 @@ def update(api, record_dict):
     
     return 1 
 
-def remove(api, xrn, type, origin_hrn=None):
-    # convert xrn to hrn     
-    if type:
-        hrn = urn_to_hrn(xrn)[0]
-    else:
-        hrn, type = urn_to_hrn(xrn)    
+# being PL specific it sounds right to expect a hrn+type (not a xrn)
+def remove(api, hrn, type, origin_hrn=None):
+#    # convert xrn to hrn     
+#    if type:
+#        hrn = urn_to_hrn(xrn)[0]
+#    else:
+#        hrn, type = urn_to_hrn(xrn)    
 
     table = SfaTable()
     filter = {'hrn': hrn}
index f13c95d..db0fe08 100644 (file)
@@ -31,11 +31,11 @@ class Remove(Method):
 
     returns = Parameter(int, "1 if successful")
     
+# this does not sound quite right, but the best I could come up with is:
+# if type is not specified then we expect a URN
     def call(self, xrn, creds, type):
-        if not type:
-            hrn = urn_to_hrn(xrn)[0]
-        else: 
-            hrn, type = urn_to_hrn(xrn)
+        if type: hrn=xrn
+        else:    (hrn,type) = urn_to_hrn(xrn)
         
         # validate the cred
         valid_creds = self.api.auth.checkCredentials(creds, "remove")
@@ -43,9 +43,9 @@ class Remove(Method):
 
         #log the call
         origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
-        self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))
-
+        self.api.logger.info("interface: %s\tmethod-name: %s\tcaller-hrn: %s\ttarget-hrn: %s\ttype: %s"%(
+                self.api.interface, self.name, origin_hrn, hrn, type))
 
         manager = self.api.get_interface_manager()
 
-        return manager.remove(self.api, xrn, type) 
+        return manager.remove(self.api, hrn, type) 
index 961b3b3..c66e526 100644 (file)
@@ -118,7 +118,8 @@ def urn_to_hrn(urn):
     # 3. replace ':' with '.'  (':' is the urn hierarchy delimiter)
     # 4. join list elements using '.' 
     #hrn = '.'.join([part.replace('.', '\\.').replace(':', '.') for part in hrn_parts if part]) 
-    hrn = '.'.join([re.sub(r'([^a-zA-Z0-9\:])', r'\\\1', part).replace(':', '.') for part in urn_parts if part]) 
+#    hrn = '.'.join([re.sub(r'([^a-zA-Z0-9\:])', r'\\\1', part).replace(':', '.') for part in urn_parts if part]) 
+    hrn = '.'.join([re.sub(r'\\.', r'\\.', part).replace(':', '.') for part in urn_parts if part]) 
     
     return str(hrn), str(type) 
     
index 2230668..30427c8 100644 (file)
@@ -3,6 +3,12 @@ import re
 from sfa.util.faults import *
 from sfa.util.sfalogging import sfa_logger
 
+# for convenience and smoother translation
+def get_leaf(hrn): return Xrn(hrn=hrn,type='any').get_leaf()
+def get_authority(hrn): return Xrn(hrn=hrn,type='any').get_authority_hrn()
+def urn_to_hrn(urn): xrn=Xrn(urn=urn); return (xrn.hrn, xrn.type)
+def hrn_to_urn(hrn,type): return Xrn(hrn=hrn, type=type).urn
+
 class Xrn:
 
     ########## basic tools on HRNs
@@ -57,26 +63,26 @@ class Xrn:
             self.type=type
             self.hrn_to_urn()
         else:
-            raise SfaAPIError,"Xrn"
+            raise SfaAPIError,"Xrn.__init__"
 
     def get_urn(self): return self.urn
     def get_hrn(self): return (self.hrn, self.type)
 
     def get_leaf(self):
-        if not self.hrn: raise SfaAPIError, "Xrn"
+        if not self.hrn: raise SfaAPIError, "Xrn.get_leaf"
         if not hasattr(self,'leaf'): 
             self.leaf=Xrn.hrn_split(self.hrn)[-1]
         return self.leaf
 
     def get_authority_hrn(self): 
-        if not self.hrn: raise SfaAPIError, "Xrn"
+        if not self.hrn: raise SfaAPIError, "Xrn.get_authority_hrn"
         # self.authority keeps a list
         if not hasattr(self,'authority'): 
             self.authority=Xrn.hrn_path_list(self.hrn)
         return '.'.join( self.authority )
     
     def get_authority_urn(self): 
-        if not self.hrn: raise SfaAPIError, "Xrn"
+        if not self.hrn: raise SfaAPIError, "Xrn.get_authority_urn"
         # self.authority keeps a list
         if not hasattr(self,'authority'): 
             self.authority=Xrn.hrn_path_list(self.hrn)
@@ -88,7 +94,7 @@ class Xrn:
         """
         
         if not self.urn or not self.urn.startswith(Xrn.URN_PREFIX):
-            raise SfaAPIError, "Xrn"
+            raise SfaAPIError, "Xrn.urn_to_hrn"
 
         parts = Xrn.urn_split(self.urn)
         type=parts.pop(2)
@@ -111,7 +117,7 @@ class Xrn:
         """
 
         if not self.hrn or self.hrn.startswith(Xrn.URN_PREFIX):
-            raise SfaAPIError, "Xrn"
+            raise SfaAPIError, "Xrn.hrn_to_urn"
 
         if self.type == 'authority':
             self.authority = Xrn.hrn_split(self.hrn)