Class: Yast::RelocationServerClass

Inherits:
Module
  • Object
show all
Defined in:
../../src/modules/RelocationServer.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) Abort

Returns a confirmation popup dialog whether user wants to really abort.



98
99
100
# File '../../src/modules/RelocationServer.rb', line 98

def Abort
  Popup.ReallyAbort(GetModified())
end

- (String) GetDefaultXendOption(option_key)

Returns default Xend Option as a list of strings.

Parameters:

  • option_key (String)

    of the Xend configuration

Returns:

  • (String)

    with option_values



125
126
127
# File '../../src/modules/RelocationServer.rb', line 125

def GetDefaultXendOption(option_key)
  Ops.get(@DEFAULT_CONFIG, option_key, "")
end

- (Object) GetLibvirtdOption(key)



215
216
217
# File '../../src/modules/RelocationServer.rb', line 215

def GetLibvirtdOption(key)
  Ops.get(@LibvirtdOptions, key, false)
end

- (Object) GetLibVirtdPorts



204
205
206
# File '../../src/modules/RelocationServer.rb', line 204

def GetLibVirtdPorts
  deep_copy(@libvirtd_ports)
end

- (Object) GetModified

Returns whether the configuration has been modified.



86
87
88
# File '../../src/modules/RelocationServer.rb', line 86

def GetModified
  @modified
end

- (String) GetXendOption(option_key)

Returns the Xend Option as a list of strings.

Parameters:

  • option_key (String)

    of the xend configuration

Returns:

  • (String)

    with option_values



116
117
118
# File '../../src/modules/RelocationServer.rb', line 116

def GetXendOption(option_key)
  Ops.get(@SETTINGS, option_key, Ops.get(@DEFAULT_CONFIG, option_key, ""))
end

- (Object) main



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
# File '../../src/modules/RelocationServer.rb', line 35

def main
  Yast.import "UI"
  textdomain "relocation-server"

  Yast.import "Arch"
  Yast.import "Progress"
  Yast.import "Report"
  Yast.import "Popup"
  Yast.import "Summary"
  Yast.import "Message"
  Yast.import "Service"
  Yast.import "SuSEFirewall"
  Yast.import "SuSEFirewallServices"

  # Data was modified?
  @modified = false

  # map of xend settings
  @SETTINGS = {}

  @DEFAULT_CONFIG = {
    "xend-relocation-server"               => "no",
    "xend-relocation-ssl-server"           => "no",
    "xend-relocation-port"                 => "8002",
    "xend-relocation-ssl-port"             => "8003",
    "xend-relocation-server-ssl-key-file"  => "xmlrpc.key",
    "xend-relocation-server-ssl-cert-file" => "xmlrpc.cert",
    "xend-relocation-ssl"                  => "no",
    "xend-relocation-address"              => "",
    "xend-relocation-hosts-allow"          => "^localhost$ ^localhost\\.localdomain$"
  }

  # Describes whether the daemon is running
  @xend_is_running = false

  @libvirtd_default_ports = "49152:49215"
  @libvirtd_ports = []

  @libvirtd_enabled = false
  @sshd_enabled = false
  @libvirtd_is_running = false
  @sshd_is_running = false

  @LibvirtdOptions = {
    "tunneled_migration" => false,
    "plain_migration"    => false,
    "default_port_range" => false
  }
end

- (Boolean) PollAbort

Checks whether an Abort button has been pressed. If so, calls function to confirm the abort call.

Returns:

  • (Boolean)

    true if abort confirmed



106
107
108
109
110
# File '../../src/modules/RelocationServer.rb', line 106

def PollAbort
  return Abort() if UI.PollInput == :abort

  false
end

- (Object) Read

Read all relocation-server settings

Returns:

  • true on success



286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
# File '../../src/modules/RelocationServer.rb', line 286

