# Path: cephinfo/cephinfo.py
# def jsoncmd(command):
# def init_df():
# def init_mon():
# def init_osd():
# def init_pg():
# def init_auth():
# def init_stat():
# def init_crush():
# def get_json():
# def get_pools_data():
# def get_n_pools():
# def get_osds_data():
# def get_n_osds():
# def get_osd_states():
# def get_pg_data():
# def get_pg_stats():
# def get_pg_stats_sum():
# def get_osd_stats_sum():
# def get_pg_stats_delta():
# def get_n_pgs():
# def get_pg_states():
# def get_n_mons():
# def get_n_mons_quorum():
# def get_write_latency():
# def get_read_latency():
# def rados_cleanup(prefix):
# def get_n_openstack_volumes():
# def get_n_openstack_images():
# def get_smooth_activity(n):


from cephinfo import cephinfo
import itertools
import random

print "End of simulation: Out of %d double failures, %d caused a data outage incident" % (nFailures, nOutage)

print "\nSimulating %d double failures if downgraded to 2 replica RADOS" % nSimulations
double_combinations = [ tuple(pg['acting'][:2]) for pg in cephinfo.get_pg_stats() ]
nFailures = 0
nDataLoss = 0

for i in xrange(0,nSimulations):
  double_failure = random.sample(osds, 2)

  nFailures += 1

  for order in itertools.permutations(double_failure):
    if order in double_combinations:
      nDataLoss += 1
#      print "2 replica data loss incident with failure %s" % str(order)

  if nFailures % 1000 == 0:
    print "Simulated %d failures. Data loss incidents = %d." % (nFailures, nDataLoss)

print "End of simulation: Out of %d double failures, %d caused a data loss incident" % (nFailures, nDataLoss)


nSimulations = 10
for n in xrange(4, 21):
  nDataLoss = 0
  nFailures = 0
  print "\nSimulating %d %d-disk failures" % (nSimulations, n)
  for i in xrange(0,nSimulations):

# Path: cephinfo/cephinfo.py
# def jsoncmd(command):
# def init_df():
# def init_mon():
# def init_osd():
# def init_pg():
# def init_auth():
# def init_stat():
# def init_crush():
# def get_json():
# def get_pools_data():
# def get_n_pools():
# def get_osds_data():
# def get_n_osds():
# def get_osd_states():
# def get_pg_data():
# def get_pg_stats():
# def get_pg_stats_sum():
# def get_osd_stats_sum():
# def get_pg_stats_delta():
# def get_n_pgs():
# def get_pg_states():
# def get_n_mons():
# def get_n_mons_quorum():
# def get_write_latency():
# def get_read_latency():
# def rados_cleanup(prefix):
# def get_n_openstack_volumes():
# def get_n_openstack_images():
# def get_smooth_activity(n):


# Path: tools/durability/simulate-failures.py
from cephinfo import cephinfo
import itertools
import random


print "End of simulation: Out of %d double failures, %d caused a data outage incident" % (nFailures, nOutage)

print "\nSimulating %d double failures if downgraded to 2 replica RADOS" % nSimulations
double_combinations = [ tuple(pg['acting'][:2]) for pg in cephinfo.get_pg_stats() ]
nFailures = 0
nDataLoss = 0

for i in xrange(0,nSimulations):
  double_failure = random.sample(osds, 2)

  nFailures += 1

  for order in itertools.permutations(double_failure):
    if order in double_combinations:
      nDataLoss += 1
#      print "2 replica data loss incident with failure %s" % str(order)

  if nFailures % 1000 == 0:
    print "Simulated %d failures. Data loss incidents = %d." % (nFailures, nDataLoss)

print "End of simulation: Out of %d double failures, %d caused a data loss incident" % (nFailures, nDataLoss)


nSimulations = 10
for n in xrange(4, 21):
  nDataLoss = 0
  nFailures = 0
  print "\nSimulating %d %d-disk failures" % (nSimulations, n)
  for i in xrange(0,nSimulations):

    n_disk_failure = random.sample(osds, n)