import rbd
import rados

if __name__ == "__main__":
	counter = 0
	x = 0
	r = rbd.RBD()

	with rados.Rados(conffile='/etc/ceph/ceph.conf') as cluster:
		with cluster.open_ioctx("sata") as ioctx:
			volumes = r.list(ioctx)

	while True:
		for volume in volumes:
			if x >= 100:
				counter += x
				x = 0
				print("Volumes counter: %s" % (counter))
			try:
				with rados.Rados(conffile='/etc/ceph/ceph.conf') as cluster:
					with cluster.open_ioctx("sata") as ioctx:
						try:
							with rbd.Image(ioctx, name=volume, read_only=True) as rbdi:
								x += 1
						except rbd.ImageNotFound:
							print("%s volume not found" % (volume))
						except rbd.ImageBusy:
							print("%s volume busy" % (volume))
						except Exception as err:
							print("%s %s" % (volume, err))
			except Exception as err:
				print("%s %s" % (volume, err))
