Skip to content

Commit

Permalink
use octavia endpoint instead of neutron for lb activites
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoehler committed Feb 14, 2024
1 parent f75df87 commit b58e761
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ def create_membership(pool_id, ip, port, subnet_id)
begin
@logger.debug("Creating load balancer pool membership with pool id '#{pool_id}', ip '#{ip}', and port '#{port}'.")
membership_id = retry_on_conflict_pending_update(pool_id) {
@openstack.network.create_lbaas_pool_member(pool_id, ip, port, subnet_id:).body['member']['id']
@openstack.loadbalancer.create_lbaas_pool_member(pool_id, ip, port, subnet_id:).body['member']['id']
}
rescue Excon::Error::Conflict => e
lbaas_pool_members = @openstack.with_openstack(retryable: true) { @openstack.network.list_lbaas_pool_members(pool_id) }
lbaas_pool_members = @openstack.with_openstack(retryable: true) { @openstack.loadbalancer.list_lbaas_pool_members(pool_id) }
membership_id =
lbaas_pool_members
.body.fetch('members', [])
Expand Down Expand Up @@ -76,7 +76,7 @@ def remove_vm_from_pool(pool_id, membership_id)
begin
@logger.debug("Deleting load balancer pool membership with pool id '#{pool_id}' and membership id '#{membership_id}'.")
retry_on_conflict_pending_update(pool_id) {
@openstack.network.delete_lbaas_pool_member(pool_id, membership_id)
@openstack.loadbalancer.delete_lbaas_pool_member(pool_id, membership_id)
}
rescue Fog::OpenStack::Network::NotFound
@logger.debug("Skipping deletion of load balancer pool membership. Member with pool_id '#{pool_id}' and membership_id '#{membership_id}' does not exist.")
Expand Down Expand Up @@ -121,7 +121,7 @@ def retry_on_conflict_pending_update(pool_id)
def loadbalancer_id(pool_id)
pool_response = @openstack.with_openstack(retryable: true) do
begin
@openstack.network.get_lbaas_pool(pool_id)
@openstack.loadbalancer.get_lbaas_pool(pool_id)
rescue Fog::OpenStack::Network::NotFound => e
raise LoadBalancerResource::NotFound, "Load balancer ID could not be determined because pool with ID '#{pool_id}' was not found. Reason: #{e.message}"
end
Expand All @@ -143,7 +143,7 @@ def retrieve_loadbalancers_via_listener(listeners, pool_id)
raise LoadBalancerResource::NotSupportedConfiguration, "More than one listener is associated with load balancer pool '#{pool_id}'. It is not possible to verify the status of the load balancer responsible for the pool membership."
end

listener_response = @openstack.with_openstack(retryable: true) { @openstack.network.get_lbaas_listener(listeners[0]['id']) }
listener_response = @openstack.with_openstack(retryable: true) { @openstack.loadbalancer.get_lbaas_listener(listeners[0]['id']) }
listener_response.body['listener']['loadbalancers']
end

Expand Down Expand Up @@ -189,7 +189,7 @@ def initialize(name, port, pool_id, membership_id)

def openstack_pool_id(pool_name)
pools = @openstack.with_openstack(retryable: true) {
@openstack.network.list_lbaas_pools('name' => pool_name).body['pools']
@openstack.loadbalancer.list_lbaas_pools('name' => pool_name).body['pools']
}

if pools.empty?
Expand All @@ -214,7 +214,7 @@ def reload

def provisioning_status
@openstack.with_openstack(retryable: true) do
@openstack.network.get_lbaas_loadbalancer(@id).body['loadbalancer']['provisioning_status']
@openstack.loadbalancer.get_lbaas_loadbalancer(@id).body['loadbalancer']['provisioning_status']
end
end

Expand Down
18 changes: 18 additions & 0 deletions src/bosh_openstack_cpi/lib/cloud/openstack/openstack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,24 @@ def network
@network
end

def loadbalancer
unless @loadbalancer
begin
Bosh::Common.retryable(@retry_options) do |tries, error|
@logger.error("Failed #{tries} times, last failure due to: #{error.inspect}") unless error.nil?
params_lb = @params.merge(:openstack_service_type => 'load-balancer')
@loadbalancer = Fog::OpenStack::Network.new(params_lb)
end
rescue Excon::Error::Socket => e
cloud_error(socket_error_msg + e.message.to_s)
rescue Bosh::Common::RetryCountExceeded, Excon::Error::Client, Excon::Error::Server, Fog::Errors::NotFound => e
cloud_error("Unable to connect to the OpenStack loadbalancer Service API: #{e.message}. Check task debug log for details.")
end
end

@loadbalancer
end

##
# Waits for a resource to be on a target state
#
Expand Down

0 comments on commit b58e761

Please sign in to comment.