-### $Id: slices.py 15842 2009-11-22 09:56:13Z anil $
-### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/plc/slices.py $
-
import datetime
import time
import traceback
import sys
import re
from types import StringTypes
-from sfa.util.namespace import *
+
+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 sfa.util.version import version_core
+from sfa.util.sfatime import utcparse
+def GetVersion(api):
+ return version_core({'interface':'aggregate',
+ 'testbed':'myplc'})
def __get_registry_objects(slice_xrn, creds, users):
"""
if users:
# dont allow special characters in the site login base
- only_alphanumeric = re.compile('[^a-zA-Z0-9]+')
- login_base = only_alphanumeric.sub('', hrn_auth[:20]).lower()
-
+ #only_alphanumeric = re.compile('[^a-zA-Z0-9]+')
+ #login_base = only_alphanumeric.sub('', hrn_auth[:20]).lower()
+ 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_lifetime().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'] = site['login_base'] + "_" + get_leaf(hrn)
+ slice['name'] = hrn_to_pl_slicename(hrn)
slice['url'] = hrn
slice['description'] = hrn
slice['pointer'] = 0
for user in users:
user['key_ids'] = []
hrn, _ = urn_to_hrn(user['urn'])
- user['email'] = hrn + "@geni.net"
+ user['email'] = hrn_to_pl_slicename(hrn) + "@geni.net"
user['first_name'] = hrn
user['last_name'] = hrn
reg_objects['users'][user['email']] = user
hostnames.append(node.hostname)
return hostnames
-def get_version():
- version = {}
- version['geni_api'] = 1
- version['sfa'] = 1
- return version
-
def slice_status(api, slice_xrn, creds):
+ hrn, type = urn_to_hrn(slice_xrn)
+ # find out where this slice is currently running
+ api.logger.info(hrn)
+ slicename = hrn_to_pl_slicename(hrn)
+
+ slices = api.plshell.GetSlices(api.plauth, [slicename], ['node_ids','person_ids','name','expires'])
+ if len(slices) == 0:
+ raise Exception("Slice %s not found (used %s as slicename internally)" % slice_xrn, slicename)
+ slice = slices[0]
+
+ nodes = api.plshell.GetNodes(api.plauth, slice['node_ids'],
+ ['hostname', 'boot_state', 'last_contact'])
+ api.logger.info(slice)
+ api.logger.info(nodes)
+
result = {}
result['geni_urn'] = slice_xrn
result['geni_status'] = 'unknown'
- result['geni_resources'] = {}
+ result['pl_login'] = slice['name']
+ result['pl_expires'] = datetime.datetime.fromtimestamp(slice['expires']).ctime()
+
+ resources = []
+
+ for node in nodes:
+ res = {}
+ 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'] = ''
+
+ resources.append(res)
+
+ result['geni_resources'] = resources
return result
def create_slice(api, slice_xrn, creds, rspec, users):
return True
-def renew_slice(api, xrn, creds, exipration_time):
+def renew_slice(api, xrn, creds, expiration_time):
hrn, type = urn_to_hrn(xrn)
slicename = hrn_to_pl_slicename(hrn)
slices = api.plshell.GetSlices(api.plauth, {'name': slicename}, ['slice_id'])
if not slices:
raise RecordNotFound(hrn)
slice = slices[0]
- slice['expires'] = expiration_time
- api.plshell.UpdateSlice(api.plauth, slice['slice_id'], slice)
+ requested_time = utcparse(expiration_time)
+ record = {'expires': int(time.mktime(requested_time.timetuple()))}
+ api.plshell.UpdateSlice(api.plauth, slice['slice_id'], record)
return 1
def start_slice(api, xrn, creds):
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