Module: Yast::BootloaderRoutinesLibIfaceInclude

Defined in:
src/include/bootloader/routines/lib_iface.rb

Defined Under Namespace

Classes: TmpYAMLFile

Constant Summary

STATE_FILE =
"/var/lib/YaST2/pbl-state"

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) CommitSettings

Flush the internal cache of the library to the disk

Returns:

  • (Boolean)

    true on success



283
284
285
286
287
288
# File 'src/include/bootloader/routines/lib_iface.rb', line 283

def CommitSettings
  Builtins.y2milestone("Writing files to system")
  run_pbl_yaml "WriteSettings()"

  true
end

- (Boolean) DefineMultipath(multipath_map)

Set the mapping (real device <-> multipath)

Parameters:

  • map (string, string)

    map from real device to multipath device

Returns:

  • (Boolean)

    true on success



233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'src/include/bootloader/routines/lib_iface.rb', line 233

def DefineMultipath(multipath_map)
  Builtins.y2milestone("Storing multipath map: %1", multipath_map)
  if Builtins.size(multipath_map) == 0
    Builtins.y2milestone("Multipath was not detected")
    return true
  end

  TmpYAMLFile.open(multipath_map) do |arg_data|
    run_pbl_yaml "DefineMultipath(#{arg_data.path})"
  end

  true
end

- (String) examineMBR(device)

Analyse content of MBR

Parameters:

  • device (String)

    name (“/dev/sda”)

Returns:

  • (String)

    result of analyse (“GRUB stage1”, “uknown”,…)



379
380
381
382
383
384
385
386
387
388
389
# File 'src/include/bootloader/routines/lib_iface.rb', line 379

def examineMBR(device)
  TmpYAMLFile.open(device) do |device_data|
    TmpYAMLFile.open do |ret_data|
      run_pbl_yaml "#{ret_data.path}=ExamineMBR(#{device_data.path})"
      ret = ret_data.data

      Builtins.y2milestone("Device: %1 includes in MBR: %2", device, ret)
      ret
    end
  end
end

- (Object) GetDeviceMap

Get the device mapping (Linux <-> Firmware)

Returns:

  • a map from Linux device to Firmware device identification



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'src/include/bootloader/routines/lib_iface.rb', line 249

def GetDeviceMap
  Builtins.y2milestone("Reading device mapping")

  TmpYAMLFile.open do |res_data|
    run_pbl_yaml "#{res_data.path}=GetDeviceMapping()"

    devmap = res_data.data

    if !devmap
      Builtins.y2error("Reading device mapping failed")
      return {}
    end

    Builtins.y2milestone("Read device mapping: %1", devmap)
    devmap
  end
end

- (Object) GetFilesContents

Get contents of files from the library cache

Returns:

  • a map filename -> contents, empty map in case of fail



347
348
349
350
351
352
353
354
355
356
357
358
359
360
# File 'src/include/bootloader/routines/lib_iface.rb', line 347

def GetFilesContents
  Builtins.y2milestone("Getting contents of files")
  TmpYAMLFile.open do |ret_data|
    run_pbl_yaml "#{ret_data.path}=GetFilesContents()"

    ret = ret_data.data
    if ret.nil?
      Builtins.y2error("Getting contents of files failed")
      return {}
    end

    ret
  end
end

- (Object) GetGlobal

Get global bootloader options

Returns:

  • a map of global bootloader options



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'src/include/bootloader/routines/lib_iface.rb', line 202

def GetGlobal
  Builtins.y2milestone("Reading bootloader global settings")
  TmpYAMLFile.open do |globals_data|
    run_pbl_yaml "#{globals_data.path}=GetGlobalSettings()"
    glob = globals_data.data

    if glob.nil?
      Builtins.y2error("Reading global settings failed")
      return {}
    end

    Builtins.y2milestone("Read global settings: %1", glob)
    glob
  end
end

- (Object) GetSections

Get boot loader sections

Returns:

  • a list of all loader sections (as maps)



171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'src/include/bootloader/routines/lib_iface.rb', line 171

def GetSections
  TmpYAMLFile.open do |sections_data|
    Builtins.y2milestone("Reading bootloader sections")
    run_pbl_yaml "#{sections_data.path}=GetSections()"
    sects = sections_data.data
    if sects.nil?
      Builtins.y2error("Reading sections failed")
      return []
    end
    Builtins.y2milestone("Read sections: %1", sects)

    sects
  end
end

