Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.6 kB
1
Indexable
Never
# Check if password is Expiring in coming two days
def check_vm_user_pwd_expiry_date(i,All_VM_Details):
    global num_pass_reset
    num_pass_reset = 0
    vm_details = get_vm_details()
    #print(vm_details)
    vm_username = vm_details[i][i]['vm_username'][0]
    vm_id = i
    vm_user_password_expiry_date = vm_details[i][i]['vm_user_password_expiry_date']
    #print(vm_user_password_expiry_date,type(vm_user_password_expiry_date))
    expiry_date = list(datefinder.find_dates(vm_user_password_expiry_date[0]))
    expiry_date = expiry_date[0].date()
    date_approachingin2days = datetime.datetime.today() + datetime.timedelta(days=2)
    date_approachingin2days = date_approachingin2days.date()
    print("Expiry date for the VM user - {} with VM ID - {}  is {}".format(vm_username,vm_id,expiry_date))
    logging.info("Expiry date for the VM user - %s with VM ID - %s is %s", vm_username, vm_id, expiry_date)
    #print(date_approachingin2days)
    if expiry_date==date_approachingin2days:
        print("Password Reset is Required for this VM User - {} with VM ID - {}.".format(vm_username,vm_id))
        logging.info("Password Reset is Required for this VM User - %s with VM ID - %s.", vm_username, vm_id)
        num_pass_reset += 1
        reset_vm_user_password(i, vm_details)

    elif expiry_date!=date_approachingin2days:
            print("Expiry date is not approaching in coming two days. Hence, No Action is needed.")
            logging.info("Expiry date is not approaching in coming two days. Hence, No Action is needed.")
    return None