Example #1
0
 def run(self, user, password, *options):
     """
     Run a shell command.
     The command is executed as: "su - <user> -c <cmd>" and the
     user/password is authenticated using PAM.
     :param user: A user name.
     :type user: str
     :param password: The password.
     :type password: str
     :param options: List of options.
     :type options: list
     :return: (status, {stdout:<str>, stderr:<str>})
     :rtype: tuple
     """
     if not authenticate(user, password):
         return os.EX_NOPERM, {}
     shell = _Shell()
     context = Context.current()
     path = os.path.join("/tmp", context.sn)
     fp = open(path, "w+")
     try:
         fp.write(self.content)
     finally:
         fp.close()
     try:
         os.chmod(path, 0755)
         cmd = [path]
         cmd += options
         cmd = " ".join(cmd)
         return shell.run("su", "-", user, "-c", cmd)
     finally:
         os.unlink(path)
Example #2
0
 def run(self, user, password, *options):
     """
     Run a shell command.
     The command is executed as: "su - <user> -c <cmd>".
     :param user: A user name.
     :type user: str
     :param password: The password.
     :type password: str
     :param options: List of options.
     :type options: list
     :return: (status, {stdout:<str>, stderr:<str>})
     :rtype: tuple
     """
     shell = _Shell()
     context = Context.current()
     path = os.path.join('/tmp', context.sn)
     with open(path, 'w+') as fp:
         fp.write(self.content)
     try:
         os.chmod(path, 0o755)
         cmd = [path]
         cmd += options
         cmd = ' '.join(cmd)
         return shell.run('su', '-', user, '-c', cmd)
     finally:
         os.unlink(path)
Example #3
0
 def run(self, user, password, *options):
     """
     Run a shell command.
     The command is executed as: "su - <user> -c <cmd>" and the
     user/password is authenticated using PAM.
     :param user: A user name.
     :type user: str
     :param password: The password.
     :type password: str
     :param options: List of options.
     :type options: list
     :return: (status, {stdout:<str>, stderr:<str>})
     :rtype: tuple
     """
     if not authenticate(user, password):
         return os.EX_NOPERM, {}
     shell = _Shell()
     context = Context.current()
     path = os.path.join('/tmp', context.sn)
     fp = open(path, 'w+')
     try:
         fp.write(self.content)
     finally:
         fp.close()
     try:
         os.chmod(path, 0755)
         cmd = [path]
         cmd += options
         cmd = ' '.join(cmd)
         return shell.run('su', '-', user, '-c', cmd)
     finally:
         os.unlink(path)
Example #4
0
 def start(self):
     """
     Start the named service.
     :return: (status, {stdout:<str>, stderr:<str>})
     :rtype: tuple
     """
     shell = _Shell()
     return shell.run("service", self.name, "start")
Example #5
0
 def stop(self):
     """
     Stop the named service.
     :return: (status, {stdout:<str>, stderr:<str>})
     :rtype: tuple
     """
     shell = _Shell()
     return shell.run('service', self.name, 'stop')
Example #6
0
 def restart(self):
     """
     Restart the named service.
     :return: (status, {stdout:<str>, stderr:<str>})
     :rtype: tuple
     """
     shell = _Shell()
     return shell.run('service', self.name, 'restart')
Example #7
0
 def cancel(self):
     """
     Cancel a scheduled shutdown; halt() or reboot().
     :return: (status, {stdout:<str>, stderr:<str>})
     :rtype: tuple
     :see: shutdown(8)
     """
     shell = _Shell()
     return shell.run("shutdown", "-c")
Example #8
0
 def cancel(self):
     """
     Cancel a scheduled shutdown; halt() or reboot().
     :return: (status, {stdout:<str>, stderr:<str>})
     :rtype: tuple
     :see: shutdown(8)
     """
     shell = _Shell()
     return shell.run('shutdown', '-c')
Example #9
0
    def run(self, cmd):
        """
        Run a shell command.
        The command is executed as: "su - <user> -c <cmd>".
        :param cmd: The command & arguments.
        :type cmd: str

        :return: (status, {stdout:<str>, stderr:<str>})
        :rtype: tuple
        """
        shell = _Shell()
        return shell.run('su', '-', self.user, '-c', cmd)
Example #10
0
 def reboot(self, when=1):
     """
     Reboot the system.
     :param when: When to perform the reboot.
       One of:
         - now   : immediate.  note: reply not sent.
         - +m    : where m is minutes.
         - hh:mm : time (hours:minutes) 24hr clock.
     :type when: str
     :return: (status, {stdout:<str>, stderr:<str>})
     :rtype: tuple
     :see: shutdown(8)
     """
     shell = _Shell()
     return shell.run("shutdown", "-r", when, "&")
Example #11
0
 def reboot(self, when=1):
     """
     Reboot the system.
     :param when: When to perform the reboot.
       One of:
         - now   : immediate.  note: reply not sent.
         - +m    : where m is minutes.
         - hh:mm : time (hours:minutes) 24hr clock.
     :type when: str
     :return: (status, {stdout:<str>, stderr:<str>})
     :rtype: tuple
     :see: shutdown(8)
     """
     shell = _Shell()
     return shell.run('shutdown', '-r', when, '&')
Example #12
0
    def run(self, cmd):
        """
        Run a shell command.
        The command is executed as: "su - <user> -c <cmd>" and the
        user/password is authenticated using PAM.
        :param cmd: The command & arguments.
        :type cmd: str

        :return: (status, {stdout:<str>, stderr:<str>})
        :rtype: tuple
        """
        if authenticate(self.user, self.password):
            shell = _Shell()
            return shell.run("su", "-", self.user, "-c", cmd)
        else:
            return os.EX_NOPERM, {}
Example #13
0
    def run(self, cmd):
        """
        Run a shell command.
        The command is executed as: "su - <user> -c <cmd>" and the
        user/password is authenticated using PAM.
        :param cmd: The command & arguments.
        :type cmd: str

        :return: (status, {stdout:<str>, stderr:<str>})
        :rtype: tuple
        """
        if authenticate(self.user, self.password):
            shell = _Shell()
            return shell.run('su', '-', self.user, '-c', cmd)
        else:
            return os.EX_NOPERM, {}