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.



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

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



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

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

- (Object) GetLibvirtdOption(key)



230
231
232
# File '../../src/modules/RelocationServer.rb', line 230

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

- (Object) GetLibVirtdPorts



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

def GetLibVirtdPorts
  deep_copy(@libvirtd_ports)
end

- (Object) GetModified

Returns whether the configuration has been modified.



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

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



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

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

- (Object) is_xend

Determine if we are using the libxl toolstack



99
100
101
102
103
104
105
# File '../../src/modules/RelocationServer.rb', line 99

def is_xend
  if !Arch.is_xen0 || !FileUtils.Exists("/etc/vm/xend-config.sxp") || !FileUtils.Exists("/usr/sbin/xend")
    return false
  end

  true
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
84
# 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 "FileUtils"
  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



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

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

  false
end

- (Object) Read

Read all relocation-server settings

Returns:

  • true on success



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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# File '../../src/modules/RelocationServer.rb', line 301

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

  xen_steps = 3
  libvirt_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
  ]

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

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

  if is_xend()
    Progress.New(caption, " ", xen_steps, xen_stg, xen_tits, "")
  else
    Progress.New(caption, " ", libvirt_steps, libvirt_stg, libvirt_tits, "")
  end

  if is_xend()
    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 || !is_xend()
    return false if PollAbort()
    Progress.NextStage
    # Error message
    if !ReadLibvirtServices()
      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) ReadLibvirtServices



240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File '../../src/modules/RelocationServer.rb', line 240

def ReadLibvirtServices
  @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



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

def ReadXendService
  xend = "/usr/sbin/xend"
  retval = 1
  if FileUtils.Exists(xend)
    retval = Convert.to_integer(SCR.Execute(path(".target.bash_output"), Builtins.sformat("%1 status", xend)))
  end
  if retval == 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



150
151
152
153
154
155
156
157
158
159
160
# File '../../src/modules/RelocationServer.rb', line 150

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)



234
235
236
237
238
# File '../../src/modules/RelocationServer.rb', line 234

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

  nil
end

- (Object) SetLibvirtdPorts(ports)



223
224
225
226
227
228
# File '../../src/modules/RelocationServer.rb', line 223

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

  nil
end

- (Object) SetModified

Sets that the configuration has been modified.



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

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



143
144
145
146
147
# File '../../src/modules/RelocationServer.rb', line 143

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



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
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
# File '../../src/modules/RelocationServer.rb', line 399

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

  xen_steps = 3
  libvirt_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
  ]

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

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

  if is_xend()
    Progress.New(caption, " ", xen_steps, xen_stg, xen_tits, "")
  else
    Progress.New(caption, " ", libvirt_steps, libvirt_stg, libvirt_tits, "")
  end

  if is_xend()
    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 !WriteLibvirtServices()
    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) WriteLibvirtServices



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File '../../src/modules/RelocationServer.rb', line 269

def WriteLibvirtServices
  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



206
207
208
209
210
211
212
213
214
215
216
217
# File '../../src/modules/RelocationServer.rb', line 206

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



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File '../../src/modules/RelocationServer.rb', line 163

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