- (Object) initialize_bootloader_routines_lib_iface(_include_target)



28
29
30
31
32
33
34
35
36
# File 'src/include/bootloader/routines/lib_iface.rb', line 28

def initialize_bootloader_routines_lib_iface(_include_target)
  textdomain "bootloader"

  Yast.import "Storage"
  Yast.import "Mode"

  # Loader the library has been initialized to use
  @library_initialized = nil
end

- (Boolean) InitializeBootloader

Initialize the boot loader (eg. modify firmware, depending on architecture)

Returns:

  • (Boolean)

    true on success



333
334
335
336
337
338
339
340
341
342
343
# File 'src/include/bootloader/routines/lib_iface.rb', line 333

def InitializeBootloader
  TmpYAMLFile.open do |ret_data|
    run_pbl_yaml "#{ret_data.path}=InitializeBootloader()"
    ret = ret_data.data
    Builtins.y2milestone("Initializing bootloader ret: #{ret.inspect}")

    # perl have slightly different evaluation of boolean, so lets convert it
    ret = ![false, nil, 0, ""].include?(ret)
    ret
  end
end

- (Boolean) InitializeLibrary(force, loader)

Initialize the bootloader library

Parameters:

  • force (Boolean)

    boolean true if the initialization is to be forced

  • loader (String)

    string the loader to initialize the library for

Returns:

  • (Boolean)

    true on success



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'src/include/bootloader/routines/lib_iface.rb', line 123

def InitializeLibrary(force, loader)
  return false if !force && loader == @library_initialized

  SCR.Execute(Path.new(".target.remove"), STATE_FILE) # remove old state file to do clear initialization

  Builtins.y2milestone("Initializing lib for %1", loader)
  architecture = BootArch.StrArch
  TmpYAMLFile.open([loader, architecture]) do |loader_data|
    TmpYAMLFile.open(::Bootloader::UdevMapping.to_hash) do |udev_data|
      run_pbl_yaml "SetLoaderType(@#{loader_data.path})",
        "DefineUdevMapping(#{udev_data.path})"
    end
  end

  Builtins.y2milestone("Putting partitioning into library")
  # pass all needed disk/partition information to library
  SetDiskInfo()
  Builtins.y2milestone("Library initialization finished")
  @library_initialized = loader
  true
end

- (Boolean) ReadFiles(avoid_reading_device_map)

Read the files from the system to internal cache of the library data

Parameters:

  • avoid_reading_device_map (Boolean)

    do not read the device map, but use internal

Returns:

  • (Boolean)

    true on success



271
272
273
274
275
276
277
278
279
# File 'src/include/bootloader/routines/lib_iface.rb', line 271

def ReadFiles(avoid_reading_device_map)
  Builtins.y2milestone("Reading Files")

  TmpYAMLFile.open(avoid_reading_device_map) do |param_data|
    run_pbl_yaml "ReadSettings(#{param_data.path})"
  end

  true
end

- (Object) run_pbl_yaml(*args)



78
79
80
81
82
83
# File 'src/include/bootloader/routines/lib_iface.rb', line 78

def run_pbl_yaml(*args)
  cmd = "pbl-yaml --state=#{STATE_FILE} "
  cmd << args.map { |e| "'#{e}'" }.join(" ")

  SCR.Execute(path(".target.bash"), cmd)
end

- (Boolean) SetDeviceMap(device_map)

Set the device mapping (Linux <-> Firmware)

Parameters:

  • device_map (Hash{String => String})

    a map from Linux device to Firmware device identification

Returns:

  • (Boolean)

    true on success



221
222
223
224
225
226
227
228
# File 'src/include/bootloader/routines/lib_iface.rb', line 221

def SetDeviceMap(device_map)
  Builtins.y2milestone("Storing device map #{device_map}")
  TmpYAMLFile.open(device_map) do |arg_data|
    run_pbl_yaml "SetDeviceMapping(#{arg_data.path})"
  end

  true
end

- (Object) SetDiskInfo

Retrieve the data for perl-Bootloader library from Storage module and pass it along @return nothing FIXME: this should be done directly in perl-Bootloader through LibStorage.pm



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'src/include/bootloader/routines/lib_iface.rb', line 89

