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.
18 from mic import chroot, msger, rt_util
19 from mic.utils import misc, errors, fs_related
20 from mic.imager import fs
21 from mic.conf import configmgr
22 from mic.plugin import pluginmgr
24 from mic.pluginbase import ImagerPlugin
25 class FsPlugin(ImagerPlugin):
29 def do_create(self, args):
30 """${cmd_name}: create fs image
33 ${name} ${cmd_name} <ksfile> [OPTS]
39 raise errors.Usage("Invalid arguments.")
41 creatoropts = configmgr.create
44 if creatoropts['runtime'] == 'bootstrap':
45 configmgr._ksconf = ksconf
46 rt_util.bootstrap_mic()
49 if len(creatoropts['record_pkgs']) > 0:
50 recording_pkgs = creatoropts['record_pkgs']
52 if creatoropts['release'] is not None:
53 if 'name' not in recording_pkgs:
54 recording_pkgs.append('name')
55 if 'vcs' not in recording_pkgs:
56 recording_pkgs.append('vcs')
58 configmgr._ksconf = ksconf
60 # try to find the pkgmgr
62 backends = pluginmgr.get_plugins('backend')
63 if 'auto' == creatoropts['pkgmgr']:
64 for key in configmgr.prefer_backends:
66 pkgmgr = backends[key]
69 for key in backends.keys():
70 if key == creatoropts['pkgmgr']:
71 pkgmgr = backends[key]
75 raise errors.CreatorError("Can't find backend: %s, "
76 "available choices: %s" %
77 (creatoropts['pkgmgr'],
78 ','.join(backends.keys())))
80 creator = fs.FsImageCreator(creatoropts, pkgmgr)
81 creator._include_src = args.include_src
83 if len(recording_pkgs) > 0:
84 creator._recording_pkgs = recording_pkgs
86 self.check_image_exists(creator.destdir,
89 creatoropts['release'])
92 creator.check_depend_tools()
93 creator.mount(None, creatoropts["cachedir"])
95 #Download the source packages ###private options
97 installed_pkgs = creator.get_installed_packages()
98 msger.info('--------------------------------------------------')
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()
107 creator.package(creatoropts["destdir"])
108 creator.create_manifest()
109 if creatoropts['release'] is not None:
110 creator.release_output(ksconf, creatoropts['destdir'],
111 creatoropts['release'])
112 creator.print_outimage_info()
113 except errors.CreatorError:
118 msger.info("Finished.")
122 def do_chroot(self, target, cmd=[]):#chroot.py parse opts&args
125 cmdline = ' '.join(cmd)
127 cmdline = "/bin/bash"
128 envcmd = fs_related.find_binary_inchroot("env", target)
130 cmdline = "%s HOME=/root %s" % (envcmd, cmdline)
131 chroot.chroot(target, None, cmdline)
133 chroot.cleanup_after_chroot("dir", None, None, None)