diff --git a/app/views/hosts/show.html.erb b/app/views/hosts/show.html.erb
index f8aef61..ee60e5e 100644
--- a/app/views/hosts/show.html.erb
+++ b/app/views/hosts/show.html.erb
@@ -1,41 +1,49 @@
<%= notifier(@host.display_message) unless @host.deployed? %>
<% if @host.can_be_disabled? %>
<%= link_to 'Disable client', disable_host_path(@host), method: :post,
data: { confirm: 'This will disable the client. Are you sure?' },
class: "btn btn-warning", role: "button" %>
<% end %>
<%= link_to 'Remove client', host_path(@host), method: :delete,
data: { confirm: 'This will remove the client from Bacula. Are you sure?' },
class: "btn btn-danger", role: "button" %>
Configuration for <%= @host.name %>
<%= host_status_label(@host) %>
<%= render partial: "host_details" %>
<%= render partial: "jobs/job_templates" %>
+
-
-
Config File
-
-<%= @host.baculize_config_no_pass %>
-
+
+
+
Client FileDeamon Config
+
+<%= @host.bacula_fd_filedeamon_config %>
+
+
+
+
Client Director Config
+
+<%= @host.bacula_fd_director_config %>
+
+
-
<%= render partial: 'jobs/modals' %>
diff --git a/lib/configuration/host.rb b/lib/configuration/host.rb
index 78bf31c..a558254 100644
--- a/lib/configuration/host.rb
+++ b/lib/configuration/host.rb
@@ -1,56 +1,81 @@
module Configuration
# Helper module to add configuration getters for Host
module Host
# Constructs the final Bacula configuration for the host by appending configs for
#
# * Client
# * Jobs
# * Schedules
# * Filesets
#
# by calling their `to_bacula_config_array` methods.
#
# @return [Array] containing each element's configuration line by line
def baculize_config
templates = job_templates.includes(:fileset, :schedule)
result = [self] + templates.map {|x| [x, x.fileset, x.schedule] }.flatten.compact.uniq
result.map(&:to_bacula_config_array)
end
# Constructs the final Bacula configuration for the host by appending configs for
#
# * Client
# * Jobs
# * Schedules
# * Filesets
#
# by calling their `to_bacula_config_array` methods.
#
# It hides the password.
#
# @return [Array] containing each element's configuration line by line
def baculize_config_no_pass
baculize_config.join("\n").gsub(/Password = ".*"$/, 'Password = "*************"')
end
# Constructs an array where each element is a line for the Client's bacula config
#
# @return [Array]
def to_bacula_config_array
[
"Client {",
" Name = #{name}",
" Address = #{fqdn}",
" FDPort = #{port}",
" Catalog = #{client_settings[:catalog]}",
" Password = \"#{password}\"",
" File Retention = #{file_retention} #{file_retention_period_type}",
" Job Retention = #{job_retention} #{job_retention_period_type}",
" AutoPrune = #{auto_prune_human}",
"}"
]
end
+
+ # Fetches the Director resource for the file-deamon configuration
+ # file
+ def bacula_fd_director_config
+ [
+ 'Director {',
+ " Name = \"#{Baas.settings[:director_name]}\"",
+ " Password = \"#{password}\"",
+ '}'
+ ].join("\n")
+ end
+
+ # Fetches the FileDeamon resource for the file-deamon configuration
+ def bacula_fd_filedeamon_config
+ [
+ 'FileDeamon {',
+ " Name = #{name}",
+ " FDport = #{port}",
+ ' WorkingDirectory = /var/lib/bacula',
+ ' Pid Directory = /var/run/bacula',
+ ' Maximum Concurrent Jobs = 10',
+ ' FDAddress = 0.0.0.0',
+ '}'
+ ].join("\n")
+ end
end
end
diff --git a/spec/lib/configuration/host_spec.rb b/spec/lib/configuration/host_spec.rb
index 52a4cd0..f4cdb29 100644
--- a/spec/lib/configuration/host_spec.rb
+++ b/spec/lib/configuration/host_spec.rb
@@ -1,83 +1,121 @@
require 'spec_helper'
describe Configuration::Host do
describe '#to_bacula_config_array' do
let(:host) { FactoryGirl.create(:host) }
it "is a valid client directive" do
expect(host.to_bacula_config_array).to include('Client {')
expect(host.to_bacula_config_array).to include('}')
end
it "contains Address directive" do
expect(host.to_bacula_config_array).to include(" Address = #{host.fqdn}")
end
it "contains FDPort directive" do
expect(host.to_bacula_config_array).to include(" FDPort = #{host.port}")
end
it "contains Catalog directive" do
expect(host.to_bacula_config_array).
to include(" Catalog = #{ConfigurationSetting.current_client_settings[:catalog]}")
end
it "contains Password directive" do
expect(host.to_bacula_config_array).to include(" Password = \"#{host.password}\"")
end
it "contains File Retention directive" do
expect(host.to_bacula_config_array).
to include(" File Retention = #{host.file_retention} days")
end
it "contains Job Retention directive" do
expect(host.to_bacula_config_array).
to include(" Job Retention = #{host.job_retention} days")
end
it "contains AutoPrune directive" do
expect(host.to_bacula_config_array).to include(" AutoPrune = yes")
end
end
describe '#baculize_config' do
let!(:host) { FactoryGirl.create(:host) }
let!(:fileset) { FactoryGirl.create(:fileset, host: host) }
let!(:other_fileset) { FactoryGirl.create(:fileset, host: host) }
let!(:schedule) { FactoryGirl.create(:schedule) }
let!(:other_schedule) { FactoryGirl.create(:schedule) }
let!(:enabled_job) do
FactoryGirl.create(:job_template, host: host, schedule: schedule,
fileset: fileset, enabled: true)
end
let!(:disabled_job) do
FactoryGirl.create(:job_template, host: host, schedule: other_schedule,
fileset: other_fileset, enabled: false)
end
subject { host.baculize_config }
it 'includes the client\'s config' do
expect(subject).to include(host.to_bacula_config_array)
end
it 'includes the all the job template\'s configs' do
expect(subject).to include(enabled_job.to_bacula_config_array)
expect(subject).to include(disabled_job.to_bacula_config_array)
end
it 'includes all the used schedules\'s configs' do
expect(subject).to include(schedule.to_bacula_config_array)
expect(subject).to include(other_schedule.to_bacula_config_array)
end
it 'includes all the used filesets\'s configs' do
expect(subject).to include(fileset.to_bacula_config_array)
expect(subject).to include(other_fileset.to_bacula_config_array)
end
end
+
+ describe '#bacula_fd_director_config' do
+ let!(:host) { FactoryGirl.build(:host) }
+
+ subject { host.bacula_fd_director_config }
+
+ it 'opens and closes a Director part' do
+ expect(subject).to match(/^Director {$/)
+ expect(subject).to match(/^}$/)
+ end
+
+ it 'includes the client\'s Name' do
+ expect(subject).to match(" Name = \"#{Baas.settings[:director_name]}\"")
+ end
+
+ it 'includes the client\'s Password' do
+ expect(subject).to match(" Password = \"#{host.password}\"")
+ end
+ end
+
+ describe '#bacula_fd_filedeamon_config' do
+ let!(:host) { FactoryGirl.build(:host) }
+
+ subject { host.bacula_fd_filedeamon_config }
+
+ it 'opens and closes a FileDeamon part' do
+ expect(subject).to match(/^FileDeamon {$/)
+ expect(subject).to match(/^}$/)
+ end
+
+ it 'includes the client\'s Port' do
+ expect(subject).to match("FDport = #{host.port}")
+ end
+
+ it 'includes the client\'s Name' do
+ expect(subject).to match("Name = #{host.name}")
+ end
+ end
end