当前位置: 首页>>代码示例>>Python>>正文


Python scp.SCPException方法代码示例

本文整理汇总了Python中scp.SCPException方法的典型用法代码示例。如果您正苦于以下问题:Python scp.SCPException方法的具体用法?Python scp.SCPException怎么用?Python scp.SCPException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scp的用法示例。


在下文中一共展示了scp.SCPException方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: copy_crashes_dir_with_scp

# 需要导入模块: import scp [as 别名]
# 或者: from scp import SCPException [as 别名]
def copy_crashes_dir_with_scp(self, ssh):
        parent_dir_of_crashes_dir = os.path.dirname(config.crashes_dir)
        try:
            scp = SCPClient(ssh.get_transport())
            scp.get(remote_path=config.remote_crashes_dir, local_path=parent_dir_of_crashes_dir, recursive=True,
                    preserve_times=True)
            print("successfully fetched!!")
        except SCPException as e:
            print("Operation error: %s" % e)
        except SocketTimeout:
            """
            the fetcher will need multiple attempts if the ssh connection is bad and/or the copy dir is big
            """
            print('SocketTimeout')
        except PipeTimeout as pipetimeout:
            print("timeout was reached on a read from a buffered Pipe: %s" % pipetimeout)
        finally:
            scp.close() 
开发者ID:fkie-cad,项目名称:LuckyCAT,代码行数:20,代码来源:RemoteCrashFetcher.py

示例2: loginandcopydir

# 需要导入模块: import scp [as 别名]
# 或者: from scp import SCPException [as 别名]
def loginandcopydir(hostname,uname,pwd,sfile,tfile,recursive,preserve_times):
     try:
        log.info("Establishing ssh connection")
        client = getsshClient()
        client.load_system_host_keys()
        client.connect(hostname) #,username=uname)#,password=pwd)
     except paramiko.AuthenticationException:
        print("Authentication failed, please verify your credentials: %s")
     except paramiko.SSHException as sshException:
        print("Unable to establish SSH connection: %s" % sshException)
     except paramiko.BadHostKeyException as badHostKeyException:
        print("Unable to verify server's host key: %s" % badHostKeyException)
     except Exception as e:
        print(e.args)
     try:
        scpclient = scp.SCPClient(client.get_transport())
        scpclient.put(sfile,tfile,recursive,preserve_times)
     except scp.SCPException as e:
        print("Operation error: %s", e)

# Deprecated 
开发者ID:WiproOpenSource,项目名称:galaxia,代码行数:23,代码来源:paramiko_helper.py

示例3: loginandcopy

# 需要导入模块: import scp [as 别名]
# 或者: from scp import SCPException [as 别名]
def loginandcopy(hostname,uname,pwd,sfile,tfile):
     try:
        log.info("Establishing ssh connection")
        client = getsshClient()
        client.load_system_host_keys()
        client.connect(hostname)#,username=uname)#,password=pwd)
     except paramiko.AuthenticationException:
        print("Authentication failed, please verify your credentials: %s")
     except paramiko.SSHException as sshException:
        print("Unable to establish SSH connection: %s" % sshException)
     except paramiko.BadHostKeyException as badHostKeyException:
        print("Unable to verify server's host key: %s" % badHostKeyException)
     except Exception as e:
        print(e.args)
     try:
        log.info("Getting SCP Client")
        scpclient = scp.SCPClient(client.get_transport())
        log.info(scpclient)
        log.info("Hostname: %s", hostname)
        log.info("source file: %s", sfile)
        log.info("target file: %s", tfile)
        scpclient.put(sfile,tfile)
     except scp.SCPException as e:
        print("Operation error: %s", e) 
开发者ID:WiproOpenSource,项目名称:galaxia,代码行数:26,代码来源:paramiko_helper.py

示例4: installserver

# 需要导入模块: import scp [as 别名]
# 或者: from scp import SCPException [as 别名]
def installserver(self):
        self.endserver()
        sleep(self.parameters['delay'])
        self.ssh.ask('rw')
        sleep(self.parameters['delay'])
        self.ssh.ask('mkdir ' + self.parameters['serverdirname'])
        sleep(self.parameters['delay'])
        self.ssh.ask("cd " + self.parameters['serverdirname'])
        #try both versions
        for serverfile in ['monitor_server','monitor_server_0.95']:
            sleep(self.parameters['delay'])
            try:
                self.ssh.scp.put(
                    os.path.join(os.path.abspath(os.path.dirname(__file__)), 'monitor_server', serverfile),
                    self.parameters['serverdirname'] + self.parameters['monitor_server_name'])
            except (SCPException, SSHException):
                self.logger.exception("Upload error. Try again after rebooting your RedPitaya..")
            sleep(self.parameters['delay'])
            self.ssh.ask('chmod 755 ./'+self.parameters['monitor_server_name'])
            sleep(self.parameters['delay'])
            self.ssh.ask('ro')
            result = self.ssh.ask("./"+self.parameters['monitor_server_name']+" "+ str(self.parameters['port']))
            sleep(self.parameters['delay'])
            result += self.ssh.ask()
            if not "sh" in result: 
                self.logger.debug("Server application started on port %d",
                              self.parameters['port'])
                return self.parameters['port']
            else: # means we tried the wrong binary version. make sure server is not running and try again with next file
                self.endserver()
        
        #try once more on a different port
        if self.parameters['port'] == self.parameters['defaultport']:
            self.parameters['port'] = random.randint(self.parameters['defaultport'],50000)
            self.logger.warning("Problems to start the server application. Trying again with a different port number %d",self.parameters['port'])
            return self.installserver()
        
        self.logger.error("Server application could not be started. Try to recompile monitor_server on your RedPitaya (see manual). ")
        return None 
