Merge "Always make resource_id positional"

This commit is contained in:
Jenkins 2015-10-09 11:09:45 +00:00 committed by Gerrit Code Review
commit 17ebc4ba74
3 changed files with 10 additions and 14 deletions

View File

@ -151,7 +151,7 @@ class MetricClientTest(base.ClientTestBase):
# PREPARE REQUIREMENT
self.gnocchi("archive-policy", params="create metric-test2 "
"--back-window 0 -d granularity:1s,points:86400")
self.gnocchi("resource", params="create -a id:metric-res")
self.gnocchi("resource", params="create metric-res")
# CREATE
result = self.gnocchi(

View File

@ -23,7 +23,7 @@ class ResourceClientTest(base.ClientTestBase):
def test_resource_scenario(self):
# CREATE
result = self.gnocchi(
u'resource', params=u"create --type generic -a id:%s" %
u'resource', params=u"create %s --type generic" %
self.RESOURCE_ID)
resource = self.details_multiple(result)
resource = self.details_multiple(result)[0]
@ -84,8 +84,7 @@ class ResourceClientTest(base.ClientTestBase):
# CREATE 2
result = self.gnocchi(
'resource', params=("create -t generic "
"-a id:%s "
'resource', params=("create %s -t generic "
"-a project_id:%s"
) % (self.RESOURCE_ID2, self.PROJECT_ID))
resource2 = self.details_multiple(result)[0]

View File

@ -123,6 +123,8 @@ class CliResourceCreate(show.ShowOne):
parser = super(CliResourceCreate, self).get_parser(prog_name)
parser.add_argument("--type", "-t", dest="resource_type",
default="generic", help="Type of resource")
parser.add_argument("resource_id",
help="ID of the resource")
parser.add_argument("-a", "--attribute", action='append',
help=("name and value of a attribute "
"separated with a ':'"))
@ -132,15 +134,16 @@ class CliResourceCreate(show.ShowOne):
"To remove a metric use 'name:-'."))
return parser
def _resource_from_args(self, parsed_args):
def _resource_from_args(self, parsed_args, update=False):
resource = {}
if not update:
resource['id'] = parsed_args.resource_id
if parsed_args.attribute:
for attr in parsed_args.attribute:
attr, __, value = attr.partition(":")
resource[attr] = value
if parsed_args.metric:
rid = getattr(parsed_args, 'resource_id', None)
if rid:
if update:
r = self.app.client.resource.get(parsed_args.resource_type,
parsed_args.resource_id)
default = r['metrics']
@ -168,14 +171,8 @@ class CliResourceCreate(show.ShowOne):
class CliResourceUpdate(CliResourceCreate):
def get_parser(self, prog_name):
parser = super(CliResourceUpdate, self).get_parser(prog_name)
parser.add_argument("resource_id",
help="ID of the resource")
return parser
def take_action(self, parsed_args):
resource = self._resource_from_args(parsed_args)
resource = self._resource_from_args(parsed_args, update=True)
res = self.app.client.resource.update(
resource_type=parsed_args.resource_type,
resource_id=parsed_args.resource_id,