Beispiel #1
0
 def get(self, path, target_path):
     try:
         if not self.local:
             with fabric.api.settings(host_string=self.host,
                                      timeout=2, warn_only=True):
                 logger.debug("Getting remote file: %s %s",
                              path, target_path)
                 return fabric.api.get(path, target_path)
         else:
             logger.debug("Getting local file: cp -r %s %s",
                          path, target_path)
             execute("mkdir -p %s" % os.path.dirname(target_path))
             return execute("cp -r %s %s" % (path, target_path))
     except Exception as e:
         logger.error("Error occured: %s", str(e))
Beispiel #2
0
 def get(self, path, target_path):
     """target_path must be the directory where to put
     copied files or directories
     """
     try:
         if not self.local:
             with fabric.api.settings(host_string=self.host,
                                      timeout=2, warn_only=True):
                 logger.debug("Getting remote file: %s %s",
                              path, target_path)
                 execute("mkdir -p %s" % target_path)
                 return fabric.api.get(path, target_path)
         else:
             logger.debug("Getting local file: cp -r %s %s",
                          path, target_path)
             execute("mkdir -p %s" % target_path)
             return execute("cp -r %s %s" % (path, target_path))
     except Exception as e:
         logger.error("Error occured: %s", str(e))
Beispiel #3
0
 def command(self, command):
     out = CommandOut()
     try:
         if not self.local:
             with fabric.api.settings(host_string=self.host,
                                      timeout=2, warn_only=True):
                 logger.debug("Running remote command: "
                              "host: %s command: %s", self.host, command)
                 output = fabric.api.run(command, pty=True)
                 out.stdout = output
                 out.return_code = output.return_code
                 out.stderr = output.stderr
         else:
             logger.debug("Running local command: %s", command)
             out.return_code, out.stdout, out.stderr = execute(command)
         logger.debug("Stderr: %s", out.stderr)
     except Exception as e:
         logger.error("Error occured: %s", str(e))
     return out
Beispiel #4
0
 def get(self, path, target_path):
     """target_path must be the directory where to put
     copied files or directories
     """
     try:
         if not self.local:
             with fabric.api.settings(host_string=self.host,
                                      timeout=2,
                                      warn_only=True):
                 logger.debug("Getting remote file: %s %s", path,
                              target_path)
                 execute("mkdir -p %s" % target_path)
                 return fabric.api.get(path, target_path)
         else:
             logger.debug("Getting local file: cp -r %s %s", path,
                          target_path)
             execute("mkdir -p %s" % target_path)
             return execute("cp -r %s %s" % (path, target_path))
     except Exception as e:
         logger.error("Error occured: %s", str(e))
Beispiel #5
0
 def command(self, command):
     out = CommandOut()
     try:
         if not self.local:
             with fabric.api.settings(host_string=self.host,
                                      timeout=2,
                                      warn_only=True):
                 logger.debug(
                     "Running remote command: "
                     "host: %s command: %s", self.host, command)
                 output = fabric.api.run(command, pty=True)
                 out.stdout = output
                 out.return_code = output.return_code
                 out.stderr = output.stderr
         else:
             logger.debug("Running local command: %s", command)
             out.return_code, out.stdout, out.stderr = execute(command)
         logger.debug("Stderr: %s", out.stderr)
     except Exception as e:
         logger.error("Error occured: %s", str(e))
     return out