Merge "Add common arguments"

This commit is contained in:
Jenkins
2015-11-25 12:24:05 +00:00
committed by Gerrit Code Review

View File

@@ -112,24 +112,34 @@ def do_hashmap_field_delete(cc, args={}):
raise exc.CommandError('Field not found: %s' % args.counter_name) raise exc.CommandError('Field not found: %s' % args.counter_name)
def common_hashmap_mapping_arguments(create=False):
def _wrapper(func):
@utils.arg('-c', '--cost', @utils.arg('-c', '--cost',
help='Mapping cost', help='Mapping cost',
required=True) required=create)
@utils.arg('-v', '--value', @utils.arg('-v', '--value',
help='Mapping value', help='Mapping value',
required=False) required=False)
@utils.arg('-t', '--type', @utils.arg('-t', '--type',
help='Mapping type (flat, rate)', help='Mapping type (flat, rate)',
required=False) required=False)
@utils.arg('-g', '--group-id',
help='Group id',
required=False)
@functools.wraps(func)
def _wrapped(*args, **kwargs):
return func(*args, **kwargs)
return _wrapped
return _wrapper
@utils.arg('-s', '--service-id', @utils.arg('-s', '--service-id',
help='Service id', help='Service id',
required=False) required=False)
@utils.arg('-f', '--field-id', @utils.arg('-f', '--field-id',
help='Field id', help='Field id',
required=False) required=False)
@utils.arg('-g', '--group-id', @common_hashmap_mapping_arguments(create=True)
help='Group id',
required=False)
def do_hashmap_mapping_create(cc, args={}): def do_hashmap_mapping_create(cc, args={}):
"""Create a mapping.""" """Create a mapping."""
arg_to_field_mapping = { arg_to_field_mapping = {
@@ -152,18 +162,7 @@ def do_hashmap_mapping_create(cc, args={}):
@utils.arg('-m', '--mapping-id', @utils.arg('-m', '--mapping-id',
help='Mapping id', help='Mapping id',
required=True) required=True)
@utils.arg('-c', '--cost', @common_hashmap_mapping_arguments()
help='Mapping cost',
required=False)
@utils.arg('-v', '--value',
help='Mapping value',
required=False)
@utils.arg('-t', '--type',
help='Mapping type (flat, rate)',
required=False)
@utils.arg('-g', '--group-id',
help='Group id',
required=False)
def do_hashmap_mapping_update(cc, args={}): def do_hashmap_mapping_update(cc, args={}):
"""Update a mapping.""" """Update a mapping."""
arg_to_field_mapping = { arg_to_field_mapping = {
@@ -272,24 +271,34 @@ def do_hashmap_group_delete(cc, args={}):
raise exc.CommandError('Group not found: %s' % args.group_id) raise exc.CommandError('Group not found: %s' % args.group_id)
def common_hashmap_threshold_arguments(create=False):
def _wrapper(func):
@utils.arg('-l', '--level', @utils.arg('-l', '--level',
help='Threshold level', help='Threshold level',
required=True) required=create)
@utils.arg('-c', '--cost', @utils.arg('-c', '--cost',
help='Threshold cost', help='Threshold cost',
required=True) required=create)
@utils.arg('-m', '--map-type', @utils.arg('-m', '--map-type',
help='Threshold type (flat, rate)', help='Threshold type (flat, rate)',
required=False) required=False)
@utils.arg('-g', '--group-id',
help='Group id',
required=False)
@functools.wraps(func)
def _wrapped(*args, **kwargs):
return func(*args, **kwargs)
return _wrapped
return _wrapper
@utils.arg('-s', '--service-id', @utils.arg('-s', '--service-id',
help='Service id', help='Service id',
required=False) required=False)
@utils.arg('-f', '--field-id', @utils.arg('-f', '--field-id',
help='Field id', help='Field id',
required=False) required=False)
@utils.arg('-g', '--group-id', @common_hashmap_threshold_arguments(create=True)
help='Group id',
required=False)
def do_hashmap_threshold_create(cc, args={}): def do_hashmap_threshold_create(cc, args={}):
"""Create a mapping.""" """Create a mapping."""
arg_to_field_mapping = { arg_to_field_mapping = {
@@ -312,18 +321,7 @@ def do_hashmap_threshold_create(cc, args={}):
@utils.arg('-t', '--threshold-id', @utils.arg('-t', '--threshold-id',
help='Threshold id', help='Threshold id',
required=True) required=True)
@utils.arg('-l', '--level', @common_hashmap_threshold_arguments()
help='Threshold level',
required=False)
@utils.arg('-c', '--cost',
help='Threshold cost',
required=False)
@utils.arg('-m', '--map-type',
help='Threshold type (flat, rate)',
required=False)
@utils.arg('-g', '--group-id',
help='Group id',
required=False)
def do_hashmap_threshold_update(cc, args={}): def do_hashmap_threshold_update(cc, args={}):
"""Update a threshold.""" """Update a threshold."""
arg_to_field_mapping = { arg_to_field_mapping = {