Class List Method List File List

# Class: Yast::VM_XENClass

Inherits:
  Module
  - Object
  - Module
  - Yast::VM_XENClass
  show all
Defined in:
  ../../src/modules/VM_XEN.rb

## Instance Method Summary (collapse)

- - (Object) ConfigureDom0(is_s390)
- - (Object) ConfigureFirewall
- - (Object) isOpenSuse
- - (Object) isPAEKernel
- - (Object) isUML
- - (Object) isX86_64
- - (Object) main

## Instance Method Details

### - (`Object`) ConfigureDom0(is_s390)

    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    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
    253
    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
    283
    284
    285
    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
    381
    382
    383
    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
    472
    473
    474
    475
    # File '../../src/modules/VM_XEN.rb', line 172

    def ConfigureDom0(is_s390)
      progress_stages = [
        # progress stage 1/2
        _("Verify Installed Packages"),
        # progress stage 2/2
        _("Network Bridge Configuration")
      ]

      progress_descriptions = []

      bridge_exists = false
      install_xen = false
      install_kvm = false
      widget_id = nil

      bridge_path = ""

      progress_length = Builtins.size(progress_stages)

      # Headline for management domain installation
      headline = _("Configuring the VM Server (domain 0)")

      # xen domain0 installation help text - 1/4
      help_text = _(
        "<p><big><b>VM Server Configuration</b></big></p><p>Configuration of the VM Server (domain 0) has two parts.</p>"
      ) +
        # xen domain0 installation help text - 2/4
        _(
          "<p>The required packages are installed into the system first. Then the boot loader is switched to GRUB (if not already used) and the Xen section is added to the boot loader menu if it is missing.</p>"
        ) +
        # xen domain0 installation help text - 3/4
        _(
          "<p>GRUB is needed because it supports the multiboot standard required to boot Xen and the Linux kernel.</p>"
        ) +
        # xen domain0 installation help text - 4/4
        _(
          "<p>When the configuration has finished successfully, you can boot the VM Server from the boot loader menu.</p>"
        )

      # error popup
      abortmsg = _("The installation will be aborted.")

      # Generate a pop dialog to allow user selection of Xen or KVM
      if is_s390 == true
        UI.OpenDialog(
          VBox(
            Label(_("Select the virtualization platform to install.")),
            Left(CheckBox(Id(:xen), Opt(:disabled), "Xen")),
            Left(CheckBox(Id(:kvm), "KVM")),
            ButtonBox(
              PushButton(Id(:accept), Label.AcceptButton),
              PushButton(Id(:cancel), Label.CancelButton)
            )
          )
        )
      else
        UI.OpenDialog(
          VBox(
            Label(_("Select the virtualization platform to install.")),
            Left(CheckBox(Id(:xen), "Xen")),
            Left(CheckBox(Id(:kvm), "KVM")),
            ButtonBox(
              PushButton(Id(:accept), Label.AcceptButton),
              PushButton(Id(:cancel), Label.CancelButton)
            )
          )
        )
      end

      widget_id = UI.UserInput
      if widget_id == :accept
        install_xen = Convert.to_boolean(UI.QueryWidget(Id(:xen), :Value))
        install_kvm = Convert.to_boolean(UI.QueryWidget(Id(:kvm), :Value))
      end

      UI.CloseDialog

      if widget_id == :cancel || install_xen == false && install_kvm == false
        Builtins.y2milestone(
          "VM_XEN::ConfigureDom0 Cancel Selected or no platform selected."
        )
        return false
      end

      Wizard.OpenNextBackDialog
      Wizard.SetDesktopTitleAndIcon("xen")

      # enable progress
      progress = Progress.set(true)

      # Headline for virtual machine installation
      Progress.New(
        headline,
        "",
        progress_length,
        progress_stages,
        progress_descriptions,
        help_text
      )

      # package stage
      Progress.NextStage

      # Common packages to both Xen and KVM
      packages = ["libvirt-python", "vm-install"]

      if install_xen
        packages = Builtins.add(packages, "libvirt-daemon-xen")
        packages = Builtins.add(packages, "xen")
        packages = Builtins.add(packages, "xen-libs")
        packages = Builtins.add(packages, "xen-tools")
        packages = Builtins.add(packages, "kernel-xen")
      end
      if install_kvm
        packages = Builtins.add(packages, "libvirt-daemon-qemu")
        packages = Builtins.add(packages, "kvm")
      end

      inst_gui = true

      Builtins.y2milestone("VM_XEN::ConfigureDom0 Checking for packages...")

      # Assume python gtk is installed. If in text mode we don't care
      if Ops.get_boolean(UI.GetDisplayInfo, "TextMode", true) == true
        inst_gui = Popup.YesNo(
          _("Running in text mode. Install graphical components anyway?")
        )
      end
      if inst_gui == true
        packages = Builtins.add(packages, "python-gtk")
        # Also make sure virt-manager and virt-viewer is there - runs GUI only
        packages = Builtins.add(packages, "virt-manager")
        packages = Builtins.add(packages, "virt-viewer")
      end

      success = true

      # progressbar title - check whether Xen packages are installed
      Progress.Title(_("Checking packages..."))
      if Package.InstalledAll(packages) == false
        # progressbar title - install the required packages
        Progress.Title(_("Installing packages..."))
        success = Package.InstallAll(packages)
        if success == false
          # error popup
          Report.Error(
            Ops.add(_("Cannot install required packages.") + "\n", abortmsg)
          )
          return false
        end
        # Now see if they really were installed (bnc#508347)
        if Package.InstalledAll(packages) == false
          Report.Error(
            Ops.add(_("Cannot install required packages.") + "\n", abortmsg)
          )
          return false
        end
      end

      # If grub2 is the bootloader and we succesfully installed Xen, update the grub2 files
      if install_xen
        Builtins.y2milestone("Checking for bootloader type")
        if Bootloader.getLoaderType == "grub2"
          Progress.Title(_("Updating grub2 configuration files..."))
          cmd = "/usr/sbin/grub2-mkconfig -o /boot/grub2/grub.cfg"
          Builtins.y2milestone("Executing: %1", cmd)
          SCR.Execute(path(".target.bash"), cmd)
        end
      end

      if is_s390 == false
        # Default Bridge stage
        Progress.NextStage

        Progress.Title(_("Configuring Default Network Bridge..."))

        # Check for the existance of /sys/class/net/*/bridge
        interfaces = Convert.convert(
          SCR.Read(path(".target.dir"), @net_path),
          :from => "any",
          :to   => "list <string>"
        )
        Builtins.foreach(interfaces) do |i|
          Builtins.y2milestone("Checking for bridges...")
          bridge_path = Ops.add(Ops.add(Ops.add(@net_path, "/"), i), "/bridge")
          if Ops.greater_or_equal(SCR.Read(path(".target.dir"), bridge_path), 0)
            Builtins.y2milestone("Dom0 already has a configured bridge.")
            bridge_exists = true
            raise Break
          end
        end

        # Popup yes/no dialog
        if bridge_exists == false
          if Popup.AnyQuestionRichText(
              _("Network Bridge."),
              _(
                "<p>For normal network configurations hosting virtual machines, a network bridge is recommended.</p><p>Configure a default network bridge?</p>"
              ),
              45,
              5,
              Label.YesButton,
              Label.NoButton,
              :focus_yes
            )
            Builtins.y2milestone("Configuring default bridge for Xen or KVM...")
            WFM.call("lan_proposal", ["MakeProposal"])
            UI.OpenDialog(VBox())
            WFM.call("lan_proposal", ["Write"])
            UI.CloseDialog
          end
        end

        # Enable the libvirtd daemon if openSUSE
        if isOpenSuse == true
          cmd = "systemctl enable libvirtd.service"
          Builtins.y2milestone("Executing: %1", cmd)
          SCR.Execute(path(".target.bash"), cmd)
        end
      else
        # For s390, make sure /etc/zipl.conf contain switch_amode
        def_section = Bootloader.getDefaultSection
        switch_amode = Bootloader.getKernelParam(def_section, "switch_amode")
        if switch_amode == "false"
          zipl_updated = false
          Builtins.y2milestone(
            "No switch_amode kernel boot parameter in /etc/zipl.conf, adding ..."
          )
          if Bootloader.setKernelParam(def_section, "switch_amode", "true") == true
            if Bootloader.Write == true
              zipl_updated = true
              cmd = "/sbin/zipl"
              Builtins.y2milestone("Executing: %1", cmd)
              SCR.Execute(path(".target.bash"), cmd)
              Builtins.y2milestone(
                "Successful update of /etc/zipl.conf with the switch_amode kernel boot parameter"
              )
            end
          end
          if zipl_updated == false
            Builtins.y2milestone(
              "Failed to correctly update /etc/zipl.conf with switch_amode kernel boot parameter"
            )
          end
        end
      end

      # Firewall stage - modify the firewall setting, add the xen bridge to FW_FORWARD_ALWAYS_INOUT_DEV
      # Progress::NextStage();

      # Configure firewall to allow xenbr+
      # success = success && ConfigureFirewall();
      # if ( success == false ) {
      #     // error popup
      #     Report::Error(_("Failed to configure the firewall to allow the Xen bridge") + "\n" + abortmsg);
      #     return false;
      # }

      Progress.Finish

      message_kvm = _(
        "For installing KVM guests, reboot the machine to load the necessary drivers."
      )
      message_xen_reboot = _(
        "For installing Xen guests, reboot the machine and select the Xen section in the boot loader menu.\n"
      )
      message_xen_ready = _("Hypervisor and tools are installed.")
      message = nil

      if install_xen == false
        Popup.LongMessage(message_kvm)
      else
        if Arch.is_xen == false
          if install_kvm == true
            message = Builtins.sformat(
              "%1\n\n%2",
              message_kvm,
              message_xen_reboot
            )
          else
            message = message_xen_reboot
          end
          # popup message - ask user to reboot the machine
          Popup.LongMessage(message)
        else
          # popup message - Notify user of successful completion (or already installed).
          if install_kvm == true
            message = Builtins.sformat(
              "%1\n\n%2",
              message_kvm,
              message_xen_ready
            )
          else
            message = message_xen_ready
          end
          Popup.Message(message)
        end
      end

      Wizard.CloseDialog

      Builtins.y2milestone("VM_XEN::ConfigureDom0 returned: %1", success)
      success
    end

