Update read_config_drive to use OS_VERSIONS tuple for readers

Updated read_config_drive: removed the unused version kwarg, used the
OS_VERSIONS tuple from the openstack helper to avoid hardcoding
versions.

Added a comment to the tuple in helpers/openstack.py asking for it to
be kept in chronological order.
This commit is contained in:
Jay Faulkner 2014-09-08 21:32:21 -07:00
parent db76f6fc88
commit bb9375f4c5
2 changed files with 11 additions and 8 deletions

View File

@ -169,15 +169,17 @@ def get_ds_mode(cfgdrv_ver, ds_cfg=None, user=None):
return "net" return "net"
def read_config_drive(source_dir, version=openstack.OS_HAVANA): def read_config_drive(source_dir):
reader = openstack.ConfigDriveReader(source_dir)
finders = [
(reader.read_v2, [], {'version': version}),
(reader.read_v2, [], {'version': openstack.OS_GRIZZLY}),
(reader.read_v2, [], {'version': openstack.OS_FOLSOM}),
(reader.read_v1, [], {}),
]
excps = [] excps = []
finders = []
reader = openstack.ConfigDriveReader(source_dir)
# openstack.OS_VERSIONS is stored in chronological order, so to check the
# newest first, use reversed()
for version in reversed(openstack.OS_VERSIONS):
finders.append((reader.read_v2, [], {'version': version}))
finders.append((reader.read_v1, [], {}))
for (functor, args, kwargs) in finders: for (functor, args, kwargs) in finders:
try: try:
return functor(*args, **kwargs) return functor(*args, **kwargs)

View File

@ -48,6 +48,7 @@ OS_LATEST = 'latest'
OS_FOLSOM = '2012-08-10' OS_FOLSOM = '2012-08-10'
OS_GRIZZLY = '2013-04-04' OS_GRIZZLY = '2013-04-04'
OS_HAVANA = '2013-10-17' OS_HAVANA = '2013-10-17'
# keep this in chronological order by time: add new entries to the end
OS_VERSIONS = ( OS_VERSIONS = (
OS_FOLSOM, OS_FOLSOM,
OS_GRIZZLY, OS_GRIZZLY,