You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by an...@apache.org on 2016/11/14 23:50:56 UTC
[09/56] [abbrv] libcloud git commit: Removed sdist
http://git-wip-us.apache.org/repos/asf/libcloud/blob/8afcda91/apache-libcloud-1.0.0rc2/libcloud/loadbalancer/drivers/elb.py
----------------------------------------------------------------------
diff --git a/apache-libcloud-1.0.0rc2/libcloud/loadbalancer/drivers/elb.py b/apache-libcloud-1.0.0rc2/libcloud/loadbalancer/drivers/elb.py
deleted file mode 100644
index f67a522..0000000
--- a/apache-libcloud-1.0.0rc2/libcloud/loadbalancer/drivers/elb.py
+++ /dev/null
@@ -1,351 +0,0 @@
-# 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.
-
-__all__ = [
- 'ElasticLBDriver'
-]
-
-
-from libcloud.utils.py3 import httplib
-from libcloud.utils.xml import findtext, findall
-from libcloud.loadbalancer.types import State
-from libcloud.loadbalancer.base import Driver, LoadBalancer, Member
-from libcloud.common.aws import AWSGenericResponse, SignedAWSConnection
-
-
-VERSION = '2012-06-01'
-HOST = 'elasticloadbalancing.%s.amazonaws.com'
-ROOT = '/%s/' % (VERSION)
-NS = 'http://elasticloadbalancing.amazonaws.com/doc/%s/' % (VERSION, )
-
-
-class ELBResponse(AWSGenericResponse):
- """
- Amazon ELB response class.
- """
- namespace = NS
- exceptions = {}
- xpath = 'Error'
-
-
-class ELBConnection(SignedAWSConnection):
- version = VERSION
- host = HOST
- responseCls = ELBResponse
- service_name = 'elb'
-
-
-class ElasticLBDriver(Driver):
- name = 'Amazon Elastic Load Balancing'
- website = 'http://aws.amazon.com/elasticloadbalancing/'
- connectionCls = ELBConnection
-
- def __init__(self, access_id, secret, region):
- super(ElasticLBDriver, self).__init__(access_id, secret)
- self.region = region
- self.connection.host = HOST % (region)
-
- def list_protocols(self):
- return ['tcp', 'ssl', 'http', 'https']
-
- def list_balancers(self):
- params = {'Action': 'DescribeLoadBalancers'}
- data = self.connection.request(ROOT, params=params).object
- return self._to_balancers(data)
-
- def create_balancer(self, name, port, protocol, algorithm, members,
- ex_members_availability_zones=None):
- if ex_members_availability_zones is None:
- ex_members_availability_zones = ['a']
-
- params = {
- 'Action': 'CreateLoadBalancer',
- 'LoadBalancerName': name,
- 'Listeners.member.1.InstancePort': str(port),
- 'Listeners.member.1.InstanceProtocol': protocol.upper(),
- 'Listeners.member.1.LoadBalancerPort': str(port),
- 'Listeners.member.1.Protocol': protocol.upper(),
- }
-
- for i, z in enumerate(ex_members_availability_zones):
- zone = ''.join((self.region, z))
- params['AvailabilityZones.member.%d' % (i + 1)] = zone
-
- data = self.connection.request(ROOT, params=params).object
-
- balancer = LoadBalancer(
- id=name,
- name=name,
- state=State.PENDING,
- ip=findtext(element=data, xpath='DNSName', namespace=NS),
- port=port,
- driver=self.connection.driver
- )
- balancer._members = []
- return balancer
-
- def destroy_balancer(self, balancer):
- params = {
- 'Action': 'DeleteLoadBalancer',
- 'LoadBalancerName': balancer.id
- }
- self.connection.request(ROOT, params=params)
- return True
-
- def get_balancer(self, balancer_id):
- params = {
- 'Action': 'DescribeLoadBalancers',
- 'LoadBalancerNames.member.1': balancer_id
- }
- data = self.connection.request(ROOT, params=params).object
- return self._to_balancers(data)[0]
-
- def balancer_attach_compute_node(self, balancer, node):
- params = {
- 'Action': 'RegisterInstancesWithLoadBalancer',
- 'LoadBalancerName': balancer.id,
- 'Instances.member.1.InstanceId': node.id
- }
- self.connection.request(ROOT, params=params)
- balancer._members.append(Member(node.id, None, None, balancer=self))
-
- def balancer_detach_member(self, balancer, member):
- params = {
- 'Action': 'DeregisterInstancesFromLoadBalancer',
- 'LoadBalancerName': balancer.id,
- 'Instances.member.1.InstanceId': member.id
- }
- self.connection.request(ROOT, params=params)
- balancer._members = [m for m in balancer._members if m.id != member.id]
- return True
-
- def balancer_list_members(self, balancer):
- return balancer._members
-
- def ex_list_balancer_policies(self, balancer):
- """
- Return a list of policy description string.
-
- :rtype: ``list`` of ``str``
- """
- params = {
- 'Action': 'DescribeLoadBalancerPolicies',
- 'LoadBalancerName': balancer.id
- }
-
- data = self.connection.request(ROOT, params=params).object
- return self._to_policies(data)
-
- def ex_list_balancer_policy_types(self):
- """
- Return a list of policy type description string.
-
- :rtype: ``list`` of ``str``
- """
- params = {'Action': 'DescribeLoadBalancerPolicyTypes'}
-
- data = self.connection.request(ROOT, params=params).object
- return self._to_policy_types(data)
-
- def ex_create_balancer_policy(self, name, policy_name, policy_type,
- policy_attributes=None):
- """
- Create a new load balancer policy
-
- :param name: Balancer name to create the policy for
- :type name: ``str``
-
- :param policy_name: policy to be created
- :type policy_name: ``str``
-
- :param policy_type: policy type being used to create policy.
- :type policy_type: ``str``
-
- :param policy_attributes: Each list contain values, ['AttributeName',
- 'value']
- :type policy_attributes: ``PolicyAttribute list``
- """
- params = {
- 'Action': 'CreateLoadBalancerPolicy',
- 'LoadBalancerName': name,
- 'PolicyName': policy_name,
- 'PolicyTypeName': policy_type
- }
-
- if policy_attributes is not None:
- for index, (name, value) in enumerate(
- policy_attributes.iteritems(), 1):
- params['PolicyAttributes.member.%d. \
- AttributeName' % (index)] = name
- params['PolicyAttributes.member.%d. \
- AttributeValue' % (index)] = value
-
- response = self.connection.request(ROOT, params=params)
- return response.status == httplib.OK
-
- def ex_delete_balancer_policy(self, name, policy_name):
- """
- Delete a load balancer policy
-
- :param name: balancer name for which policy will be deleted
- :type name: ``str``
-
- :param policy_name: The Mnemonic name for the policy being deleted
- :type policy_name: ``str``
- """
- params = {
- 'Action': 'DeleteLoadBalancerPolicy',
- 'LoadBalancerName': name,
- 'PolicyName': policy_name
- }
-
- response = self.connection.request(ROOT, params=params)
- return response.status == httplib.OK
-
- def ex_set_balancer_policies_listener(self, name, port, policies):
- """
- Associates, updates, or disables a policy with a listener on
- the load balancer
-
- :param name: balancer name to set policies for listerner
- :type name: ``str``
-
- :param port: port to use
- :type port: ``str``
-
- :param policies: List of policies to be associated with the balancer
- :type policies: ``string list``
- """
- params = {
- 'Action': 'SetLoadBalancerPoliciesOfListener',
- 'LoadBalancerName': name,
- 'LoadBalancerPort': str(port)
- }
-
- if policies:
- params = self._create_list_params(params, policies,
- 'PolicyNames.member.%d')
-
- response = self.connection.request(ROOT, params=params)
- return response.status == httplib.OK
-
- def ex_set_balancer_policies_backend_server(self, name, instance_port,
- policies):
- """
- Replaces the current set of policies associated with a port on
- which the back-end server is listening with a new set of policies
-
- :param name: balancer name to set policies of backend server
- :type name: ``str``
-
- :param instance_port: Instance Port
- :type instance_port: ``int``
-
- :param policies: List of policies to be associated with the balancer
- :type policies: ``string list`
- """
- params = {
- 'Action': 'SetLoadBalancerPoliciesForBackendServer',
- 'LoadBalancerName': name,
- 'InstancePort': str(instance_port)
- }
-
- if policies:
- params = self._create_list_params(params, policies,
- 'PolicyNames.member.%d')
-
- response = self.connection.request(ROOT, params=params)
- return response.status == httplib.OK
-
- def ex_create_balancer_listeners(self, name, listeners=None):
- """
- Creates one or more listeners on a load balancer for the specified port
-
- :param name: The mnemonic name associated with the load balancer
- :type name: ``str``
-
- :param listeners: Each tuple contain values, (LoadBalancerPortNumber,
- InstancePortNumber, Protocol,[SSLCertificateId])
- :type listeners: ``list of tuple`
- """
- params = {
- 'Action': 'CreateLoadBalancerListeners',
- 'LoadBalancerName': name
- }
-
- for index, listener in enumerate(listeners):
- i = index + 1
- protocol = listener[2].upper()
- params['Listeners.member.%d.LoadBalancerPort' % i] = listener[0]
- params['Listeners.member.%d.InstancePort' % i] = listener[1]
- params['Listeners.member.%d.Protocol' % i] = listener[2]
- if protocol == 'HTTPS' or protocol == 'SSL':
- params['Listeners.member.%d. \
- SSLCertificateId' % i] = listener[3]
- else:
- return False
-
- response = self.connection.request(ROOT, params=params)
- return response.status == httplib.OK
-
- def _to_policies(self, data):
- xpath = 'DescribeLoadBalancerPoliciesResult/PolicyDescriptions/member'
- return [findtext(element=el, xpath='PolicyName', namespace=NS)
- for el in findall(element=data, xpath=xpath, namespace=NS)]
-
- def _to_policy_types(self, data):
- xpath = 'DescribeLoadBalancerPolicyTypesResult/'
- xpath += 'PolicyTypeDescriptions/member'
- return [findtext(element=el, xpath='PolicyTypeName', namespace=NS)
- for el in findall(element=data, xpath=xpath, namespace=NS)]
-
- def _to_balancers(self, data):
- xpath = 'DescribeLoadBalancersResult/LoadBalancerDescriptions/member'
- return [self._to_balancer(el)
- for el in findall(element=data, xpath=xpath, namespace=NS)]
-
- def _to_balancer(self, el):
- name = findtext(element=el, xpath='LoadBalancerName', namespace=NS)
- dns_name = findtext(el, xpath='DNSName', namespace=NS)
- port = findtext(el, xpath='LoadBalancerPort', namespace=NS)
-
- balancer = LoadBalancer(
- id=name,
- name=name,
- state=State.UNKNOWN,
- ip=dns_name,
- port=port,
- driver=self.connection.driver
- )
-
- xpath = 'Instances/member/InstanceId'
- members = findall(element=el, xpath=xpath, namespace=NS)
- balancer._members = []
-
- for m in members:
- balancer._members.append(Member(m.text, None, None,
- balancer=balancer))
-
- return balancer
-
- def _create_list_params(self, params, items, label):
- """
- return parameter list
- """
- if isinstance(items, str):
- items = [items]
- for index, item in enumerate(items):
- params[label % (index + 1)] = item
- return params
http://git-wip-us.apache.org/repos/asf/libcloud/blob/8afcda91/apache-libcloud-1.0.0rc2/libcloud/loadbalancer/drivers/gce.py
----------------------------------------------------------------------
diff --git a/apache-libcloud-1.0.0rc2/libcloud/loadbalancer/drivers/gce.py b/apache-libcloud-1.0.0rc2/libcloud/loadbalancer/drivers/gce.py
deleted file mode 100644
index c754221..0000000
--- a/apache-libcloud-1.0.0rc2/libcloud/loadbalancer/drivers/gce.py
+++ /dev/null
@@ -1,369 +0,0 @@
-# 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.
-
-try:
- import simplejson as json
-except ImportError:
- import json # NOQA
-
-from libcloud.loadbalancer.base import LoadBalancer, Member, Driver, Algorithm
-from libcloud.compute.drivers.gce import GCEConnection, GCENodeDriver
-
-# GCE doesn't actually give you an algorithm choice, but this is here simply as
-# the closest match. The actual algorithm is described here:
-# https://developers.google.com/compute/docs/load-balancing/#overview
-DEFAULT_ALGORITHM = Algorithm.RANDOM
-
-
-class GCELBDriver(Driver):
- connectionCls = GCEConnection
- apiname = 'googleapis'
- name = 'Google Compute Engine Load Balancer'
- website = 'https://cloud.google.com/'
-
- _VALUE_TO_ALGORITHM_MAP = {
- 'RANDOM': Algorithm.RANDOM
- }
-
- def __init__(self, *args, **kwargs):
-
- if kwargs.get('gce_driver'):
- self.gce = kwargs['gce_driver']
- else:
- self.gce = GCENodeDriver(*args, **kwargs)
-
- self.connection = self.gce.connection
-
- def _get_node_from_ip(self, ip):
- """
- Return the node object that matches a given public IP address.
-
- :param ip: Public IP address to search for
- :type ip: ``str``
-
- :return: Node object that has the given IP, or None if not found.
- :rtype: :class:`Node` or None
- """
- all_nodes = self.gce.list_nodes(ex_zone='all')
- for node in all_nodes:
- if ip in node.public_ips:
- return node
- return None
-
- def list_protocols(self):
- """
- Return a list of supported protocols.
-
- For GCE, this is simply a hardcoded list.
-
- :rtype: ``list`` of ``str``
- """
- return ['TCP', 'UDP']
-
- def list_balancers(self, ex_region=None):
- """
- List all loadbalancers
-
- :keyword ex_region: The region to return balancers from. If None,
- will default to self.region. If 'all', will
- return all balancers.
- :type ex_region: ``str`` or :class:`GCERegion` or ``None``
-
- :rtype: ``list`` of :class:`LoadBalancer`
- """
- balancers = []
- for fwr in self.gce.ex_list_forwarding_rules(region=ex_region):
- balancers.append(self._forwarding_rule_to_loadbalancer(fwr))
- return balancers
-
- def create_balancer(self, name, port, protocol, algorithm, members,
- ex_region=None, ex_healthchecks=None, ex_address=None,
- ex_session_affinity=None):
- """
- Create a new load balancer instance.
-
- For GCE, this means creating a forwarding rule and a matching target
- pool, then adding the members to the target pool.
-
- :param name: Name of the new load balancer (required)
- :type name: ``str``
-
- :param port: Port or range of ports the load balancer should listen
- on, defaults to all ports. Examples: '80', '5000-5999'
- :type port: ``str``
-
- :param protocol: Load balancer protocol. Should be 'tcp' or 'udp',
- defaults to 'tcp'.
- :type protocol: ``str``
-
- :param members: List of Members to attach to balancer. Can be Member
- objects or Node objects. Node objects are preferred
- for GCE, but Member objects are accepted to comply
- with the established libcloud API. Note that the
- 'port' attribute of the members is ignored.
- :type members: ``list`` of :class:`Member` or :class:`Node`
-
- :param algorithm: Load balancing algorithm. Ignored for GCE which
- uses a hashing-based algorithm.
- :type algorithm: :class:`Algorithm` or ``None``
-
- :keyword ex_region: Optional region to create the load balancer in.
- Defaults to the default region of the GCE Node
- Driver.
- :type ex_region: C{GCERegion} or ``str``
-
- :keyword ex_healthchecks: Optional list of healthcheck objects or
- names to add to the load balancer.
- :type ex_healthchecks: ``list`` of :class:`GCEHealthCheck` or
- ``list`` of ``str``
-
- :keyword ex_address: Optional static address object to be assigned to
- the load balancer.
- :type ex_address: C{GCEAddress}
-
- :keyword ex_session_affinity: Optional algorithm to use for session
- affinity. This will modify the hashing
- algorithm such that a client will tend
- to stick to a particular Member.
- :type ex_session_affinity: ``str``
-
- :return: LoadBalancer object
- :rtype: :class:`LoadBalancer`
- """
- node_list = []
- for member in members:
- # Member object
- if hasattr(member, 'ip'):
- if member.extra.get('node'):
- node_list.append(member.extra['node'])
- else:
- node_list.append(self._get_node_from_ip(member.ip))
- # Node object
- elif hasattr(member, 'name'):
- node_list.append(member)
- # Assume it's a node name otherwise
- else:
- node_list.append(self.gce.ex_get_node(member, 'all'))
-
- # Create Target Pool
- tp_name = '%s-tp' % name
- targetpool = self.gce.ex_create_targetpool(
- tp_name, region=ex_region, healthchecks=ex_healthchecks,
- nodes=node_list, session_affinity=ex_session_affinity)
-
- # Create the Forwarding rule, but if it fails, delete the target pool.
- try:
- forwarding_rule = self.gce.ex_create_forwarding_rule(
- name, targetpool, region=ex_region, protocol=protocol,
- port_range=port, address=ex_address)
- except:
- targetpool.destroy()
- raise
-
- # Reformat forwarding rule to LoadBalancer object
- return self._forwarding_rule_to_loadbalancer(forwarding_rule)
-
- def destroy_balancer(self, balancer):
- """
- Destroy a load balancer.
-
- For GCE, this means destroying the associated forwarding rule, then
- destroying the target pool that was attached to the forwarding rule.
-
- :param balancer: LoadBalancer which should be used
- :type balancer: :class:`LoadBalancer`
-
- :return: True if successful
- :rtype: ``bool``
- """
- destroy = balancer.extra['forwarding_rule'].destroy()
- if destroy:
- tp_destroy = balancer.extra['targetpool'].destroy()
- return tp_destroy
- else:
- return destroy
-
- def get_balancer(self, balancer_id):
- """
- Return a :class:`LoadBalancer` object.
-
- :param balancer_id: Name of load balancer you wish to fetch. For GCE,
- this is the name of the associated forwarding
- rule.
- :param balancer_id: ``str``
-
- :rtype: :class:`LoadBalancer`
- """
- fwr = self.gce.ex_get_forwarding_rule(balancer_id)
- return self._forwarding_rule_to_loadbalancer(fwr)
-
- def balancer_attach_compute_node(self, balancer, node):
- """
- Attach a compute node as a member to the load balancer.
-
- :param balancer: LoadBalancer which should be used
- :type balancer: :class:`LoadBalancer`
-
- :param node: Node to join to the balancer
- :type node: :class:`Node`
-
- :return: Member after joining the balancer.
- :rtype: :class:`Member`
- """
- add_node = balancer.extra['targetpool'].add_node(node)
- if add_node:
- return self._node_to_member(node, balancer)
-
- def balancer_attach_member(self, balancer, member):
- """
- Attach a member to balancer
-
- :param balancer: LoadBalancer which should be used
- :type balancer: :class:`LoadBalancer`
-
- :param member: Member to join to the balancer
- :type member: :class:`Member`
-
- :return: Member after joining the balancer.
- :rtype: :class:`Member`
- """
- node = member.extra.get('node') or self._get_node_from_ip(member.ip)
- add_node = balancer.extra['targetpool'].add_node(node)
- if add_node:
- return self._node_to_member(node, balancer)
-
- def balancer_detach_member(self, balancer, member):
- """
- Detach member from balancer
-
- :param balancer: LoadBalancer which should be used
- :type balancer: :class:`LoadBalancer`
-
- :param member: Member which should be used
- :type member: :class:`Member`
-
- :return: True if member detach was successful, otherwise False
- :rtype: ``bool``
- """
- node = member.extra.get('node') or self._get_node_from_ip(member.ip)
- remove_node = balancer.extra['targetpool'].remove_node(node)
- return remove_node
-
- def balancer_list_members(self, balancer):
- """
- Return list of members attached to balancer
-
- :param balancer: LoadBalancer which should be used
- :type balancer: :class:`LoadBalancer`
-
- :rtype: ``list`` of :class:`Member`
- """
- return [self._node_to_member(n, balancer) for n in
- balancer.extra['targetpool'].nodes]
-
- def ex_create_healthcheck(self, *args, **kwargs):
- return self.gce.ex_create_healthcheck(*args, **kwargs)
-
- def ex_list_healthchecks(self):
- return self.gce.ex_list_healthchecks()
-
- def ex_balancer_attach_healthcheck(self, balancer, healthcheck):
- """
- Attach a healthcheck to balancer
-
- :param balancer: LoadBalancer which should be used
- :type balancer: :class:`LoadBalancer`
-
- :param healthcheck: Healthcheck to add
- :type healthcheck: :class:`GCEHealthCheck`
-
- :return: True if successful
- :rtype: ``bool``
- """
- return balancer.extra['targetpool'].add_healthcheck(healthcheck)
-
- def ex_balancer_detach_healthcheck(self, balancer, healthcheck):
- """
- Detach healtcheck from balancer
-
- :param balancer: LoadBalancer which should be used
- :type balancer: :class:`LoadBalancer`
-
- :param healthcheck: Healthcheck to remove
- :type healthcheck: :class:`GCEHealthCheck`
-
- :return: True if successful
- :rtype: ``bool``
- """
- return balancer.extra['targetpool'].remove_healthcheck(healthcheck)
-
- def ex_balancer_list_healthchecks(self, balancer):
- """
- Return list of healthchecks attached to balancer
-
- :param balancer: LoadBalancer which should be used
- :type balancer: :class:`LoadBalancer`
-
- :rtype: ``list`` of :class:`HealthChecks`
- """
- return balancer.extra['healthchecks']
-
- def _node_to_member(self, node, balancer):
- """
- Return a Member object based on a Node.
-
- :param node: Node object
- :type node: :class:`Node`
-
- :keyword balancer: The balancer the member is attached to.
- :type balancer: :class:`LoadBalancer`
-
- :return: Member object
- :rtype: :class:`Member`
- """
- # A balancer can have a node as a member, even if the node doesn't
- # exist. In this case, 'node' is simply a string to where the resource
- # would be found if it was there.
- if hasattr(node, 'name'):
- member_id = node.name
- member_ip = node.public_ips[0]
- else:
- member_id = node
- member_ip = None
-
- extra = {'node': node}
- return Member(id=member_id, ip=member_ip, port=balancer.port,
- balancer=balancer, extra=extra)
-
- def _forwarding_rule_to_loadbalancer(self, forwarding_rule):
- """
- Return a Load Balancer object based on a GCEForwardingRule object.
-
- :param forwarding_rule: ForwardingRule object
- :type forwarding_rule: :class:`GCEForwardingRule`
-
- :return: LoadBalancer object
- :rtype: :class:`LoadBalancer`
- """
- extra = {}
- extra['forwarding_rule'] = forwarding_rule
- extra['targetpool'] = forwarding_rule.targetpool
- extra['healthchecks'] = forwarding_rule.targetpool.healthchecks
-
- return LoadBalancer(id=forwarding_rule.id,
- name=forwarding_rule.name, state=None,
- ip=forwarding_rule.address,
- port=forwarding_rule.extra['portRange'],
- driver=self, extra=extra)
http://git-wip-us.apache.org/repos/asf/libcloud/blob/8afcda91/apache-libcloud-1.0.0rc2/libcloud/loadbalancer/drivers/gogrid.py
----------------------------------------------------------------------
diff --git a/apache-libcloud-1.0.0rc2/libcloud/loadbalancer/drivers/gogrid.py b/apache-libcloud-1.0.0rc2/libcloud/loadbalancer/drivers/gogrid.py
deleted file mode 100644
index 201ad03..0000000
--- a/apache-libcloud-1.0.0rc2/libcloud/loadbalancer/drivers/gogrid.py
+++ /dev/null
@@ -1,239 +0,0 @@
-# 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.
-
-import sys
-import time
-
-from libcloud.utils.py3 import httplib
-
-try:
- import simplejson as json
-except ImportError:
- import json
-
-from libcloud.utils.misc import reverse_dict
-from libcloud.common.types import LibcloudError
-from libcloud.common.gogrid import GoGridConnection, GoGridResponse,\
- BaseGoGridDriver
-from libcloud.loadbalancer.base import LoadBalancer, Member, Driver, Algorithm
-from libcloud.loadbalancer.base import DEFAULT_ALGORITHM
-from libcloud.loadbalancer.types import State, LibcloudLBImmutableError
-
-
-class GoGridLBResponse(GoGridResponse):
- def success(self):
- if self.status == httplib.INTERNAL_SERVER_ERROR:
- # Hack, but at least this error message is more useful than
- # "unexpected server error"
- body = json.loads(self.body)
- if body['method'] == '/grid/loadbalancer/add' and \
- len(body['list']) >= 1 and \
- body['list'][0]['message'].find(
- 'unexpected server error') != -1:
- raise LibcloudError(
- value='You mostly likely tried to add a member with an IP'
- ' address not assigned to your account', driver=self)
- return super(GoGridLBResponse, self).success()
-
-
-class GoGridLBConnection(GoGridConnection):
- """
- Connection class for the GoGrid load-balancer driver.
- """
- responseCls = GoGridLBResponse
-
-
-class GoGridLBDriver(BaseGoGridDriver, Driver):
- connectionCls = GoGridLBConnection
- api_name = 'gogrid_lb'
- name = 'GoGrid LB'
- website = 'http://www.gogrid.com/'
-
- LB_STATE_MAP = {'On': State.RUNNING,
- 'Unknown': State.UNKNOWN}
- _VALUE_TO_ALGORITHM_MAP = {
- 'round robin': Algorithm.ROUND_ROBIN,
- 'least connect': Algorithm.LEAST_CONNECTIONS
- }
- _ALGORITHM_TO_VALUE_MAP = reverse_dict(_VALUE_TO_ALGORITHM_MAP)
-
- def __init__(self, *args, **kwargs):
- """
- @inherits: :class:`Driver.__init__`
- """
- super(GoGridLBDriver, self).__init__(*args, **kwargs)
-
- def list_protocols(self):
- # GoGrid only supports http
- return ['http']
-
- def list_balancers(self):
- return self._to_balancers(
- self.connection.request('/api/grid/loadbalancer/list').object)
-
- def ex_create_balancer_nowait(self, name, members, protocol='http',
- port=80, algorithm=DEFAULT_ALGORITHM):
- """
- @inherits: :class:`Driver.create_balancer`
- """
- algorithm = self._algorithm_to_value(algorithm)
-
- params = {'name': name,
- 'loadbalancer.type': algorithm,
- 'virtualip.ip': self._get_first_ip(),
- 'virtualip.port': port}
- params.update(self._members_to_params(members))
-
- resp = self.connection.request('/api/grid/loadbalancer/add',
- method='GET',
- params=params)
- return self._to_balancers(resp.object)[0]
-
- def create_balancer(self, name, members, protocol='http', port=80,
- algorithm=DEFAULT_ALGORITHM):
- balancer = self.ex_create_balancer_nowait(name, members, protocol,
- port, algorithm)
-
- timeout = 60 * 20
- waittime = 0
- interval = 2 * 15
-
- if balancer.id is not None:
- return balancer
- else:
- while waittime < timeout:
- balancers = self.list_balancers()
-
- for i in balancers:
- if i.name == balancer.name and i.id is not None:
- return i
-
- waittime += interval
- time.sleep(interval)
-
- raise Exception('Failed to get id')
-
- def destroy_balancer(self, balancer):
- try:
- resp = self.connection.request(
- '/api/grid/loadbalancer/delete', method='POST',
- params={'id': balancer.id})
- except Exception:
- e = sys.exc_info()[1]
- if "Update request for LoadBalancer" in str(e):
- raise LibcloudLBImmutableError(
- "Cannot delete immutable object", GoGridLBDriver)
- else:
- raise
-
- return resp.status == 200
-
- def get_balancer(self, **kwargs):
- params = {}
-
- try:
- params['name'] = kwargs['ex_balancer_name']
- except KeyError:
- balancer_id = kwargs['balancer_id']
- params['id'] = balancer_id
-
- resp = self.connection.request('/api/grid/loadbalancer/get',
- params=params)
-
- return self._to_balancers(resp.object)[0]
-
- def balancer_attach_member(self, balancer, member):
- members = self.balancer_list_members(balancer)
- members.append(member)
-
- params = {"id": balancer.id}
-
- params.update(self._members_to_params(members))
-
- resp = self._update_balancer(params)
- return [m for m in
- self._to_members(resp.object["list"][0]["realiplist"],
- balancer)
- if m.ip == member.ip][0]
-
- def balancer_detach_member(self, balancer, member):
- members = self.balancer_list_members(balancer)
-
- remaining_members = [n for n in members if n.id != member.id]
-
- params = {"id": balancer.id}
- params.update(self._members_to_params(remaining_members))
-
- resp = self._update_balancer(params)
-
- return resp.status == 200
-
- def balancer_list_members(self, balancer):
- resp = self.connection.request('/api/grid/loadbalancer/get',
- params={'id': balancer.id})
- return self._to_members(resp.object["list"][0]["realiplist"], balancer)
-
- def _update_balancer(self, params):
- try:
- return self.connection.request('/api/grid/loadbalancer/edit',
- method='POST',
- params=params)
- except Exception:
- e = sys.exc_info()[1]
- if "Update already pending" in str(e):
- raise LibcloudLBImmutableError(
- "Balancer is immutable", GoGridLBDriver)
-
- raise LibcloudError(value='Exception: %s' % str(e), driver=self)
-
- def _members_to_params(self, members):
- """
- Helper method to convert list of :class:`Member` objects
- to GET params.
-
- """
-
- params = {}
-
- i = 0
- for member in members:
- params["realiplist.%s.ip" % i] = member.ip
- params["realiplist.%s.port" % i] = member.port
- i += 1
-
- return params
-
- def _to_balancers(self, object):
- return [self._to_balancer(el) for el in object["list"]]
-
- def _to_balancer(self, el):
- lb = LoadBalancer(id=el.get("id"),
- name=el["name"],
- state=self.LB_STATE_MAP.get(
- el["state"]["name"], State.UNKNOWN),
- ip=el["virtualip"]["ip"]["ip"],
- port=el["virtualip"]["port"],
- driver=self.connection.driver)
- return lb
-
- def _to_members(self, object, balancer=None):
- return [self._to_member(el, balancer) for el in object]
-
- def _to_member(self, el, balancer=None):
- member = Member(id=el["ip"]["id"],
- ip=el["ip"]["ip"],
- port=el["port"],
- balancer=balancer)
- return member
http://git-wip-us.apache.org/repos/asf/libcloud/blob/8afcda91/apache-libcloud-1.0.0rc2/libcloud/loadbalancer/drivers/ninefold.py
----------------------------------------------------------------------
diff --git a/apache-libcloud-1.0.0rc2/libcloud/loadbalancer/drivers/ninefold.py b/apache-libcloud-1.0.0rc2/libcloud/loadbalancer/drivers/ninefold.py
deleted file mode 100644
index cb28f6c..0000000
--- a/apache-libcloud-1.0.0rc2/libcloud/loadbalancer/drivers/ninefold.py
+++ /dev/null
@@ -1,29 +0,0 @@
-# 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.loadbalancer.providers import Provider
-
-from libcloud.loadbalancer.drivers.cloudstack import CloudStackLBDriver
-
-
-class NinefoldLBDriver(CloudStackLBDriver):
- "Driver for load balancers on Ninefold's Compute platform."
-
- host = 'api.ninefold.com'
- path = '/compute/v1.0/'
-
- type = Provider.NINEFOLD
- name = 'Ninefold LB'
- website = 'http://ninefold.com/'