main
stef 2024-04-19 18:00:10 +02:00
parent f28150b9f5
commit 9d9429ea13
4 changed files with 58 additions and 11 deletions

View File

@ -1,5 +1,7 @@
class TestController < ApplicationController
def myip
before_action :set_host_by_uuid
def get_default_cloudinit
uuid="uuid-#{sourceip}"
@host = Host.new()
sourceip = client_ip
uuid="uuid-#{sourceip}"
@ -10,15 +12,46 @@ class TestController < ApplicationController
randomstring = SecureRandom.hex(12)
@host = Host.new(hostname: hostname,uuid: uuid, installip: sourceip, installtemplate: @template,site: @site, mac: "00:00:00:00:00:00", status: "discover", discover: true,installed: false, toinstall: false,rootaccount: @account, mainaccount: @account, luskkey: randomstring )
@host.save!
string = "You IP address is #{sourceip}"
render plain: string
script = @host.installtemplate.install.content
template = @host.installtemplate
@site = @host.site
host = @host
@template = @host.installtemplate
@host.update({status: "System Install"})
result = render inline: script, layout: false, content_type: 'text/plain'
@host.update({lastinstallgenerated: result})
end
def get_ressource
if @host
script = Script.find_by(name:params[:name]).content
sourceip=request.headers['REMOTE_ADDR']
template = @host.installtemplate
@site = @host.site
host = @host
@template = @host.installtemplate
@host.update({status: "System Install"})
result = render inline: script, layout: false, content_type: 'text/plain'
end
def create
end
private
def client_ip
request.remote_ip
end
def entry_params
params.permit(:name)
end
def set_host_by_uuid
@host = Host.find_by(uuid: params[:uuid])
if ! @host
logger.debug "> NEW HOST DETECTED !!!"
sourceip=request.headers['REMOTE_ADDR']
log=Log.new({source: "#{sourceip}", crit: "warning",message: "New host with uuid #{params[:uuid]} Detected."})
log.save()
@template = Installtemplate.find_by(name:"default")
@site = Site.find_by(name:"default")
@account = Account.find_by(name:"default")
@host = Host.new(hostname: "New host detected",uuid: params["uuid"], installip: params["installip"], installtemplate: @template,site: @site, mac: params["mac"], status: "discover", discover: true,installed: false, toinstall: false,rootaccount: @account, mainaccount: @account)
@host.save!
end
end
end

View File

@ -14,6 +14,7 @@ class Host
field :lastbootgenerated, type: String , default: ''
field :lastinstallgenerated, type: String , default: ''
field :lastpostinstallgenerated, type: String, default: ''
field :luskdisk, type: String, default: '/dev/sda3'
field :luskkey, type: String, default: '123456789123456789'
belongs_to :installtemplate , class_name: "Installtemplate", inverse_of: :hostreferences
belongs_to :site , class_name: "Site", inverse_of: :sitereferences

View File

@ -104,7 +104,18 @@
</div>
</div>
</div>
<div class="field is-horizontal">
<div class="field-label is-small">
<label class="label">Lusk Disk</label>
</div>
<div class="field-body">
<div class="field">
<div class="control">
<%= form.text_field :luskdisk , { class: "input"} %>
</div>
</div>
</div>
</div>
<div class="field is-horizontal">
<div class="field-label is-small">
<label class="label">Interface</label>

View File

@ -35,5 +35,7 @@ Rails.application.routes.draw do
get '/api/host/cloudinit/:uuid/vendor-data', to: "engine#generate_metadata", defaults: { format: 'text' }
# test
get '/test/myip', to: "test#myip", defaults: { format: 'text' }
get '/test/get_default_cloudinit', to: "test#get_default_cloudinit", defaults: { format: 'text' }
get '/test/get_ressource', to: "test#get_ressource", defaults: { format: 'text' }
end