3 # Copyright (c) 2011 Intel, Inc.
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the Free
7 # Software Foundation; version 2 of the License
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 # You should have received a copy of the GNU General Public License along
15 # with this program; if not, write to the Free Software Foundation, Inc., 59
16 # Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 from mic import chroot, msger, rt_util
20 from mic.utils import misc, errors, fs_related, runner
21 from mic.imager import fs
22 from mic.conf import configmgr
23 from mic.plugin import pluginmgr
25 from mic.pluginbase import ImagerPlugin
26 class FsPlugin(ImagerPlugin):
30 def do_create(self, args):
31 """${cmd_name}: create fs image
34 ${name} ${cmd_name} <ksfile> [OPTS]
40 raise errors.Usage("Invalid arguments.")
42 creatoropts = configmgr.create
45 if creatoropts['runtime'] == 'bootstrap':
46 configmgr._ksconf = ksconf
47 rt_util.bootstrap_mic()
50 if len(creatoropts['record_pkgs']) > 0:
51 recording_pkgs = creatoropts['record_pkgs']
53 if creatoropts['release'] is not None:
54 if 'name' not in recording_pkgs:
55 recording_pkgs.append('name')
56 if 'vcs' not in recording_pkgs:
57 recording_pkgs.append('vcs')
59 configmgr._ksconf = ksconf
61 # try to find the pkgmgr
63 backends = pluginmgr.get_plugins('backend')
64 if 'auto' == creatoropts['pkgmgr']:
65 for key in configmgr.prefer_backends:
67 pkgmgr = backends[key]
70 for key in backends.keys():
71 if key == creatoropts['pkgmgr']:
72 pkgmgr = backends[key]
76 raise errors.CreatorError("Can't find backend: %s, "
77 "available choices: %s" %
78 (creatoropts['pkgmgr'],
79 ','.join(backends.keys())))
81 creator = fs.FsImageCreator(creatoropts, pkgmgr)
82 creator._include_src = args.include_src
84 if len(recording_pkgs) > 0:
85 creator._recording_pkgs = recording_pkgs
87 self.check_image_exists(creator.destdir,
90 creatoropts['release'])
93 creator.check_depend_tools()
94 creator.mount(None, creatoropts["cachedir"])
96 #Download the source packages ###private options
98 installed_pkgs = creator.get_installed_packages()
99 msger.info('Generating the image with source rpms included ...')
100 if not misc.SrcpkgsDownload(installed_pkgs, creatoropts["repomd"],
101 creator._instroot, creatoropts["cachedir"]):
102 msger.warning("Source packages can't be downloaded")
104 creator.configure(creatoropts["repomd"])
105 creator.copy_kernel()
106 creator.copy_attachment()
108 creator.package(creatoropts["destdir"])
109 creator.create_manifest()
110 if creatoropts['release'] is not None:
111 creator.release_output(ksconf, creatoropts['destdir'],
112 creatoropts['release'])
113 creator.print_outimage_info()
114 except errors.CreatorError:
119 #Run script of --run_script after image created
120 if creatoropts['run_script']:
121 cmd = creatoropts['run_script']
125 msger.warning(str(err))
128 msger.info("Finished.")
132 def do_chroot(self, target, cmd=[]):#chroot.py parse opts&args
135 cmdline = ' '.join(cmd)
137 cmdline = "/bin/bash"
138 envcmd = fs_related.find_binary_inchroot("env", target)
140 cmdline = "%s HOME=/root %s" % (envcmd, cmdline)
141 chroot.chroot(target, None, cmdline)
143 chroot.cleanup_after_chroot("dir", None, None, None)