Class: Yast::IscsiClientClass

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

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) Abort

Abort function

Returns:

  • (Boolean)

    return true if abort



74
75
76
77
# File '../../src/modules/IscsiClient.rb', line 74

def Abort
  return @AbortFunction.call == true if @AbortFunction != nil
  false
end

- (Hash) AutoPackages

Return packages needed to be installed and removed during Autoinstallation to insure module has all needed software installed.

Returns:

  • (Hash)

    with 2 lists.



308
309
310
# File '../../src/modules/IscsiClient.rb', line 308

def AutoPackages
  { "install" => ["open-iscsi"], "remove" => [] }
end

- (Hash) Export

Dump the iscsi-client settings to a single map (For use by autoinstallation.)

Returns:

  • (Hash)

    Dumped settings (later acceptable by Import ())



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

def Export
  tgets = []
  Builtins.foreach(IscsiClientLib.sessions) do |sess|
    sl = Builtins.splitstring(sess, " ")
    target = Ops.get(sl, 1, "")
    portal = Ops.get(sl, 0, "")
    iface = Ops.get(sl, 2, "default")
    IscsiClientLib.currentRecord = [portal, target, iface]
    auth = IscsiClientLib.getNode
    new_target = {
      "target"  => target,
      "portal"  => portal,
      "iface"   => iface,
      "startup" => IscsiClientLib.getStartupStatus
    }
    if Ops.get_string(auth, "authmethod", "None") == "None"
      Ops.set(new_target, "authmethod", "None")
    else
      new_target = Builtins.union(new_target, auth)
    end
    tgets = Builtins.add(tgets, new_target)
  end
  IscsiClientLib.ay_settings = {}
  if !Builtins.isempty(tgets)
    IscsiClientLib.ay_settings = {
      "version"       => "1.0",
      "initiatorname" => IscsiClientLib.initiatorname,
      "targets"       => tgets
    }
    @configured = true
    @modified = true
  end
  deep_copy(IscsiClientLib.ay_settings)
end

- (Boolean) Import(settings)

Get all iscsi-client settings from the first parameter (For use by autoinstallation.)

Parameters:

  • settings (Hash)

    The YCP structure to be imported.

Returns:

  • (Boolean)

    True on success



282
283
284
285
286
# File '../../src/modules/IscsiClient.rb', line 282

def Import(settings)
  settings = deep_copy(settings)
  IscsiClientLib.ay_settings = deep_copy(settings)
  true
end

- (Object) installed_packages

check if package open-iscsi is installed



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File '../../src/modules/IscsiClient.rb', line 88

def installed_packages
  # don't check interactively for packages (bnc#367300)
  # skip it during second stage or when create AY profile
  return true if Stage.cont || Stage.initial || Mode.config
  Builtins.y2milestone("Check if open-iscsi package installed")
  ret = false
  if !Package.InstallMsg(
      "open-iscsi",
      _(
        "<p>To configure the iSCSI initiator, the <b>%1</b> package must be installed.</p>"
      ) +
        _("<p>Install it now?</p>")
    )
    Popup.Error(Message.CannotContinueWithoutPackagesInstalled)
  else
    ret = true
  end
  ret
end

- (Object) main



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

def main
  textdomain "iscsi-client"

  Yast.import "Progress"
  Yast.import "Report"
  Yast.import "Summary"
  Yast.import "Message"
  Yast.import "Service"
  Yast.import "Package"
  Yast.import "Packages"
  Yast.import "Popup"
  Yast.import "Mode"
  Yast.import "Confirm"
  Yast.import "Label"
  Yast.import "NetworkService"
  Yast.import "IscsiClientLib"
  Yast.import "Stage"

  @configured = false

  # Data was modified?
  @modified = false


  @proposal_valid = false

  # Write only, used during autoinstallation.
  # Don't run services and SuSEconfig, it's all done at one place.
  @write_only = false

  # Abort function
  # return boolean return true if abort
  @AbortFunction = fun_ref(method(:Modified), "boolean ()")
end

- (Object) Modified

Data was modified?

Returns:

  • true if modified



