Skip to content

Instantly share code, notes, and snippets.

@i-kumagai
Created June 24, 2014 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save i-kumagai/e2673b66f34a581dded5 to your computer and use it in GitHub Desktop.
Save i-kumagai/e2673b66f34a581dded5 to your computer and use it in GitHub Desktop.
rbd_write.py
import rbd
import rados
import sys
argvs = sys.argv
tgt=argvs[1]
char=argvs[2]
size=argvs[3]
offset=argvs[4]
cluster = rados.Rados(conffile='/etc/ceph/ceph.conf')
try:
cluster.connect()
ioctx = cluster.open_ioctx('rbd')
if offset == "0":
try:
rbd_inst = rbd.RBD()
dsize= 1024**2 * int(size )
#rbd_inst.create(ioctx, tgt , dsize, None, False)
data= char * dsize
image = rbd.Image(ioctx, tgt)
try:
image.write(data,0)
finally:
image.close()
finally:
ioctx.close()
else :
try:
image = rbd.Image(ioctx, tgt)
data=char*int(size)
try:
image.write(data,int(offset))
finally:
image.close()
finally:
ioctx.close()
finally:
cluster.shutdown()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment