1 __all__ = ('BlockStorageSFTP',)
5 from pyoram.util.misc import chunkiter
6 from pyoram.storage.block_storage import \
7 BlockStorageTypeFactory
8 from pyoram.storage.block_storage_file import \
13 log = logging.getLogger("pyoram")
15 class BlockStorageSFTP(BlockStorageFile):
17 A block storage device for accessing file data through
18 an SSH portal using Secure File Transfer Protocol (SFTP).
27 "Can not open sftp block storage device "
28 "without an ssh client.")
29 super(BlockStorageSFTP, self).__init__(
31 _filesystem=sshclient.open_sftp(),
33 self._sshclient = sshclient
34 self._f.set_pipelined()
35 self._timer = Foo.Instance();
40 # Define BlockStorageInterface Methods
43 def clone_device(self):
44 f = BlockStorageSFTP(self.storage_name,
45 sshclient=self._sshclient,
53 #def compute_storage_size(...)
65 "Can not setup sftp block storage device "
66 "without an ssh client.")
68 with BlockStorageFile.setup(storage_name,
71 _filesystem=sshclient.open_sftp(),
72 threadpool_size=threadpool_size,
77 return BlockStorageSFTP(storage_name,
79 threadpool_size=threadpool_size)
91 #def storage_name(...)
93 #def update_header_data(...)
97 super(BlockStorageSFTP, self).close()
99 self._filesystem.close()
100 print("sftp close 3")
102 def read_blocks(self, indices):
106 assert 0 <= i < self.block_count
107 self._bytes_received += self.block_size
108 args.append((self._header_offset + i * self.block_size,
113 self._timer.startTimer();
114 a = self._f.readv(args)
115 self._timer.endTimer();
118 # print("Reading Blocks SFTP......" + str(time.time() - sTime));
121 def yield_blocks(self, indices, chunksize=100):
122 for chunk in chunkiter(indices, n=chunksize):
123 assert all(0 <= i <= self.block_count for i in chunk)
124 self._bytes_received += self.block_size * len(chunk)
125 args = [(self._header_offset + i * self.block_size,
130 self._timer.startTimer();
131 a = self._f.readv(args)
132 self._timer.endTimer();
134 # print("Yield SFTP......");
141 #def write_blocks(...)
143 #def write_block(...)
149 #def bytes_received(...)
151 BlockStorageTypeFactory.register_device("sftp", BlockStorageSFTP)