Skip to content
Snippets Groups Projects
ceph-disk-list.py 2.38 KiB
Newer Older
root's avatar
root committed
#!/usr/bin/python

import re
import os
import sys
import argparse
import subprocess
import socket

try:
    myfullpath = os.path.dirname(os.path.realpath(__file__))
except NameError:
    myfullpath = os.path.abspath(os.path.curdir)


hostname = socket.gethostname().split('.')[0]

tp = open("disks_lists.pp","r")

tp_lines = tp.readlines()

tp.close()
   
#Remove last parantheses
ll = tp_lines[0:-2]

disk_tag_template = 'ceph_osd_list_prod_10x'
   
disk_tag = disk_tag_template+"_"+hostname
   
ll.append("    \'"+disk_tag+"\'" + " => {\n")
ll.append('  }\n')
ll.append('}\n')

n = open("disks_lists.pp", "w")
for l in ll:
  n.write(l)
n.close()
  
#sys.exit(0)

#{
#  '23-2EH3N2JX-HGST-HUH728080AL4200/sdaa_data'=>         {
#     store_type => 'bluestore',
#     bluestore_wal => 'cs-001_journal/sdaa_wal',
#     bluestore_db => 'cs-001_journal/sdaa_db',
#     ensure     => 'present',
#  }
#{
#      '<volume group>/<logical volume>'=>         {
#         store_type => 'bluestore',
#         bluestore_db => '<ssd volume group>/<ssd logical volume>',
#         ensure     => 'present',
#      }

#  LV                       VG             Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
#  101-db01                 101-ceph-db01  -wi-a----- <74,49g                                                    


import subprocess
process = subprocess.Popen(['/sbin/lvs'], stdout=subprocess.PIPE)
stdout = process.communicate()[0]

tmp = stdout.split('\n')[1:-1]

ll = []

db_lvs = []
data_lvs = []

for l in tmp:
  el = l.split()[0:2]
  if '-db' in el[0] :
    db_lvs.append(el)
    #print 'db ',el
  else:
    data_lvs.append(el)
    #print 'data ',el
  
full_list=[]
for l in data_lvs:
  el = []
  osd = l[1][-2:]
  el.append(l[0])
  el.append(l[1])
  for d in db_lvs:
    if osd == d[0][-2:]:
      el.append(d[0])
      el.append(d[1])
  full_list.append(el)


# CREATE PARTITIONS FOR CEPH OSDS AND UPDATE PUPPET CONFIGURATION
sed_string=""

for o in full_list:
  sed_string = sed_string + "'\"'\""+o[0]+"/"+o[1]+"\"'\"'=> \
    {\\n \ \ \ \ \ \ \ \ store_type => '\"'\"'bluestore'\"'\"', \
     \\n \ \ \ \ \ \ \ \ bluestore_db => '\"'\"'"+o[1]+"/"+o[2]+"'\"'\"',\
     \\n \ \ \ \ \ \ \ \ ensure     => '\"'\"'present'\"'\"',\\n \ \ \ \ \ \},\\n"

  sed_string = sed_string + "\ \ \ \ \},"
   


#print sed_string

os.system("sed -i '/    '\"'\""+disk_tag+"\"'\"' => {/a "+sed_string+"' "+"./disks_lists.pp")