Added the ability to specify a load balancing algorithm without having to use the Aglortimh class in base.py. Changed load balancing algorithm choices to LEAST_CONNECTIONS_MEMBER, LEAST_CONNECTIONS_NODE, OBSERVED_MEMBER, OBSERVED_NODE, PREDICTIVE_MEMBER, PREDICTIVE_NODE
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/2e6156f9 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/2e6156f9 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/2e6156f9 Branch: refs/heads/trunk Commit: 2e6156f9e675926fb03c03c03c7edac63e028ad0 Parents: b19a165 Author: mitch <[email protected]> Authored: Tue Sep 18 10:32:11 2018 -0400 Committer: mitch <[email protected]> Committed: Tue Sep 18 10:32:11 2018 -0400 ---------------------------------------------------------------------- libcloud/compute/drivers/nttcis.py | 3 +- libcloud/loadbalancer/base.py | 13 ++++--- libcloud/loadbalancer/drivers/nttcis.py | 52 +++++++++++++++++++++------- tests/lib_create_test.py | 25 +++++++++---- tests/lib_list_test.py | 21 ++++++++++- 5 files changed, 85 insertions(+), 29 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/2e6156f9/libcloud/compute/drivers/nttcis.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/drivers/nttcis.py b/libcloud/compute/drivers/nttcis.py index 2f20805..57bcec5 100644 --- a/libcloud/compute/drivers/nttcis.py +++ b/libcloud/compute/drivers/nttcis.py @@ -857,7 +857,6 @@ class NttCisNodeDriver(NodeDriver): driver=self.connection.driver), ] - def list_locations(self, ex_id=None): """ List locations (datacenters) available for instantiating servers and @@ -1019,7 +1018,7 @@ class NttCisNodeDriver(NodeDriver): 'urn:guestOsCustomization' ).text = is_guest_os_customization - if len(tagkey_name_value_dictionaries) > 0: + if tagkey_name_value_dictionaries is not None and len(tagkey_name_value_dictionaries) > 0: for k, v in tagkey_name_value_dictionaries.items(): tag_elem = ET.SubElement( import_image_elem, http://git-wip-us.apache.org/repos/asf/libcloud/blob/2e6156f9/libcloud/loadbalancer/base.py ---------------------------------------------------------------------- diff --git a/libcloud/loadbalancer/base.py b/libcloud/loadbalancer/base.py index 171b6bf..9223f89 100644 --- a/libcloud/loadbalancer/base.py +++ b/libcloud/loadbalancer/base.py @@ -122,14 +122,13 @@ class Algorithm(object): """ Represents a load balancing algorithm. """ - - RANDOM = 0 ROUND_ROBIN = 1 - LEAST_CONNECTIONS = 2 - WEIGHTED_ROUND_ROBIN = 3 - WEIGHTED_LEAST_CONNECTIONS = 4 - SHORTEST_RESPONSE = 5 - PERSISTENT_IP = 6 + LEAST_CONNECTIONS_MEMBER = 2 + LEAST_CONNECTIONS_NODE = 3 + OBSERVED_MEMBER = 4 + OBSERVED_NODE = 4 + PREDICTIVE_MEMBER = 5 + PREDICTIVE_NODE = 6 DEFAULT_ALGORITHM = Algorithm.ROUND_ROBIN http://git-wip-us.apache.org/repos/asf/libcloud/blob/2e6156f9/libcloud/loadbalancer/drivers/nttcis.py ---------------------------------------------------------------------- diff --git a/libcloud/loadbalancer/drivers/nttcis.py b/libcloud/loadbalancer/drivers/nttcis.py index 85a1f51..e066d1b 100644 --- a/libcloud/loadbalancer/drivers/nttcis.py +++ b/libcloud/loadbalancer/drivers/nttcis.py @@ -97,17 +97,25 @@ class NttCisLBDriver(Driver): kwargs['region'] = self.selected_region return kwargs - def create_balancer(self, name, port=None, protocol=None, - algorithm=None, members=None, + def create_balancer(self, name, listener_port=None, port=None, protocol=None, + algorithm=None, members=None, optimization_profile=None, ex_listener_ip_address=None): """ + BUG: libcloud.common.nttcis.NttCisAPIException: CONFIGURATION_NOT_SUPPORTED: + optimizationProfile is required for type STANDARD and protocol TCP. + + Create a new load balancer instance :param name: Name of the new load balancer (required) :type name: ``str`` - :param port: An integer in the range of 1-65535. If not supplied, + :param listener_port: An integer in the range of 1-65535. If not supplied, it will be taken to mean 'Any Port' + :type port: ``int + + :param port: An integer in the range of 1-65535. If not supplied, + it will be taken to mean 'Any Port' Assumed that node ports will different from listener port. :type port: ``int`` :param protocol: Loadbalancer protocol, defaults to http. @@ -119,6 +127,10 @@ class NttCisLBDriver(Driver): :param algorithm: Load balancing algorithm, defaults to ROUND_ROBIN. :type algorithm: :class:`.Algorithm` + :param optimization_profile: For STANDARD type and protocol TCP an optimization type of + TCP, LAN_OPT, WAN_OPT, MOBILE_OPT, or TCP_LEGACY is required + :type protcol: ``str`` + :param ex_listener_ip_address: Must be a valid IPv4 in dot-decimal notation (x.x.x.x). :type ex_listener_ip_address: ``str`` @@ -129,24 +141,27 @@ class NttCisLBDriver(Driver): if protocol is None: protocol = 'http' if algorithm is None: - algorithm = Algorithm.ROUND_ROBIN + algor = Algorithm.ROUND_ROBIN + else: + algor = Algorithm.__dict__[algorithm] # Create a pool first + al = self._ALGORITHM_TO_VALUE_MAP[algor] pool = self.ex_create_pool( network_domain_id=network_domain_id, name=name, ex_description=None, - balancer_method=self._ALGORITHM_TO_VALUE_MAP[algorithm]) + balancer_method=self._ALGORITHM_TO_VALUE_MAP[algor]) # Attach the members to the pool as nodes if members is not None: for member in members: - #if not isinstance(member, Node): - # node = self.ex_create_node( - # network_domain_id=network_domain_id, - # name=member.name, - # ip=member.private_ips[0], - # ex_description=None) + if not isinstance(member, Member): + member = self.ex_create_node( + network_domain_id=network_domain_id, + name=member.name, + ip=member.private_ips[0], + ex_description=None) self.ex_create_pool_member( pool=pool, node=member, @@ -157,8 +172,10 @@ class NttCisLBDriver(Driver): network_domain_id=network_domain_id, name=name, ex_description=name, - port=port, + port=listener_port, pool=pool, + protocol=protocol, + optimization_profile=optimization_profile, listener_ip_address=ex_listener_ip_address) return LoadBalancer( @@ -580,6 +597,7 @@ class NttCisLBDriver(Driver): fallback_persistence_profile=None, irule=None, protocol='TCP', + optimization_profile = None, connection_limit=25000, connection_rate_limit=2000, source_port_preservation='PRESERVE'): @@ -619,6 +637,10 @@ class NttCisLBDriver(Driver): for PERFORMANCE_LAYER_4 choice of ANY, TCP, UDP, HTTP :type protcol: ``str`` + :param optimization_profile: For STANDARD type and protocol TCP an optimization type of + TCP, LAN_OPT, WAN_OPT, MOBILE_OPT, or TCP_LEGACY is required + :type protcol: ``str`` + :param connection_limit: Maximum number of concurrent connections per sec :type connection_limit: ``int`` @@ -638,6 +660,10 @@ class NttCisLBDriver(Driver): else: listener_type = 'STANDARD' + if listener_type == 'STANDARD' and optimization_profile is None: + raise ValueError(" CONFIGURATION_NOT_SUPPORTED: optimizationProfile is required for type STANDARD and protocol TCP") + + create_node_elm = ET.Element('createVirtualListener', {'xmlns': TYPES_URN}) ET.SubElement(create_node_elm, "networkDomainId") \ @@ -666,6 +692,8 @@ class NttCisLBDriver(Driver): if persistence_profile is not None: ET.SubElement(create_node_elm, "persistenceProfileId") \ .text = persistence_profile.id + if optimization_profile is not None: + ET.SubElement(create_node_elm, 'optimizationProfile').text = optimization_profile if fallback_persistence_profile is not None: ET.SubElement(create_node_elm, "fallbackPersistenceProfileId") \ .text = fallback_persistence_profile.id http://git-wip-us.apache.org/repos/asf/libcloud/blob/2e6156f9/tests/lib_create_test.py ---------------------------------------------------------------------- diff --git a/tests/lib_create_test.py b/tests/lib_create_test.py index 2494f31..fa52697 100644 --- a/tests/lib_create_test.py +++ b/tests/lib_create_test.py @@ -1,7 +1,7 @@ from pprint import pprint import pytest import libcloud -from libcloud import loadbalancer + from libcloud.compute.drivers.nttcis import NttCisPort, NttCisIpAddress, NttCisPublicIpBlock, NttCisNatRule from libcloud.common.nttcis import NttCisFirewallRule, NttCisVlan, NttCisFirewallAddress @@ -188,20 +188,31 @@ def test_create_ipv6_addresss(compute_driver): assert result is True -def test_create_load_balancer(lbdriver, compute_driver): +def test_import_customer_image(compute_driver): + package_name = "bitnami-couchdb-2.1.2-1-r35-linux-centos-7-x86_64.mf" + name = "bitnami-couchdb-2.1.2-1-r35-linux-centos-7-x86_64" + datacenter_id = 'EU6' + is_guest_os_customization = 'false' + result = compute_driver.import_image(package_name, name, datacenter_id=datacenter_id, + is_guest_os_customization=is_guest_os_customization) + assert result is True + +def test_create_load_balancer(lbdriver, compute_driver): member1 = compute_driver.list_nodes(ex_name='web1')[0] member2 = compute_driver.list_nodes(ex_name='web2')[0] members = [member1, member2] name = 'sdk_test_balancer' - port = '8000' - protocol = 'http' - algorithm = 1 + port = '80' + listener_port = '8000' + protocol = 'TCP' + algorithm = 'LEAST_CONNECTIONS' members = [m for m in members] ex_listener_ip_address = "168.128.13.127" - lb = lbdriver.create_balancer(name, port=port, protocol=protocol, algorithm=algorithm, members=members, + lb = lbdriver.create_balancer(name, listener_port=listener_port, port=port, protocol=protocol, + algorithm=algorithm, members=members, optimization_profile='TCP', ex_listener_ip_address=ex_listener_ip_address) - assert lb.name == name + def test_create_pool(lbdriver): http://git-wip-us.apache.org/repos/asf/libcloud/blob/2e6156f9/tests/lib_list_test.py ---------------------------------------------------------------------- diff --git a/tests/lib_list_test.py b/tests/lib_list_test.py index ce01277..55d958e 100644 --- a/tests/lib_list_test.py +++ b/tests/lib_list_test.py @@ -300,6 +300,11 @@ def test_list_no_anti_affinity_rules(compute_driver): assert len(anti_affinity_rules) == 0 +def test_list_locations(compute_driver): + locations = compute_driver.list_locations() + for location in locations: + print(location) + """ def test_list_sizes(compute_driver): @@ -359,4 +364,18 @@ def test_list_nat_rules(compute_driver): network_domain = [nd for nd in network_domains if nd.name == network_domain_name][0] rules = compute_driver.ex_list_nat_rules(network_domain) for rule in rules: - print(rule) \ No newline at end of file + print(rule) + + +def test_list_customer_images(compute_driver): + location = 'EU6' + images = compute_driver.ex_list_customer_images(location) + for image in images: + print(image, image.extra) + + +def test_get_customer_image(compute_driver): + imagee_id = '84da095f-c8c7-4ace-9fb6-eceb1047027c' + image = compute_driver.ex_get_image_by_id(imagee_id) + print(image, image.extra) +
