Merge lp:~ltrager/maas-images/limit_imports into lp:maas-images

Proposed by Lee Trager
Status: Merged
Approved by: Scott Moser
Approved revision: 355
Merged at revision: 356
Proposed branch: lp:~ltrager/maas-images/limit_imports
Merge into: lp:maas-images
Diff against target: 48 lines (+14/-3)
1 file modified
meph2/commands/mimport.py (+14/-3)
To merge this branch: bzr merge lp:~ltrager/maas-images/limit_imports
Reviewer Review Type Date Requested Status
maintainers of maas images Pending
Review via email: mp+317152@code.launchpad.net

Commit message

Allow limiting the number of CentOS images imported

Previously all CentOS images found were imported. If the image already existed in the stream it was skipped. This meant if you wanted to test building a CentOS image you had to build all images ever published. This limits the images imported to only the latest.

To post a comment you must log in.
355. By Lee Trager

Limit the number of CentOS images imported

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'meph2/commands/mimport.py'
--- meph2/commands/mimport.py 2017-02-11 01:29:31 +0000
+++ meph2/commands/mimport.py 2017-02-13 21:27:33 +0000
@@ -36,7 +36,7 @@
36 product_id = cfgdata['product_id'].format(36 product_id = cfgdata['product_id'].format(
37 version=release_info['version'], arch=arch)37 version=release_info['version'], arch=arch)
38 url = cfgdata['sha256_meta_data_path'].format(version=path_version)38 url = cfgdata['sha256_meta_data_path'].format(version=path_version)
39 images = get_sha256_meta_images(url)39 images = get_sha256_meta_images(url, args.max)
40 base_url = os.path.dirname(url)40 base_url = os.path.dirname(url)
4141
42 if product_tree['products'].get(product_id) is None:42 if product_tree['products'].get(product_id) is None:
@@ -173,7 +173,7 @@
173 }173 }
174174
175175
176def get_sha256_meta_images(url):176def get_sha256_meta_images(url, max_items=0):
177 """ Given a URL to a SHA256SUM file return a dictionary of filenames and177 """ Given a URL to a SHA256SUM file return a dictionary of filenames and
178 SHA256 checksums keyed off the file version found as a date string in178 SHA256 checksums keyed off the file version found as a date string in
179 the filename. This is used in cases where simplestream data isn't179 the filename. This is used in cases where simplestream data isn't
@@ -214,7 +214,13 @@
214 'img_name': img_name,214 'img_name': img_name,
215 'sha256': sha256,215 'sha256': sha256,
216 }216 }
217 return ret217 if max_items == 0:
218 return ret
219 else:
220 return {
221 key: ret[key]
222 for key in sorted(ret.keys(), reverse=True)[:max_items]
223 }
218224
219225
220def import_qcow2(url, expected_sha256, out, curtin_files=None, packages=None):226def import_qcow2(url, expected_sha256, out, curtin_files=None, packages=None):
@@ -297,6 +303,11 @@
297 for (args, kwargs) in COMMON_ARGS:303 for (args, kwargs) in COMMON_ARGS:
298 parser.add_argument(*args, **kwargs)304 parser.add_argument(*args, **kwargs)
299305
306 parser.add_argument('--max', type=int, default=1,
307 help=(
308 'Import at most MAX CentOS images in the target, '
309 '0 for no limit, defaults to 1.'))
310
300 for (args, kwargs) in subc['opts']:311 for (args, kwargs) in subc['opts']:
301 if isinstance(args, str):312 if isinstance(args, str):
302 args = [args]313 args = [args]

Subscribers

People subscribed via source and target branches