namespace module is gone, plxrn provides PL-specific translations
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Tue, 19 Oct 2010 10:53:00 +0000 (13:53 +0300)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Tue, 19 Oct 2010 10:53:00 +0000 (13:53 +0300)
helper functions re-implemented on top of (pl)xrn - temporarily

50 files changed:
config/default_config.xml
sfa/managers/aggregate_manager_eucalyptus.py
sfa/managers/aggregate_manager_max.py
sfa/managers/aggregate_manager_openflow.py
sfa/managers/aggregate_manager_pl.py
sfa/managers/aggregate_manager_vini.py
sfa/managers/component_manager_pl.py
sfa/managers/registry_manager_pl.py
sfa/managers/slice_manager_pl.py
sfa/methods/CreateSliver.py
sfa/methods/DeleteSliver.py
sfa/methods/GetCredential.py
sfa/methods/GetSelfCredential.py
sfa/methods/GetTicket.py
sfa/methods/List.py
sfa/methods/ListResources.py
sfa/methods/RegisterPeerObject.py
sfa/methods/Remove.py
sfa/methods/RenewSliver.py
sfa/methods/Resolve.py
sfa/methods/SliverStatus.py
sfa/methods/Start.py
sfa/methods/Stop.py
sfa/methods/get_aggregates.py
sfa/methods/get_key.py
sfa/methods/get_registries.py
sfa/methods/register_peer_object.py
sfa/methods/reset_slice.py
sfa/plc/api.py
sfa/plc/network.py
sfa/plc/peers.py
sfa/plc/sfa-import-plc.py
sfa/plc/sfaImport.py
sfa/plc/slices.py
sfa/rspecs/aggregates/rspec_manager_max.py
sfa/server/aggregate.py
sfa/server/interface.py
sfa/server/registry.py
sfa/server/sfa_component_setup.py
sfa/trust/auth.py
sfa/trust/certificate.py
sfa/trust/credential.py
sfa/trust/gid.py
sfa/trust/hierarchy.py
sfa/util/namespace.py [deleted file]
sfa/util/record.py
sfa/util/xrn.py
tests/testInterfaces.py
tests/testNamespace.py [deleted file]
tests/testXrn.py

index 37cd6cc..ce5ec40 100644 (file)
@@ -5,8 +5,6 @@ Default SFA configuration file
 
 Thierry Parmentelat 
 
-$Id$
-$URL$
 -->
 
 <!DOCTYPE configuration PUBLIC "-//PlanetLab Central//DTD PLC configuration//EN" "plc_config.dtd">
index 3d2018b..b9f6df8 100644 (file)
@@ -337,7 +337,7 @@ class ZoneResultParser(object):
 def get_rspec(api, creds, options): 
     global cloud
     # get slice's hrn from options
-    xrn = options.get('geni_slice_urn', None)
+    xrn = options.get('geni_slice_urn', '')
     hrn, type = urn_to_hrn(xrn)
 
     # get hrn of the original caller
index 14b924d..2a46cb5 100644 (file)
@@ -3,8 +3,8 @@
 from sfa.util.rspec import RSpec
 import sys
 import pdb
-from sfa.util.namespace import hrn_to_pl_slicename
 from sfa.util.xrn import urn_to_hrn, get_authority
+from sfa.util.plxrn import hrn_to_pl_slicename
 from sfa.util.rspec import *
 from sfa.util.specdict import *
 from sfa.util.faults import *
@@ -250,7 +250,7 @@ def create_slice_max_aggregate(api, hrn, nodes):
 
 def get_rspec(api, creds, options):
     # get slice's hrn from options
-    xrn = options.get('geni_slice_urn', None)
+    xrn = options.get('geni_slice_urn', '')
     hrn, type = urn_to_hrn(xrn)
     # Eg. config line:
     # plc.princeton.sapan vlan23,vlan45
index 6d12446..9285897 100755 (executable)
@@ -9,7 +9,7 @@ import struct
 #from soaplib.serializers.clazz 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
 from sfa.util.config import Config
index d3422c9..0c70dda 100644 (file)
@@ -4,11 +4,13 @@ import traceback
 import sys
 import re
 from types import StringTypes
+from dateutil.parser import parse
 
-from sfa.util.namespace import get_authority, urn_to_hrn, slicename_to_hrn, hrn_to_pl_slicename, hrn_to_urn
+from sfa.util.faults import *
+from sfa.util.xrn import get_authority, hrn_to_urn, urn_to_hrn
+from sfa.util.plxrn import slicename_to_hrn, hrn_to_pl_slicename
 from sfa.util.rspec import *
 from sfa.util.specdict import *
-from sfa.util.faults import *
 from sfa.util.record import SfaRecord
 from sfa.util.policy import Policy
 from sfa.util.record import *
@@ -19,7 +21,6 @@ import sfa.plc.peers as peers
 from sfa.plc.network import *
 from sfa.plc.api import SfaAPI
 from sfa.plc.slices import *
-from dateutil.parser import parse
 
 
 def __get_registry_objects(slice_xrn, creds, users):
@@ -265,7 +266,7 @@ def get_slices(api, creds):
     
 def get_rspec(api, creds, options):
     # get slice's hrn from options
-    xrn = options.get('geni_slice_urn', None)
+    xrn = options.get('geni_slice_urn', '')
     hrn, type = urn_to_hrn(xrn)
 
     # look in cache first
index d974259..2b56eeb 100644 (file)
@@ -4,7 +4,8 @@ import traceback
 import sys
 
 from types import StringTypes
-from sfa.util.namespace import hrn_to_pl_slicename, urn_to_hrn
+from sfa.util.xrn import urn_to_hrn
+from sfa.util.plxrn import hrn_to_pl_slicename
 from sfa.util.rspec import *
 from sfa.util.specdict import *
 from sfa.util.faults import *
