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
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
def exstr(self, errorobj): return exstr(errorobj)