-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrsdebug.py
More file actions
267 lines (217 loc) · 8.99 KB
/
rsdebug.py
File metadata and controls
267 lines (217 loc) · 8.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
import tornado
import sys
import logging.config
import types
import traceback
from tornado.options import define, options
from restfsc.service.CacheService import CacheService
from restfsc.manager.CacheManager import CacheManager
define("conf" , default="fuse.cnf" , help="configuration file")
define("rpc", default=None, help="rpc call")
define("param", default=None, help="paramaters")
define("bucket", default='londra', help="bucket")
define("info", default=None, help="Command line info")
restfs_version = "0.1"
_LOGGER = logging.getLogger('RSDEBUG')
def my_debug_help():
print "rpc=findCluster, param=bucket"
print "rpc=lookup, param=path"
print "rpc=createObject, param=path, OF.TYPE_FILE, uid, gid, st_mode, context"
print "rpc=getObjectList, param=idObj, uid, gid, context"
print "rpc=removeObject, param=bucket, idObj, uid, gid, context"
print "rpc=getAttributes, param=bucket, idObj, field, uid, gid, context"
print "rpc=setObjectMode, param=bucket, idObj, mode, uid, gid, context"
print "rpc=setObjectOwner, param=bucket, idObj, owner, group, uid, gid, context"
print "rpc=setObjectUtime, param=bucket, idObj, utime, uid, gid, context"
print "rpc=getObjectXattr, param=bucket, idObj, name, uid, gid, context"
print "rpc=setObjectXattr, param=bucket, idObj, name, value, uid, gid, context"
print "rpc=delObjectXattr, param= bucket,idObj, name, uid, gid, context"
print "rpc=listObjectXattr, param=bucket, idObj, uid, gid, context"
print "rpc=getObjectSegment, param= bucket, idObj, idSeg, uid, gid, context"
print "rpc=delObjectSegment, param=bucket, idObj, idSeg, uid, gid, context"
print "rpc=setObjectSegment, param=bucket, idObj, idSeg, seg, uid, gid, context"
print "STORAGE OPERATIONS "
print "rpc=writeBlock, param= bucket, idObj, key, block, bhash, uid, gid, context"
print "rpc=readBlock, param= bucket, idObj, key, uid, gid, context"
print "rpc=removeBlock, param= bucket, idObj, key, uid, gid, context"
print "rpc=remove, param= bucket, idObj, uid, gid, context"
print "rpc=load, param= bucket, idObj, uid, gid, context"
print "rpc=open, param= bucket, idObj, flags,uid, gid, context"
print "rpc=write, param = bucket, object_name, uid, gid, context, storage_class, object_acl, content_type, xattr, data_handler)"
print "rpc=writeMetaItem param= idObj, field, value, version"
print "rpc=getMetaItem param= idObj, field"
print "rpc=writeBlockCache param=bucket, idObj, idSeg, idBlock, block"
print "rpc=readBlockCache param=bucket, idObj, idSeg, idBlock"
print "rpc=writeOffset param =bucket, idObj, data_handler, offset, uid, gid, context"
print "rpc=loadOffset param = bucket, idObj, offset, uid, gid, context"
# Server preverred list
print "rpc=getMetaCache param=bucket, idObj"
print "\n\n"
def myhelp():
print "debug\n"
print "rpc=setbucket parqm=bucket\n"
print "help\n"
print "exit\n"
def _findService(name):
try:
return getattr(cache, name)
except AttributeError:
return None
def contatempo(func):
import time
def interna(*args,**kw):
start=time.time()
result=func(*args,**kw)
tempo=time.time()-start
_LOGGER.info(args[0])
_LOGGER.debug(tempo)
#print("Funzione: %s - tempo impiegato: %4.9f" % (args[0],tempo))
return result
return interna
@contatempo
def _dispatch(method, params):
func = _findService(method)
if func is not None:
try:
if type(params) is types.ListType:
if params[0] != '':
response = func(*params)
else:
pass
else:
response = func(**params)
return response
except:
traceback.print_exc()
return ""
else:
return "Not Found"
def debug_mode():
while True:
params = []
cmd = raw_input('restfs-debug:insert cmd name> ')
if cmd == "exit":
return
else:
if cmd != "help":
bucket = raw_input('restfs-debug:insert bucket>')
if cmd != 'findCluster':
param = raw_input('restfs-debug:insert params>')
print param
params = param.split(',')
params.insert(0,bucket)
print _dispatch(cmd,params)
#_dispatch(cmd,params)
else:
my_debug_help()
def _configure_logging():
"""
Configure logging.
When no logfile argument is given we log to stdout.
"""
logging.config.fileConfig('loggingClient.conf')
logging.info('Logging started')
if __name__ == "__main__":
_configure_logging()
cache = CacheService()
cacheMng = CacheManager()
tornado.options.parse_command_line()
# Read File
tornado.options.parse_config_file(options.conf)
if not options.rpc and not options.param:
int_exec = True
if options.help == '':
myhelp()
sys.exit()
if int_exec:
print 'Welcome to RestFS Debug Command Line\n'
print 'Version %s \n' % restfs_version
while True:
prop = None
if int_exec:
cmd = raw_input('restfs:insert cmd name> ')
if cmd != "debug" and cmd != "exit" and cmd != "help":
param=raw_input('restfs:insert params>')
params = options.param.split(',')
# operations
if cmd =="setbucket":
bucket = params[0]
if cmd.lower() =="put":
#createObject
# put FILE_INPUT PATH_SERVER
#dove sono gli altri uid, gid, context, storage_class, object_acl ,content_type, xattr ???
#readLocalFile e una funzione di cacheService ad hoc
streamData, file_name = readLocalFile(params[1])
#streamData e il mio nuovo data_handler
print _dispatch('write', params, streamData)
if cmd.lower() =="get":
#getObject
#get PATH_SERVER or ID ?
#se do solo il path prima lookup e poi open
#di default la open mette il file in tmp
idObj = _dispatch('lookup',params)
print _dispatch('open',params)
if cmd.lower() =="cd":
#get a directory or change bucket ?
pass
if cmd.lower() =="login":
#auth
pass
if cmd.lower() =="info":
#getOBjectProperties
#info PATH_SERVER or ID ?
idObj = _dispatch('lookup',params)
print _dispatch('getProperties',params)
pass
if cmd.lower() =="mkdir":
#create object type dir
#mkdir PATH_SERVER
if not params[1].endswith('/'):
params[1] = params[1]+'/'
print _dispatch('write', params)
if cmd.lower() =="del":
#delete
#del PATH_SERVER
idObj = _dispatch('lookup',params)
print _dispatch('removeObject',params)
print _dispatch('remove',params)
if cmd.lower() =="ls":
#getObjectList
#ls PATH_SERVER
#si puo fare ls del bucket ? da decidere
idObj = _dispatch('lookup',params)
print _dispatch('getObjectList',params)
if cmd.lower() =="pwd":
#getCurrentPath
#qua non capisco cosa vuole il manfred ...
#il path gia lo inserisci da input, che voglia opposto del lookup ?
pass
if cmd.lower() =="chmod":
#change mode
#chmod PATH NEW_MODE
idObj = _dispatch('lookup',params)
print _dispatch('setObjectMode',params)
if cmd.lower() =="chown":
#change owner
#chmod PATH NEW_OWNER
idObj = _dispatch('lookup',params)
print _dispatch('setObjectOwner',params)
if cmd.lower() =="getXattr":
#get xattributes
#getxattr PATH
idObj = _dispatch('lookup',params)
print _dispatch('getObjectXattr',params)
if cmd.lower() =="setXattr":
#set xattr
#setxattr PATH NEW_XATTR
idObj = _dispatch('lookup',params)
print _dispatch('setObjectXattr',params)
#mancano i comandi sull acls
elif cmd == "exit" or not int_exec:
sys.exit()
elif cmd == "debug":
debug_mode()
else:
myhelp()
if prop :
print 'RESULT =', prop