@@ -96,7 +97,7 @@ def create_slice(api, xrn, creds, xml, users):
 
 def get_rspec(api, creds, options):
     # get slice's hrn from options
-    xrn = options.get('geni_slice_urn', None)
+    xrn = options.get('geni_slice_urn', '')
     hrn, type = urn_to_hrn(xrn)
     
     # look in cache first
index 5c9506d..6c36809 100644 (file)
@@ -2,7 +2,8 @@ import os
 import xmlrpclib
 
 from sfa.util.faults import *
-from sfa.util.namespace import urn_to_hrn, hrn_to_pl_slicename
+from sfa.util.xrn import urn_to_hrn
+from sfa.util.plxrn import hrn_to_pl_slicename
 from sfa.util.sfaticket import SfaTicket
 
 def init_server():
index ac5901c..3835873 100644 (file)
@@ -7,8 +7,8 @@ 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 hrn_to_pl_login_base
 from sfa.util.xrn import Xrn, get_leaf, get_authority, hrn_to_urn, urn_to_hrn
+from sfa.util.plxrn import hrn_to_pl_login_base
 from sfa.trust.credential import Credential
 from sfa.trust.certificate import Certificate, Keypair
 from sfa.trust.gid import create_uuid
@@ -368,21 +368,18 @@ def update(api, record_dict):
     
     return 1 
 
-# 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)    
+# expecting an Xrn instance
+def remove(api, xrn, origin_hrn=None):
 
     table = SfaTable()
-    filter = {'hrn': hrn}
+    filter = {'hrn': xrn.get_hrn()}
+    hrn=xrn.get_hrn()
+    type=xrn.get_type()
     if type and type not in ['all', '*']:
         filter['type'] = type
+
     records = table.find(filter)
-    if not records:
-        raise RecordNotFound(hrn)
+    if not records: raise RecordNotFound(hrn)
     record = records[0]
     type = record['type']
 
index 2c98e24..4aca6fa 100644 (file)
@@ -11,7 +11,7 @@ from lxml import etree
 
 from sfa.util.sfalogging import sfa_logger
 from sfa.util.rspecHelper import merge_rspecs
-from sfa.util.namespace import urn_to_hrn, hrn_to_urn
+from sfa.util.xrn import urn_to_hrn, hrn_to_urn
 from sfa.util.rspec import *
 from sfa.util.specdict import *
 from sfa.util.faults import *
@@ -339,7 +339,7 @@ def get_slices(api, creds):
 def get_rspec(api, creds, options):
     
     # get slice's hrn from options
-    xrn = options.get('geni_slice_urn', None)
+    xrn = options.get('geni_slice_urn', '')
     hrn, type = urn_to_hrn(xrn)
 
     # get hrn of the original caller
index e32f9fd..0c729b9 100644 (file)
@@ -1,5 +1,5 @@
 from sfa.util.faults import *
-from sfa.util.namespace import urn_to_hrn
+from sfa.util.xrn import urn_to_hrn
 from sfa.util.method import Method
 from sfa.util.parameter import Parameter, Mixed
 from sfa.util.sfatablesRuntime import run_sfatables
index 8715407..2df5f75 100644 (file)
@@ -2,7 +2,7 @@
 ### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/methods/stop_slice.py $
 
 from sfa.util.faults import *
-from sfa.util.namespace import urn_to_hrn
+from sfa.util.xrn import urn_to_hrn
 from sfa.util.method import Method
 from sfa.util.parameter import Parameter, Mixed
 from sfa.trust.auth import Auth
index 849da80..34a4cb9 100644 (file)
@@ -1,7 +1,7 @@
 #
 from sfa.trust.rights 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.method import Method
 from sfa.util.parameter import Parameter, Mixed
 from sfa.trust.credential import Credential
index 647e636..6a8261c 100644 (file)
@@ -1,6 +1,6 @@
 
 from sfa.util.faults import *
-from sfa.util.namespace import urn_to_hrn
+from sfa.util.xrn import urn_to_hrn
 from sfa.util.method import Method
 from sfa.util.parameter import Parameter, Mixed
 from sfa.util.record import SfaRecord
index f9b8c22..812fb08 100644 (file)
@@ -2,7 +2,7 @@
 ### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/methods/get_ticket.py $
 import time
 from sfa.util.faults import *
-from sfa.util.namespace import urn_to_hrn
+from sfa.util.xrn import urn_to_hrn
 from sfa.util.method import Method
 from sfa.util.parameter import Parameter, Mixed
 from sfa.trust.auth import Auth
index a812c86..8b4fcbe 100644 (file)
@@ -1,8 +1,6 @@
-### $Id: list.py 16588 2010-01-13 17:53:44Z anil $
-### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/methods/list.py $
 
 from sfa.util.faults import *
-from sfa.util.namespace import urn_to_hrn
+from sfa.util.xrn import urn_to_hrn
 from sfa.util.method import Method
 from sfa.util.parameter import Parameter, Mixed
 from sfa.util.record import SfaRecord
index 0425853..6afeb49 100644 (file)
@@ -1,11 +1,12 @@
+import sys
+import zlib
+
 from sfa.util.faults import *
-from sfa.util.namespace import urn_to_hrn
+from sfa.util.xrn import urn_to_hrn
 from sfa.util.method import Method
 from sfa.util.parameter import Parameter, Mixed
 from sfa.trust.credential import Credential
 from sfa.util.sfatablesRuntime import run_sfatables
