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"])
97 #Download the source packages ###private options
99 installed_pkgs = creator.get_installed_packages()
100 msger.info('Generating the image with source rpms included ...')
101 if not misc.SrcpkgsDownload(installed_pkgs, creatoropts["repomd"],
102 creator._instroot, creatoropts["cachedir"]):
103 msger.warning("Source packages can't be downloaded")
105 creator.configure(creatoropts["repomd"])
106 creator.copy_kernel()
107 creator.copy_attachment()
109 creator.package(creatoropts["destdir"])
110 creator.create_manifest()
111 if creatoropts['release'] is not None:
112 creator.release_output(ksconf, creatoropts['destdir'],
113 creatoropts['release'])
114 creator.print_outimage_info()
115 except errors.CreatorError:
120 #Run script of --run_script after image created
121 if creatoropts['run_script']:
122 cmd = creatoropts['run_script']
126 msger.warning(str(err))
129 msger.info("Finished.")
133 def do_chroot(self, target, cmd=[]):#chroot.py parse opts&args
136 cmdline = ' '.join(cmd)
138 cmdline = "/bin/bash"
139 envcmd = fs_related.find_binary_inchroot("env", target)
141 cmdline = "%s HOME=/root %s" % (envcmd, cmdline)
142 chroot.chroot(target, None, cmdline)
144 chroot.cleanup_after_chroot("dir", None, None, None)