<commit_before># Copyright 2014, <NAME> (dougwig), A10 Networks
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

import logging

import acos_client.errors as acos_errors
import handler_base_v1
import v1_context as a10

LOG = logging.getLogger(__name__)


class MemberHandler(handler_base_v1.HandlerBaseV1):

    def _get_name(self, member, ip_address):
        if self.a10_driver.config.get('member_name_use_uuid'):
            return member['id']

        tenant_label = member['tenant_id'][:5]
        addr_label = str(ip_address).replace(".", "_", 4)
        server_name = "_%s_%s_neutron" % (tenant_label, addr_label)
        return server_name

    def _meta_name(self, member, ip_address):
        return self.meta(member, 'name', self._get_name(member, ip_address))

    def _create(self, c, context, member):
        server_ip = self.neutron.member_get_ip(context, member,
                                               c.device_cfg['use_float'])
        server_name = self._meta_name(member, server_ip)
        conn_limit = c.device_cfg['conn-limit']
        status = c.client.slb.UP
        if not member['admin_state_up']:
            status = c.client.slb.DOWN

        try:
            server_args = self.meta(member, 'server', {})
            if conn_limit:
                if conn_limit < 1 or conn_limit > 8000000:
                    LOG.warning("The specified member server connection limit " +
                                "(configuration setting: conn-limit) is out of " +
                                "bounds with value {0}. Please set to between " +
                                "1-8000000. Defaulting to 8000000".format(conn_limit))
                else:
                    server_args['conn-limit'] = conn_limit
            server_args = {'server': server_args}
            c.client.slb.server.create(server_name, server_ip,
                                       status=status,
                                       axapi_args=server_args)
        except (acos_errors.Exists, acos_errors.AddressSpecifiedIsInUse):
            pass

        try:
            member_args = {'member': self.meta(member, 'member', {})}
            c.client.slb.service_group.member.create(
                self._pool_name(context, member['pool_id']),
                server_name,
                member['protocol_port'],
                status=status,
                axapi_args=member_args)
        except acos_errors.Exists:<commit_msg>Adding more requested changes<commit_after># Copyright 2014, <NAME> (dougwig), A10 Networks
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

import logging

import acos_client.errors as acos_errors
import handler_base_v1
import v1_context as a10

LOG = logging.getLogger(__name__)


class MemberHandler(handler_base_v1.HandlerBaseV1):

    def _get_name(self, member, ip_address):
        if self.a10_driver.config.get('member_name_use_uuid'):
            return member['id']

        tenant_label = member['tenant_id'][:5]
        addr_label = str(ip_address).replace(".", "_", 4)
        server_name = "_%s_%s_neutron" % (tenant_label, addr_label)
        return server_name

    def _meta_name(self, member, ip_address):
        return self.meta(member, 'name', self._get_name(member, ip_address))

    def _create(self, c, context, member):
        server_ip = self.neutron.member_get_ip(context, member,
                                               c.device_cfg['use_float'])
        server_name = self._meta_name(member, server_ip)
        conn_limit = c.device_cfg.get('conn-limit')
        status = c.client.slb.UP
        if not member['admin_state_up']:
            status = c.client.slb.DOWN

        try:
            server_args = self.meta(member, 'server', {})
            if conn_limit:
                if conn_limit < 1 or conn_limit > 8000000:
                    LOG.warning("The specified member server connection limit " +
                                "(configuration setting: conn-limit) is out of " +
                                "bounds with value {0}. Please set to between " +
                                "1-8000000. Defaulting to 8000000".format(conn_limit))
                else:
                    server_args['conn-limit'] = conn_limit
            server_args = {'server': server_args}
            c.client.slb.server.create(server_name, server_ip,
                                       status=status,
                                       axapi_args=server_args)
        except (acos_errors.Exists, acos_errors.AddressSpecifiedIsInUse):
            pass

        try:
            member_args = {'member': self.meta(member, 'member', {})}
            c.client.slb.service_group.member.create(
                self._pool_name(context, member['pool_id']),
                server_name,
                member['protocol_port'],
                status=status,
                axapi_args=member_args)
        except acos_errors.Exists:
{'fraction_non_alphanumeric': 0.09217129474740716, 'fraction_numerical': 0.014720642355302778, 'mean_word_length': 2.099533437013997, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5092729', 'n_tokens_mistral': 1707, 'n_tokens_neox': 1619, 'n_words': 430}