Exemplo n.º 1
0
    def upload_file(self, ssh, ip, uploads, offset):
        # 不直接在上传的callback中调用更新状态的Caller,因为会影响上传的速度,
        # callback中只更新内存,状态更新在一个线程中定时去调用
        def upload_back(current, total):
            size[0] = current
            size[1] = total

        def get_progress():
            return int(size[0] / size[1] * offset)

        def update_thread():
            while not is_done:
                self.return_exec_start_result(ip, get_progress(), '', True)
                Common.sleep(0.2)

        size, is_done = [0, 1], False
        server_upload = Global.G_SERVER_UPLOAD % model_gate.settings_data.server_dir
        for local in uploads:
            remote = "{0}/{1}".format(server_upload, Common.basename(local))
            Common.create_thread(func=update_thread, args=())
            self.insert_text_info(ip, get_progress(),
                                  'Uploading {}'.format(local))
            ret, err = SSHUtil.upload_file(ssh, local, remote, upload_back)
            is_done = True
            if not ret:
                self.insert_text_info(
                    ip, get_progress(),
                    'Upload {} failed: {}'.format(local, err), 'ERROR')
                self.return_exec_start_result(ip, get_progress(), '', False)
                return False
            self.return_exec_start_result(ip, get_progress(), '', True)
        return True
Exemplo n.º 2
0
 def ssh_check():
     for t in range(1, retry_times + 1):
         ret1 = SSHUtil.user_login(ssh, user)[0]
         ret2 = SSHUtil.user_login(ssh, 'root')[0]
         ret3 = SSHUtil.exec_ret(ssh, 'echo')[0]
         ret4 = SSHUtil.upload_file(ssh, Global.G_SETTINGS_FILE,
                                    remote_file)[0]
         if all([ret1, ret2, ret3, ret4]):
             return True
     return False
Exemplo n.º 3
0
 def upload_package():
     remote_path = "{0}/{1}".format(server_dir, Global.G_PACK_ZIP)
     unzip_cmd = "cd {0} && unzip -o {1} && chmod 777 {0}/*".format(
         server_dir, Global.G_PACK_ZIP)
     ret, err = SSHUtil.upload_file(ssh, pack_path, remote_path)
     if not ret:
         raise Exception(
             "{} 登录失败\n重试次数:{}\nUpload package failed:{}".format(
                 ip, times, err))
     ret, err = SSHUtil.exec_ret(ssh, unzip_cmd, root=True)
     if not ret:
         raise Exception(
             "{} 登录失败\n重试次数:{}\nDecompression failed:{}".format(
                 ip, times, err))