### - (`Object`) ConfigureFirewall

    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
    85
    86
    87
    # File '../../src/modules/VM_XEN.rb', line 53

    def ConfigureFirewall
      Builtins.y2milestone("VM_XEN::ConfigureFirewall() started")
      ret = true

      # check whether the firewall option exists
      firewall_configured = false
      if Builtins.contains(
          SCR.Dir(path(".sysconfig.SuSEfirewall2")),
          "FW_FORWARD_ALWAYS_INOUT_DEV"
        )
        xen_bridge = "xenbr+"
        # read the current value
        forward = Convert.to_string(
          SCR.Read(path(".sysconfig.SuSEfirewall2.FW_FORWARD_ALWAYS_INOUT_DEV"))
        )
        Builtins.y2milestone("FW_FORWARD_ALWAYS_INOUT_DEV=%1", forward)
        if Builtins.contains(Builtins.splitstring(forward, " "), xen_bridge)
          Builtins.y2milestone("Firewall already configured!")
          firewall_configured = true # xenbr+ already exists
        end
      end

      if firewall_configured == false
        # add xenbr+ to the firewall configuration
        Builtins.y2milestone("Configuring firewall to allow Xen bridge...")
        progress_orig = Progress.set(false)
        SuSEFirewall.Read
        SuSEFirewall.AddXenSupport
        ret = ret && SuSEFirewall.Write
        Progress.set(progress_orig)
      end

      Builtins.y2milestone("VM_XEN::ConfigureFirewall returned: %1", ret)
      ret
    end

