Skip to content

Commit 52e2c25

Browse files
committed
network: Ensure data returned by allocate_ip is correct
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.
1 parent 6e07966 commit 52e2c25

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

crowbar_framework/app/models/network_service.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def allocate_ip_by_type(bc_instance, network, range, object, type, suggestion =
5454
return [404, "No node found"] if node.nil?
5555
name = node.name.to_s
5656
else
57+
node = nil
5758
name = object.to_s
5859
end
5960

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

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

430431
Rails.logger.info("Network enable_interface: Assigned: #{name} #{network}")
431-
[200, build_net_info(role, network)]
432+
[200, build_net_info(role, network, nil)]
432433
end
433434

434-
def build_net_info(role, network)
435-
net_info = {}
436-
role.default_attributes["network"]["networks"][network].each do |k, v|
437-
net_info[k] = v unless v.nil?
435+
def build_net_info(role, network, node)
436+
net_info = role.default_attributes["network"]["networks"][network].to_hash
437+
unless node.nil? || node.crowbar.nil?
438+
net_info.merge!(node.crowbar["crowbar"]["network"][network] || {})
438439
end
439440
net_info
440441
end

0 commit comments

Comments
 (0)