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:
@@ -1,3 +1,4 @@
|
|||||||
|
import locale
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
@@ -179,12 +180,19 @@ def find_resource(manager, name_or_id):
|
|||||||
return manager.find(name=name_or_id)
|
return manager.find(name=name_or_id)
|
||||||
except exceptions.NotFound:
|
except exceptions.NotFound:
|
||||||
try:
|
try:
|
||||||
# Volumes does not have name, but display_name
|
# For command-line arguments that are in Unicode
|
||||||
return manager.find(display_name=name_or_id)
|
encoding = (locale.getpreferredencoding() or
|
||||||
except exceptions.NotFound:
|
sys.stdin.encoding or
|
||||||
msg = "No %s with a name or ID of '%s' exists." % \
|
'UTF-8')
|
||||||
(manager.resource_class.__name__.lower(), name_or_id)
|
return manager.find(display_name=(name_or_id.decode(encoding)))
|
||||||
raise exceptions.CommandError(msg)
|
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:
|
except exceptions.NoUniqueMatch:
|
||||||
msg = ("Multiple %s matches found for '%s', use an ID to be more"
|
msg = ("Multiple %s matches found for '%s', use an ID to be more"
|
||||||
" specific." % (manager.resource_class.__name__.lower(),
|
" specific." % (manager.resource_class.__name__.lower(),
|
||||||
|
Reference in New Issue
Block a user