diff --git a/src/autogen/app/controllers/test_controller.rb b/src/autogen/app/controllers/test_controller.rb index 09da515..95908fb 100644 --- a/src/autogen/app/controllers/test_controller.rb +++ b/src/autogen/app/controllers/test_controller.rb @@ -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 create - + 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 end private - def client_ip - request.remote_ip - end + 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 diff --git a/src/autogen/app/models/host.rb b/src/autogen/app/models/host.rb index 39a3f02..4c7fab6 100644 --- a/src/autogen/app/models/host.rb +++ b/src/autogen/app/models/host.rb @@ -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 diff --git a/src/autogen/app/views/hosts/_form.html.erb b/src/autogen/app/views/hosts/_form.html.erb index f79f910..5ecddd7 100644 --- a/src/autogen/app/views/hosts/_form.html.erb +++ b/src/autogen/app/views/hosts/_form.html.erb @@ -104,7 +104,18 @@ - +
+
+ +
+
+
+
+ <%= form.text_field :luskdisk , { class: "input"} %> +
+
+
+
diff --git a/src/autogen/config/routes.rb b/src/autogen/config/routes.rb index 35bca83..ce8d467 100644 --- a/src/autogen/config/routes.rb +++ b/src/autogen/config/routes.rb @@ -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