Class: Installation::SystemRole

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Yast::Logger
Defined in:
src/lib/installation/system_role.rb

Overview

This class fetchs and stores the roles declared in the installation control file. It works as a storage for them and for the role selected during the installation.

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, order:, label: id, description: nil) ⇒ SystemRole

Constructor

Only the id, label and description are allowed to be initialized other options have to be set explicitly.

Examples:

SystemRole with 'services' and a 'controller node' defined

@role = SystemRole.new(id: "test_role")
@role["services"] = { "name" => "salt-minion" }
@role["controller_node"] = "salt"

Parameters:

  • id (String)

    role id or name

  • label (String) (defaults to: id)

    it uses the id as label if not given

  • description (String) (defaults to: nil)
  • order (String, nil)

    string representation of order or default if nil passed



74
75
76
77
78
79
80
# File 'src/lib/installation/system_role.rb', line 74

def initialize(id:, order:, label: id, description: nil)
  @id          = id
  @label       = label
  @description = description
  @options     = {}
  @order = order.to_i
end

Class Attribute Details

.current_roleSystemRole? (readonly)

Returns the current role

Returns:



84
85
86
# File 'src/lib/installation/system_role.rb', line 84

def current_role
  @current_role
end

Instance Attribute Details

#descriptionString?

It descripts the main capabilities of the role and it is also usually translated because it is used for description and/or for help in some cases.

Returns:

  • (String, nil)


51
52
53
# File 'src/lib/installation/system_role.rb', line 51

def description
  @description
end

#idString

This is the id or name of the role and used as reference to the role

Returns:

  • (String)


40
41
42
# File 'src/lib/installation/system_role.rb', line 40

def id
  @id
end

#labelString

The label is usually translated and shoule be a short word more descriptive than the id.

Returns:

  • (String)


45
46
47
# File 'src/lib/installation/system_role.rb', line 45

def label
  @label
end

#orderInteger (readonly)

Order of role.

Returns:

  • (Integer)


55
56
57
# File 'src/lib/installation/system_role.rb', line 55

def order
  @order
end

Class Method Details

.allHash<String, SystemRole>

Returns an array with all the SystemRole objects sorted according to order

Returns:



104
105
106
107
108
109
# File 'src/lib/installation/system_role.rb', line 104

def all
  return @roles if @roles

  @roles = raw_roles.map { |r| from_control(r) }
  @roles.sort_by!(&:order)
end

.clearObject

Clears roles cache



112
113
114
# File 'src/lib/installation/system_role.rb', line 112

def clear
  @roles = nil
end

.currentString?

Returns the current role id

Returns:

  • (String, nil)

    current role's id



140
141
142
# File 'src/lib/installation/system_role.rb', line 140

def current
  @current_role ? @current_role.id : nil
end

.default?Boolean

returns if roles should set default or have no role preselected

Returns:

  • (Boolean)


97
98
99
# File 'src/lib/installation/system_role.rb', line 97

def default?
  !all.first["no_default"]
end

.find(role_id) ⇒ SystemRole?

Returns the SystemRole object for the specific role id.

Parameters:

  • role_id (String)

Returns:



148
149
150
# File 'src/lib/installation/system_role.rb', line 148

def find(role_id)
  all.find { |r| r.id == role_id }
end

.finishObject

It runs a special finish handler for the current role if exists



176
177
178
179
180
181
182
# File 'src/lib/installation/system_role.rb', line 176

def finish
  if !current
    log.info("There is no role selected so nothing to do")
    return
  end
  SystemRoleHandlersRunner.new.finish(current)
end

.from_control(raw_role) ⇒ SystemRole

Creates a SystemRole instance for the given role (in raw format).

Parameters:

  • raw_role (Hash)

    role definition

Returns:



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'src/lib/installation/system_role.rb', line 156

def from_control(raw_role)
  id = raw_role["id"]

  role =
    new(
      id:          id,
      order:       raw_role["order"],
      label:       Yast::ProductControl.GetTranslatedText(id),
      description: Yast::ProductControl.GetTranslatedText("#{id}_description")
    )

  role["additional_dialogs"] = raw_role["additional_dialogs"]
  role["services"] = raw_role["services"] || []
  role["network"] = raw_role["network"] || {}
  role["no_default"] = raw_role["no_default"] || false

  role
end

.idsArray<String>

Returns an array with all the role ids

Examples:

SystemRole.ids #=> ["role_one", "role_two"]

Returns:

  • (Array<String>)

    array with all the role ids; empty if no roles



92
93
94
# File 'src/lib/installation/system_role.rb', line 92

def ids
  all.map(&:id)
end

.raw_rolesArray<Hash>

Fetchs the roles from the control file and returns them as they are.

Examples:

SystemRole.raw_roles #=> [{ "id" => "role_one" }]

Returns:

  • (Array<Hash>)

    returns an empty array if no roles defined



122
123
124
# File 'src/lib/installation/system_role.rb', line 122

def raw_roles
  Yast::ProductControl.system_roles
end

.select(role_id) ⇒ SystemRole

Establish as the current role the one given as parameter.

Parameters:

  • role_id (String)

    role to be used as current

Returns:

  • (SystemRole)

    the object corresponding to the selected role

See Also:



131
132
133
134
135
# File 'src/lib/installation/system_role.rb', line 131

def select(role_id)
  @current_role = find(role_id)
  log.info("Selected role: #{current}")
  current_role
end

Instance Method Details

#adapt_networkObject



215
216
217
218
219
220
221
# File 'src/lib/installation/system_role.rb', line 215

def adapt_network
  settings = Y2Network::ProposalSettings.instance
  network = Yast::ProductFeatures.GetSection("network")

  settings.modify_defaults(network.merge(self["network"] || {}))
  settings.apply_defaults
end

#adapt_servicesArray

Enables the role services defined in the control file

Returns:

  • (Array)

    the list of services to be enable



188
189
190
191
192
193
194
# File 'src/lib/installation/system_role.rb', line 188

def adapt_services
  to_enable = (self["services"] || []).map { |s| s["name"] }

  log.info "enable for #{id} these services: #{to_enable.inspect}"

  Installation::Services.enabled = to_enable
end

#overlay_featuresObject

Overlays the product features for this role with the configuration obtained from the control file



208
209
210
211
212
213
# File 'src/lib/installation/system_role.rb', line 208

def overlay_features
  features = self.class.raw_roles.find { |r| r["id"] == id }.dup

  NON_OVERLAY_ATTRIBUTES.each { |a| features.delete(a) }
  Yast::ProductFeatures.SetOverlay(features)
end