def get_valid_networks():
    '''Description:
        Gets the valid networks taking into account the all_services/networks
        and all_services/exclude_networks service properties.

    Args:
        None

    Returns:
        a set of valid networks.

    Raises:
        None
    '''
    # get the currently configured interfaces
    interfaces = getifaddrs()
    # get the exclude and networks service property values
    exclude = getboolean_property(SRVINST, EXCLPROP)
    networks = getstrings_property(SRVINST, NETSPROP)

    valid_networks = set()
    for inf in interfaces:
        # check the interface IP address against those listed in
        # the AI service SMF networks property.  Our logic for the
        # SMF exclude_networks and SMF networks list is:
        #
        #   IF ipv4 is in networks and
        #      SMF exclude_networks == false
        #   THEN include ipv4
        #   IF ipv4 is not in_networks and
        #      SMF exclude_network == true
        #   THEN include ipv4
        #   IF ipv4 is in_networks and
        #      SMF exclude_networks == true
        #   THEN exclude ipv4
        #   IF ipv4 is not in_networks and
        #      SMF exclude_network == false
        #   THEN exclude ipv4
        #
        # Assume that it is excluded and check the first 2 conditions only
        # as the last 2 conditions are covered by the assumption.
        in_net = in_networks(interfaces[inf], networks)
        include_it = False
        if (in_net and not exclude) or (not in_net and exclude):
            include_it = True

        if not include_it:
            continue

        mask = interfaces[inf].find('/')
        if mask == -1:
            mask = len(interfaces[inf])
        valid_networks.add(interfaces[inf][:mask])

    return valid_networks
Ejemplo n.º 2
0
def get_valid_networks():
    '''Description:
        Gets the valid networks taking into account the all_services/networks
        and all_services/exclude_networks service properties.

    Args:
        None

    Returns:
        a set of valid networks.

    Raises:
        None
    '''
    # get the currently configured interfaces
    interfaces = getifaddrs()
    # get the exclude and networks service property values
    exclude = getboolean_property(SRVINST, EXCLPROP)
    networks = getstrings_property(SRVINST, NETSPROP)

    valid_networks = set()
    for inf in interfaces:
        # check the interface IP address against those listed in
        # the AI service SMF networks property.  Our logic for the
        # SMF exclude_networks and SMF networks list is:
        #
        #   IF ipv4 is in networks and
        #      SMF exclude_networks == false
        #   THEN include ipv4
        #   IF ipv4 is not in_networks and
        #      SMF exclude_network == true
        #   THEN include ipv4
        #   IF ipv4 is in_networks and
        #      SMF exclude_networks == true
        #   THEN exclude ipv4
        #   IF ipv4 is not in_networks and
        #      SMF exclude_network == false
        #   THEN exclude ipv4
        #
        # Assume that it is excluded and check the first 2 conditions only
        # as the last 2 conditions are covered by the assumption.
        in_net = in_networks(interfaces[inf], networks)
        include_it = False
        if (in_net and not exclude) or (not in_net and exclude):
            include_it = True

        if not include_it:
            continue

        mask = interfaces[inf].find('/')
        if mask == -1:
            mask = len(interfaces[inf])
        valid_networks.add(interfaces[inf][:mask])

    return valid_networks
Ejemplo n.º 3
0
 def test_if_names(self):
     '''method to test the netif if_nameindex()
     '''
     interfaces = if_nameindex()
     # note: getifaddrs() skips loopback and point-to-point,
     #       therefore, test only that the getifaddrs interfaces
     #       are in the if_nameindex interfaces
     ifaddrs = getifaddrs()
     for inter in ifaddrs:
         assert inter in interfaces.values(), \
             'Unable to find %s' % inter
Ejemplo n.º 4
0
 def test_getifaddrs(self):
     '''test libaimdns.getifaddrs interface
     '''
     inter = if_nameindex()
     # note: getifaddrs() skips loopback and point-to-point,
     #       therefore, test only that the getifaddrs interfaces
     #       are in the if_nameindex interfaces
     ifaddrs = getifaddrs()
     for ifaddr in ifaddrs:
         assert ifaddr in inter.values(), \
             'Unable to find %s interface' % ifaddr
 def test_if_names(self):
     '''method to test the netif if_nameindex()
     '''
     interfaces = if_nameindex()
     # note: getifaddrs() skips loopback and point-to-point,
     #       therefore, test only that the getifaddrs interfaces
     #       are in the if_nameindex interfaces
     ifaddrs = getifaddrs()
     for inter in ifaddrs:
         assert inter in interfaces.values(), \
             'Unable to find %s' % inter
Ejemplo n.º 6
0
    def __init__(self, servicename=None, domain='local', comment=None):
        '''Method: __init__, class private
           Parameters:
                        servicename - the AI servicename
                        domain      - the domain for the registered service
                        comment     - the text comment for the service
           Raises:
               AImDNSError - when unable to retrieve setup information from
                             the host about the available interfaces or the
                             AI SMF service.
        '''
        gettext.install("ai", "/usr/lib/locale")

        # find sdref handle
        self._find = None
        self._lookup = False
        self.services = dict()
        self.servicename = servicename
        self.domain = domain
        self.txt = comment
        self.inter = None
        self.port = 0
        self.verbose = False
        self.timeout = 5
        self.done = False
        self.count = 0

        self.sdrefs = dict()

        self.interfaces = libaimdns.getifaddrs()

        self.register_initialized = False
        self.exclude = False
        self.networks = ['0.0.0.0/0']

        self.instance = None
        self.instance_services = None
    def __init__(self, servicename=None, domain='local', comment=None):
        '''Method: __init__, class private
           Parameters:
                        servicename - the AI servicename
                        domain      - the domain for the registered service
                        comment     - the text comment for the service
           Raises:
               AImDNSError - when unable to retrieve setup information from
                             the host about the available interfaces or the
                             AI SMF service.
        '''
        gettext.install("ai", "/usr/lib/locale")

        # find sdref handle
        self._find = None
        self._lookup = False
        self.services = dict()
        self.servicename = servicename
        self.domain = domain
        self.txt = comment
        self.inter = None
        self.port = 0
        self.verbose = False
        self.timeout = 5
        self.done = False
        self.count = 0

        self.sdrefs = dict()

        self.interfaces = libaimdns.getifaddrs()

        self.register_initialized = False
        self.exclude = False
        self.networks = ['0.0.0.0/0']

        self.instance = None
        self.instance_services = None