Class: Yast::DeployImageAutoClient

Inherits:
Client
  • Object
show all
Defined in:
src/lib/installation/clients/deploy_image_auto.rb

Instance Method Summary collapse

Instance Method Details

#mainObject



31
32
33
34
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
85
86
87
88
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
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
# File 'src/lib/installation/clients/deploy_image_auto.rb', line 31

def main
  Yast.import "UI"
  textdomain "installation"

  Yast.import "Label"
  Yast.import "Wizard"
  Yast.import "Progress"
  Yast.import "Installation"
  Yast.import "ImageInstallation"
  Yast.import "AutoinstSoftware"
  Yast.import "Popup"

  Builtins.y2milestone("----------------------------------------")
  Builtins.y2milestone("Starting deploy_image_auto")

  @progress_orig = Progress.set(false)

  @ret = nil
  @func = ""
  @param = {}

  # Check arguments
  if Ops.greater_than(Builtins.size(WFM.Args), 0) &&
      Ops.is_string?(WFM.Args(0))
    @func = Convert.to_string(WFM.Args(0))
    if Ops.greater_than(Builtins.size(WFM.Args), 1) &&
        Ops.is_map?(WFM.Args(1))
      @param = Convert.to_map(WFM.Args(1))
    end
  end
  Builtins.y2debug("func=%1", @func)
  Builtins.y2debug("param=%1", @param)

  if @func == "Import"
    if Builtins.haskey(@param, "image_installation")
      ImageInstallation.changed_by_user = true
      Installation.image_installation = Ops.get_boolean(
        @param,
        "image_installation",
        false
      )
      Builtins.y2milestone(
        "Using image_installation: %1",
        Installation.image_installation
      )
      @ret = true
    else
      @ret = false
      Installation.image_installation = true
      Builtins.y2warning(
        "Key image_installation not defined, using image_installation: %1",
        Installation.image_installation
      )
    end
  # Create a summary
  # return string
  elsif @func == "Summary"
    @ret = "<ul><li>" +
      (if Installation.image_installation
         _("Installation from images is: <b>enabled</b>")
       else
         _("Installation from images is: <b>disabled</b>")
       end) + "</li></ul>"
  # did configuration changed
  # return boolean
  elsif @func == "GetModified"
    @ret = true
  # set configuration as changed
  # return boolean
  elsif @func == "SetModified"
    @ret = true
  # Reset configuration
  # return map or list
  elsif @func == "Reset"
    ImageInstallation.FreeInternalVariables
    Installation.image_installation = false
  # Change configuration
  # return symbol (i.e. `finish || `accept || `next || `cancel || `abort)
  elsif @func == "Change"
    Wizard.CreateDialog
    Wizard.SetContentsButtons(
      # TRANSLATORS: dialog caption
      _("Installation from Images"),
      HBox(
        HStretch(),
        VBox(
          Frame(
            _("Installation from Images"),
            VBox(
              Label(
                _(
                  "Here you can choose to use Novell pre-defined images to speed up RPM installation."
                )
              ),
              RadioButtonGroup(
                Id(:images_rbg),
                MarginBox(
                  2,
                  1,
                  VBox(
                    Left(
                      RadioButton(
                        Id(:inst_from_images),
                        Opt(:notify),
                        _("&Install from Images"),
                        Installation.image_installation == true
                      )
                    ),
                    VSpacing(0.5),
                    Left(
                      RadioButton(
                        Id(:dont_inst_from_images),
                        Opt(:notify),
                        _("&Do not Install from Images"),
                        Installation.image_installation != true
                      )
                    )
                  )
                )
              )
            )
          ),
          VSpacing(0.5),
          Frame(
            _(
              "Custom images deployment - this needs a URL to be configured as installation source"
            ),
            # Image name, Image location
            MarginBox(
              2,
              1,
              VBox(
                Label(
                  _("Here you can create custom images.\n") +
                    _(
                      "You have to configure the software selection first before you can create an image here"
                    )
                ),
                RadioButtonGroup(
                  Id(:own_images_rbg),
                  MarginBox(
                    2,
                    1,
                    VBox(
                      Frame(
                        _(
                          "Create an image file (AutoYaST will fetch it from the given location during installation)"
                        ),
                        VBox(
                          RadioButton(
                            Id(:create_image),
                            Opt(:notify, :default, :hstretch),
                            _("Create Image")
                          ),
                          TextEntry(
                            Id(:image_location),
                            Opt(:notify),
                            _(
                              "Where will AutoYaST find the image? (e.g. http://host/)"
                            ),
                            Ops.get_string(
                              AutoinstSoftware.image,
                              "image_location",
                              ""
                            )
                          ),
                          TextEntry(
                            Id(:image_name),
                            Opt(:notify),
                            _(
                              "What is the name of the image? (e.g. my_image)"
                            ),
                            Ops.get_string(
                              AutoinstSoftware.image,
                              "image_name",
                              ""
                            )
                          ),
                          VSpacing(0.5),
                          RadioButton(
                            Id(:create_iso),
                            Opt(:notify, :default, :hstretch),
                            _(
                              "Create ISO (image and autoinst.xml will be on the media)"
                            )
                          )
                        )
                      )
                    )
                  )
                )
              )
            )
          )
        ),
        HStretch()
      ),
      # TRANSLATORS: help text
      _(
        "<p><b>Installation from Images</b> is used to speed the installation up.\n" \
          "Images contain compressed snapshots of an installed system matching your\n" \
          "selection of patterns. The rest of the packages which are not contained in the\n" \
          "images will be installed from packages the standard way.</p>\n"
      ) +
        _(
          "<p><b>Creating own Images</b> is used if you\n" \
            "want to skip the complete step of RPM installation. Instead AutoYaST will dump an\n" \
            "image on the harddisk which is a lot faster and can be pre-configured already.\n" \
            "Everything else than RPM installation is done like during a normal auto-installation.</p>"
        ),
      Label.BackButton,
      Label.OKButton
    )
    Wizard.SetAbortButton(:abort, Label.CancelButton)
    Wizard.DisableBackButton
    @selected = UI.QueryWidget(:images_rbg, :CurrentButton)
    UI.ChangeWidget(
      Id(:create_image),
      :Enabled,
      @selected == :dont_inst_from_images
    )
    UI.ChangeWidget(
      Id(:create_iso),
      :Enabled,
      @selected == :dont_inst_from_images
    )
    UI.ChangeWidget(
      Id(:image_location),
      :Enabled,
      @selected == :dont_inst_from_images
    )
    UI.ChangeWidget(
      Id(:image_name),
      :Enabled,
      @selected == :dont_inst_from_images
    )
    loop do
      if Ops.greater_than(
        Builtins.size(
          Convert.to_string(UI.QueryWidget(:image_location, :Value))
        ),
        0
      ) ||
          Ops.greater_than(
            Builtins.size(
              Convert.to_string(UI.QueryWidget(:image_name, :Value))
            ),
            0
          )
        UI.ChangeWidget(Id(:inst_from_images), :Enabled, false)
      else
        UI.ChangeWidget(Id(:inst_from_images), :Enabled, true)
      end

      if AutoinstSoftware.instsource == ""
        UI.ChangeWidget(Id(:create_image), :Enabled, false)
        UI.ChangeWidget(Id(:create_iso), :Enabled, false)
      end

      @ret = UI.UserInput
      Builtins.y2milestone("ret=%1", @ret)

      if @ret == :ok || @ret == :next
        @selected2 = UI.QueryWidget(:images_rbg, :CurrentButton)
        @image_type = UI.QueryWidget(:own_images_rbg, :CurrentButton)
        Ops.set(AutoinstSoftware.image, "run_kickoff", true)
        if @selected2 == :inst_from_images
          Installation.image_installation = true
          AutoinstSoftware.image = {}
        elsif @selected2 == :dont_inst_from_images
          Installation.image_installation = false
          if @image_type == :create_image
            Ops.set(
              AutoinstSoftware.image,
              "image_location",
              Convert.to_string(UI.QueryWidget(:image_location, :Value))
            )
            Ops.set(
              AutoinstSoftware.image,
              "image_name",
              Convert.to_string(UI.QueryWidget(:image_name, :Value))
            )
            AutoinstSoftware.createImage("")
          elsif @image_type == :create_iso
            AutoinstSoftware.createISO
          end
        end
        Builtins.y2milestone(
          "Changed by user, Installation from images will be used: %1",
          Installation.image_installation
        )
      elsif @ret == :create_image
        UI.ChangeWidget(Id(:image_location), :Enabled, true)
        UI.ChangeWidget(Id(:image_name), :Enabled, true)
        if Ops.greater_than(Builtins.size(AutoinstSoftware.patterns), 0)
          Ops.set(
            AutoinstSoftware.image,
            "image_location",
            Convert.to_string(UI.QueryWidget(:image_location, :Value))
          )
          Ops.set(
            AutoinstSoftware.image,
            "image_name",
            Convert.to_string(UI.QueryWidget(:image_name, :Value))
          )
        else
          Popup.Warning(
            _(
              "you need to do the software selection before creating an image"
            )
          )
        end
      elsif @ret == :create_iso
        UI.ChangeWidget(Id(:image_location), :Enabled, false)
        UI.ChangeWidget(Id(:image_name), :Enabled, false)
        Ops.set(AutoinstSoftware.image, "image_name", "image")
        if Ops.less_or_equal(Builtins.size(AutoinstSoftware.patterns), 0)
          Popup.Warning(
            _(
              "you need to do the software selection before creating an image"
            )
          )
        end
      elsif @ret == :inst_from_images || @ret == :dont_inst_from_images
        @selected2 = UI.QueryWidget(:images_rbg, :CurrentButton)
        UI.ChangeWidget(
          Id(:create_image),
          :Enabled,
          @selected2 == :dont_inst_from_images
        )
        UI.ChangeWidget(
          Id(:create_iso),
          :Enabled,
          @selected2 == :dont_inst_from_images
        )
        UI.ChangeWidget(
          Id(:image_location),
          :Enabled,
          @selected2 == :dont_inst_from_images
        )
        UI.ChangeWidget(
          Id(:image_name),
          :Enabled,
          @selected2 == :dont_inst_from_images
        )
        if @ret == :inst_from_images
          UI.ChangeWidget(Id(:create_image), :Value, false)
          UI.ChangeWidget(Id(:create_iso), :Value, false)
        end
      end
      break if [:ok, :next, :abort].include?(@ret)
    end

    Wizard.CloseDialog
    return deep_copy(@ret)
  # Return configuration data
  # return map or list
  elsif @func == "Export"
    @ret = { "image_installation" => Installation.image_installation }
  # Write the configuration (prepare images, deploy images)
  elsif @func == "Write"
    Builtins.y2milestone(
      "Using images: %1",
      Installation.image_installation
    )

    # BNC #442691
    # Calling image_installation only if set to do so...
    if Installation.image_installation == true
      WFM.call("inst_prepare_image")

      # moved to control.xml
      #	WFM::call ("inst_deploy_image");
    end

    @ret = true
  # Read configuration data
  # return boolean
  elsif @func == "Read"
    Builtins.y2milestone("Read not supported")
    @ret = true
  else
    Builtins.y2error("unknown function: %1", @func)
    @ret = false
  end
  Progress.set(@progress_orig)

  Builtins.y2debug("ret=%1", @ret)
  Builtins.y2milestone("deploy_image_auto finished")
  Builtins.y2milestone("----------------------------------------")

  deep_copy(@ret)

  # EOF
end