当前位置: 首页>>代码示例>>Python>>正文


Python iutil.execWithRedirect函数代码示例

本文整理汇总了Python中pyanaconda.iutil.execWithRedirect函数的典型用法代码示例。如果您正苦于以下问题:Python execWithRedirect函数的具体用法?Python execWithRedirect怎么用?Python execWithRedirect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了execWithRedirect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUserSshKey

    def setUserSshKey(self, username, key, **kwargs):
        childpid = self._prepareChroot(kwargs.get("root", iutil.getSysroot()))

        if childpid == 0:
            user = self.admin.lookupUserByName(username)
            if not user:
                log.error("setUserSshKey: user %s does not exist", username)
                os._exit(1)

            homedir = user.get(libuser.HOMEDIRECTORY)[0]
            if not os.path.exists(homedir):
                log.error("setUserSshKey: home directory for %s does not exist", username)
                os._exit(1)

            sshdir = os.path.join(homedir, ".ssh")
            if not os.path.isdir(sshdir):
                os.mkdir(sshdir, 0o700)
                iutil.eintr_retry_call(os.chown, sshdir, user.get(libuser.UIDNUMBER)[0], user.get(libuser.GIDNUMBER)[0])

            authfile = os.path.join(sshdir, "authorized_keys")
            authfile_existed = os.path.exists(authfile)
            with open(authfile, "a") as f:
                f.write(key + "\n")

            # Only change mode and ownership if we created it
            if not authfile_existed:
                iutil.eintr_retry_call(os.chmod, authfile, 0o600)
                iutil.eintr_retry_call(os.chown, authfile, user.get(libuser.UIDNUMBER)[0], user.get(libuser.GIDNUMBER)[0])
                iutil.execWithRedirect("restorecon", ["-r", sshdir])
            os._exit(0)
        else:
            return self._finishChroot(childpid)
开发者ID:KosiehBarter,项目名称:anaconda,代码行数:32,代码来源:users.py

示例2: input

    def input(self, args, key):
        """Override input so that we can launch the VNC password spoke"""

        try:
            keyid = int(key) - 1
            if 0 <= keyid < len(self._choices):
                choice = self._choices[keyid]
                if choice == _(USETEXT):
                    self._usevnc = False
                else:
                    self._usevnc = True
                    newspoke = VNCPassSpoke(self.app, self.data, self.storage,
                                            self.payload, self.instclass)
                    self.app.switch_screen_modal(newspoke)

                self.apply()
                self.close()
            return INPUT_PROCESSED
        except ValueError:
            pass

        # TRANSLATORS: 'q' to quit
        if key.lower() == C_('TUI|Spoke Navigation', 'q'):
            d = YesNoDialog(self.app, _(self.app.quit_message))
            self.app.switch_screen_modal(d)
            if d.answer:
                iutil.ipmi_report(IPMI_ABORTED)
                if can_touch_runtime_system("Quit and Reboot"):
                    execWithRedirect("systemctl", ["--no-wall", "reboot"])
                else:
                    exit(1)
        else:
            return key
开发者ID:thaygiaoth,项目名称:anaconda,代码行数:33,代码来源:askvnc.py

示例3: setUserSshKey

    def setUserSshKey(self, username, key, **kwargs):
        root = kwargs.get("root", iutil.getSysroot())

        pwent = self._getpwnam(username, root)
        if not pwent:
            raise ValueError("setUserSshKey: user %s does not exist" % username)

        homedir = root + pwent[5]
        if not os.path.exists(homedir):
            log.error("setUserSshKey: home directory for %s does not exist", username)
            raise ValueError("setUserSshKey: home directory for %s does not exist" % username)

        uid = pwent[2]
        gid = pwent[3]

        sshdir = os.path.join(homedir, ".ssh")
        if not os.path.isdir(sshdir):
            os.mkdir(sshdir, 0o700)
            os.chown(sshdir, int(uid), int(gid))

        authfile = os.path.join(sshdir, "authorized_keys")
        authfile_existed = os.path.exists(authfile)
        with iutil.open_with_perm(authfile, "a", 0o600) as f:
            f.write(key + "\n")

        # Only change ownership if we created it
        if not authfile_existed:
            os.chown(authfile, int(uid), int(gid))
            iutil.execWithRedirect("restorecon", ["-r", sshdir])
