need a real argparser for the bin/nova-manage commands

Bug #794705 reported by Trey Morris
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Fix Released
Wishlist
Kevin L. Mitchell

Bug Description

take "bin/nova-manager network create" as an example. With multi-nic it has the following parameters
label, fixed_range, num_networks, network_size, vlan_start, vpn_start, fixed_range_v6, gateway_v6, flat_network_bridge, bridge_interface
There will be times you want to create v4 networks specifying flat_network_bridge or bridge_interface, there is not way to skip over the args in between, and no way to use keyword args on the command line so you end up having to do something like
nova-manage network create public 10.0.0.0/8 1 15 0 0 0 0 xenbr1 eth1
where you fill the gaps with zeros.
nova-manage network create public 10.0.0.0/8 1 15 --flat-network_bridge xenbr1 --bridge_interface eth1
would be much more readable

Revision history for this message
Brian Waldon (bcwaldon) wrote :

I would love to see this same idea applied to all of our command line utilities

Thierry Carrez (ttx)
Changed in nova:
importance: Undecided → Wishlist
status: New → Confirmed
Revision history for this message
Kevin L. Mitchell (klmitch) wrote :

You know, it should be easy if you're willing to drop the '--': simply take any command-line arguments containing '=' and turn them into keyword arguments, then pass them in. So for instance:

  nova-manage network create public 10.0.0.0/8 1 15 flat_network_bridge=xenbr1 bridge_interface=eth1

Then you'd have something like:

def parse_args(argv):
    args = {}

Revision history for this message
Kevin L. Mitchell (klmitch) wrote :

(I hate launchpad. To continue:)

    args = ()
    kwargs = {}
    for arg in argv:
        if '=' in arg:
            k, v = arg.split('=', 1)
            kwargs[k] = v
        else:
            args.append(arg)
    return args, kwargs

Then, in main():

    args, kwargs = parse_args(argv)
    try:
        fn(*args, **kwargs)
        sys.exit(0)
    [...]

There are more subtleties we could try to take account of, too, like either prohibiting non-'=' arguments after encountering '=' arguments, or making such arguments be assigned to the parameters after the key.

Revision history for this message
Jay Pipes (jaypipes) wrote :

Incidentally, glance's CLI tool (bin/glance) uses exactly the same approach that Kevin takes above...

Changed in nova:
assignee: nobody → Kevin L. Mitchell (klmitch)
Thierry Carrez (ttx)
Changed in nova:
status: Confirmed → In Progress
Changed in nova:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in nova:
milestone: none → diablo-3
Thierry Carrez (ttx)
Changed in nova:
milestone: diablo-3 → 2011.3
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.