<commit_before># Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.

from libcloud.common.base import ConnectionKey
from libcloud.common.types import LibcloudError

__all__ = [
        "LBMember",
        "LB",
        "LBDriver",
        "LBAlgorithm"
        ]

class LBMember(object):

    def __init__(self, id, ip, port):
        self.id = str(id) if id else None
        self.ip = ip
        self.port = port

    def __repr__(self):
        return ('<LBMember: id=%s, address=%s:%s>' % (self.id,
            self.ip, self.port))

class LBAlgorithm(object):
    RANDOM = 0
    ROUND_ROBIN = 1
    LEAST_CONNECTIONS = 2

DEFAULT_ALGORITHM = LBAlgorithm.ROUND_ROBIN

class LB(object):
    """
    Provide a common interface for handling Load Balancers.
    """

    def __init__(self, id, name, state, ip, port, driver):
        self.id = str(id) if id else None
        self.name = name
        self.state = state
        self.ip = ip
        self.port = port
        self.driver = driver

    def attach_compute_node(self, node):
        return self.driver.balancer_attach_compute_node(node)

    def attach_member(self, member):
        return self.driver.balancer_attach_member(self, member)

    def detach_member(self, member):
        return self.driver.balancer_detach_member(self, member)

    def list_members(self):
        return self.driver.balancer_list_members(self)

    def __repr__(self):
        return ('<LB: id=%s, name=%s, state=%s>' % (self.id,
                self.name, self.state))


class LBDriver(object):
    """
    A base LBDriver class to derive from

    This class is always subclassed by a specific driver.

    """

    connectionCls = ConnectionKey
    _ALGORITHM_TO_VALUE_MAP = {}
    _VALUE_TO_ALGORITHM_MAP = {}

    def __init__(self, key, secret=None, secure=True):
        self.key = key
        self.secret = secret
        args = [self.key]

        if self.secret is not None:
            args.append(self.secret)

        args.append(secure)

        self.connection = self.connectionCls(*args)
        self.connection.driver = self
        self.connection.connect()

    def list_balancers(self):
        """
        List all loadbalancers

        @return: C{list} of L{LB} objects

        """

        raise NotImplementedError, \
                'list_balancers not implemented for this driver'

    def create_balancer(self, name, port, algorithm, members):
        """
        Create a new load balancer instance

        @keyword name: Name of the new load balancer (required)
        @type name: C{str}
        @keyword port: Port the load balancer should listen on (required)
        @type port: C{str}
        @keyword algorithm: Load balancing algorithm (defaults to round robin)
        @type algorithm: C{LBAlgorithm}
        @keyword members: C{list} of L{LBNode}s to attach to balancer
        @type: C{list} of L{LBNode}s

        """

        raise NotImplementedError, \
                'create_balancer not implemented for this driver'

    def destroy_balancer(self, balancer):
        """Destroy a load balancer

        @return: C{bool} True if the destroy was successful, otherwise False

        """

        raise NotImplementedError, \
                'destroy_balancer not implemented for this driver'

    def balancer_detail(self, **kwargs):
        """
        Returns a detailed info about load balancer given by
        existing L{LB} object or its id

        @keyword balancer: L{LB} object you already fetched using list method for example
        @type balancer: L{LB}
        @keyword balancer_id: id of a load balancer you want to fetch
        @type balancer_id: C{str}

        @return: L{LB}

        """

        raise NotImplementedError, \
                'balancer_detail not implemented for this driver'

    def balancer_attach_compute_node(self, balancer, node):
      """
      Attach a compute node as a member to the load balancer.

      @keyword node: Member to join to the balancer
      @type member: C{libcloud.compute.base.Node}
      @return {LBMember} Member after joining the balancer.
      """

      return self.attach_member(LBMember(None, node.public_ip[0], balancer.port))

    def balancer_attach_member(self, balancer, member):
        """
        Attach a member to balancer

        @keyword member: Member to join to the balancer
        @type member: C{LBMember}
        @return {LBMember} Member after joining the balancer.
        """
<commit_msg>Rename the balancer_detail to get_balancer and change the method signature and return value.<commit_after># Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.

