Describe(): no need to send None value in api_options
[sfa.git] / sfa / client / sfi.py
index dcd1688..8c6fe7c 100644 (file)
@@ -138,7 +138,7 @@ def save_rspec_to_file(rspec, filename):
     if not filename.endswith(".rspec"):
         filename = filename + ".rspec"
     f = open(filename, 'w')
-    f.write(rspec)
+    f.write("%s"%rspec)
     f.close()
     return
 
@@ -387,13 +387,15 @@ class Sfi:
                               help='how myslice config variables as well')
 
         if command in ("version"):
-            parser.add_option("-R","--registry-version",
-                              action="store_true", dest="version_registry", default=False,
-                              help="probe registry version instead of sliceapi")
             parser.add_option("-l","--local",
                               action="store_true", dest="version_local", default=False,
                               help="display version of the local client")
 
+        if command in ("version", "trusted"):
+            parser.add_option("-R","--registry_interface",
+                              action="store_true", dest="registry_interface", default=False,
+                              help="target the registry interface instead of slice interface")
+
         if command in ("add", "update"):
             parser.add_option('-x', '--xrn', dest='xrn', metavar='<xrn>', help='object hrn/urn (mandatory)')
             parser.add_option('-t', '--type', dest='type', metavar='<type>', help='object type', default=None)
@@ -434,7 +436,7 @@ class Sfi:
                               help="specify specific keys to be displayed from record")
         if command in ("resources", "describe"):
             # rspec version
-            parser.add_option("-r", "--rspec-version", dest="rspec_version", default="SFA 1",
+            parser.add_option("-r", "--rspec-version", dest="rspec_version", default="GENI 3",
                               help="schema type and version of resulting RSpec")
             # disable/enable cached rspecs
             parser.add_option("-c", "--current", dest="current", default=False,
@@ -878,7 +880,7 @@ use this if you mean an authority instead""")
         if options.version_local:
             version=version_core()
         else:
-            if options.version_registry:
+            if options.registry_interface:
                 server=self.registry()
             else:
                 server = self.sliceapi()
@@ -1118,10 +1120,13 @@ 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'},
                       }
+        if options.info:
+            api_options['info'] = options.info
+
         if options.rspec_version:
             version_manager = VersionManager()
             server_version = self.get_cached_server_version(server)
@@ -1136,16 +1141,16 @@ use this if you mean an authority instead""")
         if self.options.raw:
             save_raw_to_file(result, self.options.raw, self.options.rawformat, self.options.rawbanner)
         if options.file is not None:
-            save_rspec_to_file(value, options.file)
+            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)
 
         return 
 
-    @register_command("slice_hrn","")
+    @register_command("slice_hrn [<sliver_urn> ... <sliver_urn>]","")
     def delete(self, options, args):
         """
-        de-allocate and de-provision all or named slivers of the slice (Delete)
+        de-allocate and de-provision all or named slivers of the named slice (Delete)
         """
         server = self.sliceapi()
 
@@ -1153,6 +1158,13 @@ use this if you mean an authority instead""")
         slice_hrn = args[0]
         slice_urn = hrn_to_urn(slice_hrn, 'slice') 
 
+        if len(args) > 1:
+            # we have sliver urns
+            sliver_urns = args[1:]
+        else:
+            # we provision all the slivers of the slice
+            sliver_urns = [slice_urn]
+
         # creds
         slice_cred = self.slice_credential(slice_hrn)
         creds = [slice_cred]
@@ -1162,7 +1174,7 @@ use this if you mean an authority instead""")
         api_options ['call_id'] = unique_call_id()
         if options.show_credential:
             show_credentials(creds)
-        result = server.Delete([slice_urn], creds, *self.ois(server, api_options ) )
+        result = server.Delete(sliver_urns, creds, *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)
@@ -1221,21 +1233,27 @@ use this if you mean an authority instead""")
         if self.options.raw:
             save_raw_to_file(result, self.options.raw, self.options.rawformat, self.options.rawbanner)
         if options.file is not None:
-            save_rspec_to_file (value, options.file)
+            save_rspec_to_file (value['geni_rspec'], options.file)
         if (self.options.raw is None) and (options.file is None):
             print value
         return value
         
 
-    @register_command("slice_hrn","")
+    @register_command("slice_hrn [<sliver_urn> ... <sliver_urn>]","")
     def provision(self, options, args):
         """
