summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorSoonKyu Park <sk7.park@samsung.com>2016-09-23 10:35:49 +0900
committerSoonKyu Park <sk7.park@samsung.com>2016-09-23 10:35:49 +0900
commitc46ae15366c67ee9ecabd417f1773f454e724aa7 (patch)
tree12329309b8067983625c63213f658a5ec8e05ba0 /plugins
parent4915f9a5a1da5eaa20c58e798a2ac5de0ef7eeb0 (diff)
parent4161678b3bf9d2eb36fdcb82c820bce02f6ba5bc (diff)
downloadmic-c46ae15366c67ee9ecabd417f1773f454e724aa7.tar.gz
mic-c46ae15366c67ee9ecabd417f1773f454e724aa7.tar.bz2
mic-c46ae15366c67ee9ecabd417f1773f454e724aa7.zip
Change-Id: Ifba625f3902104e6a21e8340f5b292f0190057d7
Diffstat (limited to 'plugins')
-rw-r--r--plugins/backend/yumpkgmgr.py83
-rw-r--r--[-rwxr-xr-x]plugins/backend/zypppkgmgr.py122
-rw-r--r--plugins/imager/fs_plugin.py35
-rw-r--r--plugins/imager/livecd_plugin.py255
-rw-r--r--plugins/imager/liveusb_plugin.py260
-rw-r--r--plugins/imager/loop_plugin.py40
-rw-r--r--plugins/imager/qcow_plugin.py160
-rwxr-xr-x[-rw-r--r--]plugins/imager/raw_plugin.py57
8 files changed, 333 insertions, 679 deletions
diff --git a/plugins/backend/yumpkgmgr.py b/plugins/backend/yumpkgmgr.py
index 955f813..8f3112d 100644
--- a/plugins/backend/yumpkgmgr.py
+++ b/plugins/backend/yumpkgmgr.py
@@ -16,8 +16,7 @@
# with this program; if not, write to the Free Software Foundation, Inc., 59
# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-import os, sys
-import re
+import os
import tempfile
import glob
from string import Template
@@ -31,7 +30,8 @@ from mic.utils import misc, rpmmisc
from mic.utils.grabber import TextProgress
from mic.utils.proxy import get_proxy_for
from mic.utils.errors import CreatorError
-from mic.imager.baseimager import BaseImageCreator
+from mic.utils.safeurl import SafeURL
+
YUMCONF_TEMP = """[main]
installroot=$installroot
@@ -45,6 +45,10 @@ sslverify=1
"""
class MyYumRepository(yum.yumRepo.YumRepository):
+ def __init__(self, repoid, nocache):
+ super(MyYumRepository, self).__init__(repoid)
+ self.nocache = nocache
+
def __del__(self):
pass
@@ -108,12 +112,13 @@ from mic.pluginbase import BackendPlugin
class Yum(BackendPlugin, yum.YumBase):
name = 'yum'
- def __init__(self, target_arch, instroot, cachedir):
+ def __init__(self, target_arch, instroot, cachedir, strict_mode = False):
yum.YumBase.__init__(self)
self.cachedir = cachedir
self.instroot = instroot
self.target_arch = target_arch
+ self.strict_mode = strict_mode
if self.target_arch:
if not rpmUtils.arch.arches.has_key(self.target_arch):
@@ -127,6 +132,7 @@ class Yum(BackendPlugin, yum.YumBase):
self.__pkgs_license = {}
self.__pkgs_content = {}
self.__pkgs_vcsinfo = {}
+ self.check_pkgs = []
self.install_debuginfo = False
@@ -149,14 +155,6 @@ class Yum(BackendPlugin, yum.YumBase):
yum.YumBase.close(self)
self.closeRpmDB()
- if not os.path.exists("/etc/fedora-release") and \
- not os.path.exists("/etc/meego-release"):
- for i in range(3, os.sysconf("SC_OPEN_MAX")):
- try:
- os.close(i)
- except:
- pass
-
def __del__(self):
pass
@@ -194,6 +192,9 @@ class Yum(BackendPlugin, yum.YumBase):
# FIXME: handle pre-install package
return None
+ def checkPackage(self, pkg):
+ self.check_pkgs.append(pkg)
+
def selectPackage(self, pkg):
"""Select a given package.
Can be specified with name.arch or name*
@@ -268,8 +269,7 @@ class Yum(BackendPlugin, yum.YumBase):
option = option.replace("$basearch", rpmUtils.arch.getBaseArch())
option = option.replace("$arch", rpmUtils.arch.getCanonArch())
return option
-
- repo = MyYumRepository(name)
+ repo = MyYumRepository(name, nocache)
# Set proxy
repo.proxy = proxy
@@ -277,12 +277,7 @@ class Yum(BackendPlugin, yum.YumBase):
repo.proxy_password = proxy_password
if url:
- repo.baseurl.append(_varSubstitute(url))
-
- # check LICENSE files
- if not rpmmisc.checkRepositoryEULA(name, repo):
- msger.warning('skip repo:%s for failed EULA confirmation' % name)
- return None
+ repo.baseurl.append(_varSubstitute(url.full))
if mirrorlist:
repo.mirrorlist = _varSubstitute(mirrorlist)
@@ -293,7 +288,6 @@ class Yum(BackendPlugin, yum.YumBase):
repo.setAttribute(k, v)
repo.sslverify = ssl_verify
- repo.cache = not nocache
repo.basecachedir = self.cachedir
repo.base_persistdir = self.conf.persistdir
@@ -369,6 +363,12 @@ class Yum(BackendPlugin, yum.YumBase):
else:
self.__pkgs_license[license] = [pkg_long_name]
+ if pkg.name in self.check_pkgs:
+ self.check_pkgs.remove(pkg.name)
+
+ if self.check_pkgs:
+ raise CreatorError('Packages absent in image: %s' % ','.join(self.check_pkgs))
+
total_count = len(dlpkgs)
cached_count = 0
download_total_size = sum(map(lambda x: int(x.packagesize), dlpkgs))
@@ -377,7 +377,7 @@ class Yum(BackendPlugin, yum.YumBase):
for po in dlpkgs:
local = po.localPkg()
repo = filter(lambda r: r.id == po.repoid, self.repos.listEnabled())[0]
- if not repo.cache and os.path.exists(local):
+ if repo.nocache and os.path.exists(local):
os.unlink(local)
if not os.path.exists(local):
continue
@@ -386,7 +386,7 @@ class Yum(BackendPlugin, yum.YumBase):
% (os.path.basename(local), local))
else:
download_total_size -= int(po.packagesize)
- cached_count +=1
+ cached_count += 1
cache_avail_size = misc.get_filesystem_avail(self.cachedir)
if cache_avail_size < download_total_size:
@@ -439,7 +439,9 @@ class Yum(BackendPlugin, yum.YumBase):
installlogfile = "%s/__catched_stderr.buf" % (self.instroot)
msger.enable_logstderr(installlogfile)
- self.runTransaction(cb)
+ transactionResult = self.runTransaction(cb)
+ if transactionResult.return_code != 0 and self.strict_mode:
+ raise CreatorError("mic failes to install some packages")
self._cleanupRpmdbLocks(self.conf.installroot)
except rpmUtils.RpmUtilsError, e:
@@ -452,6 +454,23 @@ class Yum(BackendPlugin, yum.YumBase):
msger.disable_logstderr()
def getVcsInfo(self):
+ if self.__pkgs_vcsinfo:
+ return self.__pkgs_vcsinfo
+ if not self.ts:
+ self.__initialize_transaction()
+ mi = self.ts.dbMatch()
+ for hdr in mi:
+ lname = misc.RPM_FMT % {
+ 'name': hdr['name'],
+ 'arch': hdr['arch'],
+ 'version': hdr['version'],
+ 'release': hdr['release']
+ }
+ try:
+ self.__pkgs_vcsinfo[lname] = hdr['VCS']
+ except ValueError, KeyError:
+ self.__pkgs_vcsinfo[lname] = None
+
return self.__pkgs_vcsinfo
def getAllContent(self):
@@ -472,18 +491,18 @@ class Yum(BackendPlugin, yum.YumBase):
def package_url(self, pkgname):
pkgs = self.pkgSack.searchNevra(name=pkgname)
if pkgs:
- proxy = None
- proxies = None
- url = pkgs[0].remote_url
- repoid = pkgs[0].repoid
- repos = filter(lambda r: r.id == repoid, self.repos.listEnabled())
-
- if repos:
- proxy = repos[0].proxy
+ pkg = pkgs[0]
+
+ repo = pkg.repo
+ url = SafeURL(repo.baseurl[0]).join(pkg.remote_path)
+
+ proxy = repo.proxy
if not proxy:
proxy = get_proxy_for(url)
if proxy:
proxies = {str(url.split(':')[0]): str(proxy)}
+ else:
+ proxies = None
return (url, proxies)
diff --git a/plugins/backend/zypppkgmgr.py b/plugins/backend/zypppkgmgr.py
index c760859..9358cbe 100755..100644
--- a/plugins/backend/zypppkgmgr.py
+++ b/plugins/backend/zypppkgmgr.py
@@ -54,10 +54,11 @@ from mic.pluginbase import BackendPlugin
class Zypp(BackendPlugin):
name = 'zypp'
- def __init__(self, target_arch, instroot, cachedir):
+ def __init__(self, target_arch, instroot, cachedir, strict_mode = False):
self.cachedir = cachedir
self.instroot = instroot
self.target_arch = target_arch
+ self.strict_mode = strict_mode
self.__pkgs_license = {}
self.__pkgs_content = {}
@@ -73,11 +74,14 @@ class Zypp(BackendPlugin):
self.incpkgs = {}
self.excpkgs = {}
self.pre_pkgs = []
+ self.check_pkgs = []
self.probFilterFlags = [ rpm.RPMPROB_FILTER_OLDPACKAGE,
rpm.RPMPROB_FILTER_REPLACEPKG ]
self.has_prov_query = True
self.install_debuginfo = False
+ # this can't be changed, it is used by zypp
+ self.tmp_file_path = '/var/tmp'
def doFileLogSetup(self, uid, logfile):
# don't do the file log for the livecd as it can lead to open fds
@@ -98,14 +102,6 @@ class Zypp(BackendPlugin):
self.closeRpmDB()
- if not os.path.exists("/etc/fedora-release") and \
- not os.path.exists("/etc/meego-release"):
- for i in range(3, os.sysconf("SC_OPEN_MAX")):
- try:
- os.close(i)
- except:
- pass
-
def __del__(self):
self.close()
@@ -124,11 +120,15 @@ class Zypp(BackendPlugin):
def setup(self):
self._cleanupRpmdbLocks(self.instroot)
+ # '/var/tmp' is used by zypp to build cache, so make sure
+ # if it exists
+ if not os.path.exists(self.tmp_file_path ):
+ os.makedirs(self.tmp_file_path)
def whatObsolete(self, pkg):
query = zypp.PoolQuery()
query.addKind(zypp.ResKind.package)
- query.addAttribute(zypp.SolvAttr.obsoletes, pkg)
+ query.addDependency(zypp.SolvAttr.obsoletes, pkg.name(), pkg.edition())
query.setMatchExact()
for pi in query.queryResults(self.Z.pool()):
return pi
@@ -137,14 +137,14 @@ class Zypp(BackendPlugin):
def _zyppQueryPackage(self, pkg):
query = zypp.PoolQuery()
query.addKind(zypp.ResKind.package)
- query.addAttribute(zypp.SolvAttr.name,pkg)
+ query.addAttribute(zypp.SolvAttr.name, pkg)
query.setMatchExact()
for pi in query.queryResults(self.Z.pool()):
return pi
return None
def _splitPkgString(self, pkg):
- sp = pkg.rsplit(".",1)
+ sp = pkg.rsplit(".", 1)
name = sp[0]
arch = None
if len(sp) == 2:
@@ -211,15 +211,15 @@ class Zypp(BackendPlugin):
if endx and startx:
pattern = '%s' % (pkg[1:-1])
q.setMatchRegex()
- q.addAttribute(zypp.SolvAttr.name,pattern)
+ q.addAttribute(zypp.SolvAttr.name, pattern)
elif arch:
q.setMatchExact()
- q.addAttribute(zypp.SolvAttr.name,name)
+ q.addAttribute(zypp.SolvAttr.name, name)
else:
q.setMatchExact()
- q.addAttribute(zypp.SolvAttr.name,pkg)
+ q.addAttribute(zypp.SolvAttr.name, pkg)
for pitem in sorted(
q.queryResults(self.Z.pool()),
@@ -234,10 +234,10 @@ class Zypp(BackendPlugin):
continue
found = True
- obspkg = self.whatObsolete(item.name())
+ obspkg = self.whatObsolete(item)
if arch:
if arch == str(item.arch()):
- item.status().setToBeInstalled (zypp.ResStatus.USER)
+ pitem.status().setToBeInstalled (zypp.ResStatus.USER)
else:
markPoolItem(obspkg, pitem)
if not ispattern:
@@ -262,7 +262,7 @@ class Zypp(BackendPlugin):
continue
found = True
- obspkg = self.whatObsolete(item.name())
+ obspkg = self.whatObsolete(item)
markPoolItem(obspkg, pitem)
break
@@ -284,29 +284,32 @@ class Zypp(BackendPlugin):
if not ispattern:
if pkgarch:
if name == pkgname and str(item.arch()) == pkgarch:
- return True;
+ return True
else:
if name == pkgname:
- return True;
+ return True
else:
if startx and name.endswith(pkg[1:]):
- return True;
+ return True
if endx and name.startswith(pkg[:-1]):
- return True;
+ return True
- return False;
+ return False
def deselectPackage(self, pkg):
"""collect packages should not be installed"""
self.to_deselect.append(pkg)
def selectGroup(self, grp, include = ksparser.GROUP_DEFAULT):
+ def compareGroup(pitem):
+ item = zypp.asKindPattern(pitem)
+ return item.repoInfo().priority()
if not self.Z:
self.__initialize_zypp()
found = False
- q=zypp.PoolQuery()
+ q = zypp.PoolQuery()
q.addKind(zypp.ResKind.pattern)
- for pitem in q.queryResults(self.Z.pool()):
+ for pitem in sorted(q.queryResults(self.Z.pool()), key=compareGroup):
item = zypp.asKindPattern(pitem)
summary = "%s" % item.summary()
name = "%s" % item.name()
@@ -361,11 +364,6 @@ class Zypp(BackendPlugin):
for pkg in exc:
self.excpkgs[pkg] = name
- # check LICENSE files
- if not rpmmisc.checkRepositoryEULA(name, repo):
- msger.warning('skip repo:%s for failed EULA confirmation' % name)
- return None
-
if mirrorlist:
repo.mirrorlist = mirrorlist
@@ -382,13 +380,14 @@ class Zypp(BackendPlugin):
repo_info.setEnabled(repo.enabled)
repo_info.setAutorefresh(repo.autorefresh)
repo_info.setKeepPackages(repo.keeppackages)
- baseurl = zypp.Url(repo.baseurl[0])
+ baseurl = zypp.Url(repo.baseurl[0].full)
if not ssl_verify:
baseurl.setQueryParam("ssl_verify", "no")
if proxy:
- scheme, host, path, parm, query, frag = urlparse.urlparse(proxy)
+ host = urlparse.urlparse(proxy)[1]
+ # scheme, host, path, parm, query, frag = urlparse.urlparse(proxy)
- proxyinfo = host.split(":")
+ proxyinfo = host.rsplit(":", 1)
host = proxyinfo[0]
port = "80"
@@ -399,10 +398,28 @@ class Zypp(BackendPlugin):
host = proxy.rsplit(':', 1)[0]
port = proxy.rsplit(':', 1)[1]
+ # parse user/pass from proxy host
+ proxyinfo = host.rsplit("@", 1)
+ if len(proxyinfo) == 2:
+ host = proxyinfo[1]
+ # Known Issue: If password contains ":", which should be
+ # quoted, for example, use '123%3Aabc' instead of 123:abc
+ userpassinfo = proxyinfo[0].rsplit(":", 1)
+ if len(userpassinfo) == 2:
+ proxy_username = userpassinfo[0]
+ proxy_password = userpassinfo[1]
+ elif len(userpassinfo) == 1:
+ proxy_username = userpassinfo[0]
+
baseurl.setQueryParam ("proxy", host)
baseurl.setQueryParam ("proxyport", port)
+ if proxy_username:
+ baseurl.setQueryParam ("proxyuser", proxy_username)
+ if proxy_password:
+ baseurl.setQueryParam ("proxypass", proxy_password)
+ else:
+ baseurl.setQueryParam ("proxy", "_none_")
- repo.baseurl[0] = baseurl.asCompleteString()
self.repos.append(repo)
repo_info.addBaseUrl(baseurl)
@@ -443,6 +460,9 @@ class Zypp(BackendPlugin):
def preInstall(self, pkg):
self.pre_pkgs.append(pkg)
+ def checkPackage(self, pkg):
+ self.check_pkgs.append(pkg)
+
def runInstall(self, checksize = 0):
os.environ["HOME"] = "/"
os.environ["LD_PRELOAD"] = ""
@@ -451,12 +471,16 @@ class Zypp(BackendPlugin):
todo = zypp.GetResolvablesToInsDel(self.Z.pool())
installed_pkgs = todo._toInstall
dlpkgs = []
+
for pitem in installed_pkgs:
if not zypp.isKindPattern(pitem) and \
not self.inDeselectPackages(pitem):
item = zypp.asKindPackage(pitem)
dlpkgs.append(item)
+ if item.name() in self.check_pkgs:
+ self.check_pkgs.remove(item.name())
+
if not self.install_debuginfo or str(item.arch()) == "noarch":
continue
@@ -468,6 +492,9 @@ class Zypp(BackendPlugin):
msger.warning("No debuginfo rpm found for: %s" \
% item.name())
+ if self.check_pkgs:
+ raise CreatorError('Packages absent in image: %s' % ','.join(self.check_pkgs))
+
# record all pkg and the content
localpkgs = self.localpkgs.keys()
for pkg in dlpkgs:
@@ -544,9 +571,11 @@ class Zypp(BackendPlugin):
if download_count > 0:
msger.info("Downloading packages ...")
self.downloadPkgs(dlpkgs, download_count)
+ except CreatorError, e:
+ raise CreatorError("Package download failed: %s" %(e,))
+ try:
self.installPkgs(dlpkgs)
-
except (RepoError, RpmError):
raise
except Exception, e:
@@ -567,7 +596,11 @@ class Zypp(BackendPlugin):
'version': hdr['version'],
'release': hdr['release']
}
- self.__pkgs_vcsinfo[lname] = hdr['VCS']
+ try:
+ self.__pkgs_vcsinfo[lname] = hdr['VCS']
+ except ValueError:
+ # if rpm not support VCS, set to None
+ self.__pkgs_vcsinfo[lname] = None
return self.__pkgs_vcsinfo
@@ -686,7 +719,7 @@ class Zypp(BackendPlugin):
def getLocalPkgPath(self, po):
repoinfo = po.repoInfo()
cacheroot = repoinfo.packagesPath()
- location= po.location()
+ location = po.location()
rpmpath = str(location.filename())
pkgpath = "%s/%s" % (cacheroot, os.path.basename(rpmpath))
return pkgpath
@@ -749,7 +782,7 @@ class Zypp(BackendPlugin):
proxies = self.get_proxies(po)
try:
- filename = myurlgrab(url, filename, proxies, progress_obj)
+ filename = myurlgrab(url.full, filename, proxies, progress_obj)
except CreatorError:
self.close()
raise
@@ -844,7 +877,8 @@ class Zypp(BackendPlugin):
if len(errors) == 0:
msger.warning('scriptlet or other non-fatal errors occurred '
'during transaction.')
-
+ if self.strict_mode:
+ raise CreatorError("mic failes to install some packages")
else:
for e in errors:
msger.warning(e[0])
@@ -868,7 +902,7 @@ class Zypp(BackendPlugin):
% (package, deppkg))
elif sense == rpm.RPMDEP_SENSE_CONFLICTS:
- msger.warning("[%s] Conflicts with [%s]" %(package,deppkg))
+ msger.warning("[%s] Conflicts with [%s]" % (package, deppkg))
raise RepoError("Unresolved dependencies, transaction failed.")
@@ -931,18 +965,12 @@ class Zypp(BackendPlugin):
except IndexError:
return None
- baseurl = repo.baseurl[0]
-
- index = baseurl.find("?")
- if index > -1:
- baseurl = baseurl[:index]
-
location = pobj.location()
location = str(location.filename())
if location.startswith("./"):
location = location[2:]
- return os.path.join(baseurl, location)
+ return repo.baseurl[0].join(location)
def package_url(self, pkgname):
diff --git a/plugins/imager/fs_plugin.py b/plugins/imager/fs_plugin.py
index 8e758db..d74530f 100644
--- a/plugins/imager/fs_plugin.py
+++ b/plugins/imager/fs_plugin.py
@@ -15,11 +15,8 @@
# with this program; if not, write to the Free Software Foundation, Inc., 59
# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-import os
-import sys
-
from mic import chroot, msger, rt_util
-from mic.utils import cmdln, misc, errors, fs_related
+from mic.utils import misc, errors, fs_related
from mic.imager import fs
from mic.conf import configmgr
from mic.plugin import pluginmgr
@@ -29,12 +26,7 @@ class FsPlugin(ImagerPlugin):
name = 'fs'
@classmethod
- @cmdln.option("--include-src",
- dest="include_src",
- action="store_true",
- default=False,
- help="Generate a image with source rpms included")
- def do_create(self, subcmd, opts, *args):
+ def do_create(self, args):
"""${cmd_name}: create fs image
Usage:
@@ -43,11 +35,11 @@ class FsPlugin(ImagerPlugin):
${cmd_option_list}
"""
- if len(args) != 1:
- raise errors.Usage("Extra arguments given")
+ if args is None:
+ raise errors.Usage("Invalid arguments.")
creatoropts = configmgr.create
- ksconf = args[0]
+ ksconf = args.ksfile
if creatoropts['runtime'] == 'bootstrap':
configmgr._ksconf = ksconf
@@ -65,10 +57,6 @@ class FsPlugin(ImagerPlugin):
configmgr._ksconf = ksconf
- # Called After setting the configmgr._ksconf as the creatoropts['name'] is reset there.
- if creatoropts['release'] is not None:
- creatoropts['outdir'] = "%s/%s/images/%s/" % (creatoropts['outdir'], creatoropts['release'], creatoropts['name'])
-
# try to find the pkgmgr
pkgmgr = None
backends = pluginmgr.get_plugins('backend')
@@ -90,7 +78,7 @@ class FsPlugin(ImagerPlugin):
','.join(backends.keys())))
creator = fs.FsImageCreator(creatoropts, pkgmgr)
- creator._include_src = opts.include_src
+ creator._include_src = args.include_src
if len(recording_pkgs) > 0:
creator._recording_pkgs = recording_pkgs
@@ -105,19 +93,22 @@ class FsPlugin(ImagerPlugin):
creator.mount(None, creatoropts["cachedir"])
creator.install()
#Download the source packages ###private options
- if opts.include_src:
+ if args.include_src:
installed_pkgs = creator.get_installed_packages()
msger.info('--------------------------------------------------')
msger.info('Generating the image with source rpms included ...')
- if not misc.SrcpkgsDownload(installed_pkgs, creatoropts["repomd"], creator._instroot, creatoropts["cachedir"]):
+ if not misc.SrcpkgsDownload(installed_pkgs, creatoropts["repomd"],
+ creator._instroot, creatoropts["cachedir"]):
msger.warning("Source packages can't be downloaded")
creator.configure(creatoropts["repomd"])
creator.copy_kernel()
creator.unmount()
- creator.package(creatoropts["outdir"])
+ creator.package(creatoropts["destdir"])
+ creator.create_manifest()
if creatoropts['release'] is not None:
- creator.release_output(ksconf, creatoropts['outdir'], creatoropts['release'])
+ creator.release_output(ksconf, creatoropts['destdir'],
+ creatoropts['release'])
creator.print_outimage_info()
except errors.CreatorError:
raise
diff --git a/plugins/imager/livecd_plugin.py b/plugins/imager/livecd_plugin.py
deleted file mode 100644
index d24ef59..0000000
--- a/plugins/imager/livecd_plugin.py
+++ /dev/null
@@ -1,255 +0,0 @@
-#!/usr/bin/python -tt
-#
-# Copyright (c) 2011 Intel, Inc.
-#
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by the Free
-# Software Foundation; version 2 of the License
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-# for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program; if not, write to the Free Software Foundation, Inc., 59
-# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-import os
-import shutil
-import tempfile
-
-from mic import chroot, msger, rt_util
-from mic.utils import misc, fs_related, errors
-from mic.conf import configmgr
-import mic.imager.livecd as livecd
-from mic.plugin import pluginmgr
-
-from mic.pluginbase import ImagerPlugin
-class LiveCDPlugin(ImagerPlugin):
- name = 'livecd'
-
- @classmethod
- def do_create(self, subcmd, opts, *args):
- """${cmd_name}: create livecd image
-
- Usage:
- ${name} ${cmd_name} <ksfile> [OPTS]
-
- ${cmd_option_list}
- """
-
- if len(args) != 1:
- raise errors.Usage("Extra arguments given")
-
- creatoropts = configmgr.create
- ksconf = args[0]
-
- if creatoropts['runtime'] == 'bootstrap':
- configmgr._ksconf = ksconf
- rt_util.bootstrap_mic()
-
- if creatoropts['arch'] and creatoropts['arch'].startswith('arm'):
- msger.warning('livecd cannot support arm images, Quit')
- return
-
- recording_pkgs = []
- if len(creatoropts['record_pkgs']) > 0:
- recording_pkgs = creatoropts['record_pkgs']
-
- if creatoropts['release'] is not None:
- if 'name' not in recording_pkgs:
- recording_pkgs.append('name')
- if 'vcs' not in recording_pkgs:
- recording_pkgs.append('vcs')
-
- configmgr._ksconf = ksconf
-
- # Called After setting the configmgr._ksconf as the creatoropts['name'] is reset there.
- if creatoropts['release'] is not None:
- creatoropts['outdir'] = "%s/%s/images/%s/" % (creatoropts['outdir'], creatoropts['release'], creatoropts['name'])
-
- # try to find the pkgmgr
- pkgmgr = None
- backends = pluginmgr.get_plugins('backend')
- if 'auto' == creatoropts['pkgmgr']:
- for key in configmgr.prefer_backends:
- if key in backends:
- pkgmgr = backends[key]
- break
- else:
- for key in backends.keys():
- if key == creatoropts['pkgmgr']:
- pkgmgr = backends[key]
- break
-
- if not pkgmgr:
- raise errors.CreatorError("Can't find backend: %s, "
- "available choices: %s" %
- (creatoropts['pkgmgr'],
- ','.join(backends.keys())))
-
- creator = livecd.LiveCDImageCreator(creatoropts, pkgmgr)
-
- if len(recording_pkgs) > 0:
- creator._recording_pkgs = recording_pkgs
-
- self.check_image_exists(creator.destdir,
- creator.pack_to,
- [creator.name + ".iso"],
- creatoropts['release'])
-
- try:
- creator.check_depend_tools()
- creator.mount(None, creatoropts["cachedir"])
- creator.install()
- creator.configure(creatoropts["repomd"])
- creator.copy_kernel()
- creator.unmount()
- creator.package(creatoropts["outdir"])
- if creatoropts['release'] is not None:
- creator.release_output(ksconf, creatoropts['outdir'], creatoropts['release'])
- creator.print_outimage_info()
-
- except errors.CreatorError:
- raise
- finally:
- creator.cleanup()
-
- msger.info("Finished.")
- return 0
-
- @classmethod
- def do_chroot(cls, target, cmd=[]):
- os_image = cls.do_unpack(target)
- os_image_dir = os.path.dirname(os_image)
-
- # unpack image to target dir
- imgsize = misc.get_file_size(os_image) * 1024L * 1024L
- imgtype = misc.get_image_type(os_image)
- if imgtype == "btrfsimg":
- fstype = "btrfs"
- myDiskMount = fs_related.BtrfsDiskMount
- elif imgtype in ("ext3fsimg", "ext4fsimg"):
- fstype = imgtype[:4]
- myDiskMount = fs_related.ExtDiskMount
- else:
- raise errors.CreatorError("Unsupported filesystem type: %s" % fstype)
-
- extmnt = misc.mkdtemp()
- extloop = myDiskMount(fs_related.SparseLoopbackDisk(os_image, imgsize),
- extmnt,
- fstype,
- 4096,
- "%s label" % fstype)
- try:
- extloop.mount()
-
- except errors.MountError:
- extloop.cleanup()
- shutil.rmtree(extmnt, ignore_errors = True)
- shutil.rmtree(os_image_dir, ignore_errors = True)
- raise
-
- try:
- if len(cmd) != 0:
- cmdline = ' '.join(cmd)
- else:
- cmdline = "/bin/bash"
- envcmd = fs_related.find_binary_inchroot("env", extmnt)
- if envcmd:
- cmdline = "%s HOME=/root %s" % (envcmd, cmdline)
- chroot.chroot(extmnt, None, cmdline)
- except:
- raise errors.CreatorError("Failed to chroot to %s." %target)
- finally:
- chroot.cleanup_after_chroot("img", extloop, os_image_dir, extmnt)
-
- @classmethod
- def do_pack(cls, base_on):
- import subprocess
-
- def __mkinitrd(instance):
- kernelver = instance._get_kernel_versions().values()[0][0]
- args = [ "/usr/libexec/mkliveinitrd", "/boot/initrd-%s.img" % kernelver, "%s" % kernelver ]
- try:
- subprocess.call(args, preexec_fn = instance._chroot)
- except OSError, (err, msg):
- raise errors.CreatorError("Failed to execute /usr/libexec/mkliveinitrd: %s" % msg)
-
- def __run_post_cleanups(instance):
- kernelver = instance._get_kernel_versions().values()[0][0]
- args = ["rm", "-f", "/boot/initrd-%s.img" % kernelver]
-
- try:
- subprocess.call(args, preexec_fn = instance._chroot)
- except OSError, (err, msg):
- raise errors.CreatorError("Failed to run post cleanups: %s" % msg)
-
- convertoropts = configmgr.convert
- convertoropts['name'] = os.path.splitext(os.path.basename(base_on))[0]
- convertor = livecd.LiveCDImageCreator(convertoropts)
- imgtype = misc.get_image_type(base_on)
- if imgtype == "btrfsimg":
- fstype = "btrfs"
- elif imgtype in ("ext3fsimg", "ext4fsimg"):
- fstype = imgtype[:4]
- else:
- raise errors.CreatorError("Unsupported filesystem type: %s" % fstype)
- convertor._set_fstype(fstype)
- try:
- convertor.mount(base_on)
- __mkinitrd(convertor)
- convertor._create_bootconfig()
- __run_post_cleanups(convertor)
- convertor.launch_shell(convertoropts['shell'])
- convertor.unmount()
- convertor.package()
- convertor.print_outimage_info()
- finally:
- shutil.rmtree(os.path.dirname(base_on), ignore_errors = True)
-
- @classmethod
- def do_unpack(cls, srcimg):
- img = srcimg
- imgmnt = misc.mkdtemp()
- imgloop = fs_related.DiskMount(fs_related.LoopbackDisk(img, 0), imgmnt)
- try:
- imgloop.mount()
- except errors.MountError:
- imgloop.cleanup()
- raise
-
- # legacy LiveOS filesystem layout support, remove for F9 or F10
- if os.path.exists(imgmnt + "/squashfs.img"):
- squashimg = imgmnt + "/squashfs.img"
- else:
- squashimg = imgmnt + "/LiveOS/squashfs.img"
-
- tmpoutdir = misc.mkdtemp()
- # unsquashfs requires outdir mustn't exist
- shutil.rmtree(tmpoutdir, ignore_errors = True)
- misc.uncompress_squashfs(squashimg, tmpoutdir)
-
- try:
- # legacy LiveOS filesystem layout support, remove for F9 or F10
- if os.path.exists(tmpoutdir + "/os.img"):
- os_image = tmpoutdir + "/os.img"
- else:
- os_image = tmpoutdir + "/LiveOS/ext3fs.img"
-
- if not os.path.exists(os_image):
- raise errors.CreatorError("'%s' is not a valid live CD ISO : neither "
- "LiveOS/ext3fs.img nor os.img exist" %img)
-
- imgname = os.path.basename(srcimg)
- imgname = os.path.splitext(imgname)[0] + ".img"
- rtimage = os.path.join(tempfile.mkdtemp(dir = "/var/tmp", prefix = "tmp"), imgname)
- shutil.copyfile(os_image, rtimage)
-
- finally:
- imgloop.cleanup()
- shutil.rmtree(tmpoutdir, ignore_errors = True)
- shutil.rmtree(imgmnt, ignore_errors = True)
-
- return rtimage
diff --git a/plugins/imager/liveusb_plugin.py b/plugins/imager/liveusb_plugin.py
deleted file mode 100644
index 7aa8927..0000000
--- a/plugins/imager/liveusb_plugin.py
+++ /dev/null
@@ -1,260 +0,0 @@
-#!/usr/bin/python -tt
-#
-# Copyright (c) 2011 Intel, Inc.
-#
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by the Free
-# Software Foundation; version 2 of the License
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-# for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program; if not, write to the Free Software Foundation, Inc., 59
-# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-import os
-import shutil
-import tempfile
-
-from mic import chroot, msger, rt_util
-from mic.utils import misc, fs_related, errors
-from mic.utils.partitionedfs import PartitionedMount
-from mic.conf import configmgr
-from mic.plugin import pluginmgr
-
-import mic.imager.liveusb as liveusb
-
-from mic.pluginbase import ImagerPlugin
-class LiveUSBPlugin(ImagerPlugin):
- name = 'liveusb'
-
- @classmethod
- def do_create(self, subcmd, opts, *args):
- """${cmd_name}: create liveusb image
-
- Usage:
- ${name} ${cmd_name} <ksfile> [OPTS]
-
- ${cmd_option_list}
- """
-
- if len(args) != 1:
- raise errors.Usage("Extra arguments given")
-
- creatoropts = configmgr.create
- ksconf = args[0]
-
- if creatoropts['runtime'] == "bootstrap":
- configmgr._ksconf = ksconf
- rt_util.bootstrap_mic()
-
- if creatoropts['arch'] and creatoropts['arch'].startswith('arm'):
- msger.warning('liveusb cannot support arm images, Quit')
- return
-
- recording_pkgs = []
- if len(creatoropts['record_pkgs']) > 0:
- recording_pkgs = creatoropts['record_pkgs']
-
- if creatoropts['release'] is not None:
- if 'name' not in recording_pkgs:
- recording_pkgs.append('name')
- if 'vcs' not in recording_pkgs:
- recording_pkgs.append('vcs')
-
- configmgr._ksconf = ksconf
-
- # Called After setting the configmgr._ksconf as the creatoropts['name'] is reset there.
- if creatoropts['release'] is not None:
- creatoropts['outdir'] = "%s/%s/images/%s/" % (creatoropts['outdir'], creatoropts['release'], creatoropts['name'])
-
- # try to find the pkgmgr
- pkgmgr = None
- backends = pluginmgr.get_plugins('backend')
- if 'auto' == creatoropts['pkgmgr']:
- for key in configmgr.prefer_backends:
- if key in backends:
- pkgmgr = backends[key]
- break
- else:
- for key in backends.keys():
- if key == creatoropts['pkgmgr']:
- pkgmgr = backends[key]
- break
-
- if not pkgmgr:
- raise errors.CreatorError("Can't find backend: %s, "
- "available choices: %s" %
- (creatoropts['pkgmgr'],
- ','.join(backends.keys())))
-
- creator = liveusb.LiveUSBImageCreator(creatoropts, pkgmgr)
-
- if len(recording_pkgs) > 0:
- creator._recording_pkgs = recording_pkgs
-
- self.check_image_exists(creator.destdir,
- creator.pack_to,
- [creator.name + ".usbimg"],
- creatoropts['release'])
- try:
- creator.check_depend_tools()
- creator.mount(None, creatoropts["cachedir"])
- creator.install()
- creator.configure(creatoropts["repomd"])
- creator.copy_kernel()
- creator.unmount()
- creator.package(creatoropts["outdir"])
- if creatoropts['release'] is not None:
- creator.release_output(ksconf, creatoropts['outdir'], creatoropts['release'])
- creator.print_outimage_info()
-
- except errors.CreatorError:
- raise
- finally:
- creator.cleanup()
-
- msger.info("Finished.")
- return 0
-
- @classmethod
- def do_chroot(cls, target, cmd=[]):
- os_image = cls.do_unpack(target)
- os_image_dir = os.path.dirname(os_image)
-
- # unpack image to target dir
- imgsize = misc.get_file_size(os_image) * 1024L * 1024L
- imgtype = misc.get_image_type(os_image)
- if imgtype == "btrfsimg":
- fstype = "btrfs"
- myDiskMount = fs_related.BtrfsDiskMount
- elif imgtype in ("ext3fsimg", "ext4fsimg"):
- fstype = imgtype[:4]
- myDiskMount = fs_related.ExtDiskMount
- else:
- raise errors.CreatorError("Unsupported filesystem type: %s" % fstype)
-
- extmnt = misc.mkdtemp()
- extloop = myDiskMount(fs_related.SparseLoopbackDisk(os_image, imgsize),
- extmnt,
- fstype,
- 4096,
- "%s label" % fstype)
-
- try:
- extloop.mount()
-
- except errors.MountError:
- extloop.cleanup()
- shutil.rmtree(extmnt, ignore_errors = True)
- raise
-
- try:
- if len(cmd) != 0:
- cmdline = ' '.join(cmd)
- else:
- cmdline = "/bin/bash"
- envcmd = fs_related.find_binary_inchroot("env", extmnt)
- if envcmd:
- cmdline = "%s HOME=/root %s" % (envcmd, cmdline)
- chroot.chroot(extmnt, None, cmdline)
- except:
- raise errors.CreatorError("Failed to chroot to %s." %target)
- finally:
- chroot.cleanup_after_chroot("img", extloop, os_image_dir, extmnt)
-
- @classmethod
- def do_pack(cls, base_on):
- import subprocess
-
- def __mkinitrd(instance):
- kernelver = instance._get_kernel_versions().values()[0][0]
- args = [ "/usr/libexec/mkliveinitrd", "/boot/initrd-%s.img" % kernelver, "%s" % kernelver ]
- try:
- subprocess.call(args, preexec_fn = instance._chroot)
-
- except OSError, (err, msg):
- raise errors.CreatorError("Failed to execute /usr/libexec/mkliveinitrd: %s" % msg)
-
- def __run_post_cleanups(instance):
- kernelver = instance._get_kernel_versions().values()[0][0]
- args = ["rm", "-f", "/boot/initrd-%s.img" % kernelver]
-
- try:
- subprocess.call(args, preexec_fn = instance._chroot)
- except OSError, (err, msg):
- raise errors.CreatorError("Failed to run post cleanups: %s" % msg)
-
- convertoropts = configmgr.convert
- convertoropts['name'] = os.path.splitext(os.path.basename(base_on))[0]
- convertor = liveusb.LiveUSBImageCreator(convertoropts)
- imgtype = misc.get_image_type(base_on)
- if imgtype == "btrfsimg":
- fstype = "btrfs"
- elif imgtype in ("ext3fsimg", "ext4fsimg"):
- fstype = imgtype[:4]
- else:
- raise errors.CreatorError("Unsupported filesystem type: %s" % fstyp)
- convertor._set_fstype(fstype)
- try:
- convertor.mount(base_on)
- __mkinitrd(convertor)
- convertor._create_bootconfig()
- __run_post_cleanups(convertor)
- convertor.launch_shell(convertoropts['shell'])
- convertor.unmount()
- convertor.package()
- convertor.print_outimage_info()
- finally:
- shutil.rmtree(os.path.dirname(base_on), ignore_errors = True)
-
- @classmethod
- def do_unpack(cls, srcimg):
- img = srcimg
- imgsize = misc.get_file_size(img) * 1024L * 1024L
- imgmnt = misc.mkdtemp()
- disk = fs_related.SparseLoopbackDisk(img, imgsize)
- imgloop = PartitionedMount(imgmnt, skipformat = True)
- imgloop.add_disk('/dev/sdb', disk)
- imgloop.add_partition(imgsize/1024/1024, "/dev/sdb", "/", "vfat", boot=False)
- try:
- imgloop.mount()
- except errors.MountError:
- imgloop.cleanup()
- raise
-
- # legacy LiveOS filesystem layout support, remove for F9 or F10
- if os.path.exists(imgmnt + "/squashfs.img"):
- squashimg = imgmnt + "/squashfs.img"
- else:
- squashimg = imgmnt + "/LiveOS/squashfs.img"
-
- tmpoutdir = misc.mkdtemp()
- # unsquashfs requires outdir mustn't exist
- shutil.rmtree(tmpoutdir, ignore_errors = True)
- misc.uncompress_squashfs(squashimg, tmpoutdir)
-
- try:
- # legacy LiveOS filesystem layout support, remove for F9 or F10
- if os.path.exists(tmpoutdir + "/os.img"):
- os_image = tmpoutdir + "/os.img"
- else:
- os_image = tmpoutdir + "/LiveOS/ext3fs.img"
-
- if not os.path.exists(os_image):
- raise errors.CreatorError("'%s' is not a valid live CD ISO : neither "
- "LiveOS/ext3fs.img nor os.img exist" %img)
- imgname = os.path.basename(srcimg)
- imgname = os.path.splitext(imgname)[0] + ".img"
- rtimage = os.path.join(tempfile.mkdtemp(dir = "/var/tmp", prefix = "tmp"), imgname)
- shutil.copyfile(os_image, rtimage)
-
- finally:
- imgloop.cleanup()
- shutil.rmtree(tmpoutdir, ignore_errors = True)
- shutil.rmtree(imgmnt, ignore_errors = True)
-
- return rtimage
diff --git a/plugins/imager/loop_plugin.py b/plugins/imager/loop_plugin.py
index 8f4b030..1830230 100644
--- a/plugins/imager/loop_plugin.py
+++ b/plugins/imager/loop_plugin.py
@@ -20,7 +20,7 @@ import shutil
import tempfile
from mic import chroot, msger, rt_util
-from mic.utils import misc, fs_related, errors, cmdln
+from mic.utils import misc, fs_related, errors
from mic.conf import configmgr
from mic.plugin import pluginmgr
from mic.imager.loop import LoopImageCreator, load_mountpoints
@@ -30,16 +30,7 @@ class LoopPlugin(ImagerPlugin):
name = 'loop'
@classmethod
- @cmdln.option("--compress-disk-image", dest="compress_image",
- type='choice', choices=("gz", "bz2"), default=None,
- help="Same with --compress-image")
- # alias to compress-image for compatibility
- @cmdln.option("--compress-image", dest="compress_image",
- type='choice', choices=("gz", "bz2"), default=None,
- help="Compress all loop images with 'gz' or 'bz2'")
- @cmdln.option("--shrink", action='store_true', default=False,
- help="Whether to shrink loop images to minimal size")
- def do_create(self, subcmd, opts, *args):
+ def do_create(self, args):
"""${cmd_name}: create loop image
Usage:
@@ -48,11 +39,11 @@ class LoopPlugin(ImagerPlugin):
${cmd_option_list}
"""
- if len(args) != 1:
- raise errors.Usage("Extra arguments given")
+ if args is None:
+ raise errors.Usage("Invalid arguments")
creatoropts = configmgr.create
- ksconf = args[0]
+ ksconf = args.ksfile
if creatoropts['runtime'] == "bootstrap":
configmgr._ksconf = ksconf
@@ -70,12 +61,6 @@ class LoopPlugin(ImagerPlugin):
configmgr._ksconf = ksconf
- # Called After setting the configmgr._ksconf
- # as the creatoropts['name'] is reset there.
- if creatoropts['release'] is not None:
- creatoropts['outdir'] = "%s/%s/images/%s/" % (creatoropts['outdir'],
- creatoropts['release'],
- creatoropts['name'])
# try to find the pkgmgr
pkgmgr = None
backends = pluginmgr.get_plugins('backend')
@@ -98,8 +83,8 @@ class LoopPlugin(ImagerPlugin):
creator = LoopImageCreator(creatoropts,
pkgmgr,
- opts.compress_image,
- opts.shrink)
+ args.compress_image,
+ args.shrink)
if len(recording_pkgs) > 0:
creator._recording_pkgs = recording_pkgs
@@ -118,11 +103,12 @@ class LoopPlugin(ImagerPlugin):
creator.configure(creatoropts["repomd"])
creator.copy_kernel()
creator.unmount()
- creator.package(creatoropts["outdir"])
+ creator.package(creatoropts["destdir"])
+ creator.create_manifest()
if creatoropts['release'] is not None:
creator.release_output(ksconf,
- creatoropts['outdir'],
+ creatoropts['destdir'],
creatoropts['release'])
creator.print_outimage_info()
@@ -158,7 +144,7 @@ class LoopPlugin(ImagerPlugin):
elif fstype in ("vfat", "msdos"):
myDiskMount = fs_related.VfatDiskMount
else:
- msger.error("Cannot support fstype: %s" % fstype)
+ raise errors.CreatorError("Cannot support fstype: %s" % fstype)
name = os.path.join(tmpdir, name)
size = size * 1024L * 1024L
@@ -233,8 +219,8 @@ class LoopPlugin(ImagerPlugin):
raise
try:
- if len(cmd) != 0:
- cmdline = ' '.join(cmd)
+ if cmd is not None:
+ cmdline = cmd
else:
cmdline = "/bin/bash"
envcmd = fs_related.find_binary_inchroot("env", extmnt)
diff --git a/plugins/imager/qcow_plugin.py b/plugins/imager/qcow_plugin.py
new file mode 100644
index 0000000..8acf572
--- /dev/null
+++ b/plugins/imager/qcow_plugin.py
@@ -0,0 +1,160 @@
+#
+# Copyright (c) 2014 Intel, Inc.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the Free
+# Software Foundation; version 2 of the License
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc., 59
+# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+import os
+import shutil
+
+from mic import msger, rt_util
+from mic.conf import configmgr
+from mic.plugin import pluginmgr
+from mic.pluginbase import ImagerPlugin
+from mic.imager.loop import LoopImageCreator
+from mic.utils import errors, fs_related, runner
+
+class QcowImageCreator(LoopImageCreator):
+ img_format = 'qcow'
+
+ def __init__(self, creatoropts=None, pkgmgr=None):
+ LoopImageCreator.__init__(self, creatoropts, pkgmgr)
+ self.cmd_qemuimg = 'qemu-img'
+
+ def _stage_final_image(self):
+ try:
+ self.cmd_qemuimg = fs_related.find_binary_path('qemu-img')
+ except errors.CreatorError:
+ return LoopImageCreator._stage_final_image(self)
+
+ self._resparse()
+
+ imgfile = None
+ for item in self._instloops:
+ if item['mountpoint'] == '/':
+ if item['fstype'] == "ext4":
+ runner.show('/sbin/tune2fs -O ^huge_file,extents,uninit_bg %s'
+ % imgfile)
+ self.image_files.setdefault('partitions', {}).update(
+ {item['mountpoint']: item['label']})
+ imgfile = os.path.join(self._imgdir, item['name'])
+
+ if imgfile:
+ qemuimage = imgfile + ".x86"
+ runner.show("%s convert -O qcow2 %s %s"
+ % (self.cmd_qemuimg, imgfile, qemuimage))
+ os.unlink(imgfile)
+ os.rename(qemuimage, imgfile)
+
+ for item in os.listdir(self._imgdir):
+ shutil.move(os.path.join(self._imgdir, item),
+ os.path.join(self._outdir, item))
+
+class QcowPlugin(ImagerPlugin):
+ name = 'qcow'
+
+ @classmethod
+ def do_create(cls, args):
+ """${cmd_name}: create qcow image
+
+ Usage:
+ ${name} ${cmd_name} <ksfile> [OPTS]
+
+ ${cmd_option_list}
+ """
+ if args is None:
+ raise errors.Usage("Invalid arguments")
+
+ creatoropts = configmgr.create
+ ksconf = args.ksfile
+
+ if creatoropts['runtime'] == "bootstrap":
+ configmgr._ksconf = ksconf
+ rt_util.bootstrap_mic()
+
+ recording_pkgs = []
+ if len(creatoropts['record_pkgs']) > 0:
+ recording_pkgs = creatoropts['record_pkgs']
+
+ if creatoropts['release'] is not None:
+ if 'name' not in recording_pkgs:
+ recording_pkgs.append('name')
+ if 'vcs' not in recording_pkgs:
+ recording_pkgs.append('vcs')
+
+ configmgr._ksconf = ksconf
+
+ # try to find the pkgmgr
+ pkgmgr = None
+ backends = pluginmgr.get_plugins('backend')
+ if 'auto' == creatoropts['pkgmgr']:
+ for key in configmgr.prefer_backends:
+ if key in backends:
+ pkgmgr = backends[key]
+ break
+ else:
+ for key in backends.keys():
+ if key == creatoropts['pkgmgr']:
+ pkgmgr = backends[key]
+ break
+
+ if not pkgmgr:
+ raise errors.CreatorError("Can't find backend: %s, "
+ "available choices: %s" %
+ (creatoropts['pkgmgr'],
+ ','.join(backends.keys())))
+
+ creator = QcowImageCreator(creatoropts,
+ pkgmgr)
+
+ if len(recording_pkgs) > 0:
+ creator._recording_pkgs = recording_pkgs
+
+ image_names = [creator.name + ".img"]
+ image_names.extend(creator.get_image_names())
+ cls.check_image_exists(creator.destdir,
+ creator.pack_to,
+ image_names,
+ creatoropts['release'])
+
+ try:
+ creator.check_depend_tools()
+ creator.mount(None, creatoropts["cachedir"])
+ creator.install()
+ creator.configure(creatoropts["repomd"])
+ creator.copy_kernel()
+ creator.unmount()
+ creator.package(creatoropts["destdir"])
+ creator.create_manifest()
+
+ if creatoropts['release'] is not None:
+ creator.release_output(ksconf,
+ creatoropts['destdir'],
+ creatoropts['release'])
+ creator.print_outimage_info()
+
+ except errors.CreatorError:
+ raise
+ finally:
+ creator.cleanup()
+
+ msger.info("Finished.")
+ return 0
+
+ @classmethod
+ def do_chroot(cls, target, cmd=[]):
+ pass
+
+ @classmethod
+ def do_unpack(cls, srcimg):
+ pass
diff --git a/plugins/imager/raw_plugin.py b/plugins/imager/raw_plugin.py
index 1b9631d..09a9714 100644..100755
--- a/plugins/imager/raw_plugin.py
+++ b/plugins/imager/raw_plugin.py
@@ -21,7 +21,7 @@ import re
import tempfile
from mic import chroot, msger, rt_util
-from mic.utils import misc, fs_related, errors, runner, cmdln
+from mic.utils import misc, fs_related, errors, runner
from mic.conf import configmgr
from mic.plugin import pluginmgr
from mic.utils.partitionedfs import PartitionedMount
@@ -33,19 +33,7 @@ class RawPlugin(ImagerPlugin):
name = 'raw'
@classmethod
- @cmdln.option("--compress-disk-image", dest="compress_image", type='choice',
- choices=("gz", "bz2"), default=None,
- help="Same with --compress-image")
- @cmdln.option("--compress-image", dest="compress_image", type='choice',
- choices=("gz", "bz2"), default = None,
- help="Compress all raw images before package")
- @cmdln.option("--generate-bmap", action="store_true", default = None,
- help="also generate the block map file")
- @cmdln.option("--fstab-entry", dest="fstab_entry", type='choice',
- choices=("name", "uuid"), default="uuid",
- help="Set fstab entry, 'name' means using device names, "
- "'uuid' means using filesystem uuid")
- def do_create(self, subcmd, opts, *args):
+ def do_create(self, args):
"""${cmd_name}: create raw image
Usage:
@@ -54,11 +42,8 @@ class RawPlugin(ImagerPlugin):
${cmd_option_list}
"""
- if len(args) != 1:
- raise errors.Usage("Extra arguments given")
-
creatoropts = configmgr.create
- ksconf = args[0]
+ ksconf = args.ksfile
if creatoropts['runtime'] == "bootstrap":
configmgr._ksconf = ksconf
@@ -76,10 +61,6 @@ class RawPlugin(ImagerPlugin):
configmgr._ksconf = ksconf
- # Called After setting the configmgr._ksconf as the creatoropts['name'] is reset there.
- if creatoropts['release'] is not None:
- creatoropts['outdir'] = "%s/%s/images/%s/" % (creatoropts['outdir'], creatoropts['release'], creatoropts['name'])
-
# try to find the pkgmgr
pkgmgr = None
backends = pluginmgr.get_plugins('backend')
@@ -100,8 +81,8 @@ class RawPlugin(ImagerPlugin):
(creatoropts['pkgmgr'],
','.join(backends.keys())))
- creator = raw.RawImageCreator(creatoropts, pkgmgr, opts.compress_image,
- opts.generate_bmap, opts.fstab_entry)
+ creator = raw.RawImageCreator(creatoropts, pkgmgr, args.compress_image,
+ args.generate_bmap, args.fstab_entry)
if len(recording_pkgs) > 0:
creator._recording_pkgs = recording_pkgs
@@ -121,9 +102,10 @@ class RawPlugin(ImagerPlugin):
creator.copy_kernel()
creator.unmount()
creator.generate_bmap()
- creator.package(creatoropts["outdir"])
+ creator.package(creatoropts["destdir"])
+ creator.create_manifest()
if creatoropts['release'] is not None:
- creator.release_output(ksconf, creatoropts['outdir'], creatoropts['release'])
+ creator.release_output(ksconf, creatoropts['destdir'], creatoropts['release'])
creator.print_outimage_info()
except errors.CreatorError:
@@ -166,7 +148,7 @@ class RawPlugin(ImagerPlugin):
else:
root_mounted = False
partition_mounts = 0
- for line in runner.outs([partedcmd,"-s",img,"unit","B","print"]).splitlines():
+ for line in runner.outs([ partedcmd, "-s", img, "unit", "B", "print" ]).splitlines():
line = line.strip()
# Lines that start with number are the partitions,
@@ -178,12 +160,12 @@ class RawPlugin(ImagerPlugin):
line = line.replace(",","")
# Example of parted output lines that are handled:
- # Number Start End Size Type File system Flags
+ # Number Start End Size Type File system Flags
# 1 512B 3400000511B 3400000000B primary
# 2 3400531968B 3656384511B 255852544B primary linux-swap(v1)
- # 3 3656384512B 3720347647B 63963136B primary fat16 boot, lba
+ # 3 3656384512B 3720347647B 63963136B primary fat16 boot, lba
- partition_info = re.split("\s+",line)
+ partition_info = re.split("\s+", line)
size = partition_info[3].split("B")[0]
@@ -193,18 +175,19 @@ class RawPlugin(ImagerPlugin):
# not recognize properly.
# TODO: Can we make better assumption?
fstype = "btrfs"
- elif partition_info[5] in ["ext2","ext3","ext4","btrfs"]:
+ elif partition_info[5] in [ "ext2", "ext3", "ext4", "btrfs" ]:
fstype = partition_info[5]
- elif partition_info[5] in ["fat16","fat32"]:
+ elif partition_info[5] in [ "fat16", "fat32" ]:
fstype = "vfat"
elif "swap" in partition_info[5]:
fstype = "swap"
else:
- raise errors.CreatorError("Could not recognize partition fs type '%s'." % partition_info[5])
+ raise errors.CreatorError("Could not recognize partition fs type '%s'." %
+ partition_info[5])
if rootpart and rootpart == line[0]:
mountpoint = '/'
- elif not root_mounted and fstype in ["ext2","ext3","ext4","btrfs"]:
+ elif not root_mounted and fstype in [ "ext2", "ext3", "ext4", "btrfs" ]:
# TODO: Check that this is actually the valid root partition from /etc/fstab
mountpoint = "/"
root_mounted = True
@@ -220,9 +203,11 @@ class RawPlugin(ImagerPlugin):
else:
boot = False
- msger.verbose("Size: %s Bytes, fstype: %s, mountpoint: %s, boot: %s" % (size, fstype, mountpoint, boot))
+ msger.verbose("Size: %s Bytes, fstype: %s, mountpoint: %s, boot: %s" %
+ (size, fstype, mountpoint, boot))
# TODO: add_partition should take bytes as size parameter.
- imgloop.add_partition((int)(size)/1024/1024, "/dev/sdb", mountpoint, fstype = fstype, boot = boot)
+ imgloop.add_partition((int)(size)/1024/1024, "/dev/sdb", mountpoint,
+ fstype = fstype, boot = boot)
try:
imgloop.mount()