from libcloud.common.base import ConnectionKey
from libcloud.common.types import LibcloudError

__all__ = [
        "LBMember",
        "LB",
        "LBDriver",
        "LBAlgorithm"
        ]

class LBMember(object):

    def __init__(self, id, ip, port):
        self.id = str(id) if id else None
        self.ip = ip
        self.port = port

    def __repr__(self):
        return ('<LBMember: id=%s, address=%s:%s>' % (self.id,
            self.ip, self.port))

class LBAlgorithm(object):
    RANDOM = 0
    ROUND_ROBIN = 1
    LEAST_CONNECTIONS = 2

DEFAULT_ALGORITHM = LBAlgorithm.ROUND_ROBIN

class LB(object):
    """
    Provide a common interface for handling Load Balancers.
    """

    def __init__(self, id, name, state, ip, port, driver):
        self.id = str(id) if id else None
        self.name = name
        self.state = state
        self.ip = ip
        self.port = port
        self.driver = driver

    def attach_compute_node(self, node):
        return self.driver.balancer_attach_compute_node(node)

    def attach_member(self, member):
        return self.driver.balancer_attach_member(self, member)

    def detach_member(self, member):
        return self.driver.balancer_detach_member(self, member)

    def list_members(self):
        return self.driver.balancer_list_members(self)

    def __repr__(self):
        return ('<LB: id=%s, name=%s, state=%s>' % (self.id,
                self.name, self.state))


class LBDriver(object):
    """
    A base LBDriver class to derive from

    This class is always subclassed by a specific driver.

    """

    connectionCls = ConnectionKey
    _ALGORITHM_TO_VALUE_MAP = {}
    _VALUE_TO_ALGORITHM_MAP = {}

    def __init__(self, key, secret=None, secure=True):
        self.key = key
        self.secret = secret
        args = [self.key]

        if self.secret is not None:
            args.append(self.secret)

        args.append(secure)

        self.connection = self.connectionCls(*args)
        self.connection.driver = self
        self.connection.connect()

    def list_balancers(self):
        """
        List all loadbalancers

        @return: C{list} of L{LB} objects

        """

        raise NotImplementedError, \
                'list_balancers not implemented for this driver'

    def create_balancer(self, name, port, algorithm, members):
        """
        Create a new load balancer instance

        @keyword name: Name of the new load balancer (required)
        @type name: C{str}
        @keyword port: Port the load balancer should listen on (required)
        @type port: C{str}
        @keyword algorithm: Load balancing algorithm (defaults to round robin)
        @type algorithm: C{LBAlgorithm}
        @keyword members: C{list} of L{LBNode}s to attach to balancer
        @type: C{list} of L{LBNode}s

        """

        raise NotImplementedError, \
                'create_balancer not implemented for this driver'

    def destroy_balancer(self, balancer):
        """Destroy a load balancer

        @return: C{bool} True if the destroy was successful, otherwise False

        """

        raise NotImplementedError, \
                'destroy_balancer not implemented for this driver'

    def get_balancer(self, balancer_id):
        """
        Return a C{LB} object.

        @keyword balancer_id: id of a load balancer you want to fetch
        @type balancer_id: C{str}

        @return: C{LB}
        """

        raise NotImplementedError, \
                'get_balancer not implemented for this driver'

    def balancer_attach_compute_node(self, balancer, node):
      """
      Attach a compute node as a member to the load balancer.

      @keyword node: Member to join to the balancer
      @type member: C{libcloud.compute.base.Node}
      @return {LBMember} Member after joining the balancer.
      """

      return self.attach_member(LBMember(None, node.public_ip[0], balancer.port))

    def balancer_attach_member(self, balancer, member):
        """
        Attach a member to balancer

        @keyword member: Member to join to the balancer
        @type member: C{LBMember}
        @return {LBMember} Member after joining the balancer.
        """

{'fraction_non_alphanumeric': 0.08554486244774959, 'fraction_numerical': 0.0015553611354136288, 'mean_word_length': 2.5549412577747064, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5260382', 'n_tokens_mistral': 2994, 'n_tokens_neox': 2872, 'n_words': 998}