Page Menu
Home
GRNET
Search
Configure Global Search
Log In
Files
F1090643
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Oct 15, 9:53 AM
Size
12 KB
Mime Type
text/x-diff
Expires
Fri, Oct 17, 9:53 AM (1 d, 12 h)
Engine
blob
Format
Raw Data
Handle
280562
Attached To
rARCHIVING archiving
View Options
diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb
index d605dfa..1b45fd1 100644
--- a/app/controllers/admin/settings_controller.rb
+++ b/app/controllers/admin/settings_controller.rb
@@ -1,31 +1,61 @@
class Admin::SettingsController < Admin::BaseController
+ before_action :fetch_configuration_settings, only: [:edit, :update, :reset]
+
# GET /admin/settings
def index
@settings = ConfigurationSetting.last || ConfigurationSetting.new
end
- # GET /admin/settings/1
- def show
- end
-
# GET /admin/settings/new
def new
@setting = ConfigurationSetting.new
end
# GET /admin/settings/1/edit
def edit
end
# POST /admin/settings
def create
+ @setting = ConfigurationSetting.new(fetch_params)
+ if @setting.save
+ flash[:success] = 'Configuration Submitted'
+ redirect_to admin_settings_path
+ else
+ flash[:error] = 'Configuration was not submitted'
+ render :new
+ end
end
# PATCH /admin/settings/1/update
def update
+ if fetch_params.present? && @setting.update_attributes(fetch_params)
+ flash[:success] = 'Configuration Submitted'
+ redirect_to admin_settings_path
+ else
+ flash[:error] = 'Configuration was not submitted'
+ render :edit
+ end
+ end
+
+ # DELETE /admin/settings/1/reset
+ def reset
+ @setting.destroy
+ redirect_to admin_settings_path
+ end
+
+ private
+
+ def fetch_configuration_settings
+ @setting = ConfigurationSetting.find(params[:id])
end
- # DELETE /admin/settings/1/delete
- def destroy
+ def fetch_params
+ params.require(:configuration_setting).
+ permit(
+ job: [:storage, :pool, :messages, :priority, :'Write Bootstrap'],
+ client: [:catalog, :file_retention, :file_retention_period_type, :job_retention,
+ :job_retention_period_type, :autoprune]
+ )
end
end
diff --git a/app/models/configuration_setting.rb b/app/models/configuration_setting.rb
index 4011253..01451d3 100644
--- a/app/models/configuration_setting.rb
+++ b/app/models/configuration_setting.rb
@@ -1,60 +1,80 @@
# ConfigurationSetting class describes a model that keeps the current Bacula
# configuration.
#
# It has some hard coded settings as defaults.
# Archiving's admins can enter new settings concerning:
#
# * jobs
# * clients
#
# and override the default ones.
#
# ConfigurationSetting is supposed to have only one record in persisted in the database
# which will hold the altered configuration as a patch to the defaults.
# Admins can reset this change at any time.
class ConfigurationSetting < ActiveRecord::Base
serialize :job, JSON
serialize :client, JSON
JOB = {
storage: :File,
pool: :Default,
messages: :Standard,
priority: 10,
:'Write Bootstrap' => '"/var/lib/bacula/%c.bsr"'
}
CLIENT = {
catalog: 'MyCatalog',
file_retention: 60,
file_retention_period_type: 'days',
job_retention: 180,
job_retention_period_type: 'days',
autoprune: 'yes'
}
RETENTION_PERIODS = %w{seconds minutes hours days weeks months quarters years}
AUTOPRUNE_OPTIONS = ['yes', 'no']
# Fetches the current configuration for jobs.
#
# The current configuration is the last submitted record, patched to the default
# settings.
# If there is no record, the default settings are returned
#
# @return [Hash] with settings
def self.current_job_settings
(last || new).job.symbolize_keys.reverse_merge(JOB.dup)
end
# Fetches the current configuration for clients.
#
# The current configuration is the last submitted record, patched to the default
# settings.
# If there is no record, the default settings are returned
#
# @return [Hash] with settings
def self.current_client_settings
(last || new).client.symbolize_keys.reverse_merge(CLIENT.dup)
end
+
+ # Fetches the record's configuration for jobs.
+ #
+ # The configuration is the record's configuration patched to the default
+ # settings.
+ #
+ # @return [Hash] with settings
+ def current_job_settings
+ job.symbolize_keys.reverse_merge(JOB.dup)
+ end
+
+ # Fetches the record's configuration for clients.
+ #
+ # The configuration is the record's configuration patched to the default
+ # settings.
+ #
+ # @return [Hash] with settings
+ def current_client_settings
+ client.symbolize_keys.reverse_merge(CLIENT.dup)
+ end
end
diff --git a/app/models/pool.rb b/app/models/pool.rb
index 295a7c3..301263a 100644
--- a/app/models/pool.rb
+++ b/app/models/pool.rb
@@ -1,33 +1,37 @@
class Pool < ActiveRecord::Base
self.table_name = :Pool
self.primary_key = :PoolId
alias_attribute :pool_id, :PoolId
alias_attribute :name, :Name
alias_attribute :num_vols, :NumVols
alias_attribute :max_vols, :MaxVols
alias_attribute :use_once, :UseOnce
alias_attribute :use_catalog, :UseCatalog
alias_attribute :accept_any_volume, :AcceptAnyVolume
alias_attribute :vol_retention, :VolRetention
alias_attribute :vol_use_duration, :VolUseDuration
alias_attribute :max_vol_jobs, :MaxVolJobs
alias_attribute :max_vol_files, :MaxVolFiles
alias_attribute :max_vol_bytes, :MaxVolBytes
alias_attribute :auto_prune, :AutoPrune
alias_attribute :recycle, :Recycle
alias_attribute :action_on_purge, :ActionOnPurge
alias_attribute :pool_type, :PoolType
alias_attribute :label_type, :LabelType
alias_attribute :label_format, :LabelFormat
alias_attribute :enabled, :Enabled
alias_attribute :scratch_pool_id, :ScratchPoolId
alias_attribute :recycle_pool_id, :RecyclePoolId
alias_attribute :next_pool_id, :NextPoolId
alias_attribute :migration_high_bytes, :MigrationHighBytes
alias_attribute :migration_low_bytes, :MigrationLowBytes
alias_attribute :migration_time, :MigrationTime
has_many :jobs, foreign_key: :PoolId
has_many :media, foreign_key: :PoolId
+
+ def self.available_options
+ pluck(:Name)
+ end
end
diff --git a/app/models/storage.rb b/app/models/storage.rb
index bb6249e..f99950d 100644
--- a/app/models/storage.rb
+++ b/app/models/storage.rb
@@ -1,10 +1,14 @@
class Storage < ActiveRecord::Base
self.table_name = :Storage
self.primary_key = :StorageId
alias_attribute :storage_id, :StorageId
alias_attribute :name, :Name
alias_attribute :auto_changer, :AutoChanger
has_many :media, foreign_key: :StorageId
+
+ def self.available_options
+ pluck(:Name)
+ end
end
diff --git a/app/views/admin/settings/_form.html.erb b/app/views/admin/settings/_form.html.erb
new file mode 100644
index 0000000..66aa233
--- /dev/null
+++ b/app/views/admin/settings/_form.html.erb
@@ -0,0 +1,53 @@
+<div class="graybox">
+ <%= bootstrap_form_for(@setting, url: path, layout: :horizontal,
+ label_col: 'col-xs-5', control_col: 'col-xs-6') do |f| %>
+ <div class="row">
+ <div class="col-xs-2 col-xs-offset-9 text-right">
+ <h4>Job</h4>
+ </div>
+ </div>
+
+ <%= f.fields_for :job do |jb| %>
+ <%= jb.select :storage,
+ options_for_select(Storage.available_options, @setting.current_job_settings[:storage]) %>
+ <%= jb.select :pool,
+ options_for_select(Pool.available_options, @setting.current_job_settings[:pool]) %>
+ <%= jb.text_field :messages, :value => @setting.current_job_settings[:messages] %>
+ <%= jb.text_field :'Write Bootstrap',
+ :value => @setting.current_job_settings[:'Write Bootstrap'] %>
+ <%= jb.number_field :priority, :value => @setting.current_job_settings[:priority] %>
+ <% end %>
+
+ <div class="row">
+ <div class="col-xs-2 col-xs-offset-9 text-right">
+ <h4>Client</h4>
+ </div>
+ </div>
+
+ <%= f.fields_for :client do |c| %>
+ <%= c.text_field :catalog, :value => @setting.current_client_settings[:catalog] %>
+ <%= c.number_field :file_retention,
+ :value => @setting.current_client_settings[:file_retention] %>
+ <%= c.select :file_retention_period_type,
+ options_for_select(ConfigurationSetting::RETENTION_PERIODS,
+ @setting.current_client_settings[:file_retention_period_type]) %>
+ <%= c.number_field :job_retention,
+ :value => @setting.current_client_settings[:job_retention] %>
+ <%= c.select :job_retention_period_type,
+ options_for_select(ConfigurationSetting::RETENTION_PERIODS,
+ @setting.current_client_settings[:job_retention_period_type]) %>
+ <%= c.select :autoprune, ConfigurationSetting::AUTOPRUNE_OPTIONS,
+ :value => @setting.current_client_settings[:autoprune] %>
+ <% end %>
+
+ </br>
+
+ <div class="form-group">
+ <div class="col-xs-offset-3 col-xs-8">
+ <%= f.submit class: 'btn btn-success' %>
+ </div>
+ </div>
+
+ </br>
+ <% end %>
+</div>
diff --git a/app/views/admin/settings/edit.html.erb b/app/views/admin/settings/edit.html.erb
new file mode 100644
index 0000000..0b07f3e
--- /dev/null
+++ b/app/views/admin/settings/edit.html.erb
@@ -0,0 +1,5 @@
+<h1>Settings</h1>
+
+<%= render partial: 'form', locals: { path: admin_setting_path } %>
+
+<%= link_to 'Cancel', admin_settings_path %>
diff --git a/app/views/admin/settings/index.html.erb b/app/views/admin/settings/index.html.erb
index 6fc37b5..12ae87d 100644
--- a/app/views/admin/settings/index.html.erb
+++ b/app/views/admin/settings/index.html.erb
@@ -1,25 +1,42 @@
<h1>Settings</h1>
<% if !@settings.persisted? %>
<div class="alert alert-warning" role="alert">
The following configuration is the default configuration.
</div>
<% end %>
<div class="row">
<div class="col-xs-4">
<h3>Client Settings</h3>
</div>
<div class="col-xs-4">
<h3>Job Settings</h3>
</div>
</div>
<div class="row">
<div class="col-xs-4">
<%= table_for(ConfigurationSetting.current_job_settings) %>
</div>
<div class="col-xs-4">
<%= table_for(ConfigurationSetting.current_client_settings) %>
</div>
</div>
+
+<div class="row">
+ <div class="col-xs-2">
+ <%= link_to 'Change Config',
+ @settings.persisted? ? edit_admin_setting_path(@settings) : new_admin_setting_path,
+ class: 'btn btn-primary', role: 'button'
+ %>
+ </div>
+ <% if @settings.persisted? %>
+ <div class="col-xs-2">
+ <%= link_to 'Restore to defaults', reset_admin_setting_path(@settings), method: :delete,
+ data: { confirm: 'This will reset the configuration to the defaults' },
+ class: 'btn btn-danger', role: 'button'
+ %>
+ </div>
+ <% end %>
+</div>
diff --git a/app/views/admin/settings/new.html.erb b/app/views/admin/settings/new.html.erb
new file mode 100644
index 0000000..3054847
--- /dev/null
+++ b/app/views/admin/settings/new.html.erb
@@ -0,0 +1,5 @@
+<h1>Settings</h1>
+
+<%= render partial: 'form', locals: { path: admin_settings_path } %>
+
+<%= link_to 'Cancel', admin_settings_path %>
diff --git a/config/routes.rb b/config/routes.rb
index 140cbf4..fd1cd01 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,61 +1,65 @@
Rails.application.routes.draw do
root 'clients#index'
resources :clients, only: [:index, :show] do
member do
get :jobs
get :logs
get :stats
post :stats
end
collection do
post :index
end
end
resources :hosts, only: [:new, :create, :show, :edit, :update, :destroy] do
member do
post :submit_config
get :restore
post :run_restore
delete :revoke
end
resources :jobs, only: [:new, :create, :show, :edit, :update, :destroy] do
member do
patch :toggle_enable
post :backup_now
end
end
resources :filesets, only: [:show, :new, :create, :destroy]
resources :schedules, only: [:show, :new, :edit, :create, :update, :destroy]
end
namespace :admin do
match '/', to: 'base#index', via: [:get, :post]
- resources :settings
+ resources :settings, only: [:index, :new, :create, :edit, :update] do
+ member do
+ delete :reset
+ end
+ end
resources :clients, only: [:index, :show] do
member do
get :jobs
get :logs
get :stats
post :stats
get :configuration
end
end
resources :hosts, only: [:show] do
collection do
get :unverified
end
member do
post :verify
end
end
end
end
Event Timeline
Log In to Comment