# 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
from optparse import OptionParser
from collections import defaultdict
import ceph_osds_in_bucket
import os
  import sys
      # Assign a lower weight to overloaded OSDs. The current weight
      # is a factor to take into account the original weights,
      # to represent e.g. differing storage capacities
      weight = get_weight(osd['osd'])
      new_weight = (average_util / util) * float(weight)
      new_weight = max(new_weight, weight - options.max_change)
      print "osd.%d (%4f >= %4f) [%04f -> %04f]" % (osd['osd'], util, overload_util, weight, new_weight)
      if options.doit: change_weight(osd['osd'], new_weight, options.really)
      n += 1
      if n >= options.num_osds: break
    if not options.no_increasing and util <= underload_util:
      # assign a higher weight.. if we can
      weight = get_weight(osd['osd'])
      new_weight = (average_util / util) * float(weight)
      new_weight = max(new_weight, weight + 0.01)
      new_weight = min(new_weight, weight + options.max_change)
      if new_weight > 1.0:
        new_weight = 1.0
      if new_weight > weight:
        print "osd.%d (%4f <= %4f) [%04f -> %04f]" % (osd['osd'], util, underload_util, weight, new_weight)
        if options.doit: change_weight(osd['osd'], new_weight, options.really)
        n += 1
        if n >= options.num_osds: break

def get_weights():
  cephinfo.init_crush()
  global osd_weights

  osd_weights = dict()
 

# 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/crush-reweight-by-utilization.py
from cephinfo import cephinfo
from optparse import OptionParser
from collections import defaultdict
import ceph_osds_in_bucket
import os
  import sys

      # Assign a lower weight to overloaded OSDs. The current weight
      # is a factor to take into account the original weights,
      # to represent e.g. differing storage capacities
      weight = get_weight(osd['osd'])
      new_weight = (average_util / util) * float(weight)
      new_weight = max(new_weight, weight - options.max_change)
      print "osd.%d (%4f >= %4f) [%04f -> %04f]" % (osd['osd'], util, overload_util, weight, new_weight)
      if options.doit: change_weight(osd['osd'], new_weight, options.really)
      n += 1
      if n >= options.num_osds: break
    if not options.no_increasing and util <= underload_util:
      # assign a higher weight.. if we can
      weight = get_weight(osd['osd'])
      new_weight = (average_util / util) * float(weight)
      new_weight = max(new_weight, weight + 0.01)
      new_weight = min(new_weight, weight + options.max_change)
      if new_weight > 1.0:
        new_weight = 1.0
      if new_weight > weight:
        print "osd.%d (%4f <= %4f) [%04f -> %04f]" % (osd['osd'], util, underload_util, weight, new_weight)
        if options.doit: change_weight(osd['osd'], new_weight, options.really)
        n += 1
        if n >= options.num_osds: break

def get_weights():
  cephinfo.init_crush()
  global osd_weights

  osd_weights = dict()
 

  for osd in cephinfo.crush_data['nodes']: