Skip to content

Commit

Permalink
network: Ensure data returned by allocate_ip is correct
Browse files Browse the repository at this point in the history
When allocate_ip is called, it returns some data representing the
related network information. However, as network attributes can be
overridden by having attributes on a node (to override the conduit for a
specific network on that node, for instance), which is something that
was not reflected here, resulting in incorrect data.
  • Loading branch information
vuntz committed Apr 26, 2018
1 parent 6e07966 commit 52e2c25
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions crowbar_framework/app/models/network_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def allocate_ip_by_type(bc_instance, network, range, object, type, suggestion =
return [404, "No node found"] if node.nil?
name = node.name.to_s
else
node = nil
name = object.to_s
end

Expand All @@ -70,7 +71,7 @@ def allocate_ip_by_type(bc_instance, network, range, object, type, suggestion =
begin
lock = acquire_ip_lock
db = Chef::DataBag.load("crowbar/#{network}_network") rescue nil
net_info = build_net_info(role, network)
net_info = build_net_info(role, network, node)

# Did we already allocate this, but the node lost it?
if db["allocated_by_name"].key?(name)
Expand Down Expand Up @@ -428,13 +429,13 @@ def enable_interface(bc_instance, network, name)
node.save

Rails.logger.info("Network enable_interface: Assigned: #{name} #{network}")
[200, build_net_info(role, network)]
[200, build_net_info(role, network, nil)]
end

def build_net_info(role, network)
net_info = {}
role.default_attributes["network"]["networks"][network].each do |k, v|
net_info[k] = v unless v.nil?
def build_net_info(role, network, node)
net_info = role.default_attributes["network"]["networks"][network].to_hash
unless node.nil? || node.crowbar.nil?
net_info.merge!(node.crowbar["crowbar"]["network"][network] || {})
end
net_info
end
Expand Down

0 comments on commit 52e2c25

Please sign in to comment.