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
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',
slicename = hrn_to_pl_slicename(hrn)
login_base = slicename.split('_')[0]
reg_objects = {}
-
site = {}
site['site_id'] = 0
site['name'] = 'geni.%s' % login_base
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
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
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 = []
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'] = ''
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
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 *
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 = []
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'] = ''
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
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
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):
"""
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)
# specialized Xrn class for PlanetLab
+import re
from sfa.util.xrn import Xrn
# temporary helper functions to use this module instead of namespace
#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):
#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