Class: Staypuft::InterfaceAssignmentsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- Staypuft::InterfaceAssignmentsController
- Defined in:
- app/controllers/staypuft/interface_assignments_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/controllers/staypuft/interface_assignments_controller.rb', line 30 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 |
#destroy ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/controllers/staypuft/interface_assignments_controller.rb', line 46 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 |
#index ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# 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) @host = @hosts.first assigned_subnet_ids = ([@host.subnet_id] + @host.interfaces.map(&:subnet_id)).compact.uniq @subnets = @deployment.subnets.where(["#{Subnet.table_name}.id NOT IN (?)", assigned_subnet_ids]).uniq if @host @interfaces = @host.interfaces.where("type <> 'Nic::BMC'").order(:identifier).where(['(virtual = ? OR type = ?)', false, 'Nic::Bond']) else @interfaces = [] end 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 />') render :js => "$('#configure_networks_modal').modal('hide'); window.location = '#{deployment_path(@deployment)}'" end end |