Ejemplo n.º 1
0
    def run_as_handyrep(self, servername, commands):
        # runs a set of commands as the "handyrep" user
        # exiting when the first command fails
        # returns a dic with the results of the last command
        # run
        env.key_filename = self.servers[servername]["ssh_key"]
        env.user = self.servers[servername]["ssh_user"]
        env.disable_known_hosts = True
        env.host_string = self.servers[servername]["hostname"]
        rundict = { "result": "SUCCESS",
            "details" : "no commands provided",
            "return_code" : None }
        for command in commands:
            try:
                runit = run(command, warn_only=True)
                rundict.update({ "details" : runit ,
                    "return_code" : runit.return_code })
                if runit.succeeded:
                    rundict.update({"result":"SUCCESS"})
                else:
                    rundict.update({"result":"FAIL"})
                    break
            except Exception as ex:
                rundict = { "result" : "FAIL",
                    "details" : "connection failure: %s" % exstr(ex),
                    "return_code" : None }
                break

        disconnect_all()
        return rundict
Ejemplo n.º 2
0
    def run_as_handyrep(self, servername, commands):
        # runs a set of commands as the "handyrep" user
        # exiting when the first command fails
        # returns a dic with the results of the last command
        # run
        lock_fabric()
        env.key_filename = self.servers[servername]["ssh_key"]
        env.user = self.servers[servername]["ssh_user"]
        env.disable_known_hosts = True
        env.host_string = self.servers[servername]["hostname"]
        rundict = {
            "result": "SUCCESS",
            "details": "no commands provided",
            "return_code": None
        }
        for command in commands:
            try:
                runit = run(command, warn_only=True, quiet=True)
                rundict.update({
                    "details": runit,
                    "return_code": runit.return_code
                })
                if runit.succeeded:
                    rundict.update({"result": "SUCCESS"})
                else:
                    rundict.update({"result": "FAIL"})
                    break
            except Exception as ex:
                rundict = {
                    "result": "FAIL",
                    "details": "connection failure: %s" % exstr(ex),
                    "return_code": None
                }
                break

        self.disconnect_and_unlock()
        return rundict
Ejemplo n.º 3
0
 def exstr(self, errorobj):
     return exstr(errorobj)
Ejemplo n.º 4
0
 def exstr(self, errorobj):
     return exstr(errorobj)