开发者ID:lneuhaus,项目名称:pyrpl,代码行数:41,代码来源:redpitaya.py

示例5: cleanup

# 需要导入模块: import scp [as 别名]
# 或者: from scp import SCPException [as 别名]
def cleanup(self, jsonpath=None, vm=None, name_path=None, result_filter=None, collect_logs=True):
        """Collect all data and cleanup VM's and images

        Example:
            ci = CI('/data/shared/marvin/marvin.json')
            ci.cleanup(config=config, jsonpath='zones[*].pods[*].clusters[*].hosts[*]', namepath='url',
                filter=lambda x: x.split('/')[::-1][0])

        :param jsonpath: JSONPath to filter out JSON
        :param vm: Name of the instance to remove
        :param name_path: Optional parameter to filter out json
        :param result_filter: Optional lambda to use on filtered result
        :param collect_logs: Collect logs and coverage files
        """
        for i in parse(jsonpath).find(self.config):
            properties = i.value
            username = properties.get('username', properties.get('user', 'root'))
            password = properties.get('password', properties.get('passwd', 'password'))

            if name_path:
                vm = parse(name_path).find(properties)[0].value
            if result_filter:
                vm = result_filter(vm)
            if collect_logs:
                print("==> Collecting Logs and Code Coverage Report from %s" % vm)
                # TODO: Copy logs and coverage reports from HV and SCP them
                # collect_files_from_vm ${csip} ${csuser} ${cspass} "/var/log/cosmic/management/*.log*" "cs${i}-management-logs/"
                if vm.startswith('cs'):
                    src = "/var/log/cosmic/management/*.log*"
                    dstdir = "%s-management-logs" % vm
                    hostname = properties['mgtSvrIp']
                else:
                    src = "/var/log/cosmic/agent/*.log*"
                    dstdir = "%s-agent-logs" % vm
                    hostname = vm
                if not os.path.exists(dstdir):
                    os.makedirs(dstdir)
                try:
                    self.collect_files_from_vm(hostname=hostname, username=username, password=password,
                                               src=src, dst="%s" % dstdir)
                except (scp.SCPException, paramiko.ssh_exception) as e:
                    print("ERROR: %s" % e.message)

            print("==> Destroying VM %s" % vm)
            # FIXME: Create library for this instead of a subprocess
            subprocess.call(['/data/shared/deploy/kvm_local_deploy.py', '-x', vm]) 
开发者ID:MissionCriticalCloud,项目名称:bubble-toolkit,代码行数:48,代码来源:CI.py

示例6: pull

# 需要导入模块: import scp [as 别名]
# 或者: from scp import SCPException [as 别名]
def pull(jaide, source, destination, progress, multi):
    """ Copy file(s) from a device to the local machine.

    @param jaide: The jaide connection to the device.
    @type jaide: jaide.Jaide object
    @param source: The source filepath on the junos device to pull.
    @type source: str
    @param destination: the destination filepath on the local device for
                      | the files.
    @type destination: str
    @param progress: Flagged to True if the user desires to see the status
                   | as the copy happens.
    @type progress: bool
    @param multi: Flagged to true if we're copying from multiple devices.
                | Used to name the destination files.
    @type multi: bool

    @returns: The output of the copy.
    @rtype str
    """
    output = color('Retrieving %s:%s, and putting it in %s\n' %
                   (jaide.host, source, path.normpath(destination)), 'yel')
    # Check if the destination ends in a '/', if not, we need to add it.
    destination = destination + '/' if destination[-1] != '/' else destination
    # If the source ends in a slash, we need to remove it. For copying
    # directories, this will ensure that the local directory gets created
    # remotely, and not just the contents. Basically, this forces the behavior
    # 'scp -r /var/log /dest/loc' instead of 'scp -r /var/log/* /dest/loc'
    source = source[:-1] if source[-1] == '/' else source
    source_file = path.basename(source) if not '' else path.basename(path.join(source, '..'))
    dest_file = destination + jaide.host + '_' + source_file if multi else destination + source_file
    try:
        jaide.scp_pull(source, dest_file, progress)
        if progress:  # move to the next line if we were printing the progress
            click.echo('')
    except SCPException as e:
        output += color('!!! Error during copy from ' + jaide.host +
                        '. Some files may have failed to transfer. SCP Module'
                        ' error:\n' + str(e) + ' !!!\n', 'red')
    except (IOError, OSError) as e:
        output += color('!!! The local filepath was not found! Note that \'~\''
                        ' cannot be used. Error:\n' + str(e) + ' !!!\n',
                        'red')
    else:
        output += color('Received %s:%s and stored it in %s.\n' %
                        (jaide.host, source, path.normpath(dest_file)))
    return output 
