From 369ae3f9f06c90e8d57b71befa6bc22a843c2f7d Mon Sep 17 00:00:00 2001 From: zhiyuan_cai Date: Sun, 4 Jan 2015 11:26:18 +0800 Subject: Check if service.name available before access Currently v3 endpoint commands access service.name directly, while name is not a required attribute of service. So if we associate an endpoint to a service without name, we will get an AttributeError executing v3 endpoint commands later. This patch addresses this issue by checking if service.name is available before accessing it. Change-Id: I3dd686ef02a2e21e2049a49cb55634385c2ecfaf Closes-Bug: #1406737 --- openstackclient/identity/v3/endpoint.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'openstackclient/identity') diff --git a/openstackclient/identity/v3/endpoint.py b/openstackclient/identity/v3/endpoint.py index 0c077c5a..eba7ca14 100644 --- a/openstackclient/identity/v3/endpoint.py +++ b/openstackclient/identity/v3/endpoint.py @@ -27,6 +27,13 @@ from openstackclient.common import utils from openstackclient.identity import common +def get_service_name(service): + if hasattr(service, 'name'): + return service.name + else: + return '' + + class CreateEndpoint(show.ShowOne): """Create endpoint command""" @@ -83,7 +90,7 @@ class CreateEndpoint(show.ShowOne): info = {} endpoint._info.pop('links') info.update(endpoint._info) - info['service_name'] = service.name + info['service_name'] = get_service_name(service) info['service_type'] = service.type return zip(*sorted(six.iteritems(info))) @@ -150,7 +157,7 @@ class ListEndpoint(lister.Lister): for ep in data: service = common.find_service(identity_client, ep.service_id) - ep.service_name = service.name + ep.service_name = get_service_name(service) ep.service_type = service.type return (columns, (utils.get_item_properties( @@ -261,6 +268,6 @@ class ShowEndpoint(show.ShowOne): info = {} endpoint._info.pop('links') info.update(endpoint._info) - info['service_name'] = service.name + info['service_name'] = get_service_name(service) info['service_type'] = service.type return zip(*sorted(six.iteritems(info))) -- cgit v1.2.1