From 47a7e0908b640739528a8ceed823db25d2f6802c Mon Sep 17 00:00:00 2001 From: Tony Mack Date: Mon, 22 Nov 2010 13:18:49 -0500 Subject: [PATCH] merge from jktest7 --- sfa/managers/aggregate_manager_pl.py | 18 ++++++++++++------ sfa/managers/slice_manager_pl.py | 9 ++++++--- sfa/methods/RenewSliver.py | 8 +++++--- sfa/util/plxrn.py | 16 ++++++++++++++-- 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/sfa/managers/aggregate_manager_pl.py b/sfa/managers/aggregate_manager_pl.py index 2ebcc5a5..e3b7ddeb 100644 --- a/sfa/managers/aggregate_manager_pl.py +++ b/sfa/managers/aggregate_manager_pl.py @@ -4,7 +4,6 @@ import traceback import sys import re from types import StringTypes -from dateutil.parser import parse from sfa.util.faults import * from sfa.util.xrn import get_authority, hrn_to_urn, urn_to_hrn @@ -22,6 +21,7 @@ from sfa.plc.network import * from sfa.plc.api import SfaAPI from sfa.plc.slices import * from sfa.util.version import version_core +from sfa.util.sfatime import utcparse def GetVersion(api): return version_core({'interface':'aggregate', @@ -46,7 +46,6 @@ def __get_registry_objects(slice_xrn, creds, users): slicename = hrn_to_pl_slicename(hrn) login_base = slicename.split('_')[0] reg_objects = {} - site = {} site['site_id'] = 0 site['name'] = 'geni.%s' % login_base @@ -62,7 +61,12 @@ def __get_registry_objects(slice_xrn, creds, users): reg_objects['site'] = site slice = {} - slice['expires'] = int(time.mktime(Credential(string=creds[0]).get_expiration().timetuple())) + + extime = Credential(string=creds[0]).get_expiration() + # If the expiration time is > 60 days from now, set the expiration time to 60 days from now + if extime > datetime.datetime.utcnow() + datetime.timedelta(days=60): + extime = datetime.datetime.utcnow() + datetime.timedelta(days=60) + slice['expires'] = int(time.mktime(extime.timetuple())) slice['hrn'] = hrn slice['name'] = hrn_to_pl_slicename(hrn) slice['url'] = hrn @@ -74,7 +78,7 @@ def __get_registry_objects(slice_xrn, creds, users): for user in users: user['key_ids'] = [] hrn, _ = urn_to_hrn(user['urn']) - user['email'] = hrn_to_pl_slicename(hrn) + "@geni.net" + user['email'] = "geniuser@geni.net" user['first_name'] = hrn user['last_name'] = hrn reg_objects['users'][user['email']] = user @@ -107,7 +111,7 @@ def slice_status(api, slice_xrn, creds): result['geni_urn'] = slice_xrn result['geni_status'] = 'unknown' result['pl_login'] = slice['name'] - result['pl_expires'] = slice['expires'] + result['pl_expires'] = datetime.datetime.fromtimestamp(slice['expires']).ctime() resources = [] @@ -116,6 +120,8 @@ def slice_status(api, slice_xrn, creds): res['pl_hostname'] = node['hostname'] res['pl_boot_state'] = node['boot_state'] res['pl_last_contact'] = node['last_contact'] + if not node['last_contact'] is None: + res['pl_last_contact'] = datetime.datetime.fromtimestamp(node['last_contact']).ctime() res['geni_urn'] = '' res['geni_status'] = 'unknown' res['geni_error'] = '' @@ -187,7 +193,7 @@ def renew_slice(api, xrn, creds, expiration_time): if not slices: raise RecordNotFound(hrn) slice = slices[0] - requested_time = parse(expiration_time) + requested_time = utcparse(expiration_time) record = {'expires': int(time.mktime(requested_time.timetuple()))} api.plshell.UpdateSlice(api.plauth, slice['slice_id'], record) return 1 diff --git a/sfa/managers/slice_manager_pl.py b/sfa/managers/slice_manager_pl.py index ed46feb8..a888521f 100644 --- a/sfa/managers/slice_manager_pl.py +++ b/sfa/managers/slice_manager_pl.py @@ -10,6 +10,7 @@ from lxml import etree from sfa.util.sfalogging import sfa_logger from sfa.util.rspecHelper import merge_rspecs from sfa.util.xrn import Xrn, urn_to_hrn, hrn_to_urn +from sfa.util.plxrn import hrn_to_pl_slicename from sfa.util.rspec import * from sfa.util.specdict import * from sfa.util.faults import * @@ -53,7 +54,7 @@ def slice_status(api, slice_xrn, creds ): result['geni_urn'] = slice_xrn result['geni_status'] = 'unknown' result['pl_login'] = slice['name'] - result['pl_expires'] = slice['expires'] + result['pl_expires'] = datetime.datetime.fromtimestamp(slice['expires']).ctime() resources = [] @@ -62,6 +63,8 @@ def slice_status(api, slice_xrn, creds ): res['pl_hostname'] = node['hostname'] res['pl_boot_state'] = node['boot_state'] res['pl_last_contact'] = node['last_contact'] + if not node['last_contact'] is None: + res['pl_last_contact'] = datetime.datetime.fromtimestamp(node['last_contact']).ctime() res['geni_urn'] = '' res['geni_status'] = 'unknown' res['geni_error'] = '' @@ -120,7 +123,7 @@ def renew_slice(api, xrn, creds, expiration_time): hrn, type = urn_to_hrn(xrn) # get the callers hrn - valid_cred = api.auth.checkCredentials(creds, 'renewesliver', hrn)[0] + valid_cred = api.auth.checkCredentials(creds, 'renewsliver', hrn)[0] caller_hrn = Credential(string=valid_cred).get_gid_caller().get_hrn() # attempt to use delegated credential first @@ -135,7 +138,7 @@ def renew_slice(api, xrn, creds, expiration_time): continue server = api.aggregates[aggregate] - threads.run(server.RenewSliver, xrn, credential, expiration_time) + threads.run(server.RenewSliver, xrn, [credential], expiration_time) threads.get_results() return 1 diff --git a/sfa/methods/RenewSliver.py b/sfa/methods/RenewSliver.py index fd0971af..b574a57d 100644 --- a/sfa/methods/RenewSliver.py +++ b/sfa/methods/RenewSliver.py @@ -3,7 +3,8 @@ 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 -from dateutil.parser import parse +from sfa.util.sfatime import utcparse +import datetime class RenewSliver(Method): """ @@ -30,10 +31,11 @@ class RenewSliver(Method): valid_creds = self.api.auth.checkCredentials(creds, 'renewsliver', hrn) # Validate that the time does not go beyond the credential's expiration time - requested_time = parse(expiration_time) + requested_time = utcparse(expiration_time) if requested_time > Credential(string=valid_creds[0]).get_expiration(): raise InsufficientRights('SliverStatus: Credential expires before requested expiration time') - + if requested_time > datetime.datetime.utcnow() + datetime.timedelta(days=60): + raise Exception('Cannot renew > 60 days from now') manager = self.api.get_interface_manager() manager.renew_slice(self.api, slice_xrn, valid_creds, expiration_time) diff --git a/sfa/util/plxrn.py b/sfa/util/plxrn.py index 3e608b61..89efd4d3 100644 --- a/sfa/util/plxrn.py +++ b/sfa/util/plxrn.py @@ -1,4 +1,5 @@ # specialized Xrn class for PlanetLab +import re from sfa.util.xrn import Xrn # temporary helper functions to use this module instead of namespace @@ -48,7 +49,9 @@ class PlXrn (Xrn): #def hrn_to_pl_slicename(hrn): def pl_slicename (self): self._normalize() - return self.authority[-1] + '_' + self.leaf + leaf = self.leaf + leaf = re.sub('[^a-zA-Z0-9]', '', leaf) + return self.pl_login_base() + '_' + leaf #def hrn_to_pl_authname(hrn): def pl_authname (self): @@ -58,4 +61,13 @@ class PlXrn (Xrn): #def hrn_to_pl_login_base(hrn): def pl_login_base (self): self._normalize() - return self.authority[-1] + base = self.authority[-1] + + # Fix up names of GENI Federates + base = base.lower() + base = re.sub('\\\[^a-zA-Z0-9]', '', base) + + if len(base) > 20: + base = base[len(base)-20:] + + return base -- 2.47.0