summaryrefslogtreecommitdiffstats
path: root/scripts/lib/mic/plugins/imager/fs_plugin.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib/mic/plugins/imager/fs_plugin.py')
-rw-r--r--scripts/lib/mic/plugins/imager/fs_plugin.py143
1 files changed, 143 insertions, 0 deletions
diff --git a/scripts/lib/mic/plugins/imager/fs_plugin.py b/scripts/lib/mic/plugins/imager/fs_plugin.py
new file mode 100644
index 0000000000..8e758db544
--- /dev/null
+++ b/scripts/lib/mic/plugins/imager/fs_plugin.py
@@ -0,0 +1,143 @@
1#!/usr/bin/python -tt
2#
3# Copyright (c) 2011 Intel, Inc.
4#
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
8#
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
12# for more details.
13#
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.
17
18import os
19import sys
20
21from mic import chroot, msger, rt_util
22from mic.utils import cmdln, misc, errors, fs_related
23from mic.imager import fs
24from mic.conf import configmgr
25from mic.plugin import pluginmgr
26
27from mic.pluginbase import ImagerPlugin
28class FsPlugin(ImagerPlugin):
29 name = 'fs'
30
31 @classmethod
32 @cmdln.option("--include-src",
33 dest="include_src",
34 action="store_true",
35 default=False,
36 help="Generate a image with source rpms included")
37 def do_create(self, subcmd, opts, *args):
38 """${cmd_name}: create fs image
39
40 Usage:
41 ${name} ${cmd_name} <ksfile> [OPTS]
42
43 ${cmd_option_list}
44 """
45
46 if len(args) != 1:
47 raise errors.Usage("Extra arguments given")
48
49 creatoropts = configmgr.create
50 ksconf = args[0]
51
52 if creatoropts['runtime'] == 'bootstrap':
53 configmgr._ksconf = ksconf
54 rt_util.bootstrap_mic()
55
56 recording_pkgs = []
57 if len(creatoropts['record_pkgs']) > 0:
58 recording_pkgs = creatoropts['record_pkgs']
59
60 if creatoropts['release'] is not None:
61 if 'name' not in recording_pkgs:
62 recording_pkgs.append('name')
63 if 'vcs' not in recording_pkgs:
64 recording_pkgs.append('vcs')
65
66 configmgr._ksconf = ksconf
67
68 # Called After setting the configmgr._ksconf as the creatoropts['name'] is reset there.
69 if creatoropts['release'] is not None:
70 creatoropts['outdir'] = "%s/%s/images/%s/" % (creatoropts['outdir'], creatoropts['release'], creatoropts['name'])
71
72 # try to find the pkgmgr
73 pkgmgr = None
74 backends = pluginmgr.get_plugins('backend')
75 if 'auto' == creatoropts['pkgmgr']:
76 for key in configmgr.prefer_backends:
77 if key in backends:
78 pkgmgr = backends[key]
79 break
80 else:
81 for key in backends.keys():
82 if key == creatoropts['pkgmgr']:
83 pkgmgr = backends[key]
84 break
85
86 if not pkgmgr:
87 raise errors.CreatorError("Can't find backend: %s, "
88 "available choices: %s" %
89 (creatoropts['pkgmgr'],
90 ','.join(backends.keys())))
91
92 creator = fs.FsImageCreator(creatoropts, pkgmgr)
93 creator._include_src = opts.include_src
94
95 if len(recording_pkgs) > 0:
96 creator._recording_pkgs = recording_pkgs
97
98 self.check_image_exists(creator.destdir,
99 creator.pack_to,
100 [creator.name],
101 creatoropts['release'])
102
103 try:
104 creator.check_depend_tools()
105 creator.mount(None, creatoropts["cachedir"])
106 creator.install()
107 #Download the source packages ###private options
108 if opts.include_src:
109 installed_pkgs = creator.get_installed_packages()
110 msger.info('--------------------------------------------------')
111 msger.info('Generating the image with source rpms included ...')
112 if not misc.SrcpkgsDownload(installed_pkgs, creatoropts["repomd"], creator._instroot, creatoropts["cachedir"]):
113 msger.warning("Source packages can't be downloaded")
114
115 creator.configure(creatoropts["repomd"])
116 creator.copy_kernel()
117 creator.unmount()
118 creator.package(creatoropts["outdir"])
119 if creatoropts['release'] is not None:
120 creator.release_output(ksconf, creatoropts['outdir'], creatoropts['release'])
121 creator.print_outimage_info()
122 except errors.CreatorError:
123 raise
124 finally:
125 creator.cleanup()
126
127 msger.info("Finished.")
128 return 0
129
130 @classmethod
131 def do_chroot(self, target, cmd=[]):#chroot.py parse opts&args
132 try:
133 if len(cmd) != 0:
134 cmdline = ' '.join(cmd)
135 else:
136 cmdline = "/bin/bash"
137 envcmd = fs_related.find_binary_inchroot("env", target)
138 if envcmd:
139 cmdline = "%s HOME=/root %s" % (envcmd, cmdline)
140 chroot.chroot(target, None, cmdline)
141 finally:
142 chroot.cleanup_after_chroot("dir", None, None, None)
143 return 1