def Read
  # RelocationServer read dialog caption
  caption = _("Initializing relocation-server Configuration")

  xen_steps = 3
  kvm_steps = 2

  sl = 500
  Builtins.sleep(sl)

  xen_stg = [
    # Progress stage 1/3
    _("Read the current xend configuration"),
    # Progress stage 2/3
    _("Read the current xend state"),
    # Progress stage 3/3
    _("Read firewall settings")
  ]

  xen_tits = [
    # Progress step 1/3
    _("Reading the current xend configuration..."),
    # Progress step 2/3
    _("Reading the current xend state..."),
    # Progress step 3/3
    _("Reading firewall settings..."),
    # Progress finished
    Message.Finished
  ]

  kvm_stg = [
    # Progress stage 1/2
    _("Read firewall settings"),
    # Progress stage 2/2
    _("Read the current libvirtd/sshd state")
  ]

  kvm_tits = [
    # Progress step 1/2
    _("Reading firewall settings..."),
    # Progress stage 2/2
    _("Reading the current libvirtd/sshd state..."),
    # Progress finished
    Message.Finished
  ]

  if Arch.is_xen0
    Progress.New(caption, " ", xen_steps, xen_stg, xen_tits, "")
  else
    Progress.New(caption, " ", kvm_steps, kvm_stg, kvm_tits, "")
  end

  if Arch.is_xen0
    return false if PollAbort()
    Progress.NextStage
    # Error message
    Report.Error(Message.CannotReadCurrentSettings) if !ReadXendSettings()
    Builtins.sleep(sl)

    return false if PollAbort()
    Progress.NextStage
    # Error message
    if !ReadXendService()
      Report.Error(_("Cannot read the current Xend state."))
    end
    Builtins.sleep(sl)
  end

  return false if PollAbort()
  Progress.NextStage
  progress_state = Progress.set(false)
  # Error message
  Report.Warning(_("Cannot read firewall settings.")) if !SuSEFirewall.Read
  Progress.set(progress_state)
  Builtins.sleep(sl)

  if Arch.is_kvm
    return false if PollAbort()
    Progress.NextStage
    # Error message
    if !ReadKVMServices()
      Report.Error(_("Cannot read the current libvirtd/sshd state."))
    end
    Builtins.sleep(sl)
  end

  return false if PollAbort()
  # Progress finished
  Progress.NextStage
  Builtins.sleep(sl)

  return false if PollAbort()
  @modified = false
  true
end

- (Object) ReadKVMServices



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File '../../src/modules/RelocationServer.rb', line 225

def ReadKVMServices
  @libvirtd_enabled = Service.Enabled("libvirtd")
  @sshd_enabled = Service.Enabled("sshd")

  if Service.Status("libvirtd") == 0
    @libvirtd_is_running = true
    Builtins.y2milestone("libvirtd is running")
  else
    @libvirtd_is_running = false
    Builtins.y2milestone("libvirtd is not running")
  end
  if Service.Status("sshd") == 0
    @sshd_is_running = true
    Builtins.y2milestone("sshd is running")
  else
    @sshd_is_running = false
    Builtins.y2milestone("sshd is not running")
  end

  ports = SuSEFirewallServices.GetNeededTCPPorts(
    "service:libvirtd-relocation-server"
  )
  @libvirtd_ports = Builtins.filter(ports) do |s|
    s != @libvirtd_default_ports
  end

  true
end

- (Object) ReadXendService

Reads current xend status



178
179
180
181
182
183
184
185
186
187
188
# File '../../src/modules/RelocationServer.rb', line 178

def ReadXendService
  if Service.Status("xend") == 0
    @xend_is_running = true
    Builtins.y2milestone("Xend is running")
  else
    @xend_is_running = false
    Builtins.y2milestone("Xend is not running")
  end

  true
end

- (Object) ReadXendSettings

Reads current xend configuration



140
141
142
143
144
145
146
147
148
149
150
# File '../../src/modules/RelocationServer.rb', line 140

def ReadXendSettings
  Builtins.foreach(SCR.Dir(path(".etc.xen.xend-config"))) do |key|
    val = Convert.to_string(
      SCR.Read(Builtins.add(path(".etc.xen.xend-config"), key))
    )
    Ops.set(@SETTINGS, key, val) if val != nil
  end

  Builtins.y2milestone("Xend configuration has been read: %1", @SETTINGS)
  true
end

- (Object) SetLibvirtdOption(key, val)



219
220
221
222
223
# File '../../src/modules/RelocationServer.rb', line 219

def SetLibvirtdOption(key, val)
  Ops.set(@LibvirtdOptions, key, val)

  nil
end

- (Object) SetLibvirtdPorts(ports)



208
209
210
211
212
213
# File '../../src/modules/RelocationServer.rb', line 208

def SetLibvirtdPorts(ports)
  ports = deep_copy(ports)
  @libvirtd_ports = deep_copy(ports)

  nil
end

- (Object) SetModified

Sets that the configuration has been modified.



91
92
93
94
95
# File '../../src/modules/RelocationServer.rb', line 91

def SetModified
  @modified = true

  nil
end

- (Object) SetXendOption(option_key, option_vals)

Sets values for an option.

Parameters:

  • option_key (String)

    with the Xend configuration key

  • string

    option_values with the Xend configuration values



133
134
135
136
137
# File '../../src/modules/RelocationServer.rb', line 133

def SetXendOption(option_key, option_vals)
  Ops.set(@SETTINGS, option_key, option_vals)

  nil
end

- (Object) Write

Write all relocation-server settings

Returns:

  • true on success



384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
# File '../../src/modules/RelocationServer.rb', line 384

