|
5 | 5 | #from eventlet.green import urllib2
|
6 | 6 | #import eventlet
|
7 | 7 |
|
8 |
| -DEBUG = False |
| 8 | +DEBUG = True |
| 9 | +SIMULATE = True |
9 | 10 |
|
10 | 11 | class EsuRestApi(object):
|
11 | 12 |
|
@@ -84,9 +85,10 @@ def create_object(self, data, listable_meta = None, non_listable_meta = None, mi
|
84 | 85 | error_message = e.read()
|
85 | 86 | return error_message
|
86 | 87 |
|
87 |
| - else: # If there was no HTTPError, parse the location header in the response body to get the object_id |
88 |
| - object_id = self.__parse_location(response) |
89 |
| - return object_id |
| 88 | + else: # If there was no HTTPError, parse the location header in the response body to get the object_id |
| 89 | + if not SIMULATE: |
| 90 | + object_id = self.__parse_location(response) |
| 91 | + return object_id |
90 | 92 |
|
91 | 93 | def create_object_on_path(self, path, listable_meta = None, non_listable_meta = None, mime_type = None, data = None):
|
92 | 94 | """ Creates an object in the namespace interface and returns an object_id.
|
@@ -151,8 +153,10 @@ def create_object_on_path(self, path, listable_meta = None, non_listable_meta =
|
151 | 153 | return error_message
|
152 | 154 |
|
153 | 155 | else: # If there was no HTTPError, parse the location header in the response body to get the object_id
|
154 |
| - object_id = self.__parse_location(response) |
155 |
| - return object_id |
| 156 | + |
| 157 | + if not SIMULATE: |
| 158 | + object_id = self.__parse_location(response) |
| 159 | + return object_id |
156 | 160 |
|
157 | 161 | def list_objects(self, metadata_key, include_meta = False, filter_user_tags = None):
|
158 | 162 | """ Takes a listable metadata key and returns a list of objects that match.
|
@@ -207,8 +211,9 @@ def list_objects(self, metadata_key, include_meta = False, filter_user_tags = No
|
207 | 211 | return error_message
|
208 | 212 |
|
209 | 213 | else:
|
210 |
| - object_list = response.read() |
211 |
| - return object_list |
| 214 | + if not SIMULATE: |
| 215 | + object_list = response.read() |
| 216 | + return object_list |
212 | 217 |
|
213 | 218 | def list_directory(self, path, limit = None, include_meta = False, token = None, filter_user_tags = None):
|
214 | 219 | """ Lists objects in the namespace based on path
|
@@ -266,16 +271,17 @@ def list_directory(self, path, limit = None, include_meta = False, token = None,
|
266 | 271 |
|
267 | 272 | else:
|
268 | 273 |
|
269 |
| - dir_list = response.read() |
270 |
| - |
271 |
| - |
272 |
| - if response.info().getheader('x-emc-token'): |
273 |
| - token = response.info().getheader('x-emc-token') |
| 274 | + if not SIMULATE: |
| 275 | + dir_list = response.read() |
| 276 | + |
274 | 277 |
|
275 |
| - return dir_list, token |
276 |
| - |
277 |
| - else: |
278 |
| - return dir_list |
| 278 | + if response.info().getheader('x-emc-token'): |
| 279 | + token = response.info().getheader('x-emc-token') |
| 280 | + |
| 281 | + return dir_list, token |
| 282 | + |
| 283 | + else: |
| 284 | + return dir_list |
279 | 285 |
|
280 | 286 | def delete_object(self, object_id):
|
281 | 287 | """ Deletes objects based on object_id. """
|
@@ -304,8 +310,9 @@ def delete_object(self, object_id):
|
304 | 310 | error_message = e.read()
|
305 | 311 | return error_message
|
306 | 312 |
|
307 |
| - else: # If there was no HTTPError, parse the location header in the response body to get the object_id |
308 |
| - return response |
| 313 | + else: |
| 314 | + if not SIMULATE: |
| 315 | + return response |
309 | 316 |
|
310 | 317 |
|
311 | 318 | def delete_directory(self, path):
|
@@ -339,7 +346,8 @@ def delete_directory(self, path):
|
339 | 346 | return error_message
|
340 | 347 |
|
341 | 348 | else: # If there was no HTTPError, parse the location header in the response body to get the object_id
|
342 |
| - return response |
| 349 | + if not SIMULATE: |
| 350 | + return response |
343 | 351 |
|
344 | 352 |
|
345 | 353 | def read_object(self, object_id, extent = None, head = False):
|
@@ -390,33 +398,33 @@ def read_object(self, object_id, extent = None, head = False):
|
390 | 398 | return e
|
391 | 399 |
|
392 | 400 | else:
|
393 |
| - |
394 |
| - if head: |
395 |
| - group_acl = {} |
396 |
| - user_acl = {} |
397 |
| - system_meta = {} |
398 |
| - policy = {} |
399 |
| - |
400 |
| - if response.info().getheader('x-emc-groupacl'): |
401 |
| - group_acl = response.info().getheader('x-emc-groupacl') |
402 |
| - group_acl = dict(u.split("=") for u in group_acl.split(",")) # Create a Python dictionary of the data in the header and return it. |
403 |
| - |
404 |
| - if response.info().getheader('x-emc-user-acl'): |
405 |
| - user_acl = response.info().getheader('x-emc-user-acl') |
406 |
| - user_acl = dict(u.split("=") for u in user_acl.split(",")) |
407 |
| - |
408 |
| - if response.info().getheader('x-emc-meta'): |
409 |
| - system_meta = response.info().getheader('x-emc-meta') |
410 |
| - system_meta = dict(u.split("=") for u in system_meta.split(",")) |
411 |
| - |
412 |
| - if response.info().getheader('x-emc-policy'): |
413 |
| - policy = response.info().getheader('x-emc-policy') |
414 |
| - |
415 |
| - return {"group_acl" : group_acl , "user_acl" : user_acl, "system_meta" : system_meta, "policy" : policy} |
416 |
| - |
417 |
| - else: |
418 |
| - body = response.read() |
419 |
| - return body |
| 401 | + if not SIMULATE: |
| 402 | + if head: |
| 403 | + group_acl = {} |
| 404 | + user_acl = {} |
| 405 | + system_meta = {} |
| 406 | + policy = {} |
| 407 | + |
| 408 | + if response.info().getheader('x-emc-groupacl'): |
| 409 | + group_acl = response.info().getheader('x-emc-groupacl') |
| 410 | + group_acl = dict(u.split("=") for u in group_acl.split(",")) # Create a Python dictionary of the data in the header and return it. |
| 411 | + |
| 412 | + if response.info().getheader('x-emc-user-acl'): |
| 413 | + user_acl = response.info().getheader('x-emc-user-acl') |
| 414 | + user_acl = dict(u.split("=") for u in user_acl.split(",")) |
| 415 | + |
| 416 | + if response.info().getheader('x-emc-meta'): |
| 417 | + system_meta = response.info().getheader('x-emc-meta') |
| 418 | + system_meta = dict(u.split("=") for u in system_meta.split(",")) |
| 419 | + |
| 420 | + if response.info().getheader('x-emc-policy'): |
| 421 | + policy = response.info().getheader('x-emc-policy') |
| 422 | + |
| 423 | + return {"group_acl" : group_acl , "user_acl" : user_acl, "system_meta" : system_meta, "policy" : policy} |
| 424 | + |
| 425 | + else: |
| 426 | + body = response.read() |
| 427 | + return body |
420 | 428 |
|
421 | 429 | def read_object_from_path(self, path, extent = None, head = False):
|
422 | 430 | """ Returns an entire object or a partial object based on a byte range from the namespace interface.
|
@@ -469,32 +477,33 @@ def read_object_from_path(self, path, extent = None, head = False):
|
469 | 477 |
|
470 | 478 | else:
|
471 | 479 |
|
472 |
| - if head: |
473 |
| - group_acl = {} |
474 |
| - user_acl = {} |
475 |
| - system_meta = {} |
476 |
| - policy = {} |
477 |
| - |
478 |
| - if response.info().getheader('x-emc-groupacl'): |
479 |
| - group_acl = response.info().getheader('x-emc-groupacl') |
480 |
| - group_acl = dict(u.split("=") for u in group_acl.split(",")) # Create a Python dictionary of the data in the header and return it. |
481 |
| - |
482 |
| - if response.info().getheader('x-emc-user-acl'): |
483 |
| - user_acl = response.info().getheader('x-emc-user-acl') |
484 |
| - user_acl = dict(u.split("=") for u in user_acl.split(",")) |
485 |
| - |
486 |
| - if response.info().getheader('x-emc-meta'): |
487 |
| - system_meta = response.info().getheader('x-emc-meta') |
488 |
| - system_meta = dict(u.split("=") for u in system_meta.split(",")) |
489 |
| - |
490 |
| - if response.info().getheader('x-emc-policy'): |
491 |
| - policy = response.info().getheader('x-emc-policy') |
492 |
| - |
493 |
| - return {"group_acl" : group_acl , "user_acl" : user_acl, "system_meta" : system_meta, "policy" : policy} |
494 |
| - |
495 |
| - else: |
496 |
| - body = response.read() |
497 |
| - return body |
| 480 | + if not SIMULATE: |
| 481 | + if head: |
| 482 | + group_acl = {} |
| 483 | + user_acl = {} |
| 484 | + system_meta = {} |
| 485 | + policy = {} |
| 486 | + |
| 487 | + if response.info().getheader('x-emc-groupacl'): |
| 488 | + group_acl = response.info().getheader('x-emc-groupacl') |
| 489 | + group_acl = dict(u.split("=") for u in group_acl.split(",")) # Create a Python dictionary of the data in the header and return it. |
| 490 | + |
| 491 | + if response.info().getheader('x-emc-user-acl'): |
| 492 | + user_acl = response.info().getheader('x-emc-user-acl') |
| 493 | + user_acl = dict(u.split("=") for u in user_acl.split(",")) |
| 494 | + |
| 495 | + if response.info().getheader('x-emc-meta'): |
| 496 | + system_meta = response.info().getheader('x-emc-meta') |
| 497 | + system_meta = dict(u.split("=") for u in system_meta.split(",")) |
| 498 | + |
| 499 | + if response.info().getheader('x-emc-policy'): |
| 500 | + policy = response.info().getheader('x-emc-policy') |
| 501 | + |
| 502 | + return {"group_acl" : group_acl , "user_acl" : user_acl, "system_meta" : system_meta, "policy" : policy} |
| 503 | + |
| 504 | + else: |
| 505 | + body = response.read() |
| 506 | + return body |
498 | 507 |
|
499 | 508 | def update_object(self, object_id, data, extent = None, listable_meta = None, non_listable_meta = None, mime_type = None):
|
500 | 509 | """ Updates an existing object with listable metadata, non-listable metadata, and/or bytes of actual object data based on range.
|
@@ -645,8 +654,10 @@ def create_directory(self, path):
|
645 | 654 | return error_message
|
646 | 655 |
|
647 | 656 | else: # If there was no HTTPError, parse the location header in the response body to get the object_id
|
648 |
| - object_id = self.__parse_location(response) |
649 |
| - return object_id |
| 657 | + |
| 658 | + if not SIMULATE: |
| 659 | + object_id = self.__parse_location(response) |
| 660 | + return object_id |
650 | 661 |
|
651 | 662 | # Renames won't work before Atmos 1.3.x
|
652 | 663 | def rename_object(self, source, destination, force):
|
@@ -685,7 +696,8 @@ def rename_object(self, source, destination, force):
|
685 | 696 | return error_message
|
686 | 697 |
|
687 | 698 | else:
|
688 |
| - return response |
| 699 | + if not SIMULATE: |
| 700 | + return response |
689 | 701 |
|
690 | 702 | def set_user_metadata(self, object_id, listable_meta = None, non_listable_meta = None):
|
691 | 703 | """ Updates an existing object with listable and/or non-listable user metadata
|
@@ -770,7 +782,8 @@ def delete_user_metadata(self, object_id, metadata_key):
|
770 | 782 | return error_message
|
771 | 783 |
|
772 | 784 | else:
|
773 |
| - return response |
| 785 | + if not SIMULATE: |
| 786 | + return response |
774 | 787 |
|
775 | 788 |
|
776 | 789 | def get_user_metadata(self, object_id):
|
@@ -807,18 +820,19 @@ def get_user_metadata(self, object_id):
|
807 | 820 | return error_message
|
808 | 821 |
|
809 | 822 | else:
|
810 |
| - nl_user_meta = {} |
811 |
| - listable_user_meta = {} |
812 |
| - |
813 |
| - if response.info().getheader('x-emc-meta'): |
814 |
| - nl_user_meta = response.info().getheader('x-emc-meta') |
815 |
| - nl_user_meta = dict(u.split("=") for u in nl_user_meta.split(",")) # Create a Python dictionary of the data in the header and return it. |
816 |
| - |
817 |
| - if response.info().getheader('x-emc-listable-meta'): |
818 |
| - listable_user_meta = response.info().getheader('x-emc-listable-meta') |
819 |
| - listable_user_meta = dict(u.split("=") for u in listable_user_meta.split(",")) |
820 |
| - |
821 |
| - return {"listable_user_meta" : listable_user_meta , "nl_user_meta" : nl_user_meta} |
| 823 | + if not SIMULATE: |
| 824 | + nl_user_meta = {} |
| 825 | + listable_user_meta = {} |
| 826 | + |
| 827 | + if response.info().getheader('x-emc-meta'): |
| 828 | + nl_user_meta = response.info().getheader('x-emc-meta') |
| 829 | + nl_user_meta = dict(u.split("=") for u in nl_user_meta.split(",")) # Create a Python dictionary of the data in the header and return it. |
| 830 | + |
| 831 | + if response.info().getheader('x-emc-listable-meta'): |
| 832 | + listable_user_meta = response.info().getheader('x-emc-listable-meta') |
| 833 | + listable_user_meta = dict(u.split("=") for u in listable_user_meta.split(",")) |
| 834 | + |
| 835 | + return {"listable_user_meta" : listable_user_meta , "nl_user_meta" : nl_user_meta} |
822 | 836 |
|
823 | 837 |
|
824 | 838 | def get_system_metadata(self, object_id, sys_tags = None):
|
@@ -863,10 +877,11 @@ def get_system_metadata(self, object_id, sys_tags = None):
|
863 | 877 | return error_message
|
864 | 878 |
|
865 | 879 | else:
|
866 |
| - system_meta = [] |
867 |
| - system_meta = response.info().getheader('x-emc-meta') |
868 |
| - system_meta = dict(u.split("=") for u in system_meta.split(",")) # Create a Python dictionary of the data in the header and return it. |
869 |
| - return system_meta |
| 880 | + if not SIMULATE: |
| 881 | + system_meta = [] |
| 882 | + system_meta = response.info().getheader('x-emc-meta') |
| 883 | + system_meta = dict(u.split("=") for u in system_meta.split(",")) # Create a Python dictionary of the data in the header and return it. |
| 884 | + return system_meta |
870 | 885 |
|
871 | 886 | def get_listable_tags(self, metadata_key = None):
|
872 | 887 | """ Returns all the top level listable keys for which the given UID has access to in their namespace.
|
@@ -904,16 +919,19 @@ def get_listable_tags(self, metadata_key = None):
|
904 | 919 | hashout = self.__sign(headers)
|
905 | 920 |
|
906 | 921 | try:
|
| 922 | + |
907 | 923 | response = self.__send_request(request, hashout, headers)
|
908 | 924 |
|
909 | 925 | except urllib2.HTTPError, e:
|
910 | 926 | error_message = e.read()
|
911 | 927 | return error_message
|
912 | 928 |
|
913 | 929 | else:
|
914 |
| - listable_tags = [] |
915 |
| - listable_tags = response.info().getheader('x-emc-listable-tags') |
916 |
| - return listable_tags |
| 930 | + |
| 931 | + if not SIMULATE: |
| 932 | + listable_tags = [] |
| 933 | + listable_tags = response.info().getheader('x-emc-listable-tags') |
| 934 | + return listable_tags |
917 | 935 |
|
918 | 936 | def get_service_information(self):
|
919 | 937 | """ Returns Atmos version information. """
|
@@ -957,9 +975,10 @@ def __send_request(self, request, hashout, headers):
|
957 | 975 | if DEBUG:
|
958 | 976 | print request.headers
|
959 | 977 |
|
960 |
| - response = urllib2.urlopen(request) |
961 |
| - |
962 |
| - return response |
| 978 | + if not SIMULATE: |
| 979 | + |
| 980 | + response = urllib2.urlopen(request) |
| 981 | + return response |
963 | 982 |
|
964 | 983 |
|
965 | 984 | def __sign(self, headers):
|
|
0 commit comments