开发者ID:dougsland,项目名称:anaconda,代码行数:29,代码来源:users.py

示例4: time_initialize

def time_initialize(timezone, storage, bootloader):
    """
    Try to guess if RTC uses UTC time or not, set timezone.isUtc properly and
    set system time from RTC using the UTC guess.
    Guess is done by searching for bootable ntfs devices.

    :param timezone: ksdata.timezone object
    :param storage: blivet.Blivet instance
    :param bootloader: bootloader.Bootloader instance

    """

    if arch.is_s390():
        # nothing to do on s390(x) were hwclock doesn't exist
        return

    if not timezone.isUtc and not flags.automatedInstall:
        # if set in the kickstart, no magic needed here
        threadMgr.wait(THREAD_STORAGE)
        ntfs_devs = filter(lambda dev: dev.format.name == "ntfs",
                           storage.devices)

        timezone.isUtc = not bootloader.has_windows(ntfs_devs)

    cmd = "hwclock"
    args = ["--hctosys"]
    if timezone.isUtc:
        args.append("--utc")
    else:
        args.append("--localtime")

    iutil.execWithRedirect(cmd, args)
开发者ID:jaymzh,项目名称:anaconda,代码行数:32,代码来源:timezone.py

示例5: execute

    def execute(self, storage, ksdata, instClass, users, payload):
        """ Execute the addon

        :param storage: Blivet storage object
        :param ksdata: Kickstart data object
        :param instClass: Anaconda installclass object
        :param users: Anaconda users object
        :param payload: object managing packages and environment groups
                        for the installation
        """
        if not self.enabled:
            return

        log.info("Executing docker addon")
        # This gets called after installation, before initramfs regeneration and kickstart %post scripts.
        execWithRedirect("mount", ["-o", "bind", getSysroot()+"/var/lib/docker", "/var/lib/docker"])
        execWithRedirect("mount", ["-o", "bind", getSysroot()+"/etc/docker", "/etc/docker"])

        # Start up the docker daemon
        log.debug("Starting docker daemon")
        docker_cmd = ["docker", "daemon"]
        if ksdata.selinux.selinux:
            docker_cmd += ["--selinux-enabled"]

        # Add storage specific arguments to the command
        docker_cmd += self.storage.docker_cmd(storage, ksdata, instClass, users)

        docker_cmd += ["--ip-forward=false", "--iptables=false"]
        docker_cmd += self.extra_args
        docker_proc = startProgram(docker_cmd, stdout=open("/tmp/docker-daemon.log", "w"), reset_lang=True)

        log.debug("Running docker commands")
        script = AnacondaKSScript(self.content, inChroot=False, logfile="/tmp/docker-addon.log")
        script.run("/")

        # Kill the docker process
        log.debug("Shutting down docker daemon")
        docker_proc.kill()

        log.debug("Writing docker configs")
        self.storage.write_configs(storage, ksdata, instClass, users)

        # Rewrite the OPTIONS entry with the extra args and/or storage specific changes
        try:
            docker_cfg = SimpleConfigFile(getSysroot()+"/etc/sysconfig/docker")
            docker_cfg.read()
            options = self.storage.options(docker_cfg.get("OPTIONS"))
            if self.save_args:
                log.info("Adding extra args to docker OPTIONS")
                options += " " + " ".join(self.extra_args)
            docker_cfg.set(("OPTIONS", options))
            docker_cfg.write()
        except IOError as e:
            log.error("Error updating OPTIONS in /etc/sysconfig/docker: %s", e)

        # Copy the log files to the system
        dstdir = "/var/log/anaconda/"
        os.makedirs(dstdir, exist_ok=True)
        for l in ["docker-daemon.log", "docker-addon.log"]:
            shutil.copy2("/tmp/"+l, dstdir+l)
开发者ID:rhinstaller,项目名称:docker-anaconda-addon,代码行数:60,代码来源:docker.py

