Fix the KeyError for getting the volume types

Change-Id: I6e4499a32702f950710ab951aa90f305d9e3e9e1
This commit is contained in:
Lingxian Kong 2019-01-15 15:33:52 +13:00
parent f39851c2ef
commit 6bb4321087

View File

@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from collections import defaultdict
import re import re
from ceilometerclient import client as ceilometerclient from ceilometerclient import client as ceilometerclient
@ -28,7 +29,7 @@ from distil.common import general
CONF = cfg.CONF CONF = cfg.CONF
KS_SESSION = None KS_SESSION = None
cache = {} cache = defaultdict(list)
ROOT_DEVICE_PATTERN = re.compile('^/dev/(x?v|s|h)da1?$') ROOT_DEVICE_PATTERN = re.compile('^/dev/(x?v|s|h)da1?$')
@ -136,7 +137,7 @@ def get_root_volume(instance_id):
@general.disable_ssl_warnings @general.disable_ssl_warnings
def get_volume_type(volume_type): def get_volume_type(volume_type):
if not cache['volume_types']: if not cache.get("volume_types"):
cinder = get_cinder_client() cinder = get_cinder_client()
for vtype in cinder.volume_types.list(): for vtype in cinder.volume_types.list():
cache['volume_types'].append({'id': vtype.id, 'name': vtype.name}) cache['volume_types'].append({'id': vtype.id, 'name': vtype.name})