Ejemplo n.º 1
0
    def run(self,
            cmd=None,
            stdin=None,
            plan_to=None,
            wipe=False,
            instant=False):
        """
        Add cmd into queue if instant is False, otherwise run instantly
        """
        cmd = cmd or self._default_cmd
        r = Request(action='run' if not wipe else 'run|wipe')
        r.machine = self._server_name()
        r.data = json.dumps({"action": "run", "cmd": cmd, "stdin": stdin})
        r.user = self.user

        if not instant:
            r.plan_to_date = plan_to
            r.save()

        else:
            stdout, stderr, retcode = self._run(cmd, stdin)

            r.done_date = datetime.now()
            r.done = True
            r.stdout = stdout
            r.stderr = stderr
            r.save()

            return stdout, stderr, retcode
Ejemplo n.º 2
0
 def unlink(self, filename, plan_to=None):
     """Add request into queue to unlink filename."""
     r = Request(action='unlink')
     r.machine = self._server_name()
     r.data = json.dumps({"action": "unlink", "filename": filename})
     r.user = self.user
     if plan_to: r.plan_to_date = plan_to
     r.save()
Ejemplo n.º 3
0
 def unlink(self, filename, plan_to=None):
     """Add request into queue to unlink filename."""
     r = Request(action='unlink')
     r.machine = self._server_name()
     r.data = json.dumps({"action": "unlink", "filename": filename})
     r.user = self.user
     if plan_to: r.plan_to_date = plan_to
     r.save()
Ejemplo n.º 4
0
 def write(self, filename, content, plan_to=None):
     """
     Add request into queue to write the content into filename.
     """
     r = Request(action='write')
     r.machine = self._server_name()
     r.data = json.dumps({"action": "write", "filename": filename, "content": content})
     r.user = self.user
     if plan_to: r.plan_to_date = plan_to
     r.save()
Ejemplo n.º 5
0
 def write(self, filename, content, plan_to=None):
     """
     Add request into queue to write the content into filename.
     """
     r = Request(action='write')
     r.machine = self._server_name()
     r.data = json.dumps({"action": "write", "filename": filename, "content": content})
     r.user = self.user
     if plan_to: r.plan_to_date = plan_to
     r.save()
Ejemplo n.º 6
0
    def isfile(self, filename):
        """Return true, if filename is exists."""
        cmd = "if [ `ls %s 2> /dev/null` ]; then echo 1; fi;" % filename

        r = Request(action="read")
        r.machine = self._server_name()
        r.data = json.dumps({"action": "isfile", "cmd": cmd})
        r.user = self.user
        r.save()

        stdout, stderr, retcode = self._run(cmd)

        r.done_date = datetime.today()
        r.done = True
        r.stdout = stdout
        r.stderr = stderr
        r.retcode = retcode

        r.save()

        return stdout.strip() == "1"
Ejemplo n.º 7
0
    def read(self, filename):
        """Read filename promtly."""
        cmd = "cat %s" % filename

        r = Request(action="read")
        r.machine = self._server_name()
        r.data = json.dumps({"action": "read", "cmd": cmd})
        r.user = self.user
        r.save()

        stdout, stderr, retcode = self._run(cmd)

        r.done_date = datetime.today()
        r.done = True
        r.stdout = stdout
        r.stderr = stderr
        r.retcode = retcode

        r.save()

        return stdout
Ejemplo n.º 8
0
    def isfile(self, filename):
        """Return true, if filename is exists."""
        cmd = "if [ `ls %s 2> /dev/null` ]; then echo 1; fi;" % filename

        r = Request(action="read")
        r.machine = self._server_name()
        r.data = json.dumps({"action": "isfile", "cmd": cmd})
        r.user = self.user
        r.save()

        stdout, stderr, retcode = self._run(cmd)

        r.done_date = datetime.today()
        r.done = True
        r.stdout = stdout
        r.stderr = stderr
        r.retcode = retcode

        r.save()

        return stdout.strip() == "1"
Ejemplo n.º 9
0
    def read(self, filename):
        """Read filename promtly."""
        cmd = "cat %s" % filename

        r = Request(action="read")
        r.machine = self._server_name()
        r.data = json.dumps({"action": "read", "cmd": cmd})
        r.user = self.user
        r.save()

        stdout, stderr, retcode = self._run(cmd)

        r.done_date = datetime.today()
        r.done = True
        r.stdout = stdout
        r.stderr = stderr
        r.retcode = retcode

        r.save()

        return stdout
Ejemplo n.º 10
0
    def run(self, cmd=None, stdin=None, plan_to=None, wipe=False, instant=False):
        """
        Add cmd into queue if instant is False, otherwise run instantly
        """
        cmd = cmd or self._default_cmd
        r = Request(action='run' if not wipe else 'run|wipe')
        r.machine = self._server_name()
        r.data = json.dumps({"action": "run", "cmd": cmd, "stdin": stdin})
        r.user = self.user

        if not instant:
            r.plan_to_date = plan_to
            r.save()

        else:
            stdout, stderr, retcode = self._run(cmd, stdin)

            r.done_date = datetime.now()
            r.done = True
            r.stdout = stdout
            r.stderr = stderr
            r.save()

            return stdout, stderr, retcode