from sfa.util.rspec import RSpec
import sys
import pdb
-from sfa.util.namespace import hrn_to_pl_slicename, hrn_to_urn
--from sfa.util.xrn import urn_to_hrn, get_authority
++from sfa.util.xrn import urn_to_hrn, hrn_to_urn, get_authority
++from sfa.util.plxrn import hrn_to_pl_slicename
+from sfa.util.plxrn import hrn_to_pl_slicename
from sfa.util.rspec import *
from sfa.util.specdict import *
from sfa.util.faults import *
registries = Registries(api)
registry = registries[api.hrn]
credential = api.getCredential()
- records = registry.resolve(credential, hrn)
+ urn = hrn_to_urn(hrn, 'slice')
+ records = registry.Resolve(urn, credential)
for record in records:
if record.get_type() in ['slice']:
slice = record.as_dict()
sites = api.plshell.GetSites(api.plauth, [login_base])
if not sites:
authority = get_authority(hrn)
- site_records = registry.resolve(credential, authority)
+ authority_urn = hrn_to_urn(authority, 'authority')
+ site_records = registry.Resolve(authority_urn, credential)
site_record = {}
if not site_records:
raise RecordNotFound(authority)
researchers = record.get('researcher', [])
for researcher in researchers:
person_record = {}
- person_records = registry.resolve(credential, researcher)
+ researcher_urn = hrn_to_urn(researcher, 'user')
+ person_records = registry.Resolve(researcher_urn, credential)
for record in person_records:
if record.get_type() in ['user']:
person_record = record
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 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
records = []
if registry_hrn != api.hrn:
credential = api.getCredential()
- record_list = registries[registry_hrn].list(credential, xrn, origin_hrn)
+ record_list = registries[registry_hrn].List(xrn, credential)
records = [SfaRecord(dict=record).as_dict() for record in record_list]
# if we still have not found the record yet, try the local registry
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.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 not xrn:
- if urn:
- xrn = urn
- elif hrn:
- xrn = hrn
++ # user has specified xrn : guess if urn or hrn
+ if xrn is not None:
+ if xrn.startswith(Xrn.URN_PREFIX):
+ self.urn=xrn
+ self.urn_to_hrn()
else:
- raise SfaAPIError,"Xrn.__init__"
-
- if xrn.startswith(Xrn.URN_PREFIX):
- self.urn=xrn
+ self.hrn=xrn
+ self.type=type
+ self.hrn_to_urn()
++ # user has specified urn, let's use it
+ elif urn is not None:
+ self.urn=urn
self.urn_to_hrn()
- else:
- self.hrn=xrn
++ # user has specified hrn and type
+ elif hrn is not None and type is not None:
+ self.hrn=hrn
self.type=type
self.hrn_to_urn()
-
- if not type:
- sfa_logger().debug("type-less Xrn's are not safe")
++ # what should we do ?
+ else:
+ raise SfaAPIError,"Xrn.__init__"
+# 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()