Exemplo n.º 1
0
def get_copy(host):
    '''copy a remote file to local file'''
    log(ok=True, msg="start to copy...")
    hostip     = ENV[host]['ipaddress']
    name       = ENV[host]['username']
    passwd     = ENV[host]['password']
    paths      = ENV[host]['file']
    repo       = ENV[C_GIT]['repopath']
    
    log(ok=True, msg="connect to %s  user %s"%(hostip, name))
    print "%s %s %s"%(hostip, name, passwd)
    client = ssh.open(hostip, name, passwd)
    ssh.scp(client, paths, repo)
    client.close()
    log(ok=True, msg="copy ok")
Exemplo n.º 2
0
def get_copy_remote(host):
    '''copy a remote file to local file, which was copied from pc6248 to remote file. 
       we must delete the remote file'''
    log(ok=True, msg="start to copy...")
    hostip     = ENV[C_SSH]['ipaddress']
    name       = ENV[C_SSH]['username']
    passwd     = ENV[C_SSH]['password']
    paths      = ENV[host]['pc6428']
    repo       = ENV[C_GIT]['repopath']
    
    # TODO: it is better if we have temporaer local files
    log(ok=True, msg="connect to %s  user %s"%(hostip, name))
    client = ssh.open(hostip, name, passwd)
    ssh.scp(client, paths, repo)
    for x in paths:
        ssh.remove(client, x['remotepath'])
    client.close()
    log(ok=True, msg="copy ok")
Exemplo n.º 3
0
def get_directory(host):
    ''' get the remote diretory with ssh, tar and untar. '''
    log(ok=True, msg="start to copy a directory...")
    hostip     = ENV[host]['ipaddress']
    name       = ENV[host]['username']
    passwd     = ENV[host]['password']
    paths      = ENV[host]['dirs']
    repo       = ENV[C_GIT]['repopath']
    
    log(ok=True, msg="connect to %s  user %s"%(hostip, name))
    client = ssh.open(hostip, name, passwd)
    ftp = client.open_sftp()
    for x in paths:
        remote = x['remotepath']
        local  = x['localpath']
        log(ok=True, msg="copy dirs %s:/%s to local %s/%s"%(host,remote,repo,local))
        tokens = remote.split('/')
        if tokens[-1] == '':
            name = tokens[-2]
            directory = '/'.join(tokens[:-2])
        else:
            name = tokens[-1]
            directory = '/'.join(tokens[:-1])
    #    print "client: %s   name: %s   dir: %s"%(client, name, directory)
        err, lines = ssh.tar_c(client, name, directory)
        if not err:  # move to the repo
            tarname='/tmp/%s.tgz'%name
            log(ok=True, msg="untar %s"%tarname)
            ssh.scp_file(ftp, tarname, tarname)
            ssh.remove(client, tarname)
            tar = tarfile.open(tarname)
            tar.extractall(path=repo+'/'+local)
            tar.close()
            os.remove(tarname)
        else:
            log(ok=False, msg="something is wrong on ssh tar: %s"%lines)
            sys.exit(-1)
    client.close()