Class: Actions::ForemanProbing::CreateSubnets

Inherits:
EntryAction
  • Object
show all
Defined in:
app/lib/actions/create_subnets.rb

Instance Method Summary collapse

Instance Method Details

#runObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/lib/actions/create_subnets.rb', line 5

def run
  proxy = SmartProxy.find(input[:proxy_id])
  output[:subnet_ids] = input[:scan][:proxy_output][:local_addresses].map do |str, hash|
    network_addr = IPAddr.new(hash[:addr]).mask(hash[:cidr]).to_s
    subnet = Subnet.where(:network => network_addr, :mask => hash[:netmask]).first
    if subnet.nil?
      subnet = Subnet.new
      subnet.network = network_addr
      subnet.mask = hash[:netmask]
      subnet.name = "#{str} at #{proxy.name}"
      subnet.location_ids = proxy.location_ids
      subnet.organization_ids = proxy.organization_ids
      subnet.save!
    end
    proxy.subnets << subnet
    proxy.save!
    subnet.id
  end
end