from sfa.rspecs.elements.granularity import Granularity
from sfa.rspecs.version_manager import VersionManager
-from sfa.planetlab.plxrn import PlXrn, hostname_to_urn, hrn_to_pl_slicename, slicename_to_hrn
+from sfa.planetlab.plxrn import PlXrn, hostname_to_urn, hrn_to_pl_slicename, slicename_to_hrn, xrn_to_ext_slicename, top_auth
from sfa.planetlab.vlink import get_tc_rate
from sfa.planetlab.topology import Topology
from sfa.storage.alchemy import dbsession
pass
else:
slice_hrn = xrn.get_hrn()
- site_hrn = get_authority(slice_hrn)
- top_auth_hrn = site_hrn.split('.')[0]
+ top_auth_hrn = top_auth(slice_hrn)
if top_auth_hrn == self.driver.hrn:
slice_name = hrn_to_pl_slicename(slice_hrn)
else:
- login_base = '8'.join(site_hrn.split('.'))
- slice_name = '_'.join([login_base, get_leaf(slice_hrn)])
-
+ slice_name = xrn_to_ext_slicename(slice_hrn)
names.add(slice_name)
filter = {}
import sfa.planetlab.peers as peers
from sfa.planetlab.plaggregate import PlAggregate
from sfa.planetlab.plslices import PlSlices
-from sfa.planetlab.plxrn import PlXrn, slicename_to_hrn, hostname_to_hrn, hrn_to_pl_slicename, xrn_to_hostname
+from sfa.planetlab.plxrn import PlXrn, slicename_to_hrn, hostname_to_hrn, hrn_to_pl_slicename, xrn_to_hostname, xrn_to_ext_slicename, top_auth
def list_to_dict(recs, key):
# set the 'enabled' tag to 0
def shutdown (self, xrn, options={}):
- xrn = PlXrn(xrn=xrn, type='slice')
- slicename = xrn.pl_slicename()
+ hrn = urn_to_hrn(xrn)
+ top_auth_hrn = top_auth(hrn)
+ if top_auth_hrn == self.hrn:
+ slicename = hrn_to_pl_slicename(hrn)
+ else:
+ slicename = xrn_to_ext_slicename(hrn)
slices = self.shell.GetSlices({'name': slicename}, ['slice_id'])
if not slices:
raise RecordNotFound(slice_hrn)
from sfa.rspecs.rspec import RSpec
from sfa.planetlab.vlink import VLink
from sfa.planetlab.topology import Topology
-from sfa.planetlab.plxrn import PlXrn, hrn_to_pl_slicename, xrn_to_hostname
+from sfa.planetlab.plxrn import PlXrn, hrn_to_pl_slicename, xrn_to_hostname, xrn_to_ext_slicename, hrn_to_ext_loginbase, top_auth
from sfa.storage.model import SliverAllocation
from sfa.storage.alchemy import dbsession
requested_leases = []
for lease in rspec_requested_leases:
requested_lease = {}
- slice_name = hrn_to_pl_slicename(lease['slice_id'])
+ slice_hrn, _ = urn_to_hrn(lease['slice_id'])
+ top_auth_hrn = top_auth(slice_hrn)
+ if top_auth_hrn == self.driver.hrn:
+ slice_name = hrn_to_pl_slicename(lease['slice_id'])
+ else:
+ slice_name = xrn_to_ext_slicename(lease['slice_id'])
if slice_name != slice['name']:
continue
elif Xrn(lease['component_id']).get_authority_urn().split(':')[0] != self.driver.hrn:
def verify_site(self, slice_xrn, slice_record={}, peer=None, sfa_peer=None, options={}):
(slice_hrn, type) = urn_to_hrn(slice_xrn)
- site_hrn = get_authority(slice_hrn)
- top_auth_hrn = site_hrn.split('.')[0]
+ top_auth_hrn = top_auth(slice_hrn)
if top_auth_hrn == self.driver.hrn:
# login base can't be longer than 20 characters
slicename = hrn_to_pl_slicename(slice_hrn)
authority_name = slicename.split('_')[0]
login_base = authority_name[:20]
else:
- login_base = '8'.join(site_hrn.split('.'))[:20]
+ login_base = hrn_to_ext_loginbase(slice_hrn)
authority_name = login_base
sites = self.driver.shell.GetSites(login_base)
def verify_slice(self, slice_hrn, slice_record, peer, sfa_peer, expiration, options={}):
- site_hrn = get_authority(slice_hrn)
- top_auth_hrn = site_hrn.split('.')[0]
+ top_auth_hrn = top_auth(slice_hrn)
if top_auth_hrn == self.driver.hrn:
slicename = hrn_to_pl_slicename(slice_hrn)
parts = slicename.split("_")
login_base = parts[0]
else:
- login_base = '8'.join(site_hrn.split('.'))
- slicename = '_'.join([login_base, slice_hrn.split('.')[-1]])
+ login_base = hrn_to_ext_loginbase(slice_hrn)
+ slicename = xrn_to_ext_slicename(slice_hrn)
slices = self.driver.shell.GetSlices([slicename])
expires = int(datetime_to_epoch(utcparse(expiration)))
#def get_existing_persons(self, users):
def verify_persons(self, slice_hrn, slice_record, users, peer, sfa_peer, options={}):
-
- site_hrn = get_authority(slice_hrn)
- top_auth_hrn = site_hrn.split('.')[0]
- if top_auth_hrn == self.driver.hrn:
- slicename = hrn_to_pl_slicename(slice_hrn)
- parts = slicename.split("_")
- login_base = parts[0]
- else:
- login_base = '8'.join(site_hrn.split('.'))
- slice_name = '_'.join([login_base, slice_hrn.split('.')[-1]])
-
-
-
users_by_email = {}
users_by_site = defaultdict(list)
users_dict = {}
username = get_leaf(hrn)
user['username'] = username
- site_hrn = get_authority(hrn)
- top_auth_hrn = site_hrn.split('.')[0]
+ top_auth_hrn = top_auth(hrn)
if top_auth_hrn == self.driver.hrn:
login_base = PlXrn(xrn=user['urn']).pl_login_base()
else:
- login_base = '8'.join(site_hrn.split('.'))
+ login_base = hrn_to_ext_loginbase(hrn)
user['site'] = login_base
if 'email' in user:
# specialized Xrn class for PlanetLab
import re
-from sfa.util.xrn import Xrn
+from sfa.util.xrn import Xrn, get_authority
# temporary helper functions to use this module instead of namespace
def hostname_to_hrn (auth, login_base, hostname):
def xrn_to_hostname(hrn):
return Xrn.unescape(PlXrn(xrn=hrn, type='node').get_leaf())
+# helpers to handle external objects created via fedaration
+def xrn_to_ext_slicename (xrn):
+ slice_hrn=PlXrn(xrn=xrn,type='slice').get_hrn()
+ site_hrn = get_authority(slice_hrn)
+ login_base = '8'.join(site_hrn.split('.'))
+ slice_name = '_'.join([login_base, slice_hrn.split('.')[-1]])
+ return slice_name
+
+def hrn_to_ext_loginbase (hrn):
+ site_hrn = get_authority(hrn)
+ login_base = '8'.join(site_hrn.split('.'))[:20]
+ return login_base
+
+def top_auth (hrn):
+ return hrn.split('.')[0]
+
class PlXrn (Xrn):
@staticmethod