Пример #1
0
    def _init_member(address, port, default_route_domain):
        u"""Initialize the pool member name and address.

        An address is of the form:
        <ip_address>[%<route_domain_id>]
        """
        if not address or not port:
            LOGGER.error(
                "pool member definition must contain address and port")
            raise TypeError(
                "F5CCCL poolMember definition must contain address and port")

        # force address to include route domain
        address, ip, _ = normalize_address_with_route_domain(
            address, default_route_domain)

        ip_address = IPAddress(ip)

        # force name to be defined as <ip>%<rd>:<port>
        if ip_address.version == 4:
            name_format = "{}:{}"
        else:
            name_format = "{}.{}"
        name = name_format.format(address, port)

        return name
Пример #2
0
    def _init_member(address, port, default_route_domain):
        u"""Initialize the pool member name and address.

        An address is of the form:
        <ip_address>[%<route_domain_id>]
        """
        if not address or not port:
            LOGGER.error(
                "pool member definition must contain address and port")
            raise TypeError(
                "F5CCCL poolMember definition must contain address and port")

        # force address to include route domain
        address, ip, _ = normalize_address_with_route_domain(
            address, default_route_domain)

        ip_address = IPAddress(ip)

        # force name to be defined as <ip>%<rd>:<port>
        if ip_address.version == 4:
            name_format = "{}:{}"
        else:
            name_format = "{}.{}"
        name = name_format.format(address, port)

        return name
Пример #3
0
    def __init__(self, name, partition, default_route_domain, **properties):
        """Create a VirtualAddress instance."""
        super(VirtualAddress, self).__init__(name, partition, **properties)

        for key, value in list(self.properties.items()):
            self._data[key] = properties.get(key, value)
        if self._data['address'] is not None:
            self._data['address'] = normalize_address_with_route_domain(
                self._data['address'], default_route_domain)[0]
Пример #4
0
    def __init__(self, name, partition, default_route_domain, **properties):
        """Create a VirtualAddress instance."""
        super(VirtualAddress, self).__init__(name, partition, **properties)

        for key, value in self.properties.items():
            self._data[key] = properties.get(key, value)
        if self._data['address'] is not None:
            self._data['address'] = normalize_address_with_route_domain(
                self._data['address'], default_route_domain)[0]
Пример #5
0
    def normalizeAddresses(self, default_rd):
        '''Normalize destination and source fields to include route domain

        Adds the default route domain to the destination field if one is
        not provided.

        Also adds the destination route domain to the source field if it
        does not proivde one (probably could just force it since they both
        have to be in the same route domain).
        '''

        # Save the route domain info for use with the source field.
        ip_ver = 4
        dest_rd = default_rd
        if self._data.get('destination') is not None:
            # Add route domain if not supplied
            path, bigip_addr, port = self.destination[1:]
            bigip_addr, dest_ip, dest_rd = normalize_address_with_route_domain(
                bigip_addr, default_rd)
            ip_address = IPAddress(dest_ip)
            ip_ver = ip_address.version
            # force name to be defined as <ip>%<rd>:<port>
            if ip_ver == 4:
                dest_format = '/{}/{}:{}'
            else:
                dest_format = '/{}/{}.{}'
            self._data['destination'] = dest_format.format(
                path, bigip_addr, port)

        source = self._data.get('source')
        if source is None:
            if ip_ver == 4:
                source = '0.0.0.0%{}/0'.format(dest_rd)
            else:
                source = '::%{}/0'.format(dest_rd)
        else:
            match = self.source_pattern.match(source)
            if match:
                bigip_addr = match.group(1)
                mask = match.group(2)
                bigip_addr = normalize_address_with_route_domain(
                    bigip_addr, dest_rd)[0]
                source = '{}/{}'.format(bigip_addr, mask)
        self._data['source'] = source
Пример #6
0
    def _iapp_build_variables(self, config):
        """Create a list of name-value objects."""
        variables = []
        for key, value in config['variables'].items():
            var = {'name': key, 'value': value}
            if var['name'] == "pool__addr":
                var['value'] = normalize_address_with_route_domain(
                    var['value'], self._default_route_domain)[0]
            variables.append(var)

        return variables
Пример #7
0
    def _iapp_build_tables(self, members, config):
        """Create a dict that defines the tables for an iApp.

        Args:
            members: list of pool members
            config: BIG-IP config dict
        """
        tables = []
        if 'poolMemberTable' in config:
            tableConfig = config['poolMemberTable']

            # Construct columnNames array from the 'name' prop of each column
            columnNames = [col['name'] for col in tableConfig['columns']]

            # Construct rows array - one row for each node, interpret the
            # 'kind' or 'value' from the column spec.
            rows = []
            for node in members:
                row = []
                for col in tableConfig['columns']:
                    if 'value' in col:
                        row.append(col['value'])
                    elif 'kind' in col:
                        if col['kind'] == 'IPAddress':
                            address = normalize_address_with_route_domain(
                                node['address'], self._default_route_domain)[0]
                            row.append(address)
                        elif col['kind'] == 'Port':
                            row.append(str(node['port']))

                rows.append({'row': row})

            # Done - add the generated pool member table to the set of tables
            # we're going to configure.
            tables.append({
                'name': tableConfig['name'],
                'columnNames': columnNames,
                'rows': rows
            })

        # Add other tables
        if 'tables' in config:
            for key in config['tables']:
                data = config['tables'][key]
                table = {
                    'columnNames': data['columns'],
                    'name': key,
                    'rows': []
                }
                for row in data['rows']:
                    table['rows'].append({'row': row})
                tables.append(table)

        return tables
