X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fmanagers%2Faggregate_manager_pl.py;h=887d2f308d6cded3cce293bcd5131e0da0f68eac;hb=9f7ec7438cee94d3049307b2c0edefb119a0b465;hp=4b8f34db7fbeece259d1978897163ac196a6e747;hpb=5307e4e09dd0a7982f0c6dfdd13065425c802005;p=sfa.git diff --git a/sfa/managers/aggregate_manager_pl.py b/sfa/managers/aggregate_manager_pl.py index 4b8f34db..887d2f30 100644 --- a/sfa/managers/aggregate_manager_pl.py +++ b/sfa/managers/aggregate_manager_pl.py @@ -95,8 +95,10 @@ def __get_hostnames(nodes): hostnames.append(node.hostname) return hostnames -def slice_status(api, slice_xrn, creds): - hrn, type = urn_to_hrn(slice_xrn) +def SliverStatus(api, slice_xrn, creds, call_id): + if Callids().already_handled(call_id): return {} + + (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) @@ -106,19 +108,12 @@ def slice_status(api, slice_xrn, creds): 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', 'site_id', 'boot_state', 'last_contact']) + # report about the local nodes only + nodes = api.plshell.GetNodes(api.plauth, {'node_id':slice['node_ids'],'peer_id':None}, + ['hostname', 'site_id', 'boot_state', 'last_contact']) site_ids = [node['site_id'] for node in nodes] sites = api.plshell.GetSites(api.plauth, site_ids, ['site_id', 'login_base']) - sites_dict = {} - for site in sites: - sites_dict[site['site_id']] = site['login_base'] - - # XX remove me - #api.logger.info(slice_xrn) - #api.logger.info(slice) - #api.logger.info(nodes) - # XX remove me + sites_dict = dict ( [ (site['site_id'],site['login_base'] ) for site in sites ] ) result = {} top_level_status = 'unknown' @@ -134,7 +129,7 @@ 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: + if node['last_contact'] is not None: res['pl_last_contact'] = datetime.datetime.fromtimestamp(node['last_contact']).ctime() res['geni_urn'] = hostname_to_urn(api.hrn, sites_dict[node['site_id']], node['hostname']) if node['boot_state'] == 'boot': @@ -209,8 +204,9 @@ def CreateSliver(api, slice_xrn, creds, rspec, users, call_id): return network.toxml() -def renew_slice(api, xrn, creds, expiration_time): - hrn, type = urn_to_hrn(xrn) +def RenewSliver(api, xrn, creds, expiration_time, call_id): + if Callids().already_handled(call_id): return True + (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: @@ -218,8 +214,11 @@ def renew_slice(api, xrn, creds, expiration_time): slice = slices[0] requested_time = utcparse(expiration_time) record = {'expires': int(time.mktime(requested_time.timetuple()))} - api.plshell.UpdateSlice(api.plauth, slice['slice_id'], record) - return 1 + try: + api.plshell.UpdateSlice(api.plauth, slice['slice_id'], record) + return True + except: + return False def start_slice(api, xrn, creds): hrn, type = urn_to_hrn(xrn) @@ -274,9 +273,13 @@ def DeleteSliver(api, xrn, creds, call_id): api.plshell.BindObjectToPeer(api.plauth, 'slice', slice['slice_id'], peer, slice['peer_slice_id']) return 1 -def get_slices(api, creds): +# xxx Thierry : caching at the aggregate level sounds wrong... +caching=True +#caching=False +def ListSlices(api, creds, call_id): + if Callids().already_handled(call_id): return [] # look in cache first - if api.cache: + if caching and api.cache: slices = api.cache.get('slices') if slices: return slices @@ -287,14 +290,11 @@ def get_slices(api, creds): slice_urns = [hrn_to_urn(slice_hrn, 'slice') for slice_hrn in slice_hrns] # cache the result - if api.cache: + if caching and api.cache: api.cache.add('slices', slice_urns) return slice_urns -# xxx Thierry : caching at the aggregate level sounds wrong... -caching=True -#caching=False def ListResources(api, creds, options,call_id): if Callids().already_handled(call_id): return "" # get slice's hrn from options