Advertisement
TShiva

python_rbd_rados

Nov 9th, 2017
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.69 KB | None | 0 0
  1. File: rbd_script.py
  2.  
  3. import rados,sys,rbd
  4.  
  5. cluster = rados.Rados(conffile='/etc/ceph/ceph.conf')
  6. cluster.connect()
  7.  
  8. ioctx = cluster.open_ioctx('big_dick')
  9. try:
  10.     rbd_inst = rbd.RBD()
  11.     #size = 4 * 1024**3
  12.     #rbd_inst.create(ioctx,'cock_image',size)
  13.     image = rbd.Image(ioctx, 'cock_image')
  14.     try:
  15.         data = 'SanyaHyiSosi' * 100
  16.         image.write(data,0)
  17.     finally:
  18.         image.close()
  19. finally:
  20.     ioctx.close()
  21. cluster.shutdown()
  22.  
  23. ------------------------------------------------------------------------------
  24.  
  25.   GNU nano 2.5.3                           File: connect_to_ceph.py                                                            
  26.  
  27. import rados, sys
  28.  
  29. cluster = rados.Rados(conffile='/etc/ceph/ceph.conf')
  30. print "\nlibrados version: " + str(cluster.version())
  31. print "Will attempt to connect to: " + str(cluster.conf_get('mon initial members'))
  32.  
  33. cluster.connect()
  34. print "\nCluster ID: " + cluster.get_fsid()
  35.  
  36. print "\n\nCluster Statistics"
  37. print "=================="
  38. cluster_stats = cluster.get_cluster_stats()
  39.  
  40. for key, value in cluster_stats.iteritems():
  41.     print key, value
  42.  
  43. print "\n\nPool Operations"
  44. print "==============="
  45.  
  46. print "\nAvailable Pools"
  47. print "----------------"
  48. pools = cluster.list_pools()
  49.  
  50. for pool in pools:
  51.     print pool
  52.  
  53. print "\nCreate 'test' Pool"
  54. print "------------------"
  55. cluster.create_pool('test')
  56.  
  57. print "\nPool named 'test' exists: " + str(cluster.pool_exists('test'))
  58. print "\nVerify 'test' Pool Exists"
  59. print "-------------------------"
  60. pools = cluster.list_pools()
  61.  
  62. for pool in pools:
  63.     print pool
  64.  
  65. print "\nDelete 'test' Pool"
  66. print "------------------"
  67. cluster.delete_pool('test')
  68. print "\nPool named 'test' exists: " + str(cluster.pool_exists('test'))
  69.  
  70. ioctx = cluster.open_ioctx('big_dick')
  71. print "\nWriting object 'hw' with contents 'Hello World!' to pool 'big_dick'."
  72. ioctx.write_full("hw","Hello World")
  73. print "\n\nContents of object 'hw'\n------------------------\n"
  74. print ioctx.read("hw")
  75. print "\nRemoving object 'hw'"
  76. ioctx.remove_object("hw")
  77.  
  78. print "\nClosing the connection."
  79. ioctx.close()
  80.  
  81. ------------------------------------------------------------------------------
  82.  
  83.   GNU nano 2.5.3                           File: watch_objects.py                                                              
  84.  
  85. import rados, sys
  86.  
  87. cluster = rados.Rados(conffile='/etc/ceph/ceph.conf')
  88. cluster.connect()
  89. ioctx = cluster.open_ioctx('big_dick')
  90. object_iterator = ioctx.list_objects()
  91. while True:
  92.     try :
  93.         rados_object = object_iterator.next()
  94.         print "Object contents = " + rados_object.read()
  95.     except StopIteration :
  96.         break
  97. ioctx.close()
  98. cluster.shutdown()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement