Fix support for Unicode volume names
It is possible to create a Unicode volume from the command line, but it cannot be manipulated by name for operations such as delete. This is because the find_resource function tries to match the Unicode string to a regular byte string, and a UnicodeWarning is issued, failing the match. Fix by decoding the Unicode name when trying to match. Fixes bug 1065275. Change-Id: I8e19a78bbc1ccb503ccd39dc3b904fc4f6f77858
This commit is contained in:
parent
5a3a18d0cb
commit
01dad32c07
@ -1,3 +1,4 @@
|
||||
import locale
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
@ -179,12 +180,19 @@ def find_resource(manager, name_or_id):
|
||||
return manager.find(name=name_or_id)
|
||||
except exceptions.NotFound:
|
||||
try:
|
||||
# Volumes does not have name, but display_name
|
||||
return manager.find(display_name=name_or_id)
|
||||
except exceptions.NotFound:
|
||||
msg = "No %s with a name or ID of '%s' exists." % \
|
||||
(manager.resource_class.__name__.lower(), name_or_id)
|
||||
raise exceptions.CommandError(msg)
|
||||
# For command-line arguments that are in Unicode
|
||||
encoding = (locale.getpreferredencoding() or
|
||||
sys.stdin.encoding or
|
||||
'UTF-8')
|
||||
return manager.find(display_name=(name_or_id.decode(encoding)))
|
||||
except (UnicodeDecodeError, exceptions.NotFound):
|
||||
try:
|
||||
# Volumes does not have name, but display_name
|
||||
return manager.find(display_name=name_or_id)
|
||||
except exceptions.NotFound:
|
||||
msg = "No %s with a name or ID of '%s' exists." % \
|
||||
(manager.resource_class.__name__.lower(), name_or_id)
|
||||
raise exceptions.CommandError(msg)
|
||||
except exceptions.NoUniqueMatch:
|
||||
msg = ("Multiple %s matches found for '%s', use an ID to be more"
|
||||
" specific." % (manager.resource_class.__name__.lower(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user