def SetDiskInfo
  BootStorage.InitDiskInfo

  Builtins.y2milestone(
    "Information about partitioning: %1",
    BootStorage.partinfo
  )
  Builtins.y2milestone(
    "Information about MD arrays: %1",
    BootStorage.md_info
  )
  Builtins.y2milestone(
    "Mapping real disk to multipath: %1",
    BootStorage.multipath_mapping
  )

  TmpYAMLFile.open(BootStorage.mountpoints) do |mp_data|
    TmpYAMLFile.open(BootStorage.partinfo) do |part_data|
      TmpYAMLFile.open(BootStorage.md_info) do |md_data|
        run_pbl_yaml "DefineMountPoints(#{mp_data.path})",
          "DefinePartitions(#{part_data.path})",
          "DefineMDArrays(#{md_data.path})"
      end
    end
  end
  DefineMultipath(BootStorage.multipath_mapping)

  nil
end

- (Boolean) SetFilesContents(files)

Set the contents of all files to library cache

Parameters:

  • files (Hash{String => String})

    a map filename -> contents

Returns:

  • (Boolean)

    true on success



365
366
367
368
369
370
371
372
373
# File 'src/include/bootloader/routines/lib_iface.rb', line 365

def SetFilesContents(files)
  Builtins.y2milestone("Storing contents of files")

  TmpYAMLFile.open(files) do |files_data|
    run_pbl_yaml "SetFilesContents(#{files_data.path})"
  end

  true
end

- (Boolean) SetGlobal(globals)

Set global bootloader options

Parameters:

  • globals (Hash{String => String})

    a map of global bootloader options

Returns:

  • (Boolean)

    true on success



189
190
191
192
193
194
195
196
197
198
# File 'src/include/bootloader/routines/lib_iface.rb', line 189

def SetGlobal(globals)
  globals = deep_copy(globals)
  Builtins.y2milestone("Storing global settings %1", globals)
  Ops.set(globals, "__modified", "1")
  TmpYAMLFile.open(globals) do |globals_data|
    run_pbl_yaml "SetGlobalSettings(#{globals_data.path})"
  end

  true
end

- (Boolean) SetSections(sections)

Set boot loader sections

Parameters:

  • sections (Array<Hash{String => Object>})

    a list of all loader sections (as maps)

Returns:

  • (Boolean)

    true on success



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'src/include/bootloader/routines/lib_iface.rb', line 148

def SetSections(sections)
  sections = deep_copy(sections)
  sections = Builtins.maplist(sections) do |s|
    if Mode.normal
      if Ops.get_boolean(s, "__changed", false) ||
          Ops.get_boolean(s, "__auto", false)
        Ops.set(s, "__modified", "1")
      end
    else
      Ops.set(s, "__modified", "1")
    end
    deep_copy(s)
  end
  Builtins.y2milestone("Storing bootloader sections %1", sections)
  TmpYAMLFile.open(sections) do |sections_data|
    run_pbl_yaml "SetSections(#{sections_data.path})"
  end

  true
end

- (Object) SetSecureBoot(enable)



300
301
302
303
304
305
306
307
# File 'src/include/bootloader/routines/lib_iface.rb', line 300

def SetSecureBoot(enable)
  Builtins.y2milestone("Set SecureBoot #{enable}")
  TmpYAMLFile.open(enable) do |arg_data|
    run_pbl_yaml "SetSecureBoot(#{arg_data.path})"
  end

  true
end

- (Boolean) UpdateBootloader

Update the bootloader settings, make updated saved settings active

Returns:

  • (Boolean)

    true on success



292
293
294
295
296
297
298
# File 'src/include/bootloader/routines/lib_iface.rb', line 292

def UpdateBootloader
  # true mean avoid init of bootloader
  TmpYAMLFile.open(true) do |arg_data|
    Builtins.y2milestone("Updating bootloader configuration")
    run_pbl_yaml "UpdateBootloader(#{arg_data.path})"
  end
end

- (String) UpdateSerialConsole(append, console)

Update append in from boot section, it means take value from “console” and add it to “append”

Parameters:

  • append (String)

    from section

  • console (String)

    from section

Returns:

  • (String)

    updated append with console



315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# File 'src/include/bootloader/routines/lib_iface.rb', line 315

def UpdateSerialConsole(append, console)
  Builtins.y2milestone(
    "Updating append: %1 with console: %2",
    append,
    console
  )

  TmpYAMLFile.open([append, console]) do |args_data|
    TmpYAMLFile.open do |append_data|
      run_pbl_yaml "#{append_data.path}=UpdateSerialConsole(@#{args_data.path})"

      append_data.data
    end
  end
end