Skip to content
Snippets Groups Projects
ceph-standalone-deploy.py 4.01 KiB
Newer Older
  • Learn to ignore specific revisions
  • #!/usr/bin/python
    
    import re
    import os
    import sys
    import argparse
    
    try:
        myfullpath = os.path.dirname(os.path.realpath(__file__))
    except NameError:
        myfullpath = os.path.abspath(os.path.curdir)
    
    parser = argparse.ArgumentParser(description='Perform standalone CEPH installation.')
    parser.add_argument('-t','--data', help='Data partition size')
    parser.add_argument('-w','--wal', help='Wal partition size')
    parser.add_argument('-d','--db', help='DB partition size')
    args = parser.parse_args()
    
    if args.wal == None or args.db == None or args.data == None:
        print("Required arguments not provided. Exit.")
        sys.exit(1)
    
    pattern = re.compile("^\d+(K|M|G|T|P)$")
    
    if pattern.match(args.wal) and pattern.match(args.db) and pattern.match(args.data):
    
        # CREATE JBOD DISKS MAP IF DOES NOT EXIST
        fn = os.path.join(myfullpath,'diskPosition2.out')
        if not os.path.isfile(fn):
            os.system(myfullpath+"/diskPosition2 > "+myfullpath+"/diskPosition2.out")
    
        # OPEN JBOD DISKS MAP FILE
        with open(fn, 'r') as f:
            lines = f.readlines()
    
        # CHECK PUPPET CONFIGURATION DIRS
        storage_dn = os.path.join(myfullpath,'storage')
        if not os.path.isdir(storage_dn):
            os.system("git clone https://baltig.infn.it/cnaf-provisioning/storage.git")
    
        cnprov_dn = os.path.join(myfullpath,'modules')
        if not os.path.isdir(cnprov_dn):
            os.system("git clone https://baltig.infn.it/cnaf-provisioning/modules.git")
    
        # CREATE PARTITIONS FOR CEPH OSDS AND UPDATE PUPPET CONFIGURATION
        os.system(\
        "sed -n -i '/    '\"'\"'ceph_osd_test'\"'\"' => {/{p; :a; N; /    '\"'\"'ceph_osd_list_prod'\"'\"' => {/!ba; s/.*\\n//}; p' "\
        +storage_dn+"/modules/storage_ceph/manifests/disks/disks_lists.pp")
    
        sed_string=""
    
        for i in range(0,len(lines),3):
    
            res_dev = re.search(r"/sys/block/\wd[a-z]+",lines[i])
    
            res_bayid = re.search(r"BayID: \d+", lines[i])
            res_sn = re.search(r"Serial number:        \w+",lines[i])
            res_vnd = re.search(r"Vendor:               \w+", lines[i])
            res_prd = re.search(r"Product:              \w+", lines[i])
    
    
            dev = str(re.search(r"\wd[a-z]+",res_dev.group()).group())
    
            bayid = int(re.search(r"\d+",res_bayid.group()).group())
            sn = str(re.search(r"        \w+",res_sn.group()).group()).strip()
            vnd = str(re.search(r"               \w+",res_vnd.group()).group()).strip()
            prd = str(re.search(r"              \w+",res_prd.group()).group()).strip()
    
            os.system("pvcreate /dev/"+dev)
            os.system("vgcreate "+str(bayid)+"-"+sn+"-"+vnd+"-"+prd+" /dev/"+dev)
            os.system("lvcreate -L"+args.data+" -n "+dev+"_data "+str(bayid)+"-"+sn+"-"+vnd+"-"+prd)
            os.system("lvcreate -L"+args.wal+" -n "+dev+"_wal "+str(bayid)+"-"+sn+"-"+vnd+"-"+prd)
            os.system("lvcreate -L"+args.db+" -n "+dev+"_db "+str(bayid)+"-"+sn+"-"+vnd+"-"+prd)
    
            sed_string = sed_string + "\ \ \ \ \ \ \'\"'\"'"+str(bayid)+"-"+sn+"-"+vnd+"-"+prd+"/"+dev+"_data\'\"'\"'=> \
            {\\n \ \ \ \ \ \ \ \ store_type => '\"'\"'bluestore'\"'\"',\
            \\n \ \ \ \ \ \ \ \ bluestore_wal => '\"'\"'"+str(bayid)+"-"+sn+"-"+vnd+"-"+prd+"/"+dev+"_wal'\"'\"',\
            \\n \ \ \ \ \ \ \ \ bluestore_db => '\"'\"'"+str(bayid)+"-"+sn+"-"+vnd+"-"+prd+"/"+dev+"_db'\"'\"',\
            \\n \ \ \ \ \ \ \ \ ensure     => '\"'\"'present'\"'\"',\\n \ \ \ \ \ \},\\n"
    
        sed_string = sed_string + "\ \ \ \ \},"
        os.system("sed -i '/    '\"'\"'ceph_osd_test'\"'\"' => {/a "+sed_string+\
        "' "+storage_dn+"/modules/storage_ceph/manifests/disks/disks_lists.pp")
    
        # UPDATE NETWORKS
        os.system("sed -i \"s%131.154.128.0\/22%$(ip route show | sed -n 2p | awk '{print $1}')%g\" "\
        +storage_dn+"/modules/storage_ceph/manifests/params.pp")
    
        # DEPLOY CEPH WITH PUPPET
        os.system("puppet apply --modulepath="+storage_dn+"/modules:"+cnprov_dn+\
        " -e \"class {'storage_ceph' : isprovisioned => false, isallinone => true,\
        public_network => '$(ip route show | sed -n 2p | awk '{print $1}')',\
        cluster_network => '$(ip route show | sed -n 2p | awk '{print $1}')'}\"")