Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.