def Write
  # RelocationServer read dialog caption
  caption = _("Saving relocation-server Configuration")

  xen_steps = 3
  kvm_steps = 2

  sl = 500
  Builtins.sleep(sl)

  xen_stg = [
    # Progress stage 1
    _("Write the Xend settings"),
    # Progress stage 2
    _("Adjust the Xend service"),
    # Progress stage 3
    _("Write firewall settings")
  ]

  xen_tits = [
    # Progress step 1
    _("Writing the Xend settings..."),
    # Progress step 2
    _("Adjusting the Xend service..."),
    # Progress step 3
    _("Writing firewall settings..."),
    Message.Finished
  ]

  kvm_stg = [
    # Progress stage 1
    _("Adjust the libvirtd/sshd service"),
    # Progress stage 2
    _("Write firewall settings")
  ]

  kvm_tits = [
    # Progress step 1
    _("Adjusting the libvirtd/sshd service"),
    # Progress stage 2
    _("Writing firewall settings..."),
    Message.Finished
  ]

  if Arch.is_xen0
    Progress.New(caption, " ", xen_steps, xen_stg, xen_tits, "")
  else
    Progress.New(caption, " ", kvm_steps, kvm_stg, kvm_tits, "")
  end

  if Arch.is_xen0
    return false if PollAbort()
    Progress.NextStage
    # Error message
    if !WriteXendSettings()
      Report.Error(_("Cannot write the xend settings."))
    end
    Builtins.sleep(sl)

    return false if PollAbort()
    Progress.NextStage
    # Error message
    Report.Error(Message.CannotAdjustService("xend")) if !WriteXendService()
    Builtins.sleep(sl)
  else
    return false if PollAbort()
    Progress.NextStage
    # Error message
    Report.Error(Message.CannotAdjustService("xend")) if !WriteKVMServices()
    Builtins.sleep(sl)
  end

  return false if PollAbort()
  Progress.NextStage
  progress_state = Progress.set(false)
  # Error message
  Report.Error(_("Cannot write firewall settings.")) if !SuSEFirewall.Write
  Progress.set(progress_state)
  Builtins.sleep(sl)

  return false if PollAbort()
  # Progress finished
  Progress.NextStage
  Builtins.sleep(sl)

  return false if PollAbort()
  true
end

- (Object) WriteKVMServices



254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File '../../src/modules/RelocationServer.rb', line 254

def WriteKVMServices
  all_ok = true

  if GetLibvirtdOption("tunneled_migration") ||
      GetLibvirtdOption("plain_migration")
    all_ok = Service.Start("libvirtd") && all_ok if !@libvirtd_is_running
    all_ok = Service.Enable("libvirtd") && all_ok if !@libvirtd_enabled
  end
  if GetLibvirtdOption("tunneled_migration")
    all_ok = Service.Start("sshd") && all_ok if !@sshd_is_running
    all_ok = Service.Enable("sshd") && all_ok if !@sshd_enabled
  end
  if GetLibvirtdOption("plain_migration")
    if GetLibvirtdOption("default_port_range")
      if !Builtins.contains(@libvirtd_ports, @libvirtd_default_ports)
        @libvirtd_ports = Builtins.add(
          @libvirtd_ports,
          @libvirtd_default_ports
        )
      end
    end
    SuSEFirewallServices.SetNeededPortsAndProtocols(
      "service:libvirtd-relocation-server",
      { "tcp_ports" => @libvirtd_ports }
    )
  end

  all_ok
end

- (Object) WriteXendService

Restarts the xend when the daemon was running when starting the configuration



191
192
193
194
195
196
197
198
199
200
201
202
# File '../../src/modules/RelocationServer.rb', line 191

def WriteXendService
  all_ok = true

  if @xend_is_running
    Builtins.y2milestone("Restarting xend daemon")
    all_ok = Service.Restart("xend")
  else
    Builtins.y2milestone("Xend is not running - leaving...")
  end

  all_ok
end

- (Object) WriteXendSettings

Writes current xend configuration



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File '../../src/modules/RelocationServer.rb', line 153

def WriteXendSettings
  Builtins.y2milestone("Writing Xend configuration: %1", @SETTINGS)

  Builtins.foreach(@SETTINGS) do |option_key, option_val|
    SCR.Write(
      Builtins.add(path(".etc.xen.xend-config"), option_key),
      option_val
    )
  end
  # This is very important
  # it flushes the cache, and stores the configuration on the disk
  SCR.Write(path(".etc.xen.xend-config"), nil)

  port = GetXendOption("xend-relocation-port")
  ssl_port = GetXendOption("xend-relocation-ssl-port")
  ports_list = [port, ssl_port]
  SuSEFirewallServices.SetNeededPortsAndProtocols(
    "service:xend-relocation-server",
    { "tcp_ports" => ports_list }
  )

  true
end