Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.6 kB
1
Indexable
Never
def searching_copying_logs(bookmark_record,syslog_record_no,i,log_block_size):
    print("The function with searching_copying_logs is getting called.")
    vm_id=i
    print("VM ID :",vm_id)
    bookmark_line=bookmark_record
    number_of_lines=log_block_size
    print("No of Lines to copy : ",number_of_lines)
    print("Bookmark Record",bookmark_record)
    old_line_number=syslog_record_no
    print('Old line number : ',old_line_number)
    last_line_no= int(old_line_number)+ int(number_of_lines)
    print('New Line Number :',last_line_no)
    all_vm_details = get_vm_details()
    vm_ip = all_vm_details[vm_id][vm_id]['vm_ip'][0]
    vm_log_filename=all_vm_details[vm_id][vm_id]['vm_log_filename'][0]
    syslog_record = str(vm_ip)+"_bookmark_log="
    print(syslog_record)
    print("VM Log FIle : ",vm_log_filename)
    # Finding the line with index as line number -->Make changes here for filename as vm_log_filename
    last_line_output = linecache.getline('/Analytics/venv/Jup/CAPE_Apache_Beam/Data/LONSTBYRDEV02-10.72.209.183.txt', last_line_no)
    print("Content for nth line :",last_line_output)
    filename=str(vm_ip)+"-T" +str(current_time) + ".txt"
    print(filename)
    import itertools
    X = int(old_line_number)
    print(f"Old Value is {X}")# Starting line number
    Y = int(last_line_no)  # Ending line number
    print(f'New Value is {Y}')
    with open('/Analytics/venv/Jup/CAPE_Apache_Beam/Data/LONSTBYRDEV02-10.72.209.183.txt', 'r') as input_file, open(filename, 'w') as output_file:
        output_file.writelines(itertools.islice(input_file, X - 1, Y))