You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
2.0 KiB
86 lines
2.0 KiB
class HostsController < ApplicationController
|
|
before_action :set_host,
|
|
only: [:auth, :add_key, :show, :edit, :update, :destroy]
|
|
|
|
# GET /hosts
|
|
# GET /hosts.json
|
|
def index
|
|
@hosts = Host.all
|
|
end
|
|
|
|
# GET /hosts/1
|
|
# GET /hosts/1.json
|
|
def show
|
|
end
|
|
|
|
# GET /hosts/new
|
|
def new
|
|
@host = Host.new
|
|
end
|
|
|
|
# GET /hosts/1/edit
|
|
def edit
|
|
end
|
|
|
|
# GET /hosts/1/auth
|
|
def auth
|
|
end
|
|
|
|
# PATCH/PUT /hosts/1/add_key
|
|
def add_key
|
|
@host.lxd_authenticate params[:hosts][:password]
|
|
redirect_to session.delete(:return_to)
|
|
end
|
|
|
|
# POST /hosts
|
|
# POST /hosts.json
|
|
def create
|
|
@host = Host.new(host_params)
|
|
|
|
respond_to do |format|
|
|
if @host.save
|
|
format.html { redirect_to @host, notice: 'Host was successfully created.' }
|
|
format.json { render :show, status: :created, location: @host }
|
|
else
|
|
format.html { render :new }
|
|
format.json { render json: @host.errors, status: :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
# PATCH/PUT /hosts/1
|
|
# PATCH/PUT /hosts/1.json
|
|
def update
|
|
respond_to do |format|
|
|
if @host.update(host_params)
|
|
format.html { redirect_to @host, notice: 'Host was successfully updated.' }
|
|
format.json { render :show, status: :ok, location: @host }
|
|
else
|
|
format.html { render :edit }
|
|
format.json { render json: @host.errors, status: :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
# DELETE /hosts/1
|
|
# DELETE /hosts/1.json
|
|
def destroy
|
|
@host.destroy
|
|
respond_to do |format|
|
|
format.html { redirect_to hosts_url, notice: 'Host was successfully destroyed.' }
|
|
format.json { head :no_content }
|
|
end
|
|
end
|
|
|
|
private
|
|
# Use callbacks to share common setup or constraints between actions.
|
|
def set_host
|
|
@host = Host.find(params[:id])
|
|
end
|
|
|
|
# Never trust parameters from the scary internet, only allow the white list through.
|
|
def host_params
|
|
params.require(:host).permit(:name, :uri, :password, :password_confirmation)
|
|
end
|
|
end
|
|
# vim: set et ts=2 sw=2:
|