### - (`Object`) isOpenSuse

    89
    90
    91
    92
    93
    94
    95
    96
    97
    # File '../../src/modules/VM_XEN.rb', line 89

    def isOpenSuse
      Builtins.y2milestone("Checking to see if this is openSUSE ...")
      distro = OSRelease.ReleaseName
      if distro.include? "openSUSE"
        Builtins.y2milestone("Platform is %1", distro)
        return true
      end
      false
    end

### - (`Object`) isPAEKernel

    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    # File '../../src/modules/VM_XEN.rb', line 99

    def isPAEKernel
      # check is we're running on 32 bit pae.
      Builtins.y2milestone("Checking for PAE kernel...")
      isPAE = false
      cmd = "uname -r"
      Builtins.y2milestone("Executing: %1", cmd)
      retmap = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd))
      Ops.set(
        retmap,
        "stdout",
        Builtins.deletechars(Ops.get_string(retmap, "stdout", ""), "\n\t ")
      ) # remove whitespace
      Builtins.y2milestone("retmap=%1", retmap)
      if Ops.get_string(retmap, "stdout", "") != nil &&
          Ops.get_string(retmap, "stdout", "") != ""
        if Builtins.regexpmatch(
            Ops.get_string(retmap, "stdout", ""),
            ".*xenpae$"
          ) # check for kernel-xenpae
          isPAE = true
        elsif Builtins.regexpmatch(
            Ops.get_string(retmap, "stdout", ""),
            ".*bigsmp$"
          ) # check for kernel-bigsmp
          isPAE = true
        else
          isPAE = false
        end
      end
      Builtins.y2milestone("VM_XEN::isPAEKernel returned: %1", isPAE)
      isPAE
    end

### - (`Object`) isUML

    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    # File '../../src/modules/VM_XEN.rb', line 152

    def isUML
      ret = false

      if Arch.is_uml == true
        # we are already in UML, nested virtual machine is not supported
        Report.Error(
          _(
            "Virtual machine installation cannot be started inside the UML machine.\nStart installation in the host system.\n"
          )
        )
        ret = true
      else
        ret = false
      end

      Builtins.y2milestone("VM_XEN::isUML returned: %1", ret)
      false
    end

### - (`Object`) isX86_64

    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    # File '../../src/modules/VM_XEN.rb', line 132

    def isX86_64
      ret = true

      if Arch.x86_64 == false
        arch = Arch.architecture
        Report.Error(
          Ops.add(
            _(
              "x86_64 is the only supported architecture for hosting virtual machines. Your architecture is "
            ),
            arch
          )
        )
        ret = false
      end

      Builtins.y2milestone("VM_XEN::isX86_64 returned: %1", ret)
      ret
    end

### - (`Object`) main

    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    # File '../../src/modules/VM_XEN.rb', line 32

    def main
      Yast.import "UI"

      textdomain "vm"

      Yast.import "Arch"
      Yast.import "OSRelease"
      Yast.import "Package"
      Yast.import "Progress"
      Yast.import "Popup"
      Yast.import "Report"
      Yast.import "SuSEFirewall"
      Yast.import "Wizard"
      Yast.import "Label"
      Yast.import "Bootloader"

      @net_path = "/sys/class/net/"
    end