import ipaddress


def getResourceManagerIpv4(args):
    """Retrieve the IPv4 address of the cloudFPGA Resource Manager.
    :param args The options passed as arguments to the script.
    :return     The IP address as an 'ipaddress.IPv4Address'."""
    ipResMngrStr = args.mngr_ipv4
    while True:
        if args.mngr_ipv4 == '':
            # Take an IP address from the console
            print("Enter the IPv4 address of the cloudFPGA Resource Manager (e.g. 10.12.0.132)")
            ipResMngrStr = input()
        try:
            ipResMngr = ipaddress.ip_address(ipResMngrStr)
        except ValueError:
            print('[ERROR] Unrecognized IPv4 address.')
        else:
            return ipResMngr