示例6: _startLldpad

    def _startLldpad(self):
        if self.lldpadStarted:
            return

        iutil.execWithRedirect("lldpad", [ "-d" ],
                               stdout = "/dev/tty5", stderr="/dev/tty5")
        self.lldpadStarted = True
开发者ID:mattias-ohlsson,项目名称:anaconda,代码行数:7,代码来源:fcoe.py

示例7: runShell

def runShell(screen=None, msg=""):
    if screen:
        screen.suspend()

    print()
    if msg:
        print(msg)

    if flags.imageInstall:
        print(_("Run %s to unmount the system when you are finished.")
              % ANACONDA_CLEANUP)
    else:
        print(_("When finished please exit from the shell and your "
                "system will reboot."))
    print()

    proc = None

    if os.path.exists("/usr/bin/firstaidkit-qs"):
        iutil.execWithRedirect("/usr/bin/firstaidkit-qs", [])

    if proc is None or proc.returncode != 0:
        if os.path.exists("/bin/bash"):
            iutil.execConsole()
        else:
            print(_("Unable to find /bin/sh to execute!  Not starting shell"))
            time.sleep(5)

    if screen:
        screen.finish()
开发者ID:jresch,项目名称:anaconda,代码行数:30,代码来源:rescue.py

示例8: exec_with_redirect_test

    def exec_with_redirect_test(self):
        """Test execWithRedirect."""
        # correct calling should return rc==0
        self.assertEqual(iutil.execWithRedirect('ls', []), 0)

        # incorrect calling should return rc!=0
        self.assertNotEqual(iutil.execWithRedirect('ls', ['--asdasd']), 0)
开发者ID:cyclefusion,项目名称:anaconda,代码行数:7,代码来源:iutil_test.py

示例9: recreateInitrds

    def recreateInitrds(self, force=False):
        """ Recreate the initrds by calling new-kernel-pkg

            This needs to be done after all configuration files have been
            written, since dracut depends on some of them.

            :param force: Always recreate, default is to only do it on first call
            :type force: bool
            :returns: None
        """
        if not force and self._createdInitrds:
            return

        for kernel in self.kernelVersionList:
            log.info("recreating initrd for %s", kernel)
            if not flags.imageInstall:
                iutil.execWithRedirect("new-kernel-pkg",
                                       ["--mkinitrd", "--dracut",
                                        "--depmod", "--update", kernel],
                                       root=ROOT_PATH)
            else:
                # hostonly is not sensible for disk image installations
                # using /dev/disk/by-uuid/ is necessary due to disk image naming
                iutil.execWithRedirect("dracut",
                                       ["-N",
                                        "--persistent-policy", "by-uuid",
                                        "-f", "/boot/initramfs-%s.img" % kernel,
                                        kernel],
                                        root=ROOT_PATH)

        self._createdInitrds = True
开发者ID:akozumpl,项目名称:anaconda,代码行数:31,代码来源:__init__.py

示例10: input

    def input(self, args, key):
        """Move along home."""
        run_shell()

        if not flags.imageInstall:
            iutil.execWithRedirect("systemctl", ["--no-wall", "reboot"])

        return INPUT_PROCESSED
开发者ID:rtruxal,项目名称:anaconda,代码行数:8,代码来源:rescue.py

示例11: has_fcoe

def has_fcoe():
    global _fcoe_module_loaded
    if not _fcoe_module_loaded:
        iutil.execWithRedirect("modprobe", [ "fcoe" ],
                               stdout = "/dev/tty5", stderr="/dev/tty5")
        _fcoe_module_loaded = True

    return os.access("/sys/module/fcoe", os.X_OK)
开发者ID:masami256,项目名称:Anaconda-for-ore-ore-kernel,代码行数:8,代码来源:fcoe.py

