Uploaded image for project: 'Libcloud'
  1. Libcloud
  2. LIBCLOUD-879

GCE Load balancer suppose that all VM have public ip

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: LoadBalancer
    • Labels:
      None
    • Environment:

      GCE MASTER

    • Flags:
      Patch

      Description

      When calling "list_members()" on a GCe load balancer libcloud object I end up with the following stack :

      Retrieve 2 Lbs. Here is the list : [<LoadBalancer: id=68XXXXXXXX707, name=europe-lb-forwarding-rule, state=None, ip=10XXXXXXXX.77, port=30012-30012>, <LoadBalancer: id=87688XXXXXXXX64, name=load-balancer-prd-comp-forwarding-rule-2, state=None, ip=10XXXXXXXX93, port=30001-30001>]
      --Printing the node obj for DBG : <Node: uuid=9001a5d9d425dc0e5dd1db5352296b08920bde21, name=tec-XXXXXXXX-infra-2ktm, state=RUNNING, public_ips=[], private_ips=['10.XXXXXXXX'], provider=Google Compute Engine ...>
      Traceback (most recent call last):
        File "LbTestPy.py", line 43, in <module>
          print ("Members: " +str(aLbs[0].list_members()))
        File "/home/cloud-user/LbTest/src/apache-libcloud/libcloud/loadbalancer/base.py", line 110, in list_members
          return self.driver.balancer_list_members(balancer=self)
        File "/home/cloud-user/LbTest/src/apache-libcloud/libcloud/loadbalancer/drivers/gce.py", line 274, in balancer_list_members
          balancer.extra['targetpool'].nodes]
        File "/home/cloud-user/LbTest/src/apache-libcloud/libcloud/loadbalancer/drivers/gce.py", line 342, in _node_to_member
          member_ip = node.public_ips[0]
      IndexError: list index out of range
      

      After some investigations it appears to comes from the method "def _node_to_member(self, node, balancer):" in loadbalancer/drivers/gce.py. Mode precisely this piece of the code :

      code1.py
      if hasattr(node, 'name'):
      	member_id = node.name
      	member_ip = node.public_ips[0]
      else:
      	member_id = node
      	member_ip = None
      

      which imply that all VM in the load balancer will have public IP. This is not necessarly the case and thus when it happen the process crash (as you can see in the previous stack where i added some debug log in my libcloud version to print the node where the error occurs).

      I would had suggest to use private ip instead of public but I do not want to impact the existing user of libcloud so I was thinking of a simple fix :

      code1.py
      if hasattr(node, 'name'):
          member_id = node.name
      else:
          member_id = node
      
      if (len(node.public_ips) > 0):
          member_ip = node.public_ips[0]
      else:
          member_ip = None
      

        Issue Links

          Activity

          Hide
          charly37 charles walker added a comment - - edited

          I give it a try tonight and it break the test case because the node object can be a string. This works better :

          @@ -338,9 +338,12 @@ class GCELBDriver(Driver):
                   # 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
          +
          +        if (hasattr(node, 'public_ips') and (len(node.public_ips) > 0)):
          +            member_ip = node.public_ips[0]
          +        else:
                       member_ip = None
          
          Show
          charly37 charles walker added a comment - - edited I give it a try tonight and it break the test case because the node object can be a string. This works better : @@ -338,9 +338,12 @@ class GCELBDriver(Driver): # 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 + + if (hasattr(node, 'public_ips') and (len(node.public_ips) > 0)): + member_ip = node.public_ips[0] + else: member_ip = None
          Hide
          githubbot ASF GitHub Bot added a comment -

          GitHub user charly37 opened a pull request:

          https://github.com/apache/libcloud/pull/952

          LIBCLOUD-879 Add support of node without public IP in LB

            1. Add support of Node without public IP in GCP load balancer
              1. Description

          Link to jira ticket 879
          https://issues.apache.org/jira/browse/LIBCLOUD-879

          I had a condition to only try to grab the publicIP of a node if it had one since publicIP is not mandatory.

              1. Status

          This PR is ready to be review. I run the test (tox) before and after the change and no impact.

              1. Checklist (tick everything that applies)
          • [X] [Code linting] I tried to followed the guidline
          • [X] [Documentation] No change require
          • [X] [Tests] No impact on existing test (but no time to had more)
          • [X] [ICLA] Minor change so I skip it

          You can merge this pull request into a Git repository by running:

          $ git pull https://github.com/charly37/libcloud 879_PublicIpOpt

          Alternatively you can review and apply these changes as the patch at:

          https://github.com/apache/libcloud/pull/952.patch

          To close this pull request, make a commit to your master/trunk branch
          with (at least) the following in the commit message:

          This closes #952


          commit 38ae70157de7176e486b9c9965e9d9f385de3221
          Author: Charles Walker <charles.walker.37@gmail.com>
          Date: 2016-11-23T01:34:05Z

          LIBCLOUD-879 Add support of node without public IP in LB


          Show
          githubbot ASF GitHub Bot added a comment - GitHub user charly37 opened a pull request: https://github.com/apache/libcloud/pull/952 LIBCLOUD-879 Add support of node without public IP in LB Add support of Node without public IP in GCP load balancer Description Link to jira ticket 879 https://issues.apache.org/jira/browse/LIBCLOUD-879 I had a condition to only try to grab the publicIP of a node if it had one since publicIP is not mandatory. Status This PR is ready to be review. I run the test (tox) before and after the change and no impact. Checklist (tick everything that applies) [X] [Code linting] I tried to followed the guidline [X] [Documentation] No change require [X] [Tests] No impact on existing test (but no time to had more) [X] [ICLA] Minor change so I skip it You can merge this pull request into a Git repository by running: $ git pull https://github.com/charly37/libcloud 879_PublicIpOpt Alternatively you can review and apply these changes as the patch at: https://github.com/apache/libcloud/pull/952.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #952 commit 38ae70157de7176e486b9c9965e9d9f385de3221 Author: Charles Walker <charles.walker.37@gmail.com> Date: 2016-11-23T01:34:05Z LIBCLOUD-879 Add support of node without public IP in LB
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit 1666a8da34068db0557cc9b186736f571e73df58 in libcloud's branch refs/heads/trunk from charles walker
          [ https://git-wip-us.apache.org/repos/asf?p=libcloud.git;h=1666a8d ]

          LIBCLOUD-879 Add support of node without public IP in LB

          closes #879

          Signed-off-by: Allard Hoeve <allardhoeve@gmail.com>

          Show
          jira-bot ASF subversion and git services added a comment - Commit 1666a8da34068db0557cc9b186736f571e73df58 in libcloud's branch refs/heads/trunk from charles walker [ https://git-wip-us.apache.org/repos/asf?p=libcloud.git;h=1666a8d ] LIBCLOUD-879 Add support of node without public IP in LB closes #879 Signed-off-by: Allard Hoeve <allardhoeve@gmail.com>
          Hide
          henkslaaf Allard Hoeve added a comment -

          I tried to close this using a commit message but failed. Can be closed, thanks.

          Show
          henkslaaf Allard Hoeve added a comment - I tried to close this using a commit message but failed. Can be closed, thanks.
          Hide
          charly37 charles walker added a comment -

          Solved with change in code to allow LoadBalancer with node that do not have publicIP.

          Show
          charly37 charles walker added a comment - Solved with change in code to allow LoadBalancer with node that do not have publicIP.

            People

            • Assignee:
              Unassigned
              Reporter:
              charly37 charles walker
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 1h
                1h
                Remaining:
                Remaining Estimate - 1h
                1h
                Logged:
                Time Spent - Not Specified
                Not Specified

                  Development