Rewrite link parsing for finding v2 schemas
What we called 'links' are no longer returned in a container of objects, they are top-level entity attribtues. This fixes the parsing of the entities to look in the correct place when trying to locate a specific schema. Add a helper for printing to stderr and exiting with a non-zero exit code. Map 'name' to 'Attribute' when explaining a schema. Related to bp glance-client-v2 Change-Id: Ib98e912a7af0bb570b4fd738733edd9b837d1a05
This commit is contained in:
parent
53acf1a0ca
commit
f0445a1b44
@ -14,6 +14,7 @@
|
||||
# under the License.
|
||||
|
||||
import os
|
||||
import sys
|
||||
import uuid
|
||||
|
||||
import prettytable
|
||||
@ -47,7 +48,7 @@ def print_list(objs, fields, formatters={}):
|
||||
row.append(formatters[field](o))
|
||||
else:
|
||||
field_name = field.lower().replace(' ', '_')
|
||||
data = getattr(o, field_name, '')
|
||||
data = getattr(o, field_name, None) or ''
|
||||
row.append(data)
|
||||
pt.add_row(row)
|
||||
|
||||
@ -123,3 +124,9 @@ def import_versioned_module(version, submodule=None):
|
||||
if submodule:
|
||||
module = '.'.join((module, submodule))
|
||||
return importutils.import_module(module)
|
||||
|
||||
|
||||
def exit(msg=''):
|
||||
if msg:
|
||||
print >> sys.stderr, msg
|
||||
sys.exit(1)
|
||||
|
@ -52,7 +52,7 @@ class Controller(object):
|
||||
|
||||
def _find_schema_uri(self, schema_name):
|
||||
_, schema_index = self.http_client.json_request('GET', '/v2/schemas')
|
||||
for link in schema_index['links']:
|
||||
if link['rel'] == schema_name:
|
||||
return link['href']
|
||||
raise exc.SchemaNotFound(schema_name)
|
||||
try:
|
||||
return schema_index[schema_name]
|
||||
except KeyError:
|
||||
raise exc.SchemaNotFound(schema_name)
|
||||
|
@ -14,6 +14,7 @@
|
||||
# under the License.
|
||||
|
||||
from glanceclient.common import utils
|
||||
from glanceclient import exc
|
||||
|
||||
|
||||
def do_image_list(gc, args):
|
||||
@ -23,9 +24,14 @@ def do_image_list(gc, args):
|
||||
utils.print_list(images, columns)
|
||||
|
||||
|
||||
@utils.arg('name', metavar='<NAME>', help='Name of model to describe.')
|
||||
@utils.arg('model', metavar='<MODEL>', help='Name of model to describe.')
|
||||
def do_explain(gc, args):
|
||||
"""Describe a specific model."""
|
||||
schema = gc.schemas.get(args.name)
|
||||
columns = ['Name', 'Description']
|
||||
utils.print_list(schema.properties, columns)
|
||||
try:
|
||||
schema = gc.schemas.get(args.model)
|
||||
except exc.SchemaNotFound:
|
||||
utils.exit('Unable to find requested model \'%s\'' % args.model)
|
||||
else:
|
||||
formatters = {'Attribute': lambda m: m.name}
|
||||
columns = ['Attribute', 'Description']
|
||||
utils.print_list(schema.properties, columns, formatters)
|
||||
|
@ -23,10 +23,10 @@ fixtures = {
|
||||
'/v2/schemas': {
|
||||
'GET': (
|
||||
{},
|
||||
{'links': [
|
||||
{'rel': 'image', 'href': '/v2/schemas/image'},
|
||||
{'rel': 'access', 'href': '/v2/schemas/image/access'},
|
||||
]},
|
||||
{
|
||||
'image': '/v2/schemas/image',
|
||||
'access': '/v2/schemas/image/access',
|
||||
},
|
||||
),
|
||||
},
|
||||
'/v2/schemas/image': {
|
||||
|
Loading…
x
Reference in New Issue
Block a user