provide an example to sfi renew help
[sfa.git] / sfa / client / sfi.py
index b2ba2a0..fc4e609 100644 (file)
@@ -260,6 +260,11 @@ def declare_command (args_string, example,aliases=None):
         return new_method
     return wrap
 
+
+def remove_none_fields (record):
+    none_fields=[ k for (k,v) in record.items() if v is None ]
+    for k in none_fields: del record[k]
+
 ##########
 
 class Sfi:
@@ -500,9 +505,9 @@ class Sfi:
                              metavar="slice_hrn", help="delegate cred. for slice HRN")
            parser.add_option("-a", "--auths", dest='delegate_auths',action='append',default=[],
                              metavar='auth_hrn', help="delegate cred for auth HRN")
-           # this primarily is a shorthand for -a my_hrn
+           # this primarily is a shorthand for -A my_hrn^
            parser.add_option("-p", "--pi", dest='delegate_pi', default=None, action='store_true',
-                             help="delegate your PI credentials, so s.t. like -a your_hrn^")
+                             help="delegate your PI credentials, so s.t. like -A your_hrn^")
            parser.add_option("-A","--to-authority",dest='delegate_to_authority',action='store_true',default=False,
                              help="""by default the mandatory argument is expected to be a user, 
 use this if you mean an authority instead""")
@@ -1031,12 +1036,12 @@ use this if you mean an authority instead""")
 
         # don't translate into an object, as this would possibly distort
         # user-provided data; e.g. add an 'email' field to Users
-        if record_dict['type'] == "user":
+        if record_dict['type'] in ['user']:
             if record_dict['hrn'] == self.user:
                 cred = self.my_credential_string
             else:
                 cred = self.my_authority_credential_string()
-        elif record_dict['type'] in ["slice"]:
+        elif record_dict['type'] in ['slice']:
             try:
                 cred = self.slice_credential_string(record_dict['hrn'])
             except ServerException, e:
@@ -1046,9 +1051,9 @@ use this if you mean an authority instead""")
                    cred = self.my_authority_credential_string()
                else:
                    raise
-        elif record_dict['type'] in ["authority"]:
+        elif record_dict['type'] in ['authority']:
             cred = self.my_authority_credential_string()
-        elif record_dict['type'] == 'node':
+        elif record_dict['type'] in ['node']:
             cred = self.my_authority_credential_string()
         else:
             raise "unknown record type" + record_dict['type']
@@ -1144,7 +1149,7 @@ use this if you mean an authority instead""")
 
         api_options = {'call_id': unique_call_id(),
                        'cached': True,
-                       #'info': options.info,
+                       'info': options.info,
                        'list_leases': options.list_leases,
                        'geni_rspec_version': {'type': 'geni', 'version': '3'},
                       }
@@ -1159,7 +1164,8 @@ use this if you mean an authority instead""")
                 api_options['geni_rspec_version'] = version_manager.get_version(options.rspec_version).to_dict()
             else:
                 api_options['geni_rspec_version'] = {'type': 'geni', 'version': '3'}
-        urn = Xrn(args[0], type='slice').get_urn()        
+        urn = Xrn(args[0], type='slice').get_urn()
+        remove_none_fields(api_options) 
         result = server.Describe([urn], creds, api_options)
         value = ReturnValue.get_value(result)
         if self.options.raw:
@@ -1167,7 +1173,7 @@ use this if you mean an authority instead""")
         if options.file is not None:
             save_rspec_to_file(value['geni_rspec'], options.file)
         if (self.options.raw is None) and (options.file is None):
-            display_rspec(value, options.format)
+            display_rspec(value['geni_rspec'], options.format)
 
         return 
 
@@ -1241,6 +1247,7 @@ use this if you mean an authority instead""")
         sfa_users = []
         geni_users = []
         slice_records = self.registry().Resolve(slice_urn, [self.my_credential_string])
+        remove_none_fields(slice_records[0])
         if slice_records and 'reg-researchers' in slice_records[0] and slice_records[0]['reg-researchers']!=[]:
             slice_record = slice_records[0]
             user_hrns = slice_record['reg-researchers']
@@ -1389,7 +1396,7 @@ use this if you mean an authority instead""")
             print value
         return value
 
-    @declare_command("slice_hrn [<sliver_urn>...] time","")
+    @declare_command("slice_hrn [<sliver_urn>...] time","sfi renew onelab.ple.heartbeat 2015-04-31")
     def renew(self, options, args):
         """
         renew slice (Renew)