From: Sandrine Avakian Date: Thu, 5 Jul 2012 15:00:08 +0000 (+0200) Subject: Merge branch 'master' into senslab2 X-Git-Tag: sfa-2.1-24~3^2~135 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=bc77b3e1ce73d7f748d9cc978472dba246034d74;hp=-c;p=sfa.git Merge branch 'master' into senslab2 --- bc77b3e1ce73d7f748d9cc978472dba246034d74 diff --combined sfa/client/sfi.py index 43e5b985,a8a012c0..512bf9a3 --- a/sfa/client/sfi.py +++ b/sfa/client/sfi.py @@@ -356,6 -356,9 +356,9 @@@ class Sfi help="type filter ([all]|user|slice|authority|node|aggregate)", choices=("all", "user", "slice", "authority", "node", "aggregate"), default="all") + if command in ("show"): + parser.add_option("-k","--key",dest="keys",action="append",default=[], + help="specify specific keys to be displayed from record") if command in ("resources"): # rspec version parser.add_option("-r", "--rspec-version", dest="rspec_version", default="SFA 1", @@@ -454,7 -457,9 +457,9 @@@ def print_help (self): + print "==================== Generic sfi usage" self.sfi_parser.print_help() + print "==================== Specific command usage" self.command_parser.print_help() # @@@ -491,9 -496,8 +496,8 @@@ self.dispatch(command, command_options, command_args) except KeyError: self.logger.critical ("Unknown command %s"%command) - raise sys.exit(1) - + return #################### @@@ -824,6 -828,16 +828,16 @@@ or version information about sfi itsel record_dicts = filter_records(options.type, record_dicts) if not record_dicts: self.logger.error("No record of type %s"% options.type) + return + # user has required to focus on some keys + if options.keys: + def project (record): + projected={} + for key in options.keys: + try: projected[key]=record[key] + except: pass + return projected + record_dicts = [ project (record) for record in record_dicts ] records = [ Record(dict=record_dict) for record_dict in record_dicts ] for record in records: if (options.format == "text"): record.dump(sort=True) @@@ -1034,7 -1048,6 +1048,7 @@@ or with an slice hrn, shows currently p rspec.filter({'component_manager_id': server_version['urn']}) rspec = RSpecConverter.to_pg_rspec(rspec.toxml(), content_type='request') else: + print >>sys.stderr, "\r\n \r\n \r\n WOOOOOO" users = sfa_users_arg(user_records, slice_record) # do not append users, keys, or slice tags. Anything @@@ -1186,21 -1199,23 +1200,23 @@@ renew slice (RenewSliver) """ server = self.sliceapi() + if len(args) != 2: + self.print_help() + sys.exit(1) + [ slice_hrn, input_time ] = args # slice urn - slice_hrn = args[0] slice_urn = hrn_to_urn(slice_hrn, 'slice') + # time: don't try to be smart on the time format, server-side will # creds slice_cred = self.slice_credential_string(args[0]) creds = [slice_cred] if options.delegate: delegated_cred = self.delegate_cred(slice_cred, get_authority(self.authority)) creds.append(delegated_cred) - # time - time = args[1] # options and call_id when supported api_options = {} api_options['call_id']=unique_call_id() - result = server.RenewSliver(slice_urn, creds, time, *self.ois(server,api_options)) + result = server.RenewSliver(slice_urn, creds, input_time, *self.ois(server,api_options)) value = ReturnValue.get_value(result) if self.options.raw: save_raw_to_file(result, self.options.raw, self.options.rawformat, self.options.rawbanner) diff --combined sfa/planetlab/plslices.py index 49f2fbb3,eb600665..58ee4f42 --- a/sfa/planetlab/plslices.py +++ b/sfa/planetlab/plslices.py @@@ -1,6 -1,5 +1,6 @@@ from types import StringTypes from collections import defaultdict +import sys from sfa.util.sfatime import utcparse, datetime_to_epoch from sfa.util.sfalogging import logger @@@ -131,11 -130,13 +131,11 @@@ class PlSlices # slice belongs to out local plc or a myplc peer. We will assume it # is a local site, unless we find out otherwise peer = None - # get this slice's authority (site) slice_authority = get_authority(hrn) # get this site's authority (sfa root authority or sub authority) site_authority = get_authority(slice_authority).lower() - # check if we are already peered with this site_authority, if so peers = self.driver.shell.GetPeers({}, ['peer_id', 'peername', 'shortname', 'hrn_root']) for peer_record in peers: @@@ -161,6 -162,7 +161,7 @@@ def verify_slice_leases(self, slice, requested_leases, kept_leases, peer): leases = self.driver.shell.GetLeases({'name':slice['name']}, ['lease_id']) + grain = self.driver.shell.GetLeaseGranularity() current_leases = [lease['lease_id'] for lease in leases] deleted_leases = list(set(current_leases).difference(kept_leases)) @@@ -169,7 -171,7 +170,7 @@@ self.driver.shell.UnBindObjectFromPeer('slice', slice['slice_id'], peer['shortname']) deleted=self.driver.shell.DeleteLeases(deleted_leases) for lease in requested_leases: - added=self.driver.shell.AddLeases(lease['hostname'], slice['name'], int(lease['t_from']), int(lease['t_until'])) + added=self.driver.shell.AddLeases(lease['hostname'], slice['name'], int(lease['start_time']), int(lease['duration']) * grain + int(lease['start_time'])) except: logger.log_exc('Failed to add/remove slice leases') diff --combined sfa/util/xrn.py index 19b1fc18,ff605714..e3871b5f --- a/sfa/util/xrn.py +++ b/sfa/util/xrn.py @@@ -22,7 -22,7 +22,7 @@@ #---------------------------------------------------------------------- import re - +import sys from sfa.util.faults import SfaAPIError # for convenience and smoother translation - we should get rid of these functions eventually @@@ -121,7 -121,6 +121,7 @@@ class Xrn # provide either urn, or (hrn + type) def __init__ (self, xrn, type=None): if not xrn: xrn = "" + # user has specified xrn : guess if urn or hrn if Xrn.is_urn(xrn): self.hrn=None @@@ -155,8 -154,7 +155,8 @@@ # self.authority keeps a list if not hasattr(self,'authority'): self.authority=Xrn.hrn_auth_list(self.hrn) - + + def get_leaf(self): self._normalize() return self.leaf @@@ -225,17 -223,20 +225,20 @@@ raise SfaAPIError, "Xrn.hrn_to_urn, hrn=%s"%self.hrn if self.type and self.type.startswith('authority'): - self.authority = Xrn.hrn_split(self.hrn) + self.authority = Xrn.hrn_auth_list(self.hrn) + leaf = self.get_leaf() + if not self.authority: + self.authority = [self.hrn] type_parts = self.type.split("+") self.type = type_parts[0] name = 'sa' if len(type_parts) > 1: name = type_parts[1] + authority_string = ":".join([self.get_authority_urn(), leaf]) else: self.authority = Xrn.hrn_auth_list(self.hrn) name = Xrn.hrn_leaf(self.hrn) - - authority_string = self.get_authority_urn() + authority_string = self.get_authority_urn() if self.type == None: urn = "+".join(['',authority_string,Xrn.unescape(name)])