Untitled

 avatar
unknown
plain_text
2 years ago
2.9 kB
4
Indexable
# 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

# Check Password Expiry Parameter/Policy for VM Users for all VMs in VM List through Iteration
def check_vm_user_password_expiry_parameter():
    for i in VMList:
        if All_VM_Details[i][i]['vm_user_password_expiry_date']==['Never Expires']:
            print("Password Expiry Parameter was set to Never Expires for the VM User - {} with vm id - {}. Hence, No action is needed!".format(All_VM_Details[i][i]['vm_username'],i))
            logging.info("Password Expiry Parameter was set to Never Expires for the VM User - %s with vm id - %s. Hence, No action is needed!", All_VM_Details[i][i]['vm_username'], i)

        elif All_VM_Details[i][i]['vm_user_password_expiry_date']!=['Never Expires']:
            print("Password Expiry date was set for the VM User - {} with vm id - {}, Please check the Expiry date for password!".format(All_VM_Details[i][i]['vm_username'],i))
            logging.info("Password Expiry date was set for the VM User - %s with vm id - %s. Please check the Expiry date for password!", All_VM_Details[i][i]['vm_username'], i)
            check_vm_user_pwd_expiry_date(i,All_VM_Details[i])
    return None

check_vm_user_password_expiry_parameter()

if num_pass_reset >=1:
    print("Num Pass reset count ",num_pass_reset)
    restart_services(i, vm_details)
Editor is loading...