示例12: execute

    def execute(self, storage, ksdata, instClass, users):
        """ Execute the addon

        :param storage: Blivet storage object
        :param ksdata: Kickstart data object
        :param instClass: Anaconda installclass object
        :param users: Anaconda users object
        """
        log.info("Executing docker addon")
        # This gets called after installation, before initramfs regeneration and kickstart %post scripts.
        execWithRedirect("mount", ["-o", "bind", getSysroot()+"/var/lib/docker", "/var/lib/docker"])
        execWithRedirect("mount", ["-o", "bind", getSysroot()+"/etc/docker", "/etc/docker"])

        # Start up the docker daemon
        log.debug("Starting docker daemon")
        dm_fs = "dm.fs=%s" % self.fstype
        pool_name = "dm.thinpooldev=/dev/mapper/%s-docker--pool" % self.vgname
        docker_cmd = ["docker", "daemon"]
        if ksdata.selinux.selinux:
            docker_cmd += ["--selinux-enabled"]
        docker_cmd += ["--storage-driver", "devicemapper",
                      "--storage-opt", dm_fs,
                      "--storage-opt", pool_name, "--ip-forward=false", "--iptables=false"]
        docker_cmd += self.extra_args
        docker_proc = startProgram(docker_cmd, stdout=open("/tmp/docker-daemon.log", "w"), reset_lang=True)

        log.debug("Running docker commands")
        script = AnacondaKSScript(self.content, inChroot=False, logfile="/tmp/docker-addon.log")
        script.run("/")

        # Kill the docker process
        log.debug("Shutting down docker daemon")
        docker_proc.kill()

        log.debug("Writing docker configs")
        with open(getSysroot()+"/etc/sysconfig/docker-storage", "w") as fp:
            fp.write('DOCKER_STORAGE_OPTIONS="--storage-driver devicemapper '
                     '--storage-opt %s --storage-opt %s"\n' % (dm_fs, pool_name))

        with open(getSysroot()+"/etc/sysconfig/docker-storage-setup", "a") as fp:
            fp.write("VG=%s\n" % self.vgname)

        # Rewrite the OPTIONS entry with the extra args, if requested.
        if self.extra_args and self.save_args:
            try:
                docker_cfg = SimpleConfigFile(getSysroot()+"/etc/sysconfig/docker")
                docker_cfg.read()
                options = docker_cfg.get("OPTIONS")+" " + " ".join(self.extra_args)
                docker_cfg.set(("OPTIONS", options))
                docker_cfg.write()
            except IOError as e:
                log.error("Error updating OPTIONS in /etc/sysconfig/docker: %s", e)

        # Copy the log files to the system
        dstdir = "/var/log/anaconda/"
        os.makedirs(dstdir, exist_ok=True)
        for l in ["docker-daemon.log", "docker-addon.log"]:
            shutil.copy2("/tmp/"+l, dstdir+l)
开发者ID:bcl,项目名称:docker-anaconda-addon,代码行数:58,代码来源:docker.py

示例13: delete_interfaces

 def delete_interfaces(self):
     if not self.ifaces:
         return None
     for iscsi_iface_name in self.ifaces:
         #iscsiadm -m iface -I iface0 --op=delete
         iutil.execWithRedirect("iscsiadm",
                                ["-m", "iface", "-I", iscsi_iface_name,
                                 "--op=delete"],
                                stdout="/dev/tty5",
                                stderr="/dev/tty5")
     self.ifaces = {}
开发者ID:mattias-ohlsson,项目名称:anaconda,代码行数:11,代码来源:iscsi.py

示例14: set_x_resolution

def set_x_resolution(runres):
    """Set X server screen resolution.

    :param str runres: a resolution specification string
    """
    try:
        log.info("Setting the screen resolution to: %s.", runres)
        iutil.execWithRedirect("xrandr", ["-d", ":1", "-s", runres])
    except RuntimeError:
        log.error("The X resolution was not set")
        iutil.execWithRedirect("xrandr", ["-d", ":1", "-q"])
开发者ID:dougsland,项目名称:anaconda,代码行数:11,代码来源:display.py

示例15: execute

    def execute(self, storage, ksdata, instClass, users):
        # Write out the config file
        with open(os.path.normpath(ROOT_PATH + CONFIG_FILE), "w") as fobj:
            fobj.write("%s" % self.content)

        if self.enabled:
            action = "enable"
        else:
            action = "disable"

        iutil.execWithRedirect("systemctl", [action, "kdump.service"], root=ROOT_PATH)
开发者ID:bcl,项目名称:kdump-anaconda-addon,代码行数:11,代码来源:kdump.py


注:本文中的pyanaconda.iutil.execWithRedirect函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。