added dir option
[sfa.git] / cmdline / sfi.py
1 #! /usr/bin/env python
2
3 # sfi -- slice-based facility interface
4
5 import sys
6 import os
7 #from cert import Keypair, Certificate
8 from optparse import OptionParser
9
10 def create_cmd_parser(command):
11    cmdargs = {"list": "name",
12               "show": "name",
13               "delete": "name",
14               "add": "name record",
15               "update": "name record",
16               "nodes": "[name]",
17               "slices": "",
18               "resources": "name",
19               "create": "name rspec",
20               "delete": "name",
21               "reset": "name",
22               "start": "name",
23               "stop": "name"
24              }
25    if command not in cmdargs:
26       print "Invalid command\n"
27       print "Commands:list,show,delete,add,update,nodes,slices,resources,create,delete,start,stop,reset"
28       sys.exit(2)
29
30    parser = OptionParser(usage="sfi [sfi_options] %s [options] %s" \
31       % (command, cmdargs[command]))
32    if command in ("nodes", "resources"):
33       parser.add_option("-f", "--format", dest="format",type="choice",
34            help="output format (dns|ip|hrn|rspec)",default="rspec",
35            choices=("dns","ip","hrn","rspec"))
36    elif command in ("list", "show", "delete"):
37       parser.add_option("-t", "--type", dest="type",type="choice",
38            help="type filter (user|slice|sa|ma|node|aggregate)", 
39            choices=("user","slice","sa","ma","node","aggregate"))
40    return parser
41
42 def main():
43    parser = OptionParser(usage="sfi [options] command [command_options] [command_args]",
44         description="Commands: list,show,delete,add,update,nodes,slices,resources,create,delete,start,stop,reset")
45    parser.add_option("-r", "--registry", dest="registry",
46         help="root registry", metavar="URL")
47    parser.add_option("-s", "--slicemgr", dest="sm",
48         help="slice manager", metavar="URL")
49    parser.add_option("-d", "--dir", dest="dir",
50         help="working directory", metavar="PATH")
51    parser.add_option("-v", "--verbose",
52         action="store_true", dest="verbose", default=False,
53         help="verbose mode")
54    parser.disable_interspersed_args()
55    (options, args) = parser.parse_args()
56    command = args[0]
57    (cmd_opts, cmd_args) = create_cmd_parser(command).parse_args(args[1:])
58    if options.verbose :
59       print options.registry,options.sm,options.dir,options.verbose
60       print command
61       if command in ("nodes", "resources"):
62          print cmd_opts.format
63       elif command in ("list","show","delete"):
64          print cmd_opts.type
65       print cmd_args
66    return
67
68 if __name__=="__main__":
69    main()