Fix new Swift UI to work with Ceph backend

First, tolerate missing '/info' API endpoint, which Ceph doesn't
support yet. Second, `content_type` attribute on objects may be not
set, don't rely heavily on it.

Change-Id: I101338aa9c96a6551bfbf2dd9c460a4801b4e7b6
Closes-Bug: #1564834
This commit is contained in:
Timur Sufiev 2016-04-04 16:05:35 +03:00
parent e1f07e2794
commit 80e52c1ae5
2 changed files with 10 additions and 4 deletions

View File

@ -25,6 +25,7 @@ from horizon import exceptions
from openstack_dashboard import api
from openstack_dashboard.api.rest import urls
from openstack_dashboard.api.rest import utils as rest_utils
from openstack_dashboard.api import swift
@urls.register
@ -128,9 +129,9 @@ class Objects(generic.View):
'path': o.name,
'name': o.name.split('/')[-1],
'bytes': o.bytes,
'is_subdir': o.content_type == 'application/pseudo-folder',
'is_object': o.content_type != 'application/pseudo-folder',
'content_type': o.content_type
'is_subdir': isinstance(o, swift.PseudoFolder),
'is_object': not isinstance(o, swift.PseudoFolder),
'content_type': getattr(o, 'content_type', None)
} for o in objects[0] if o.name != path]
return {'items': contents}

View File

@ -359,4 +359,9 @@ def swift_get_object(request, container_name, object_name, with_data=True,
def swift_get_capabilities(request):
return swift_api(request).get_capabilities()
try:
return swift_api(request).get_capabilities()
# NOTE(tsufiev): Ceph backend currently does not support '/info', even
# some Swift installations do not support it (see `expose_info` docs).
except swiftclient.exceptions.ClientException:
return {}