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

Proposed by Lee Trager
Status: Rejected
Rejected by: Scott Moser
Proposed branch: lp:~ltrager/maas-images/create
Merge into: lp:maas-images
Diff against target: 129 lines (+90/-2)
2 files modified
meph2/commands/flags.py (+19/-0)
meph2/commands/meph2_util.py (+71/-2)
To merge this branch: bzr merge lp:~ltrager/maas-images/create
Reviewer Review Type Date Requested Status
maintainers of maas images Pending
Review via email: mp+321213@code.launchpad.net

Commit message

Add create command which allows creation of streams for arbitrary images.

Description of the change

The create command allows creating streams for arbitrary images. It can be used for ubuntu-core as follows

wget http://cdimage.ubuntu.com/ubuntu-core/16/stable/current/ubuntu-core-16-amd64.img.xz

meph2-util create --fields arch=amd64,kernel_snap=pc-kernel,gadget_snap=pc,gadget_title='PC',model_name=pc-amd64,brand_id=canonical,channel=stable,label=daily,os=ubuntu-core,os_title='Ubuntu Core',release=16,release_title='16',maas_supported=2.2,support_eol=2018-04-26 --image-path-postfix 16/pc ubuntu-core amd64 com.ubuntu.maas.daily:v4:download com.ubuntu.maas.daily:v4:16:amd64:pc:stable root-dd.xz curtin-ubuntu-core-16-amd64.img.xz ubuntu-core

Sample output - http://162.213.35.187/ubuntu-core/

To post a comment you must log in.
lp:~ltrager/maas-images/create updated
360. By Lee Trager

Set the item name to the ftype

361. By Lee Trager

Set the filename to the same as the ftype

Revision history for this message
Scott Moser (smoser) wrote :

I think this is more generically already present in streams in json2streams.
Do you think that could be used?

Revision history for this message
Scott Moser (smoser) wrote :

I'm going to mark this 'rejected'.

Lee, you can feel free to re-submit it to git.

Just trying to clean things up.

Unmerged revisions

361. By Lee Trager

Set the filename to the same as the ftype

360. By Lee Trager

Set the item name to the ftype

359. By Lee Trager

Add create command which creates streams for custom images.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'meph2/commands/flags.py'
--- meph2/commands/flags.py 2016-09-26 15:21:43 +0000
+++ meph2/commands/flags.py 2017-03-29 19:56:36 +0000
@@ -102,6 +102,25 @@
102 COMMON_FLAGS['data_d'], COMMON_FLAGS['no-sign'],102 COMMON_FLAGS['data_d'], COMMON_FLAGS['no-sign'],
103 ],103 ],
104 },104 },
105 'create': {
106 'help': 'Create a new image entry in the stream.',
107 'opts': [
108 COMMON_FLAGS['no-sign'],
109 ('--fields', {
110 'help': (
111 'Comma seperated key value pairs to be added to listing.'),
112 }),
113 ('--image-path-postfix', {
114 'help': 'Optional path to postfix to standard image-path.'}),
115 ('os', {'help': 'The OS name'}),
116 ('arch', {'help': 'The architecture for the image.'}),
117 ('content_id', {'help': 'The content_id of the stream.'}),
118 ('product_name', {'help': 'The product name in the stream.'}),
119 ('ftype', {'help': 'The filetype of the image.'}),
120 ('image', {'help': 'The image to be imported.'}),
121 COMMON_FLAGS['target'],
122 ]
123 },
105}124}
106125
107# vi: ts=4 expandtab syntax=python126# vi: ts=4 expandtab syntax=python
108127
=== modified file 'meph2/commands/meph2_util.py'
--- meph2/commands/meph2_util.py 2017-02-11 01:29:31 +0000
+++ meph2/commands/meph2_util.py 2017-03-29 19:56:36 +0000
@@ -1,9 +1,11 @@
1#!/usr/bin/python31#!/usr/bin/python3
22
3from datetime import datetime
4from functools import partial
3import argparse5import argparse
4import copy6import copy
7import hashlib
5import os8import os
6from functools import partial
7import shutil9import shutil
8import sys10import sys
911
@@ -13,8 +15,9 @@
13from simplestreams import (15from simplestreams import (
14 filters,16 filters,
15 mirrors,17 mirrors,
18 objectstores,
16 util as sutil,19 util as sutil,
17 objectstores)20)
1821
1922
20class BareMirrorWriter(mirrors.ObjectFilterMirror):23class BareMirrorWriter(mirrors.ObjectFilterMirror):
@@ -418,6 +421,72 @@
418 return(mimport.main_import(args))421 return(mimport.main_import(args))
419422
420423
424def main_create(args):
425 product_stream_path = os.path.join(
426 'streams', 'v1', args.content_id + '.json')
427 product_tree = util.empty_iid_products(args.content_id)
428 product_tree['products'] = util.load_products(
429 args.target, [product_stream_path])
430 product_tree['updated'] = util.timestamp()
431 product_tree['datatype'] = 'image-downloads'
432
433 product = product_tree['products'].get(args.product_name, {})
434 if 'versions' not in product:
435 product['os'] = args.os
436 product['arch'] = args.arch
437 product['versions'] = {}
438 if args.fields is not None:
439 for pair in args.fields.split(','):
440 key, value = pair.split('=')
441 product[key] = value
442
443 today = datetime.utcnow().strftime('%Y%m%d')
444 ver_str = today
445 i = 0
446 while ver_str in product['versions']:
447 i += 1
448 ver_str = '%s.%d' % (today, i)
449
450 image_path = os.path.join(args.os, args.arch, ver_str)
451 if args.image_path_postfix is not None:
452 image_path = os.path.join(image_path, args.image_path_postfix)
453 image_path = os.path.join(image_path, args.ftype)
454 full_image_path = os.path.join(args.target, image_path)
455 os.makedirs(os.path.dirname(full_image_path))
456 shutil.copy2(args.image, full_image_path)
457
458 sha256 = hashlib.sha256()
459 size = 0
460 with open(args.image, 'rb') as fp:
461 while True:
462 chunk = fp.read(2**20)
463 if not chunk:
464 break
465 sha256.update(chunk)
466 size += len(chunk)
467
468 product['versions'][ver_str] = {
469 'items': {
470 args.ftype: {
471 'ftype': args.ftype,
472 'path': image_path,
473 'sha256': sha256.hexdigest(),
474 'size': size,
475 },
476 },
477 }
478 product_tree['products'][args.product_name] = product
479
480 full_product_stream_path = os.path.join(args.target, product_stream_path)
481 full_product_stream_dir = os.path.dirname(full_product_stream_path)
482 if not os.path.exists(full_product_stream_dir):
483 os.makedirs(full_product_stream_dir)
484 with open(full_product_stream_path, 'wb') as fp:
485 fp.write(util.dump_data(product_tree))
486
487 util.gen_index_and_sign(args.target, not args.no_sign)
488
489
421def main():490def main():
422 parser = argparse.ArgumentParser()491 parser = argparse.ArgumentParser()
423492

Subscribers

People subscribed via source and target branches