-        provision already allocated resources of named slice (Provision)
+        provision all or named already allocated slivers of the named slice (Provision)
         """
         server = self.sliceapi()
         server_version = self.get_cached_server_version(server)
         slice_hrn = args[0]
         slice_urn = Xrn(slice_hrn, type='slice').get_urn()
+        if len(args) > 1:
+            # we have sliver urns
+            sliver_urns = args[1:]
+        else:
+            # we provision all the slivers of the slice
+            sliver_urns = [slice_urn]
 
         # credentials
         creds = [self.slice_credential(slice_hrn)]
@@ -1276,12 +1294,12 @@ use this if you mean an authority instead""")
             users = pg_users_arg(user_records)
         
         api_options['geni_users'] = users
-        result = server.Provision([slice_urn], creds, api_options)
+        result = server.Provision(sliver_urns, creds, 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)
         if options.file is not None:
-            save_rspec_to_file (value, options.file)
+            save_rspec_to_file (value['geni_rspec'], options.file)
         if (self.options.raw is None) and (options.file is None):
             print value
         return value     
@@ -1289,7 +1307,7 @@ use this if you mean an authority instead""")
     @register_command("slice_hrn","")
     def status(self, options, args):
         """
-        retrieve the status of the slivers belonging to tne named slice (Status)
+        retrieve the status of the slivers belonging to the named slice (Status)
         """
         server = self.sliceapi()
 
@@ -1315,17 +1333,23 @@ use this if you mean an authority instead""")
         # Thierry: seemed to be missing
         return value
 
-    @register_command("slice_hrn action","")
+    @register_command("slice_hrn [<sliver_urn> ... <sliver_urn>] action","")
     def action(self, options, args):
         """
-        Perform the named operational action on these slivers
+        Perform the named operational action on all or named slivers of the named slice
         """
         server = self.sliceapi()
         api_options = {}
         # slice urn
         slice_hrn = args[0]
-        action = args[1]
-        slice_urn = Xrn(slice_hrn, type='slice').get_urn() 
+        slice_urn = Xrn(slice_hrn, type='slice').get_urn()
+        if len(args) > 2:
+            # we have sliver urns
+            sliver_urns = args[1:-1]
+        else:
+            # we provision all the slivers of the slice
+            sliver_urns = [slice_urn]
+        action = args[-1]
         # cred
         slice_cred = self.slice_credential(args[0])
         creds = [slice_cred]
@@ -1333,7 +1357,7 @@ use this if you mean an authority instead""")
             delegated_cred = self.delegate_cred(slice_cred, get_authority(self.authority))
             creds.append(delegated_cred)
         
-        result = server.PerformOperationalAction([slice_urn], creds, action , api_options)
+        result = server.PerformOperationalAction(sliver_urns, creds, action , 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)
@@ -1341,18 +1365,26 @@ use this if you mean an authority instead""")
             print value
         return value
 
-    @register_command("slice_hrn time","")
+    @register_command("slice_hrn [<sliver_urn> ... <sliver_urn>] time","")
     def renew(self, options, args):
         """
-        renew slice (RenewSliver)
+        renew slice (Renew)
         """
         server = self.sliceapi()
-        if len(args) != 2:
+        if len(args) < 2:
             self.print_help()
             sys.exit(1)
-        [ slice_hrn, input_time ] = args
-        # slice urn    
-        slice_urn = hrn_to_urn(slice_hrn, 'slice') 
+        slice_hrn = args[0]
+        slice_urn = Xrn(slice_hrn, type='slice').get_urn()
+
+        if len(args) > 2:
+            # we have sliver urns
+            sliver_urns = args[1:-1]
+        else:
+            # we provision all the slivers of the slice
+            sliver_urns = [slice_urn]
+        input_time = args[-1]
+
         # time: don't try to be smart on the time format, server-side will
         # creds
         slice_cred = self.slice_credential(args[0])
@@ -1362,7 +1394,7 @@ use this if you mean an authority instead""")
         api_options['call_id']=unique_call_id()
         if options.show_credential:
             show_credentials(creds)
-        result =  server.Renew([slice_urn], creds, input_time, *self.ois(server,api_options))
+        result =  server.Renew(sliver_urns, 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)
@@ -1616,7 +1648,15 @@ $ sfi m -b http://mymanifold.foo.com:7080/
         """
         return the trusted certs at this interface (get_trusted_certs)
         """ 
-        trusted_certs = self.registry().get_trusted_certs()
+        if options.registry_interface:
+            server=self.registry()
+        else:
+            server = self.sliceapi()
+        cred = self.my_authority_credential_string()
+        trusted_certs = server.get_trusted_certs(cred)
+        if not options.registry_interface:
+            trusted_certs = ReturnValue.get_value(trusted_certs)
+
         for trusted_cert in trusted_certs:
             print "\n===========================================================\n"
             gid = GID(string=trusted_cert)