foreman/app/controllers/subnets_controller.rb @ 4d8b2799
06823dc7 | Ohad Levy | class SubnetsController < ApplicationController
|
|
8104eced | Ohad Levy | include Foreman::Controller::AutoCompleteSearch
|
|
06823dc7 | Ohad Levy | def index
|
|
8104eced | Ohad Levy | values = Subnet.search_for(params[:search], :order => params[:order])
|
|
b28fdce4 | Ohad Levy | respond_to do |format|
|
|
8104eced | Ohad Levy | format.html { @subnets = values.paginate :page => params[:page] }
|
|
format.json { render :json => values }
|
|||
b28fdce4 | Ohad Levy | end
|
|
06823dc7 | Ohad Levy | end
|
|
def new
|
|||
@subnet = Subnet.new
|
|||
end
|
|||
def create
|
|||
@subnet = Subnet.new(params[:subnet])
|
|||
if @subnet.save
|
|||
b28fdce4 | Ohad Levy | process_success
|
|
06823dc7 | Ohad Levy | else
|
|
b28fdce4 | Ohad Levy | process_error
|
|
06823dc7 | Ohad Levy | end
|
|
end
|
|||
def edit
|
|||
@subnet = Subnet.find(params[:id])
|
|||
end
|
|||
def update
|
|||
@subnet = Subnet.find(params[:id])
|
|||
if @subnet.update_attributes(params[:subnet])
|
|||
b28fdce4 | Ohad Levy | process_success
|
|
06823dc7 | Ohad Levy | else
|
|
b28fdce4 | Ohad Levy | process_error
|
|
06823dc7 | Ohad Levy | end
|
|
end
|
|||
def destroy
|
|||
@subnet = Subnet.find(params[:id])
|
|||
b28fdce4 | Ohad Levy | if @subnet.destroy
|
|
process_success
|
|||
else
|
|||
process_error
|
|||
end
|
|||
06823dc7 | Ohad Levy | end
|
|
# query our subnet dhcp proxy for an unused IP
|
|||
def freeip
|
|||
85edffc1 | Ohad Levy | not_found and return unless (s=params[:subnet_id].to_i) > 0
|
|
06823dc7 | Ohad Levy | not_found and return unless subnet = Subnet.find(s)
|
|
if ip = subnet.unused_ip
|
|||
1aa9ef0d | Ohad Levy | respond_to do |format|
|
|
format.html do
|
|||
render :update do |page|
|
|||
page['host_ip'].value = ip
|
|||
page['indicator'].hide
|
|||
page['host_ip'].visual_effect :highlight
|
|||
end
|
|||
end
|
|||
format.json { render :json => {:ip => ip} }
|
|||
06823dc7 | Ohad Levy | end
|
|
8a9357c9 | Paul Kelly | else
|
|
# we don't want any failures if we failed to query our proxy
|
|||
head :status => 200
|
|||
06823dc7 | Ohad Levy | end
|
|
rescue => e
|
|||
455f5d2b | Paul Kelly | logger.warn "Failed to query #{subnet} for free ip: #{e}"
|
|
06823dc7 | Ohad Levy | head :status => 500
|
|
end
|
|||
4c091cd8 | Ohad Levy | def import
|
|
proxy = SmartProxy.find(params[:smart_proxy_id])
|
|||
@subnets = Subnet.import(proxy)
|
|||
if @subnets.empty?
|
|||
redirect_to :subnets, :notice => "No new subnets found"
|
|||
end
|
|||
end
|
|||
def create_multiple
|
|||
4d8b2799 | Ohad Levy | if params[:subnets].empty?
|
|
return redirect_to subnets_path, :notice => "No Subnets selected"
|
|||
end
|
|||
4c091cd8 | Ohad Levy | @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
|
|||
06823dc7 | Ohad Levy | end
|