def get_current_smt():
    """Return the data for the current SMT server.
       The current SMT server is the server aginst which this client
       is registered."""
    smt = get_smt_from_store(__get_registered_smt_file_path())
    if not smt:
        return
    # Verify that this system is also in /etc/hosts and we are in
    # a consistent state
    # Handle entries as bytes,
    # Yes users put non ascii characters into /etc/hosts
    smt_ipv4 = smt.get_ipv4()
    smt_ipv6 = smt.get_ipv6()
    smt_fqdn = smt.get_FQDN()
    # A bit cumbersome to support Python 3.4
    ipv4_search = '%s\s' % smt_ipv4
    ipv6_search = '%s\s' % smt_ipv6
    fqdn_search = '\s%s\s' % smt_fqdn
    hosts = open(HOSTSFILE_PATH, 'rb').read()
    if (not (re.search(ipv4_search.encode(), hosts)
             or re.search(ipv6_search.encode(), hosts))
            or not re.search(fqdn_search.encode(), hosts)):
        os.unlink(__get_registered_smt_file_path())
        return
    if not check_registration(smt_fqdn):
        return

    return smt
Example #2
0
def get_current_smt():
    """Return the data for the current SMT server.
       The current SMT server is the server aginst which this client
       is registered."""
    smt = get_smt_from_store(__get_registered_smt_file_path())
    if not smt:
        return
    # Verify that this system is also in /etc/hosts and we are in
    # a consistent state
    smt_ipv4 = smt.get_ipv4()
    smt_ipv6 = smt.get_ipv6()
    smt_fqdn = smt.get_FQDN()
    hosts = open(HOSTSFILE_PATH, 'r').read()
    if (
            not (
                re.search(r'%s\s' % smt_ipv4, hosts) or
                re.search(r'%s\s' % smt_ipv6, hosts)
            ) or not
            re.search(r'\s%s\s' % smt_fqdn, hosts)
    ):
        os.unlink(__get_registered_smt_file_path())
        return
    if not check_registration(smt_fqdn):
        return

    return smt
Example #3
0
def remove_registration_data(smt_servers):
    """Reset the instance to an unregistered state"""
    smt_data_file = __get_registered_smt_file_path()
    if os.path.exists(smt_data_file):
        os.unlink(smt_data_file)
    for smt in smt_servers:
        server_name = smt.get_FQDN()
        domain_name = smt.get_domain_name()
        clean_hosts_file(domain_name)
        __remove_credentials(server_name)
        __remove_repos(server_name)
        __remove_service(server_name)
def remove_registration_data():
    """Reset the instance to an unregistered state"""
    smt_data_file = __get_registered_smt_file_path()
    if os.path.exists(smt_data_file):
        smt = get_smt_from_store(smt_data_file)
        smt_ips = (smt.get_ipv4(), smt.get_ipv6())
        logging.info('Clean current registration server: %s' % str(smt_ips))
        server_name = smt.get_FQDN()
        domain_name = smt.get_domain_name()
        clean_hosts_file(domain_name)
        __remove_credentials(server_name)
        __remove_repos(server_name)
        __remove_service(server_name)
        os.unlink(smt_data_file)
        if os.path.exists('/etc/SUSEConnect'):
            os.unlink('/etc/SUSEConnect')
    else:
        logging.info('No current registration server set.')
def is_registered(smt):
    """Figure out if any of the servers is known"""
    if check_registration(smt.get_FQDN()):
        return 1

    return None
Example #6
0
def is_registered(smt):
    """Figure out if any of the servers is known"""
    if check_registration(smt.get_FQDN()):
        return 1

    return None