Пример #8
0
    def _iapp_build_variables(self, config):
        """Create a list of name-value objects."""
        variables = []
        for key, value in list(config['variables'].items()):
            var = {'name': key, 'value': value}
            if var['name'] == "pool__addr":
                var['value'] = normalize_address_with_route_domain(
                    var['value'], self._default_route_domain)[0]
            variables.append(var)

        return variables
Пример #9
0
    def _iapp_build_tables(self, members, config):
        """Create a dict that defines the tables for an iApp.

        Args:
            members: list of pool members
            config: BIG-IP config dict
        """
        tables = []
        if 'poolMemberTable' in config:
            tableConfig = config['poolMemberTable']

            # Construct columnNames array from the 'name' prop of each column
            columnNames = [col['name'] for col in tableConfig['columns']]

            # Construct rows array - one row for each node, interpret the
            # 'kind' or 'value' from the column spec.
            rows = []
            for node in members:
                row = []
                for col in tableConfig['columns']:
                    if 'value' in col:
                        row.append(col['value'])
                    elif 'kind' in col:
                        if col['kind'] == 'IPAddress':
                            address = normalize_address_with_route_domain(
                                node['address'], self._default_route_domain)[0]
                            row.append(address)
                        elif col['kind'] == 'Port':
                            row.append(str(node['port']))

                rows.append({'row': row})

            # Done - add the generated pool member table to the set of tables
            # we're going to configure.
            tables.append({
                'name': tableConfig['name'],
                'columnNames': columnNames,
                'rows': rows
            })

        # Add other tables
        if 'tables' in config:
            for key in config['tables']:
                data = config['tables'][key]
                table = {'columnNames': data['columns'],
                         'name': key,
                         'rows': []}
                for row in data['rows']:
                    table['rows'].append({'row': row})
                tables.append(table)

        return tables
Пример #10
0
def test_normalize_address_with_route_domain():
    """Test proper behavior of normalize_address_with_route_domain."""

    # If route domain is not specified, add the default
    tests = [["1.2.3.4%1", 2, "1.2.3.4%1", "1.2.3.4", 1],
             ["1.2.3.4", 2, "1.2.3.4%2", "1.2.3.4", 2],
             ["64:ff9b::%1", 2, "64:ff9b::%1", "64:ff9b::", 1],
             ["64:ff9b::", 2, "64:ff9b::%2", "64:ff9b::", 2]]
    for test in tests:
        results = normalize_address_with_route_domain(test[0], test[1])
        assert results[0] == test[2]
        assert results[1] == test[3]
        assert results[2] == test[4]
Пример #11
0
def test_normalize_address_with_route_domain():
    """Test proper behavior of normalize_address_with_route_domain."""

    # If route domain is not specified, add the default
    tests = [
        ["1.2.3.4%1", 2, "1.2.3.4%1", "1.2.3.4", 1],
        ["1.2.3.4", 2, "1.2.3.4%2", "1.2.3.4", 2],
        ["64:ff9b::%1", 2, "64:ff9b::%1", "64:ff9b::", 1],
        ["64:ff9b::", 2, "64:ff9b::%2", "64:ff9b::", 2]
    ]
    for test in tests:
        results = normalize_address_with_route_domain(test[0], test[1])
        assert results[0] == test[2]
        assert results[1] == test[3]
        assert results[2] == test[4]
Пример #12
0
 def __init__(self, name, partition, default_route_domain, **properties):
     # The address from the BigIP needs the route domain added if it
     # happens to match the default for the partition
     properties['address'] = normalize_address_with_route_domain(
         properties.get('address'), default_route_domain)[0]
     super(IcrNode, self).__init__(name, partition, **properties)
Пример #13
0
 def __init__(self, name, default_route_domain, **data):
     """Create a record from CCCL recordType."""
     super(Record, self).__init__(name, partition=None)
     endpoint = data.get('endpoint', None)
     self._data['endpoint'] = normalize_address_with_route_domain(
         endpoint, default_route_domain)[0]
Пример #14
0
 def __init__(self, name, default_route_domain, **data):
     """Create a record from CCCL recordType."""
     super(Record, self).__init__(name, partition=None)
     endpoint = data.get('endpoint', None)
     self._data['endpoint'] = normalize_address_with_route_domain(
         endpoint, default_route_domain)[0]
Пример #15
0
 def __init__(self, name, partition, default_route_domain, **properties):
     # The expected node should have route domain as part of name
     name = normalize_address_with_route_domain(
         properties.get('address'), default_route_domain)[0]
     super(ApiNode, self).__init__(name, partition, **properties)
Пример #16
0
 def __init__(self, name, partition, default_route_domain, **properties):
     # The expected node should have route domain as part of name
     name = normalize_address_with_route_domain(
         properties.get('address'), default_route_domain)[0]
     super(ApiNode, self).__init__(name, partition, **properties)
Пример #17
0
 def __init__(self, name, partition, default_route_domain, **properties):
     # The address from the BigIP needs the route domain added if it
     # happens to match the default for the partition
     properties['address'] = normalize_address_with_route_domain(
         properties.get('address'), default_route_domain)[0]
     super(IcrNode, self).__init__(name, partition, **properties)