Add the ability to enable DNF plugins for lorax

Pass --dnfplugin='*' to enable all of them.
Pass --dnfplugin='plugin-name' to enable one fo them. You can use it
multiple times to enable multiple plugins. Globs work as well.
This commit is contained in:
Brian C. Lane 2018-06-21 14:43:08 -07:00
parent 86c4ef5f45
commit 56926baaec
2 changed files with 14 additions and 2 deletions

View File

@ -107,6 +107,8 @@ def lorax_parser(dracut_default=""):
help="Size of root filesystem in GiB. Defaults to 2.")
optional.add_argument("--noverifyssl", action="store_true", default=False,
help="Do not verify SSL certificates")
optional.add_argument("--dnfplugin", action="append", default=[], dest="dnfplugins",
help="Enable a DNF plugin by name/glob, or * to enable all of them.")
# dracut arguments
dracut_group = parser.add_argument_group("dracut arguments")

View File

@ -98,7 +98,8 @@ def main():
dnfbase = get_dnf_base_object(installtree, opts.source, opts.mirrorlist, opts.repos,
opts.enablerepos, opts.disablerepos,
dnftempdir, opts.proxy, opts.version, opts.cachedir,
os.path.dirname(opts.logfile), not opts.noverifyssl)
os.path.dirname(opts.logfile), not opts.noverifyssl,
opts.dnfplugins)
if dnfbase is None:
print("error: unable to create the dnf base object", file=sys.stderr)
@ -146,7 +147,7 @@ def main():
def get_dnf_base_object(installroot, sources, mirrorlists=None, repos=None,
enablerepos=None, disablerepos=None,
tempdir="/var/tmp", proxy=None, releasever="29",
cachedir=None, logdir=None, sslverify=True):
cachedir=None, logdir=None, sslverify=True, dnfplugins=None):
""" Create a dnf Base object and setup the repositories and installroot
:param string installroot: Full path to the installroot
@ -193,6 +194,15 @@ def get_dnf_base_object(installroot, sources, mirrorlists=None, repos=None,
os.mkdir(logdir)
dnfbase = dnf.Base()
# Enable DNF pluings
# NOTE: These come from the HOST system's environment
if dnfplugins:
if dnfplugins[0] == "*":
# Enable them all
dnfbase.init_plugins()
else:
# Only enable the listed plugins
dnfbase.init_plugins(disabled_glob=["*"], enable_plugins=dnfplugins)
conf = dnfbase.conf
conf.logdir = logdir
conf.cachedir = cachedir