Class: Yast::AutoinstCloneClass

Inherits:
Module
  • Object
show all
Includes:
Logger
Defined in:
../../src/modules/AutoinstClone.rb

Instance Method Summary (collapse)

Instance Method Details

- (Array) CommonClone(resource, resourceMap)

Clone a Resource

Parameters:

  • resource (String)
  • resource (String)

    name

Returns:

  • (Array)


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
# File '../../src/modules/AutoinstClone.rb', line 88

def CommonClone(resource, resourceMap)
  resourceMap = deep_copy(resourceMap)
  data_type = Ops.get_string(
    resourceMap,
    "X-SuSE-YaST-AutoInstDataType",
    "map"
  )
  auto = Ops.get_string(resourceMap, "X-SuSE-YaST-AutoInstClient", "")
  resource = Ops.get_string(
    resourceMap,
    "X-SuSE-YaST-AutoInstResource",
    resource
  )

  # Do not read settings from system in first stage, autoyast profile
  # should contain only proposed and user modified values.
  # Exception: Storage and software module have autoyast modules which are
  #            defined in autoyast itself.
  #            So, these modules have to be called.
  if !Stage.initial ||
    ["software_auto", "storage_auto"].include?(auto)
    Call.Function(auto, ["Read"])
  end
  # Flagging YAST module for export
  Call.Function(auto, ["SetModified"])

  true
end

- (Array) createClonableList

Create a list of clonable resources

Returns:

  • (Array)

    list to be used in widgets



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
# File '../../src/modules/AutoinstClone.rb', line 121

def createClonableList
  items = []
  Builtins.foreach(Y2ModuleConfig.ModuleMap) do |def_resource, resourceMap|
    Builtins.y2debug(
      "r: %1 => %2",
      def_resource,
      Ops.get_string(resourceMap, "X-SuSE-YaST-AutoInstClonable", "false")
    )
    clonable = Ops.get_string(
      resourceMap,
      "X-SuSE-YaST-AutoInstClonable",
      "false"
    ) == "true"
    if clonable || "partitioning" == def_resource ||
        "software" == def_resource || # has no desktop file
        "bootloader" == def_resource # has no desktop file
      desktop_file = Builtins.substring(
        Ops.get_string(resourceMap, "X-SuSE-DocTeamID", ""),
        4
      )
      name = Builtins.dpgettext(
        "desktop_translations",
        "/usr/share/locale/",
        Ops.add(
          Ops.add(Ops.add("Name(", desktop_file), ".desktop): "),
          Ops.get_string(resourceMap, "Name", "")
        )
      )
      if name ==
          Ops.add(
            Ops.add(Ops.add("Name(", desktop_file), ".desktop): "),
            Ops.get_string(resourceMap, "Name", "")
          )
        name = Ops.get_string(resourceMap, "Name", "")
      end
      # Set resource name, if not using default value
      resource = Ops.get_string(
        resourceMap,
        "X-SuSE-YaST-AutoInstResource",
        ""
      )
      resource = def_resource if resource == ""
      if resource != ""
        items = Builtins.add(items, Item(Id(resource), name))
      else
        items = Builtins.add(items, Item(Id(def_resource), name))
      end
    end
  end
  # sort items for nicer display
  items = Builtins.sort(
    Convert.convert(items, :from => "list", :to => "list <term>")
  ) do |x, y|
    Ops.less_than(Ops.get_string(x, 1, "x"), Ops.get_string(y, 1, "y"))
  end
  deep_copy(items)
end

- (void) Export

This method returns an undefined value.

Export profile, Used only from within autoyast2



226
227
228
229
230
231
# File '../../src/modules/AutoinstClone.rb', line 226

def Export
  Yast.import "Profile"
  Profile.Reset
  Process()
  nil
end

- (Hash) General

General options

Returns:

  • (Hash)

    general options



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
# File '../../src/modules/AutoinstClone.rb', line 57

def General
  Yast.import "Mode"
  Mode.SetMode("normal")

  general = {}

  general["mode"] = { "confirm" => false }

  general["signature-handling"] = {
    "accept_unsigned_file"         => true,
    "accept_file_without_checksum" => true,
    "accept_unknown_gpg_key"       => true,
    "accept_verification_failed"   => false,
    "import_gpg_key"               => true,
    "accept_non_trusted_gpg_key"   => true
  }

  general["storage"] = {
    "start_multipath" => multipath_in_use?,
    "partition_alignment" => Storage.GetPartitionAlignment,
  }

  Mode.SetMode("autoinst_config")
  general
end

- (Object) main



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File '../../src/modules/AutoinstClone.rb', line 24

def main
  Yast.import "Mode"

  Yast.import "XML"
  Yast.import "Call"
  Yast.import "Profile"
  Yast.import "Y2ModuleConfig"
  Yast.import "Misc"
  Yast.import "Storage"
  Yast.import "AutoinstConfig"
  Yast.import "Report"

  Yast.include self, "autoinstall/xml.rb"

  @Profile = {}
  @bytes_per_unit = 0


  # spceial treatment for base resources
  @base = []

  # aditional configuration resources o be cloned
  @additional = []
end

- (Boolean) multipath_in_use?

Detects whether the current system uses multipath

Returns:

  • (Boolean)

    if in use



51
52
53
# File '../../src/modules/AutoinstClone.rb', line 51

def multipath_in_use?
  Storage.GetTargetMap.detect{|k,e| e.fetch("type",:X)==:CT_DMMULTIPATH} ? true:false
end

- (void) Process

This method returns an undefined value.

Build the profile



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
# File '../../src/modules/AutoinstClone.rb', line 181

def Process
  log.info "Base resources: #{@base} additional: #{@additional}"
  Profile.Reset
  Profile.prepare = true
  Mode.SetMode("autoinst_config")

  Builtins.foreach(Y2ModuleConfig.ModuleMap) do |def_resource, resourceMap|
    # Set resource name, if not using default value
    resource = Ops.get_string(
      resourceMap,
      "X-SuSE-YaST-AutoInstResource",
      ""
    )
    resource = def_resource if resource == ""

    if @additional.include?(resource)
      log.info "Now cloning: #{resource}"
      time_start = Time.now
      ret = CommonClone(def_resource, resourceMap)
      log.info "Cloning #{resource} took: #{(Time.now - time_start).round} sec"
    end
  end

  Call.Function("general_auto", ["Import", General()])
  Call.Function("general_auto", ["SetModified"])

  Call.Function("report_auto", ["Import", Report.Export])
  Call.Function("report_auto", ["SetModified"])

  Profile.Prepare
  nil
end

- (Boolean) Write(outputFile)

Write the profile to a defined path

Parameters:

  • outputFile (String)

    Output file path

Returns:

  • (Boolean)

    true on success



217
218
219
220
221
# File '../../src/modules/AutoinstClone.rb', line 217

def Write(outputFile)
  Process()
  ret = Profile.Save(outputFile)
  ret
end