-import sys
-import zlib
 
 class ListResources(Method):
     """
@@ -26,7 +27,7 @@ class ListResources(Method):
         self.api.logger.info("interface: %s\tmethod-name: %s" % (self.api.interface, self.name))
         
         # get slice's hrn from options    
-        xrn = options.get('geni_slice_urn', None)
+        xrn = options.get('geni_slice_urn', '')
         hrn, _ = urn_to_hrn(xrn)
 
         # Find the valid credentials
index e4cea96..864b1d5 100644 (file)
@@ -5,7 +5,7 @@ from sfa.trust.certificate import Keypair, convert_public_key
 from sfa.trust.gid import *
 
 from sfa.util.faults import *
-from sfa.util.namespace import get_authority
+from sfa.util.xrn import get_authority
 from sfa.util.method import Method
 from sfa.util.parameter import Parameter, Mixed
 from sfa.util.record import SfaRecord
index db0fe08..73fcdf8 100644 (file)
@@ -1,8 +1,5 @@
-### $Id: remove.py 16497 2010-01-07 03:33:24Z tmack $
-### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/methods/remove.py $
-
 from sfa.util.faults import *
-from sfa.util.namespace import urn_to_hrn
+from sfa.util.xrn import Xrn
 from sfa.util.method import Method
 from sfa.util.parameter import Parameter, Mixed
 from sfa.trust.credential import Credential
@@ -31,21 +28,18 @@ 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 type: hrn=xrn
-        else:    (hrn,type) = urn_to_hrn(xrn)
+        xrn=Xrn(xrn=xrn,type=type)
         
         # validate the cred
         valid_creds = self.api.auth.checkCredentials(creds, "remove")
-        self.api.auth.verify_object_permission(hrn)
+        self.api.auth.verify_object_permission(xrn.get_hrn())
 
         #log the call
         origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
-        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))
+        self.api.logger.info("interface: %s\tmethod-name: %s\tcaller-hrn: %s\ttarget-urn: %s"%(
+                self.api.interface, self.name, origin_hrn, xrn.get_urn()))
 
         manager = self.api.get_interface_manager()
 
-        return manager.remove(self.api, hrn, type
+        return manager.remove(self.api, xrn
index 1d7c540..fd0971a 100644 (file)
@@ -1,5 +1,5 @@
 from sfa.util.faults import *
-from sfa.util.namespace import urn_to_hrn
+from sfa.util.xrn import urn_to_hrn
 from sfa.util.method import Method
 from sfa.util.parameter import Parameter
 from sfa.trust.credential import Credential
index d8a536e..92aeec2 100644 (file)
@@ -3,7 +3,7 @@
 import traceback
 import types
 from sfa.util.faults import *
-from sfa.util.namespace import urn_to_hrn
+from sfa.util.xrn import urn_to_hrn
 from sfa.util.method import Method
 from sfa.util.parameter import Parameter, Mixed
 from sfa.trust.credential import Credential
index 0842c14..842c3e4 100644 (file)
@@ -1,5 +1,5 @@
 from sfa.util.faults import *
-from sfa.util.namespace import urn_to_hrn
+from sfa.util.xrn import urn_to_hrn
 from sfa.util.method import Method
 from sfa.util.parameter import Parameter, Mixed
 
index 3619106..e1ca60e 100644 (file)
@@ -2,7 +2,7 @@
 ### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/methods/stop_slice.py $
 
 from sfa.util.faults import *
-from sfa.util.namespace import urn_to_hrn
+from sfa.util.xrn import urn_to_hrn
 from sfa.util.method import Method
 from sfa.util.parameter import Parameter, Mixed
 from sfa.trust.auth import Auth
index 13106e7..579a77d 100644 (file)
@@ -2,7 +2,7 @@
 ### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/methods/stop_slice.py $
 
 from sfa.util.faults import *
-from sfa.util.namespace import urn_to_hrn
+from sfa.util.xrn import urn_to_hrn
 from sfa.util.method import Method
 from sfa.util.parameter import Parameter, Mixed
 from sfa.trust.auth import Auth
index cfc9daa..59d6001 100644 (file)
@@ -1,6 +1,6 @@
 from types import StringTypes
 from sfa.util.faults import *
-from sfa.util.namespace import urn_to_hrn
+from sfa.util.xrn import urn_to_hrn
 from sfa.util.method import Method
 from sfa.util.parameter import Parameter, Mixed
 from sfa.trust.auth import Auth
index 5e3f3fd..9cec0ec 100644 (file)
@@ -1,10 +1,8 @@
-### $Id:  $
-### $URL:  $
 import os
 import tempfile
 import commands
 from sfa.util.faults import *
-from sfa.util.namespace import hrn_to_urn
+from sfa.util.xrn import hrn_to_urn
 from sfa.util.method import Method
 from sfa.util.parameter import Parameter, Mixed
 from sfa.trust.auth import Auth
index e233143..a2a65a5 100644 (file)
@@ -2,7 +2,7 @@
 ### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/methods/get_registries.py $
 from types import StringTypes
 from sfa.util.faults import *
-from sfa.util.namespace import urn_to_hrn
+from sfa.util.xrn import urn_to_hrn
 from sfa.util.method import Method
 from sfa.util.parameter import Parameter, Mixed
 from sfa.trust.auth import Auth
index 51fbe25..e89f18b 100644 (file)
@@ -5,7 +5,7 @@ from sfa.trust.certificate import Keypair, convert_public_key
 from sfa.trust.gid import *
 
 from sfa.util.faults import *
-from sfa.util.namespace import get_authority
+from sfa.util.xrn import get_authority
 from sfa.util.method import Method
 from sfa.util.parameter import Parameter, Mixed
 from sfa.util.record import SfaRecord
index 21fec61..9d02364 100644 (file)
@@ -2,7 +2,7 @@
 ### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/methods/reset_slices.py $
 
 from sfa.util.faults import *
-from sfa.util.namespace import urn_to_hrn
+from sfa.util.xrn import urn_to_hrn
 from sfa.util.method import Method
 from sfa.util.parameter import Parameter, Mixed
 from sfa.trust.auth import Auth
index 7e68a6b..9e77dda 100644 (file)
@@ -17,7 +17,8 @@ from sfa.trust.auth import Auth
 from sfa.trust.rights import Right, Rights, determine_rights
 from sfa.trust.credential import Credential,Keypair
 from sfa.trust.certificate import Certificate
-from sfa.util.namespace import get_authority, hrn_to_pl_slicename, hrn_to_pl_slicename, hrn_to_urn, slicename_to_hrn, hostname_to_hrn
+from sfa.util.xrn import get_authority, hrn_to_urn
+from sfa.util.plxrn import hostname_to_hrn, hrn_to_pl_slicename, hrn_to_pl_slicename, slicename_to_hrn
 from sfa.util.nodemanager import NodeManager
 try:
     from collections import defaultdict
index 4293301..7d2f235 100644 (file)
@@ -1,7 +1,8 @@
 from __future__ import with_statement
 import re
 import socket
-from sfa.util.namespace import get_authority, hrn_to_pl_slicename
+from sfa.util.xrn import get_authority
+from sfa.util.plxrn import hrn_to_pl_slicename
 from sfa.util.faults import *
 from xmlbuilder import XMLBuilder
 from lxml import etree
index 455c682..e85800c 100644 (file)
@@ -1,4 +1,4 @@
-from sfa.util.namespace import *
+from sfa.util.xrn import get_authority
 from types import StringTypes
 
 def get_peer(api, hrn):
index 0fed065..637109a 100755 (executable)
@@ -20,7 +20,8 @@ import tempfile
 
 from sfa.util.record import *
 from sfa.util.table import SfaTable
-from sfa.util.namespace import get_leaf, get_authority, hostname_to_hrn, slicename_to_hrn, email_to_hrn, hrn_to_pl_slicename
+from sfa.util.xrn import get_leaf, get_authority
+from sfa.util.plxrn import hostname_to_hrn, slicename_to_hrn, email_to_hrn, hrn_to_pl_slicename
 from sfa.util.config import Config
 from sfa.trust.certificate import convert_public_key, Keypair
 from sfa.trust.trustedroot import *
index 2e8f9d9..ecad66f 100644 (file)
@@ -16,7 +16,8 @@ from sfa.util.sfalogging import sfa_logger_goes_to_import,sfa_logger
 
 from sfa.util.record import *
 from sfa.util.table import SfaTable
-from sfa.util.namespace import get_authority, hrn_to_urn, email_to_hrn
+from sfa.util.xrn import get_authority, hrn_to_urn
+from sfa.util.plxrn import email_to_hrn
 from sfa.util.config import Config
 from sfa.trust.certificate import convert_public_key, Keypair
 from sfa.trust.trustedroot import *
index 9df40c8..c5a9c14 100644 (file)
@@ -4,7 +4,8 @@ import traceback
 import sys
 
 from types import StringTypes
-from sfa.util.namespace import get_leaf, get_authority, hrn_to_urn, hrn_to_pl_slicename, urn_to_hrn
+from sfa.util.xrn import get_leaf, get_authority, hrn_to_urn, urn_to_hrn
+from sfa.util.plxrn import hrn_to_pl_slicename
 from sfa.util.rspec import *
 from sfa.util.specdict import *
 from sfa.util.faults import *
index 99b390a..c055d2d 100644 (file)
@@ -3,7 +3,8 @@
 from sfa.util.rspec import RSpec
 import sys
 import pdb
-from sfa.util.namespace import get_authority, hrn_to_pl_slicename, 
+from sfa.util.xrn import get_authority
+from sfa.util.plxrn import hrn_to_pl_slicename 
 from sfa.util.rspec import *
 from sfa.util.specdict import *
 from sfa.util.faults import *
index 3dee184..f4f380c 100644 (file)
@@ -4,7 +4,7 @@
 
 from sfa.util.faults import *
 from sfa.util.server import SfaServer
-from sfa.util.namespace import hrn_to_urn
+from sfa.util.xrn import hrn_to_urn
 from sfa.server.interface import Interfaces
 import sfa.util.xmlrpcprotocol as xmlrpcprotocol
 import sfa.util.soapprotocol as soapprotocol
index 7ae027d..0804fc1 100644 (file)
@@ -5,7 +5,7 @@
 
 from sfa.util.faults import *
 from sfa.util.storage import *
-from sfa.util.namespace import get_authority, hrn_to_urn
+from sfa.util.xrn import get_authority, hrn_to_urn
 from sfa.trust.gid import GID
 from sfa.util.record import SfaRecord
 import traceback
index 1dea183..b7bfdd8 100644 (file)
@@ -7,7 +7,7 @@
 
 from sfa.util.server import SfaServer
 from sfa.util.faults import *
-from sfa.util.namespace import hrn_to_urn
+from sfa.util.xrn import hrn_to_urn
 from sfa.server.interface import Interfaces
 import sfa.util.xmlrpcprotocol as xmlrpcprotocol
 import sfa.util.soapprotocol as soapprotocol
index 80a03a8..b0a5a47 100755 (executable)
@@ -3,10 +3,11 @@ import sys
 import os
 import tempfile
 from optparse import OptionParser
+
+from sfa.util.faults import *
 from sfa.util.config import Config
 import sfa.util.xmlrpcprotocol as xmlrpcprotocol
-from sfa.util.namespace import hrn_to_pl_slicename, slicename_to_hrn
-from sfa.util.faults import *
+from sfa.util.plxrn import hrn_to_pl_slicename, slicename_to_hrn
 from sfa.trust.certificate import Keypair, Certificate
 from sfa.trust.credential import Credential
 from sfa.trust.gid import GID
index 3952272..0b76d9e 100644 (file)
@@ -9,7 +9,7 @@ from sfa.trust.trustedroot import TrustedRootList
 from sfa.util.faults import *
 from sfa.trust.hierarchy import Hierarchy
 from sfa.util.config import *
-from sfa.util.namespace import get_authority
+from sfa.util.xrn import get_authority
 from sfa.util.sfaticket import *
 
 from sfa.util.sfalogging import sfa_logger
index 25bb99a..839d1df 100644 (file)
@@ -46,7 +46,7 @@ import M2Crypto
 from M2Crypto import X509
 
 from sfa.util.sfalogging import sfa_logger
-from sfa.util.namespace import urn_to_hrn
+from sfa.util.xrn import urn_to_hrn
 from sfa.util.faults import *
 
 def convert_public_key(key):
index 43dc768..5aa7631 100644 (file)
@@ -41,7 +41,7 @@ from sfa.trust.certificate import Keypair
 from sfa.trust.credential_legacy import CredentialLegacy
 from sfa.trust.rights import Right, Rights
 from sfa.trust.gid import GID
-from sfa.util.namespace import urn_to_hrn
+from sfa.util.xrn import urn_to_hrn
 
 # 2 weeks, in seconds 
 DEFAULT_CREDENTIAL_LIFETIME = 86400 * 14
index 5976b66..94240cd 100644 (file)
 # descendant of the certificate class.
 ##
 
-### $Id$
-### $URL$
 import xmlrpclib
 import uuid
 
 from sfa.util.sfalogging import sfa_logger
 from sfa.trust.certificate import Certificate
-from sfa.util.namespace import hrn_to_urn, urn_to_hrn
+from sfa.util.xrn import hrn_to_urn, urn_to_hrn
 
 ##
 # Create a new uuid. Returns the UUID as a string.
index 0aafa5f..0f3af46 100644 (file)
@@ -15,7 +15,7 @@
 import os
 
 from sfa.util.sfalogging import sfa_logger
-from sfa.util.namespace import get_leaf, get_authority, hrn_to_urn, urn_to_hrn
+from sfa.util.xrn import get_leaf, get_authority, hrn_to_urn, urn_to_hrn
 from sfa.trust.certificate import Keypair
 from sfa.trust.credential import Credential
 from sfa.trust.gid import GID, create_uuid
diff --git a/sfa/util/namespace.py b/sfa/util/namespace.py
deleted file mode 100644 (file)
index c66e526..0000000
+++ /dev/null
@@ -1,153 +0,0 @@
-#
-#  WARNING - This file should be soon deprecated in favor of sfa.util.xrn
-#
-#
-#  WARNING - This file should be soon deprecated in favor of sfa.util.xrn
-#
-#
-#  WARNING - This file should be soon deprecated in favor of sfa.util.xrn
-#
-#
-#  WARNING - This file should be soon deprecated in favor of sfa.util.xrn
-#
-#
-#  WARNING - This file should be soon deprecated in favor of sfa.util.xrn
-#
-#
-#  WARNING - This file should be soon deprecated in favor of sfa.util.xrn
-#
-import re
-from sfa.util.faults import *
-URN_PREFIX = "urn:publicid:IDN"
-
-def __get_hierarchy_delim_indexes(hrn):
-    # find all non escaped '.'
-    hierarchy_delim = '([a-zA-Z0-9][\.])'
-    parts = re.findall(hierarchy_delim, hrn)
-    # list of indexes for every  hierarchy delimieter
-    indexes = []
-    for part in parts:
-        indexes.append(hrn.index(part) + 1)
-    return indexes 
-
-def get_leaf(hrn):
-    delim_indexes = __get_hierarchy_delim_indexes(hrn)
-    if not delim_indexes:
-        return hrn
-    
-    last_delim_index = delim_indexes[-1:][0] + 1
-    return hrn[last_delim_index:] 
-
-def get_authority(xrn):
-    hrn, type = urn_to_hrn(xrn)
-    if type and type == 'authority':
-        return hrn
-  
-    delim_indexes = __get_hierarchy_delim_indexes(hrn)
-    if not delim_indexes:
-        return ''
-    last_delim_index = delim_indexes[-1:][0] 
-    return hrn[:last_delim_index] 
-    
-def hrn_to_pl_slicename(hrn):
-    # remove any escaped no alpah numeric characters
-    #hrn = re.sub('\\\[^a-zA-Z0-9]', '', hrn)
-    hrn = re.sub(r'\\(.)', '', hrn)
-    parts = hrn.split(".")
-    return parts[-2] + "_" + parts[-1]
-
-# assuming hrn is the hrn of an authority, return the plc authority name
-def hrn_to_pl_authname(hrn):
-    # remove any escaped no alpah numeric characters
-    hrn = re.sub(r'\\(.)', '', hrn)
-    parts = hrn.split(".")
-    return parts[-1]
-
-# assuming hrn is the hrn of an authority, return the plc login_base
-def hrn_to_pl_login_base(hrn):
-    # remove any escaped no alpah numeric characters
-    hrn = re.sub(r'\\(.)', '', hrn)
-    return hrn_to_pl_authname(hrn)
-
-def hostname_to_hrn(auth_hrn, login_base, hostname):
-    """
-    Convert hrn to plantelab name.
-    """
-    sfa_hostname = ".".join([auth_hrn, login_base, hostname.split(".")[0]])
-    return sfa_hostname
-
-def slicename_to_hrn(auth_hrn, slicename):
-    """
-    Convert hrn to planetlab name.
-    """
-    parts = slicename.split("_")
-    slice_hrn = ".".join([auth_hrn, parts[0]]) + "." + "_".join(parts[1:])
-
-    return slice_hrn
-
-def email_to_hrn(auth_hrn, email):
-    parts = email.split("@")
-    username = parts[0]
-    username = username.replace(".", "_").replace("+", "_") 
-    person_hrn = ".".join([auth_hrn, username])
-    
-    return person_hrn 
-
-def urn_to_hrn(urn):
-    """
-    convert a urn to hrn
-    return a tuple (hrn, type)
-    """
-
-    # if this is already a hrn dont do anything
-    if not urn or not urn.startswith(URN_PREFIX):
-        return urn, None
-
-    name = urn[len(URN_PREFIX):]
-    urn_parts = name.split("+")
-    type = urn_parts.pop(2)
-    
-         
-    # Remove the authority name (e.g. '.sa')
-    if type == 'authority':
-        urn_parts = urn_parts[:-1]
-
-    # convert hrn_parts (list) into hrn (str) by doing the following
-    # 1. remove blank elements
-    # 2. escape all non alpha numeric chars (excluding ':')
-    # 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'\\.', r'\\.', part).replace(':', '.') for part in urn_parts if part]) 
-    
-    return str(hrn), str(type) 
-    
-    
-def hrn_to_urn(hrn, type=None):
-    """
-    convert an hrn and type to a urn string
-    """
-    # if  this is already a urn dont do anything 
-    if not hrn or hrn.startswith(URN_PREFIX):
-        return hrn
-
-    if type == 'authority':
-        authority = hrn
-        name = 'sa'   
-    else:
-        authority = get_authority(hrn)
-        name = get_leaf(hrn)   
-  
-    # convert from hierarchy delimiter from '.' to ':'   
-    authority = re.sub(r'([a-zA-Z0-9])[\.]', r'\1:', authority) 
-    # unescape escaped characters
-    authority = re.sub(r'\\(.)', r'\1', authority)
-    
-    if type == None:
-        urn = "+".join(['',authority,name])
-    else:
-        urn = "+".join(['',authority,type,name])
-
-        
-    return URN_PREFIX + urn
index 6cb9d37..a539f62 100644 (file)
@@ -13,7 +13,7 @@ from sfa.trust.gid import *
 
 from sfa.util.rspec import *
 from sfa.util.parameter import *
-from sfa.util.namespace import get_authority
+from sfa.util.xrn import get_authority
 from sfa.util.row import Row
 
 class SfaRecord(Row):
index 86a1f86..eb0d39e 100644 (file)
@@ -3,10 +3,9 @@ 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).get_leaf()
-def get_authority(hrn): return Xrn(hrn=hrn).get_authority_hrn()
-# these methods we should get rid of eventually
+# for convenience and smoother translation - we should get rid of these functions eventually 
+def get_leaf(hrn): return Xrn(xrn=hrn).get_leaf()
+def get_authority(hrn): return Xrn(xrn=hrn).get_authority_hrn()
 def urn_to_hrn(urn): xrn=Xrn(xrn=urn); return (xrn.hrn, xrn.type)
 def hrn_to_urn(hrn,type): return Xrn(hrn=hrn, type=type).urn
 
@@ -24,13 +23,13 @@ class Xrn:
     @staticmethod
     def hrn_leaf(hrn): return Xrn.hrn_split(hrn)[-1]
 
-    # e.g. hrn_path_list ('a\.b.c.d') -> ['a\.b', 'c']
+    # e.g. hrn_auth_list ('a\.b.c.d') -> ['a\.b', 'c']
     @staticmethod
-    def hrn_path_list(hrn): return Xrn.hrn_split(hrn)[0:-1]
+    def hrn_auth_list(hrn): return Xrn.hrn_split(hrn)[0:-1]
     
-    # e.g. hrn_path ('a\.b.c.d') -> 'a\.b.c'
+    # e.g. hrn_auth ('a\.b.c.d') -> 'a\.b.c'
     @staticmethod
-    def hrn_path(hrn): return '.'.join(Xrn.hrn_path_list(hrn))
+    def hrn_auth(hrn): return '.'.join(Xrn.hrn_auth_list(hrn))
     
     # e.g. escape ('a.b') -> 'a\.b'
     @staticmethod
@@ -54,9 +53,15 @@ class Xrn:
     def urn_split (urn):
         return Xrn.urn_meaningful(urn).split('+')
 
+    ####################
+    # the local fields that are kept consistent
+    # self.urn
+    # self.hrn
+    # self.type
+    # self.path
     # provide either urn, or (hrn + type)
     def __init__ (self, xrn=None, urn=None, hrn=None, type=None):
-        if xrn:
+        if xrn is not None:
             if xrn.startswith(Xrn.URN_PREFIX):
                 self.urn=xrn
                 self.urn_to_hrn()
@@ -64,39 +69,42 @@ class Xrn:
                 self.hrn=xrn
                 self.type=type
                 self.hrn_to_urn()
-        elif urn: 
+        elif urn is not None
             self.urn=urn
             self.urn_to_hrn()
-        elif hrn and type: 
+        elif hrn is not None and type is not None: 
             self.hrn=hrn
             self.type=type
             self.hrn_to_urn()
         else:
             raise SfaAPIError,"Xrn.__init__"
-        if not type:
-            sfa_logger().debug("type-less Xrn's are not safe")
+# happens all the time ..
+#        if not type:
+#            sfa_logger().debug("type-less Xrn's are not safe")
 
     def get_urn(self): return self.urn
-    def get_hrn(self): return (self.hrn, self.type)
+    def get_hrn(self): return self.hrn
+    def get_type(self): return self.type
+    def get_hrn_type(self): return (self.hrn, self.type)
 
-    def get_leaf(self):
-        if not self.hrn: raise SfaAPIError, "Xrn.get_leaf"
+    def _normalize(self):
+        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)
+
+    def get_leaf(self):
+        self._normalize()
         return self.leaf
 
     def get_authority_hrn(self): 
-        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)
+        self._normalize()
         return '.'.join( self.authority )
     
     def get_authority_urn(self): 
-        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)
+        self._normalize()
         return ':'.join( [Xrn.unescape(x) for x in self.authority] )
     
     def urn_to_hrn(self):
@@ -104,7 +112,8 @@ class Xrn:
         compute tuple (hrn, type) from urn
         """
         
