Method: Staypuft::InterfaceAssigner#assign

Defined in:
app/models/staypuft/interface_assigner.rb

#assignObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/models/staypuft/interface_assigner.rb', line 24

def assign
  if virtual_assignment?
    if (existing = conflicting_interface)
      @errors.push _("Another interface %s on same physical interface with same VLAN exists") % existing.identifier
      return false
    end
    ActiveRecord::Base.transaction do
      unassign_from_other_nics
      assign_virtual
      raise ActiveRecord::Rollback if @errors.present?
      return true
    end
  else
    if @interface.subnet.present? && @interface.subnet != @subnet
      @errors.push _("Interface is already assigned to subnet %s") % @interface.subnet.name
      return false
    end
    ActiveRecord::Base.transaction do
      unassign_from_other_nics
      assign_physical
      raise ActiveRecord::Rollback if @errors.present?
      return true
    end
  end

  return false # we can get there only after rollback
end