Exemplo n.º 1
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
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
Exemplo n.º 3
0
def find_equivalent_smt_server(configured_smt, known_smt_servers):
    """Find an SMT server that is equivalent to the currently configured
       SMT server, only consider responsive servers"""
    for smt in known_smt_servers:
        # Take a shortcut and only compare the IPv4 address to
        # skip the same server in the list. If the IPv4 addresses of
        # a given object are the same and other data is different we have
        # a really big problem.
        if smt.get_ipv4() == configured_smt.get_ipv4():
            continue
        if smt.is_equivalent(configured_smt) and smt.is_responsive():
            return smt

    return None
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.')