81
82
83
84
# File '../../src/modules/IscsiClient.rb', line 81

def Modified
  Builtins.y2debug("modified=%1", @modified)
  @modified
end

- (Object) Overview

Create an overview table with all configured cards

Returns:

  • table items



299
300
301
302
# File '../../src/modules/IscsiClient.rb', line 299

def Overview
  # TODO FIXME: your code here...
  []
end

- (Object) Read

Read all iscsi-client settings

Returns:

  • true on success



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

def Read
  # IscsiClient read dialog caption
  caption = _("Initializing iSCSI Initiator Configuration")

  # TODO FIXME Set the right number of stages
  steps = 4

  sl = 500
  Builtins.sleep(sl)

  # TODO FIXME Names of real stages
  # We do not set help text here, because it was set outside
  Progress.New(
    caption,
    " ",
    steps,
    [
      # Progress stage 1/3
      _("Read the database"),
      # Progress stage 2/3
      _("Read the previous settings"),
      # Progress stage 3/3
      _("Detect the devices")
    ],
    [
      # Progress step 1/3
      _("Reading the database..."),
      # Progress step 2/3
      _("Reading the previous settings..."),
      # Progress step 3/3
      _("Detecting the devices..."),
      # Progress finished
      _("Finished")
    ],
    ""
  )

  # check if user is root - must be root
  return false if !Confirm.MustBeRoot
  return false if !NetworkService.RunningNetworkPopup
  Progress.NextStage
  return false if false
  Builtins.sleep(sl)

  # check if required package is installed
  return false if !installed_packages
  return false if IscsiClientLib.getiBFT == nil
  # Progress finished
  Progress.NextStage
  Builtins.sleep(sl)

  Progress.NextStage
  # check initiatorname - create it if no exists
  Builtins.y2milestone("Check initiator name")
  return false if !IscsiClientLib.checkInitiatorName
  Builtins.sleep(sl)

  return false if Abort()
  #    Progress::NextStep();
  # read status of service
  return false if !IscsiClientLib.getServiceStatus
  Builtins.sleep(sl)

  # read current settings
  #    if(!IscsiClientLib::autoLogOn()) return false;
  Progress.NextStage


  # read config file
  if IscsiClientLib.readSessions == false
    Report.Error(Message.CannotReadCurrentSettings)
    return false
  end
  Builtins.sleep(sl)

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

- (Object) Summary

Create a textual summary and a list of unconfigured cards

Returns:

  • summary of the current configuration



291
292
293
294
295
# File '../../src/modules/IscsiClient.rb', line 291

def Summary
  # TODO FIXME: your code here...
  # Configuration summary text for autoyast
  [IscsiClientLib.Overview, []]
end

- (Object) Write

Write all iscsi-client settings

Returns:

  • true on success



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

def Write
  # IscsiClient read dialog caption
  caption = _("Saving iSCSI Initiator Configuration")

  # TODO FIXME And set the right number of stages

  sl = 500
  Builtins.sleep(sl)

  descr = [
    # Progress stage 1/2
    _("Write AutoYaST settings"),
    # Progress stage 2/2
    _("Set up service status")
  ]
  descr = Builtins.remove(descr, 0) if !(Mode.autoinst || Mode.autoupgrade)
  # TODO FIXME Names of real stages
  # We do not set help text here, because it was set outside
  Progress.New(caption, " ", Builtins.size(descr), descr, [], "")

  if Mode.autoinst || Mode.autoupgrade
    return false if Abort()
    Progress.NextStage
    IscsiClientLib.autoyastPrepare
    IscsiClientLib.autoyastWrite
    Builtins.sleep(sl)
  end

  return false if Abort()
  Progress.NextStage
  # set open-iscsi service status
  return false if !IscsiClientLib.setServiceStatus
  Builtins.sleep(sl)

  return false if Abort()
  Progress.NextStage
  if Stage.initial &&
      Ops.greater_than(Builtins.size(IscsiClientLib.sessions), 0)
    Packages.addAdditionalPackage("open-iscsi")
  end
  Builtins.sleep(sl)

  true
end