Skip to content

Commit

Permalink
adapt services according to settings in roles
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Jan 12, 2017
1 parent bd0438c commit 1394a38
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/Makefile.am
Expand Up @@ -69,6 +69,7 @@ client_DATA = \
clients/remote_finish.rb \
clients/save_config_finish.rb \
clients/save_hw_status_finish.rb \
clients/services_finish.rb \
clients/snapshots_finish.rb \
clients/ssh_import_proposal.rb \
clients/ssh_import_auto.rb \
Expand Down Expand Up @@ -126,6 +127,7 @@ ylib_DATA = \
lib/installation/snapshots_finish.rb \
lib/installation/updates_manager.rb \
lib/installation/update_repository.rb \
lib/installation/services.rb \
lib/installation/ssh_config.rb \
lib/installation/ssh_key.rb \
lib/installation/ssh_config_file.rb \
Expand Down Expand Up @@ -190,6 +192,7 @@ ylibclient_DATA = \
lib/installation/clients/proxy_finish.rb \
lib/installation/clients/save_config_finish.rb \
lib/installation/clients/save_hw_status_finish.rb \
lib/installation/clients/services_finish.rb \
lib/installation/clients/ssh_import_proposal.rb \
lib/installation/clients/ssh_settings_finish.rb \
lib/installation/clients/stroj-casu.rb \
Expand Down
3 changes: 3 additions & 0 deletions src/clients/services_finish.rb
@@ -0,0 +1,3 @@
require "installation/clients/services_finish"

::Installation::Clients::ServicesFinish.run
3 changes: 2 additions & 1 deletion src/lib/installation/clients/inst_finish.rb
Expand Up @@ -388,7 +388,8 @@ def save_config_steps
"save_hw_status",
"users",
"autoinst_scripts2",
"installation_settings"
"installation_settings",
"services"
].freeze

def save_settings_steps
Expand Down
17 changes: 17 additions & 0 deletions src/lib/installation/clients/services_finish.rb
@@ -0,0 +1,17 @@
require "installation/finish_client"
require "installation/services"

module Installation
module Clients
class ServicesFinish < ::Installation::FinishClient
def title
textdomain "installation"
_("Adapting system services ...")
end

def write
::Installation::Services.write
end
end
end
end
15 changes: 14 additions & 1 deletion src/lib/installation/select_system_role.rb
Expand Up @@ -19,6 +19,7 @@

require "yast"
require "ui/installation_dialog"
require "installation/services"

Yast.import "GetInstArgs"
Yast.import "Popup"
Expand All @@ -34,7 +35,8 @@ class << self

NON_OVERLAY_ATTRIBUTES = [
"additional_dialogs",
"id"
"id",
"services"
].freeze

def initialize
Expand Down Expand Up @@ -187,6 +189,17 @@ def apply_role(role_id)
features = features.dup
NON_OVERLAY_ATTRIBUTES.each { |a| features.delete(a) }
Yast::ProductFeatures.SetOverlay(features)
adapt_services(role_id)
end

def adapt_services(role_id)
services = raw_roles.find { |r| r["id"] == role_id }["services"]
services ||= []

to_enable = services.map { |s| s["name"] }
log.info "enable for #{role_id} these services: #{to_enable.inspect}"

Installation::Services.enabled = to_enable
end

# the contents is an overlay for ProductFeatures sections
Expand Down
34 changes: 34 additions & 0 deletions src/lib/installation/services.rb
@@ -0,0 +1,34 @@
require "yast"

Yast.import 'SystemdService'

module Installation
# Represents services manipulation in installation.
class Services
class << self
include Yast::Logger

def enabled
@enabled ||= []
@enabled
end

def enabled=(services)
if !services.is_a?(::Array)
raise ArgumentError, "Services#enabled= allows only Array as " \
"argument, not #{services.inspect}"
end

@enabled = services
end

def write
enabled.each do |service|
log.info "Enabling service #{service}"
s = Yast::SystemdService.find!(service)
s.enable
end
end
end
end
end

0 comments on commit 1394a38

Please sign in to comment.