Thierry Parmentelat
-$Id$
-$URL$
-->
<!DOCTYPE configuration PUBLIC "-//PlanetLab Central//DTD PLC configuration//EN" "plc_config.dtd">
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
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 *
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
#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
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 *
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):
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
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 *
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
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():
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
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']
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 *
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
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
### $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
#
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
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
### $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
-### $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
+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):
"""
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
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
-### $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
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)
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
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
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
### $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
### $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
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
-### $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
### $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
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
### $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
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
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
-from sfa.util.namespace import *
+from sfa.util.xrn import get_authority
from types import StringTypes
def get_peer(api, hrn):
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 *
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 *
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 *
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 *
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
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
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
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
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
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):
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
# 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.
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
+++ /dev/null
-#
-# 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
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):
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
@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
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()
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):
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)
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()
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 *
+++ /dev/null
-#!/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)
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)