Class: Installation::AutoClient

Inherits:
Yast::Client
  • Object
show all
Includes:
Yast::Logger
Defined in:
library/general/src/lib/installation/auto_client.rb

Overview

An abstract class that simplifies writing *_auto.rb clients for AutoYaST.

It provides a single entry point which dispatches calls to the abstract methods that all proposal clients need to implement.

You need to implement all the methods, except #packages.

"Autoinstall" basically means #import, then #write.

The workflow for interactive editing in the UI (Mode.config == true, see Yast::ModeClass) is more complicated. The user can choose to perform any action, and a corresponding method is called:

  • #summary: clicking on the icon of the module.
  • #reset: clicking Clear.
  • if the user clicks to Edit a module, at first #export is called, then #change is called for UI interaction, which can end up in multiple situations:
    • if cancelled/aborted, #import is called (on the previous result of #export)
    • otherwise #export is called. If the output is different from the previous call, then #modified is called.
  • #write: clicking Apply to System.
  • #read: clicking Clone.
  • #import: selecting File/Open to load an autoyast profile
  • it calls #modified? to recognize if a given module is modified and needs its section with content of #export when saving the profile
  • the order of all calls is independent, so the client should not depend on a certain order unless it is defined here as a workflow call

Examples:

how to run a client

require "installation/example_auto"
::Installation::ExampleAuto.run

See Also:

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.runObject

Entry point for calling the client. The only part needed in client rb file.

Returns:

  • response from abstract methods


51
52
53
# File 'library/general/src/lib/installation/auto_client.rb', line 51

def self.run
  new.run
end

Instance Method Details

#changeSymbol (protected)

Run UI to modify the configuration.

Returns:

  • (Symbol)

    If one of :accept, :next, :finish is returned, the changes are accepted, otherwise they are discarded.

Raises:

  • (NotImplementedError)

127
128
129
# File 'library/general/src/lib/installation/auto_client.rb', line 127

def change
  raise NotImplementedError, "Calling abstract method 'change'"
end

#export(target:) ⇒ Hash, Array (protected)

Export profile data from AutoYaST.

The profile is a Hash or an Array according to the configuration item X-SuSE-YaST-AutoInstDataType

Parameters:

  • target (Symbol)

    Control how much information should be exported (e.g., :default or :compact).

Returns:

  • (Hash, Array)

    profile data

Raises:

  • (NotImplementedError)

108
109
110
# File 'library/general/src/lib/installation/auto_client.rb', line 108

def export(target:)
  raise NotImplementedError, "Calling abstract method 'export' with target '#{target}'"
end

#import(_profile) ⇒ Object (protected)

Import data from AutoYaST profile.

The profile is a Hash or an Array according to the configuration item X-SuSE-YaST-AutoInstDataType

Parameters:

  • _profile (Hash, Array)

    profile data specific to this module.

Returns:

  • true on success

Raises:

  • (NotImplementedError)

97
98
99
# File 'library/general/src/lib/installation/auto_client.rb', line 97

def import(_profile)
  raise NotImplementedError, "Calling abstract method 'import'"
end

#modifiedvoid (protected)

This method returns an undefined value.

Set that the profile data has beed modified and should be exported from the interactive editor, or included in the cloned data.

Raises:

  • (NotImplementedError)

167
168
169
# File 'library/general/src/lib/installation/auto_client.rb', line 167

def modified
  raise NotImplementedError, "Calling abstract method 'modified'"
end

#modified?Boolean (protected)

Query whether the profile data has beed modified and should be exported from the interactive editor, or included in the cloned data.

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)

175
176
177
# File 'library/general/src/lib/installation/auto_client.rb', line 175

def modified?
  raise NotImplementedError, "Calling abstract method 'modified?'"
end

#packagesHash (protected)

Return a hash with packages that need to be installed or removed for configuration.

The default implementation returns an empty hash.

Examples:


def packages
  { "install" => ["package1"], "remove" => ["package2"] }
end

Returns:

  • (Hash)

    of packages to be installed and removed


148
149
150
151
152
# File 'library/general/src/lib/installation/auto_client.rb', line 148

def packages
  log.info "#{self.class}#packages not implemented, returning {}."

  {}
end

#readvoid (protected)

This method returns an undefined value.

Read settings from the target system.

It is used to initialize configuration from the current system for further represent in AutoYaST profile.

Raises:

  • (NotImplementedError)

159
160
161
# File 'library/general/src/lib/installation/auto_client.rb', line 159

def read
  raise NotImplementedError, "Calling abstract method 'write'"
end

#resetvoid (protected)

This method returns an undefined value.

Reset configuration to default state.

Raises:

  • (NotImplementedError)

120
121
122
# File 'library/general/src/lib/installation/auto_client.rb', line 120

def reset
  raise NotImplementedError, "Calling abstract method 'reset'"
end

#runObject

Dispatches to abstract method based on passed Arguments to client


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'library/general/src/lib/installation/auto_client.rb', line 56

def run
  func, param = Yast::WFM.Args
  log.info "Called #{self.class}.run with #{func} and params #{param}"

  case func
  when "Import"
    import(param)
  when "Export"
    target = param["target"] if param.is_a?(Hash)
    target ||= "default"
    m = method(:export)
    m.arity.zero? ? export : export(target: target.to_sym)
  when "Summary"
    summary
  when "Reset"
    reset
  when "Change"
    change
  when "Write"
    write
  when "Packages"
    packages
  when "Read"
    read
  when "GetModified"
    modified?
  when "SetModified"
    modified
  else
    raise ArgumentError, "Invalid action for auto client '#{func.inspect}'"
  end
end

#summaryString (protected)

Provide a brief summary of configuration.

Returns:

  • (String)

    description in RichText format

Raises:

  • (NotImplementedError)

114
115
116
# File 'library/general/src/lib/installation/auto_client.rb', line 114

def summary
  raise NotImplementedError, "Calling abstract method 'summary'"
end

#writeBoolean (protected)

Write settings to the target system.

Returns:

  • (Boolean)

    true on success

Raises:

  • (NotImplementedError)

133
134
135
# File 'library/general/src/lib/installation/auto_client.rb', line 133

def write
  raise NotImplementedError, "Calling abstract method 'write'"
end