-        if not self.urn or not self.urn.startswith(Xrn.URN_PREFIX):
+#        if not self.urn or not self.urn.startswith(Xrn.URN_PREFIX):
+        if not self.urn.startswith(Xrn.URN_PREFIX):
             raise SfaAPIError, "Xrn.urn_to_hrn"
 
         parts = Xrn.urn_split(self.urn)
@@ -127,14 +136,15 @@ class Xrn:
         compute urn from (hrn, type)
         """
 
-        if not self.hrn or self.hrn.startswith(Xrn.URN_PREFIX):
-            raise SfaAPIError, "Xrn.hrn_to_urn"
+#        if not self.hrn or self.hrn.startswith(Xrn.URN_PREFIX):
+        if self.hrn.startswith(Xrn.URN_PREFIX):
+            raise SfaAPIError, "Xrn.hrn_to_urn, hrn=%s"%self.hrn
 
         if self.type == 'authority':
             self.authority = Xrn.hrn_split(self.hrn)
             name = 'sa'   
         else:
-            self.authority = Xrn.hrn_path_list(self.hrn)
+            self.authority = Xrn.hrn_auth_list(self.hrn)
             name = Xrn.hrn_leaf(self.hrn)
 
         authority_string = self.get_authority_urn()
index c43da2c..2b35801 100755 (executable)
@@ -8,7 +8,7 @@ import sfa.util.xmlrpcprotocol as xmlrpc
 from unittest import TestCase
 from optparse import OptionParser
 from sfa.util.xmlrpcprotocol import ServerException
-from sfa.util.namespace import *
+from sfa.util.xrn import get_authority
 from sfa.util.config import *
 from sfa.trust.certificate import *
 from sfa.trust.credential import *
diff --git a/tests/testNamespace.py b/tests/testNamespace.py
deleted file mode 100755 (executable)
index 7994bc9..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-#!/usr/bin/python
-import sys
-import unittest
-
-from sfa.util.namespace import *
-
-class TestNamespace(unittest.TestCase):
-
-    hrns=[
-        ('plc.princeton.tmack','user'),
-        ('fake-pi1@onelab.eu','user'),
-        ('ple.inria.baris','user'),
-        ('emulab\.net.slice.jktest','slice'),
-        ]
-    
-    urns=[
-        'urn:publicid:IDN+emulab:net+slice+jktest',
-        'urn:publicid:IDN+emulab.net+slice+jktest',
-
-        ]
-
-    def test_hrns(self):
-        for (h,t) in TestNamespace.hrns:
-            print 'testing hrn',h,t
-            urn=hrn_to_urn(h,t)
-            (h1,t1) = urn_to_hrn(urn)
-            self.assertEqual(h1,h)
-            self.assertEqual(t1,t)
-            if h1!=h or t1!=t:
-                print "hrn->urn->hrn : MISMATCH with in=(%s,%s) -- out=(%s,%s) -- urn=%s"%(h,t,h1,t1,urn)
-
-    def test_urns(self):
-        for urn in TestNamespace.urns:
-            print 'testing urn',urn
-            (h,t)=urn_to_hrn(urn)
-            urn1 = hrn_to_urn(h,t)
-            self.assertEqual(urn1,urn)
-            if urn1!=urn:
-                print "urn->hrn->urn : MISMATCH with in=(%s) -- out=(%s) -- hrn=(%s,%s)"%(urn,urn1,h,t)
index 82707ac..9725652 100755 (executable)
@@ -4,62 +4,104 @@ import unittest
 
 from sfa.util.faults import *
 from sfa.util.xrn import Xrn
+from sfa.util.plxrn import PlXrn
 
 verbose=False
 
 class TestXrn(unittest.TestCase):
 
-    hrns=[ # hrn, type, expected_urn
-        ('ple.inria.baris','user', "urn:publicid:IDN+ple:inria+user+baris"),
-        ('emulab\.net.slice.jktest','slice', "urn:publicid:IDN+emulab.net:slice+slice+jktest"),
-        ('plc.princeton.tmack','user', "urn:publicid:IDN+plc:princeton+user+tmack"),
-        ('fake-pi1@onelab.eu','user', "urn:publicid:IDN+fake-pi1@onelab+user+eu"),
-        # not providing a type is currently not supported
-        ('fake-pi1@onelab.eu',None, None),
-        ]
+    def __hrn(self,h,t,exp_urn):
+        if verbose: print 'testing (',h,t,') expecting',exp_urn
+        if exp_urn:
+            xrn=Xrn(hrn=h,type=t)
+            if verbose: print xrn.dump_string()
+            urn=xrn.get_urn()
+            (h1,t1) = Xrn(urn=urn).get_hrn_type()
+            if h1!=h or t1!=t or urn!=exp_urn:
+                print "hrn->urn->hrn : MISMATCH with in=(%s,%s) -- out=(%s,%s) -- urn=%s"%(h,t,h1,t1,urn)
+            self.assertEqual(h1,h)
+            self.assertEqual(t1,t)
+            self.assertEqual(urn,exp_urn)
+        else:
+            # could not figure how to use assertFails on object construction..
+            # with self.assertRaises(SfaAPIError):
+            #    Xrn(hrn=h,type=t).get_urn()
+            try:
+                Xrn(hrn=h,type=t).get_urn()
+                failure="Unexpectedly created Xrn object"
+            except SfaAPIError:
+                failure=False
+            except Exception,e:
+                failure="Xrn creation raised unexpected exception %r"%e
+            if failure: 
+                print "hrn->urn->hrn - %s with HRN=%s TYPE=%s"%(failure,h,t)
+                self.assertFalse(True)
+
+
+    def test_hrn001 (self): 
+        self.__hrn("ple.inria.baris",'user',
+                   "urn:publicid:IDN+ple:inria+user+baris")
+    def test_hnr002 (self): 
+        self.__hrn("emulab\.net.myslice.jktest",'slice',
+                   "urn:publicid:IDN+emulab.net:myslice+slice+jktest")
+    def test_hrn003(self):
+        self.__hrn("emulab\\.net.jktest", "slice",
+                   "urn:publicid:IDN+emulab.net+slice+jktest")
+    def test_hrn004(self):
+        self.__hrn("plc.princeton.tmack",'user',
+                   "urn:publicid:IDN+plc:princeton+user+tmack")
+    def test_hrn005(self):
+        self.__hrn("fake-pi1@onelab.eu",'user',
+                   "urn:publicid:IDN+fake-pi1@onelab+user+eu")
+    def test_hrn006(self):
+        self.__hrn("plc.princeton.tmack", 'user',
+                   "urn:publicid:IDN+plc:princeton+user+tmack" )
+    def test_hrn007(self):
+        # not providing a type is currently not supporte
+        self.__hrn("fake-pi1@onelab.eu",None,
+                   None)
+    def test_hrn008(self):
+        self.__hrn("plc.princeton.planetlab1", 'node',
+                   "urn:publicid:IDN+plc:princeton+node+planetlab1" )
+    def test_hrn009(self):
+        self.__hrn("plc.princeton", 'authority',
+                   "urn:publicid:IDN+plc:princeton+authority+sa" )
+    def test_hrn010(self):
+        self.__hrn("plc.vini.site", 'authority',
+                   "urn:publicid:IDN+plc:vini:site+authority+sa" )
+        
+
     
-    urns=[ # urn, expected_hrn, expected_type
-        ('urn:publicid:IDN+emulab:net+slice+jktest', "emulab.net.jktest", "slice"),
-        ('urn:publicid:IDN+emulab.net+slice+jktest', "emulab\\.net.jktest", "slice"),
-        ("urn:publicid:IDN+plc:princeton+user+tmack", "plc.princeton.tmack", "user"),
-        ]
+    def test_host001 (self):
+        xrn=PlXrn (auth="ple.inria",hostname="onelab09.pl.sophia.inria.fr")
+        self.assertEqual (xrn.get_hrn_type(), ("ple.inria.onelab09",'node'))
+    def test_host002 (self):
+        xrn=PlXrn (auth="ple\\.inria",hostname="onelab09.pl.sophia.inria.fr")
+        self.assertEqual (xrn.get_hrn_type(), ("ple\\.inria.onelab09",'node'))
+
+    def test_slice001  (self):
+        xrn=PlXrn (auth="ple",slicename="inria_omftest")
+        self.assertEqual (xrn.get_hrn_type(), ("ple.inria.omftest",'slice'))
+
+    def test_person001 (self):
+        xrn=PlXrn (auth="ple.inria",email="first.last@some.domain.com")
+        self.assertEqual (xrn.get_hrn_type(), ("ple.inria.first_last",'person'))
+    def test_person002 (self):
+        xrn=PlXrn (auth="ple.inria",email="first+last@some.domain.com")
+        self.assertEqual (xrn.get_hrn_type(), ("ple.inria.first_last",'person'))
+        
+
+
+    def test_login_base_001 (self):
+        xrn=PlXrn(hrn='ple.inria.omftest',type='slice')
+        self.assertEqual(xrn.login_base(),'inria')
+
+    def test_slicename_001 (self):
+        xrn=PlXrn(hrn='ple.inria.omftest',type='slice')
+        self.assertEqual(xrn.slicename(),'inria_omftest')
+
+    def test_authname_001 (self):
+        xrn=PlXrn(hrn='ple.inria.omftest',type='slice')
+        self.assertEqual(xrn.authname(),'inria')
 
-    def test_hrns(self):
-        for (h,t,exp_urn) in TestXrn.hrns:
-            print 'testing (',h,t,') expecting',exp_urn
-            if exp_urn:
-                xrn=Xrn(hrn=h,type=t)
-                if verbose: print xrn.dump_string()
-                urn=xrn.get_urn()
-                (h1,t1) = Xrn(urn=urn).get_hrn()
-                if h1!=h or t1!=t or urn!=exp_urn:
-                    print "hrn->urn->hrn : MISMATCH with in=(%s,%s) -- out=(%s,%s) -- urn=%s"%(h,t,h1,t1,urn)
-                self.assertEqual(h1,h)
-                self.assertEqual(t1,t)
-                self.assertEqual(urn,exp_urn)
-            else:
-                # could not figure how to use assertFails on object construction..
-                # with self.assertRaises(SfaAPIError):
-                #    Xrn(hrn=h,type=t).get_urn()
-                try:
-                    Xrn(hrn=h,type=t).get_urn()
-                    failure="Unexpectedly created Xrn object"
-                except SfaAPIError:
-                    failure=False
-                except Exception,e:
-                    failure="Xrn creation raised unexpected exception %r"%e
-                if failure: 
-                    print "hrn->urn->hrn - %s with HRN=%s TYPE=%s"%(failure,h,t)
-                    self.assertFalse(True)
-                    
 
-    def test_urns(self):
-        for (urn, exp_hrn, exp_type) in TestXrn.urns:
-            xrn=Xrn(urn=urn)
-            print 'testing urn',urn,'expecting (',exp_hrn,exp_type,')'
-            if verbose: print xrn.dump_string()
-            (h,t)=xrn.get_hrn()
-            urn1 = Xrn(hrn=h,type=t).get_urn()
-            if urn1!=urn:
-                print "urn->hrn->urn : MISMATCH with in=(%s) -- out=(%s) -- hrn=(%s,%s)"%(urn,urn1,h,t)
-            self.assertEqual(urn1,urn)