Allow to list resource-types

Change-Id: I7dfdbab08d2d7ad79efedf4d83d471835ced9a6e
This commit is contained in:
Mehdi Abaakouk 2016-04-12 15:32:00 +02:00
parent 0b1c1829de
commit 6e9e005859
6 changed files with 86 additions and 0 deletions

View File

@ -31,6 +31,7 @@ from gnocchiclient.v1 import archive_policy_rule_cli as ap_rule_cli
from gnocchiclient.v1 import capabilities_cli
from gnocchiclient.v1 import metric_cli
from gnocchiclient.v1 import resource_cli
from gnocchiclient.v1 import resource_type_cli
from gnocchiclient.v1 import status_cli
from gnocchiclient.version import __version__
@ -46,6 +47,7 @@ class GnocchiCommandManager(commandmanager.CommandManager):
"resource update": resource_cli.CliResourceUpdate,
"resource delete": resource_cli.CliResourceDelete,
"resource list-types": resource_cli.CliResourceTypeList,
"resource-type list": resource_type_cli.CliResourceTypeList,
"archive-policy list": archive_policy_cli.CliArchivePolicyList,
"archive-policy show": archive_policy_cli.CliArchivePolicyShow,
"archive-policy create": archive_policy_cli.CliArchivePolicyCreate,

View File

@ -0,0 +1,25 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from gnocchiclient.tests.functional import base
class ResourceTypeClientTest(base.ClientTestBase):
def test_help(self):
self.gnocchi("help", params="resource list")
def test_resource_type_scenario(self):
# LIST
result = self.gnocchi('resource-type', params="list")
r = self.parser.listing(result)
self.assertEqual([{'attributes': '', 'name': 'generic'}], r)

View File

@ -128,6 +128,13 @@ def format_dict_list(objs, field):
for elem in objs[field])
def format_dict_dict(value):
return "\n".join(
"- %s: " % name + " , ".join("%s: %s" % (k, v)
for k, v in elem.items())
for name, elem in value.items())
def format_move_dict_to_root(obj, field):
for attr in obj[field]:
obj["%s/%s" % (field, attr)] = obj[field][attr]

View File

@ -19,6 +19,7 @@ from gnocchiclient.v1 import archive_policy_rule
from gnocchiclient.v1 import capabilities
from gnocchiclient.v1 import metric
from gnocchiclient.v1 import resource
from gnocchiclient.v1 import resource_type
from gnocchiclient.v1 import status
@ -34,6 +35,7 @@ class Client(object):
self.api = client.SessionClient(session, service_type=service_type,
**kwargs)
self.resource = resource.ResourceManager(self)
self.resource_type = resource_type.ResourceTypeManager(self)
self.archive_policy = archive_policy.ArchivePolicyManager(self)
self.archive_policy_rule = (
archive_policy_rule.ArchivePolicyRuleManager(self))

View File

@ -0,0 +1,22 @@
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from gnocchiclient.v1 import base
class ResourceTypeManager(base.Manager):
url = "v1/resource_type/"
def list(self):
"""List resource types."""
return self._get(self.url).json()

View File

@ -0,0 +1,28 @@
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from cliff import lister
from gnocchiclient import utils
class CliResourceTypeList(lister.Lister):
"""List resource types"""
COLS = ('name', 'attributes')
def take_action(self, parsed_args):
resource_types = self.app.client.resource_type.list()
for resource_type in resource_types:
resource_type['attributes'] = utils.format_dict_dict(
resource_type['attributes'])
return utils.list2cols(self.COLS, resource_types)