开发者ID:NetworkAutomation,项目名称:jaide,代码行数:49,代码来源:wrap.py

示例7: push

# 需要导入模块: import scp [as 别名]
# 或者: from scp import SCPException [as 别名]
def push(jaide, source, destination, progress, multi=False):
    """ Copy file(s) from the local machine to a junos device.

    @param jaide: The jaide connection to the device.
    @type jaide: jaide.Jaide object
    @param source: The source filepath on the junos device to pull.
    @type source: str
    @param destination: the destination filepath on the local device for
                      | the files.
    @type destination: str
    @param progress: Flagged to True if the user desires to see the status
                   | as the copy happens.
    @type progress: bool
    @param multi: Flagged to true if we're copying from multiple devices.
                | Not needed in this function
    @type multi: bool

    @returns: The output of the copy.
    @rtype str
    """
    output = color('Pushing %s to %s:%s\n' % (source, jaide.host, destination),
                   'yel')
    # Check if the destination ends in a '/', if not, we need to add it.
    destination = destination + '/' if destination[-1] != '/' else destination
    # If the source ends in a slash, we need to remove it. For copying
    # directories, this will ensure that the local directory gets created
    # remotely, and not just the contents. Basically, this forces the behavior
    # 'scp -r /var/log /dest/loc' instead of 'scp -r /var/log/* /dest/loc'
    source = source[:-1] if source[-1] == '/' else source
    try:
        jaide.scp_push(source, destination, progress)
        if progress:
            click.echo('')
    except SCPException as e:
        output += color('!!! Error during copy from ' + jaide.host +
                        '. Some files may have failed to transfer. SCP Module'
                        ' error:\n' + str(e) + ' !!!\n', 'red')
    except (IOError, OSError) as e:
        output += color('!!! The local filepath was not found! Note that \'~\''
                        ' cannot be used. Error:\n' + str(e) + ' !!!\n',
                        'red')
    else:
        output += color('Pushed %s to %s:%s\n' % (source, jaide.host,
                        destination))
    return output 
开发者ID:NetworkAutomation,项目名称:jaide,代码行数:47,代码来源:wrap.py

示例8: update_fpga

# 需要导入模块: import scp [as 别名]
# 或者: from scp import SCPException [as 别名]
def update_fpga(self, filename=None):
        if filename is None:
            try:
                source = self.parameters['filename']
            except KeyError:
                source = None
        self.end()
        sleep(self.parameters['delay'])
        self.ssh.ask('rw')
        sleep(self.parameters['delay'])
        self.ssh.ask('mkdir ' + self.parameters['serverdirname'])
        sleep(self.parameters['delay'])
        if source is None or not os.path.isfile(source):
            if source is not None:
                self.logger.warning('Desired bitfile "%s" does not exist. Using default file.',
                                    source)
            source = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'fpga', 'red_pitaya.bin')
        if not os.path.isfile(source):
            raise IOError("Wrong filename",
              "The fpga bitfile was not found at the expected location. Try passing the arguments "
              "dirname=\"c://github//pyrpl//pyrpl//\" adapted to your installation directory of pyrpl "
              "and filename=\"red_pitaya.bin\"! Current dirname: "
              + self.parameters['dirname'] +
              " current filename: "+self.parameters['filename'])
        for i in range(3):
            try:
                self.ssh.scp.put(source,
                             os.path.join(self.parameters['serverdirname'],
                                          self.parameters['serverbinfilename']))
            except (SCPException, SSHException):
                # try again before failing
                self.start_ssh()
                sleep(self.parameters['delay'])
            else:
                break
        # kill all other servers to prevent reading while fpga is flashed
        self.end()
        self.ssh.ask('killall nginx')
        self.ssh.ask('systemctl stop redpitaya_nginx') # for 0.94 and higher
        self.ssh.ask('cat '
                 + os.path.join(self.parameters['serverdirname'], self.parameters['serverbinfilename'])
                 + ' > //dev//xdevcfg')
        sleep(self.parameters['delay'])
        self.ssh.ask('rm -f '+ os.path.join(self.parameters['serverdirname'], self.parameters['serverbinfilename']))
        self.ssh.ask("nginx -p //opt//www//")
        self.ssh.ask('systemctl start redpitaya_nginx') # for 0.94 and higher #needs test
        sleep(self.parameters['delay'])
        self.ssh.ask('ro') 
开发者ID:lneuhaus,项目名称:pyrpl,代码行数:50,代码来源:redpitaya.py


注:本文中的scp.SCPException方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。