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
1=== modified file 'meph2/commands/mimport.py'
2--- meph2/commands/mimport.py 2017-02-11 01:29:31 +0000
3+++ meph2/commands/mimport.py 2017-02-13 21:27:33 +0000
4@@ -36,7 +36,7 @@
5 product_id = cfgdata['product_id'].format(
6 version=release_info['version'], arch=arch)
7 url = cfgdata['sha256_meta_data_path'].format(version=path_version)
8- images = get_sha256_meta_images(url)
9+ images = get_sha256_meta_images(url, args.max)
10 base_url = os.path.dirname(url)
11
12 if product_tree['products'].get(product_id) is None:
13@@ -173,7 +173,7 @@
14 }
15
16
17-def get_sha256_meta_images(url):
18+def get_sha256_meta_images(url, max_items=0):
19 """ Given a URL to a SHA256SUM file return a dictionary of filenames and
20 SHA256 checksums keyed off the file version found as a date string in
21 the filename. This is used in cases where simplestream data isn't
22@@ -214,7 +214,13 @@
23 'img_name': img_name,
24 'sha256': sha256,
25 }
26- return ret
27+ if max_items == 0:
28+ return ret
29+ else:
30+ return {
31+ key: ret[key]
32+ for key in sorted(ret.keys(), reverse=True)[:max_items]
33+ }
34
35
36 def import_qcow2(url, expected_sha256, out, curtin_files=None, packages=None):
37@@ -297,6 +303,11 @@
38 for (args, kwargs) in COMMON_ARGS:
39 parser.add_argument(*args, **kwargs)
40
41+ parser.add_argument('--max', type=int, default=1,
42+ help=(
43+ 'Import at most MAX CentOS images in the target, '
44+ '0 for no limit, defaults to 1.'))
45+
46 for (args, kwargs) in subc['opts']:
47 if isinstance(args, str):
48 args = [args]

Subscribers

People subscribed via source and target branches