Merge release-0.28.17 from 'tools/mic'
[platform/upstream/mic.git] / plugins / imager / qcow_plugin.py
1 #
2 # Copyright (c) 2014 Intel, Inc.
3 #
4 # This program is free software; you can redistribute it and/or modify it
5 # under the terms of the GNU General Public License as published by the Free
6 # Software Foundation; version 2 of the License
7 #
8 # This program is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11 # for more details.
12 #
13 # You should have received a copy of the GNU General Public License along
14 # with this program; if not, write to the Free Software Foundation, Inc., 59
15 # Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17 import os
18 import subprocess
19 import shutil
20
21 from mic import msger, rt_util
22 from mic.plugin import pluginmgr
23 from mic.pluginbase import ImagerPlugin
24 from mic.imager.qcow import QcowImageCreator
25 from mic.utils import errors, runner
26
27 class QcowPlugin(ImagerPlugin):
28     name = 'qcow'
29
30     @classmethod
31     def do_create(cls, args):
32         """${cmd_name}: create qcow image
33         """
34
35         creatoropts, pkgmgr, recording_pkgs = rt_util.prepare_create(args)
36
37         creator = QcowImageCreator(creatoropts,
38                                    pkgmgr)
39
40         if len(recording_pkgs) > 0:
41             creator._recording_pkgs = recording_pkgs
42
43         image_names = [creator.name + ".img"]
44         image_names.extend(creator.get_image_names())
45         cls.check_image_exists(creator.destdir,
46                                 creator.pack_to,
47                                 image_names,
48                                 creatoropts['release'])
49
50         try:
51             creator.check_depend_tools()
52             creator.mount(None, creatoropts["cachedir"])
53             creator.install()
54             creator.tpkinstall()
55             creator.configure(creatoropts["repomd"])
56             creator.copy_kernel()
57             creator.create_cpio_image()
58             creator.unmount()
59             creator.copy_cpio_image()
60             creator.package(creatoropts["destdir"])
61             creator.create_manifest()
62
63             if creatoropts['release'] is not None:
64                 creator.release_output(args.ksfile,
65                                        creatoropts['destdir'],
66                                        creatoropts['release'])
67             creator.print_outimage_info()
68
69         except errors.CreatorError:
70             raise
71         finally:
72             creator.cleanup()
73
74         #Run script of --run_script after image created
75         if creatoropts['run_script']:
76             cmd = creatoropts['run_script']
77             try:
78                 runner.show(cmd)
79             except OSError as err:
80                 msger.warning(str(err))
81
82
83         msger.info("Finished.")
84         return 0
85
86     @classmethod
87     def do_chroot(cls, target, cmd=[]):
88         pass
89
90     @classmethod
91     def do_unpack(cls, srcimg):
92         pass