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)


130
131
132
# File 'library/general/src/lib/installation/auto_client.rb', line 130

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)


111
112
113
# File 'library/general/src/lib/installation/auto_client.rb', line 111

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)


100
101
102
# File 'library/general/src/lib/installation/auto_client.rb', line 100

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)


170
171
172
# File 'library/general/src/lib/installation/auto_client.rb', line 170

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)


178
179
180
# File 'library/general/src/lib/installation/auto_client.rb', line 178

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



151
152
153
154
155
# File 'library/general/src/lib/installation/auto_client.rb', line 151

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)


162
163
164
# File 'library/general/src/lib/installation/auto_client.rb', line 162

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

#resetvoid (protected)

This method returns an undefined value.

Reset configuration to default state.

Raises:

  • (NotImplementedError)


123
124
125
# File 'library/general/src/lib/installation/auto_client.rb', line 123

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
88
89
90
# 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
    nil # return type is ignored, so always return nil to avoid issues with ycp component system
  when "Change"
    change
  when "Write"
    write
  when "Packages"
    packages
  when "Read"
    read
    nil # return type is ignored, so always return nil to avoid issues with ycp component system
  when "GetModified"
    modified?
  when "SetModified"
    modified
    nil # return type is ignored, so always return nil to avoid issues with ycp component system
  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)


117
118
119
# File 'library/general/src/lib/installation/auto_client.rb', line 117

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

#writeBoolean (protected)

Write settings to the target system.

Returns:

  • (Boolean)

    true on success

Raises:

  • (NotImplementedError)


136
137
138
# File 'library/general/src/lib/installation/auto_client.rb', line 136

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