substantial cleanup of the renew method and client
[sfa.git] / sfa / client / sfi.py
index 49156ec..4cceb51 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:
@@ -443,6 +448,9 @@ class Sfi:
         if canonical in ("list","resources", "describe", "provision", "allocate", "register","update","remove","delete","status","renew"):
             parser.add_option("-C","--credential",dest='show_credential',action='store_true',default=False,
                               help="show credential(s) used in human-readable form")
+        if canonical in ("renew"):
+            parser.add_option("-l","--as-long-as-possible",dest='alap',action='store_true',default=False,
+                              help="renew as long as possible")
         # registy filter option
         if canonical in ("list", "show", "remove"):
             parser.add_option("-t", "--type", dest="type", type="choice",
@@ -1144,7 +1152,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 +1167,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 +1176,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 +1250,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 +1399,12 @@ 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",
+                     "\n".join(["sfi renew onelab.ple.heartbeat 2015-04-31",
+                                "sfi renew onelab.ple.heartbeat 2015-04-31T14:00:00Z",
+                                "sfi renew onelab.ple.heartbeat +5d",
+                                "sfi renew onelab.ple.heartbeat +3w",
+                                "sfi renew onelab.ple.heartbeat +2m",]))
     def renew(self, options, args):
         """
         renew slice (Renew)
@@ -1416,6 +1431,8 @@ use this if you mean an authority instead""")
         # options and call_id when supported
         api_options = {}
         api_options['call_id']=unique_call_id()
+        if options.alap:
+            api_options['geni_extend_alap']=True
         if options.show_credential:
             show_credentials(creds)
         result =  server.Renew(sliver_urns, creds, input_time, *self.ois(server,api_options))