Class: SubnetsController

Inherits:
ApplicationController show all
Includes:
Foreman::Controller::AutoCompleteSearch
Defined in:
app/controllers/subnets_controller.rb

Instance Method Summary collapse

Methods included from Foreman::Controller::AutoCompleteSearch

#auto_complete_search, #invalid_search_query

Methods inherited from ApplicationController

#api_request?, #welcome

Methods included from Foreman::ThreadSession::Cleaner

#clear_thread, included

Instance Method Details

#createObject


16
17
18
19
20
21
22
23
# File 'app/controllers/subnets_controller.rb', line 16

def create
  @subnet = Subnet.new(params[:subnet])
  if @subnet.save
    process_success
  else
    process_error
  end
end

#create_multipleObject


75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/controllers/subnets_controller.rb', line 75

def create_multiple
  if params[:subnets].empty?
    return redirect_to subnets_path, :notice => _("No subnets selected")
  end

  @subnets = Subnet.create(params[:subnets]).reject { |s| s.errors.empty? }
  if @subnets.empty?
    process_success(:object => @subnets, :success_msg => _("Imported Subnets"))
  else
    render :action => "import"
  end
end

#destroyObject


38
39
40
41
42
43
44
45
# File 'app/controllers/subnets_controller.rb', line 38

def destroy
  @subnet = Subnet.find(params[:id])
  if @subnet.destroy
    process_success
  else
    process_error
  end
end

#editObject


25
26
27
# File 'app/controllers/subnets_controller.rb', line 25

def edit
  @subnet = Subnet.find(params[:id])
end

#freeipObject

query our subnet dhcp proxy for an unused IP


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/controllers/subnets_controller.rb', line 48

def freeip
  not_found and return unless (s=params[:subnet_id].to_i) > 0
  organization = params[:organization_id].blank? ? nil : Organization.find(params[:organization_id])
  location = params[:location_id].blank? ? nil : Location.find(params[:location_id])
  Taxonomy.as_taxonomy organization, location do
    not_found and return unless (subnet = Subnet.find(s))
    if (ip = subnet.unused_ip(params[:host_mac]))
      render :json => {:ip => ip}
    else
      # we don't want any failures if we failed to query our proxy
      head :status => 200
    end
  end
rescue => e
  logger.warn "Failed to query #{subnet} for free ip: #{e}"
  head :status => 500
end

#importObject


66
67
68
69
70
71
72
73
# File 'app/controllers/subnets_controller.rb', line 66

def import
  proxy = SmartProxy.find(params[:smart_proxy_id])
  @subnets = Subnet.import(proxy)
  if @subnets.empty?
    flash[:warning] = _("No new subnets found")
    redirect_to :subnets
  end
end

#indexObject


4
5
6
7
8
9
10
# File 'app/controllers/subnets_controller.rb', line 4

def index
  values = Subnet.search_for(params[:search], :order => params[:order])
  respond_to do |format|
    format.html { @subnets = values.includes(:domains, :dhcp).paginate :page => params[:page] }
    format.json { render :json => values }
  end
end

#newObject


12
13
14
# File 'app/controllers/subnets_controller.rb', line 12

def new
  @subnet = Subnet.new
end

#updateObject


29
30
31
32
33
34
35
36
# File 'app/controllers/subnets_controller.rb', line 29

def update
  @subnet = Subnet.find(params[:id])
  if @subnet.update_attributes(params[:subnet])
    process_success
  else
    process_error
  end
end