Verbose messaging. We should import a logger here...
[sfa.git] / cmdline / sfi.py
index b7ef9ac..d3aa6be 100755 (executable)
@@ -227,9 +227,8 @@ def create_cmd_parser(command, additional_cmdargs = None):
               "remove": "name",
               "add": "record",
               "update": "record",
-              "nodes": "[name]",
               "slices": "",
-              "resources": "name",
+              "resources": "[name]",
               "create": "name rspec",
               "delete": "name",
               "reset": "name",
@@ -250,7 +249,7 @@ def create_cmd_parser(command, additional_cmdargs = None):
 
    parser = OptionParser(usage="sfi [sfi_options] %s [options] %s" \
       % (command, cmdargs[command]))
-   if command in ("nodes", "resources"):
+   if command in ("resources"):
       parser.add_option("-f", "--format", dest="format",type="choice",
            help="display format (dns|ip|rspec)",default="rspec",
            choices=("dns","ip","rspec"))
@@ -259,7 +258,7 @@ def create_cmd_parser(command, additional_cmdargs = None):
            help="type filter (user|slice|sa|ma|node|aggregate)",
            choices=("user","slice","sa","ma","node","aggregate", "all"),
            default="all")
-   if command in ("show", "list", "nodes", "resources"):
+   if command in ("show", "list", "resources"):
       parser.add_option("-o", "--output", dest="file",
            help="output XML to file", metavar="FILE", default=None)
    return parser
@@ -305,14 +304,17 @@ def main():
    (cmd_opts, cmd_args) = create_cmd_parser(command).parse_args(args[1:])
    verbose = options.verbose
    if verbose :
-      print options.registry, options.sm, options.dir, options.verbose,\
-         options.user, options.auth
-      print command
-      if command in ("nodes", "resources"):
-         print cmd_opts.format
+      print "Resgistry %s, sm %s, dir %s, user %s, auth %s" % (options.registry, 
+                                            options.sm, 
+                                            options.dir,
+                                            options.user, 
+                                            options.auth)
+      print "Command %s" %command
+      if command in ("resources"):
+         print "resources cmd_opts %s" %cmd_opts.format
       elif command in ("list","show","remove"):
-         print cmd_opts.type
-      print cmd_args
+         print "cmd_opts.type %s" %cmd_opts.type
+      print "cmd_args %s" %cmd_args
 
    set_servers(options)
 
@@ -390,9 +392,8 @@ def update(opts, args):
    user_cred = get_user_cred()
    rec_file = get_record_file(args[0])
    record = load_record_from_file(rec_file)
-
    if record.get_type() == "user":
-       if record.get_name() == user_cred.get_object_gid().get_hrn():
+       if record.get_name() == user_cred.get_gid_object().get_hrn():
           cred = user_cred
        else:
           create = get_auth_cred()
@@ -408,30 +409,29 @@ def update(opts, args):
        cred = get_auth_cred()
    else:
        raise "unknown record type" + record.get_type()
-
    return registry.update(cred, record)
 
 #
 # Slice-related commands
 #
 
-# list available nodes
-def nodes(opts, args):
-   global slicemgr
-   user_cred = get_user_cred() 
-   if not opts.format:
-      context = None
-   else:
-      context = opts.format
-   results = slicemgr.list_nodes(user_cred)
-   if opts.format in ['rspec']:     
-      display_rspec(results)
-   else:
-      display_list(results)
-   if (opts.file is not None):
-      rspec = slicemgr.list_nodes(user_cred, 'rspec')
-      save_rspec_to_file(rspec, opts.file)
-   return
+# list available nodes -- now use 'resources' w/ no argument instead
+#def nodes(opts, args):
+#   global slicemgr
+#   user_cred = get_user_cred() 
+#   if not opts.format:
+#      context = None
+#   else:
+#      context = opts.format
+#   results = slicemgr.list_nodes(user_cred)
+#   if opts.format in ['rspec']:     
+#      display_rspec(results)
+#   else:
+#      display_list(results)
+#   if (opts.file is not None):
+#      rspec = slicemgr.list_nodes(user_cred)
+#      save_rspec_to_file(rspec, opts.file)
+#   return
 
 # list instantiated slices
 def slices(opts, args):
@@ -444,8 +444,12 @@ def slices(opts, args):
 # show rspec for named slice
 def resources(opts, args):
    global slicemgr
-   slice_cred = get_slice_cred(args[0])
-   result = slicemgr.get_resources(slice_cred, args[0])
+   if args: 
+       slice_cred = get_slice_cred(args[0])
+       result = slicemgr.get_resources(slice_cred, args[0])
+   else:
+       user_cred = get_user_cred()
+       result = slicemgr.get_resources(user_cred)   
    display_rspec(result)
    if (opts.file is not None):
       save_rspec_to_file(opts.file, result)
@@ -544,7 +548,6 @@ def save_records_to_file(filename, recordList):
 def save_record_to_file(filename, record):
    if not filename.startswith(os.sep):
        filename = sfi_dir + filename
-   print "saving record", record.name, "to file", filename
    str = record.save_to_string()
    file(filename, "w").write(str)
    return