Class: Staypuft::InterfaceAssignmentsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/staypuft/interface_assignments_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/staypuft/interface_assignments_controller.rb', line 25

def create
  @errors = {}
  @deployment = Deployment.find(params[:deployment_id])
  host_ids = params[:host_ids]
  host_ids = host_ids.split(',') unless host_ids.is_a? Array
  @hosts = Host::Managed.where(:id => host_ids)
  @hosts.each do |host|
    @interface = host.interfaces.find_by_identifier(params[:interface]) || host
    @subnet = Subnet.find(params[:subnet_id])
    @assigner = InterfaceAssigner.new(@deployment, @interface, @subnet)
    @assigner.assign
    @errors[host.name] = @assigner.errors if @assigner.errors.present?
  end
  @saved = @errors.blank?
end

#destroyObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/staypuft/interface_assignments_controller.rb', line 41

def destroy
  @errors = {}
  @deployment = Deployment.find(params[:deployment_id])
  host_ids = params[:host_ids]
  host_ids = host_ids.split(',') unless host_ids.is_a? Array
  @hosts = Host::Managed.where(:id => host_ids)
  @hosts.each do |host|
    @interface = host.interfaces.find_by_identifier(params[:interface]) || host
    @subnet = Subnet.find(params[:subnet_id])
    @assigner = InterfaceAssigner.new(@deployment, @interface, @subnet)
    @assigner.unassign
    @errors[host.name] = @assigner.errors if @assigner.errors.present?
  end
  @destroyed = @errors.blank?
end

#indexObject



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

def index
  @deployment = Deployment.find(params[:deployment_id])
  host_ids = params[:host_ids]
  host_ids = host_ids.split(',') unless host_ids.is_a? Array
  @hosts = Host::Managed.where(:id => host_ids).includes(:interfaces)
  @subnets = @deployment.subnets.uniq
  @host = @hosts.first
  @interfaces = @host ? @host.interfaces.where("type <> 'Nic::BMC'").non_vip.order(:identifier).physical : []

  errors = {}
  @hosts.each do |host|
    host_errors = compare(host, @host)
    errors[host.name] = host_errors.join(' and ') if host_errors.present?
  end

  if errors.present?
    flash[:error] = errors.map{ |k, v| "#{k}: #{v}" }.join('<br />')
    redirect_to deployment_path(@deployment)
  end
end