-
Notifications
You must be signed in to change notification settings - Fork 7
/
widgets.rb
359 lines (316 loc) · 9.62 KB
/
widgets.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
# encoding: utf-8
# File: clients/isns.ycp
# Package: Configuration of isns
# Summary: Main file
# Authors: Michal Zugec <mzugec@suse.cz>
#
# $Id: isns.ycp 28597 2006-03-06 11:29:38Z mzugec $
#
# Main file for isns configuration. Uses all other files.
module Yast
module IsnsWidgetsInclude
def initialize_isns_widgets(include_target)
textdomain "isns"
Yast.import "Label"
Yast.import "IsnsServer"
Yast.import "String"
Yast.import "Report"
end
# **************** global funcions and variables *****
def DiscoveryDomainDetailDialog(values_before)
ret_map = {}
dd_dialog = VBox(
Heading(_("Create New Discovery Domain")),
HSpacing(50),
HWeight(
3,
InputField(Id(:ddentry), Opt(:hstretch), _("Discovery Domain Name"))
),
ButtonBox(
PushButton(Id(:ok), Opt(:default), Label.OKButton),
PushButton(Id(:cancel), Label.CancelButton)
),
VSpacing(1)
)
UI.OpenDialog(dd_dialog)
UI.SetFocus(:ddentry)
ret = :nil
while ret != :ok && ret != :cancel
enable = false
ret = UI.UserInput
end
if ret == :cancel
ret_map = {}
else
dd_name = UI.QueryWidget(:ddentry, :Value)
IsnsServer.addDD(dd_name)
ret_map = { "VALUE" => dd_name }
end
UI.CloseDialog
ret_map
end
def CreateNode()
ret_map = {}
node_dialog = HBox(
HSpacing(5),
VBox(
VSpacing(1),
Left(
HWeight(
3,
InputField(Id(:nodeentry), Opt(:hstretch), _("iSCSI Node Name"))
)
),
Left(
ButtonBox(
PushButton(Id(:ok), Label.OKButton),
PushButton(Id(:cancel), Label.CancelButton)
)
),
VSpacing(1)
),
HSpacing(5)
)
UI.OpenDialog(node_dialog)
ret = :nil
while ret != :ok && ret != :cancel
enable = false
ret = Convert.to_symbol(UI.UserInput)
end
if ret == :cancel
ret_map = {}
else
value = Convert.to_string(UI.QueryWidget(:nodeentry, :Value))
ret_map = { "VALUE" => value }
end
UI.CloseDialog
deep_copy(ret_map)
end
def DisplayAllMembersDialog(dd_name, dd_id)
ret_map = {}
iscsi_member_dialog = VBox(
Heading(_("Add iSCSI node to discovery domain")),
Label(dd_name),
HSpacing(100),
Heading(_("Available Nodes to Add")),
HBox(
VSpacing(10),
Table(Id(:members_table), Header(_("Name"), _("Node Type")), [])
),
Left(
HBox(
PushButton(Id(:add), _("Add Node")),
PushButton(Id(:exit), _("Done"))
)
)
)
UI.OpenDialog(iscsi_member_dialog)
initDiscoveryDomainPotentialISCSI(dd_id)
ret = :nil
while ret != :exit
enable = false
ret = Convert.to_symbol(UI.UserInput)
if ret == :add
Builtins.y2milestone("Add a node")
index = UI.QueryWidget(Id(:members_table), :CurrentItem)
iqn = Ops.get_string(
Convert.to_term(
UI.QueryWidget(Id(:members_table), term(:Item, index))
),
1,
""
)
IsnsServer.addDDMember(dd_id, iqn)
initDiscoveryDomainPotentialISCSI(dd_id)
end
end
UI.CloseDialog
deep_copy(ret_map)
end
def initISCSI(key)
type = _("Target or Initiator")
inc_items = []
checkISNS
list = IsnsServer.readISCSI
list.each_with_index do |key, index|
inc_items.push(Item(
Id(index),
key["NODE"],
key["TYPE"]
)
)
end
UI.ChangeWidget(Id(:members_table), :Items, inc_items)
nil
end
def initDiscoveryDomainPotentialISCSI(key)
count = 0
type = _("Target or Initiator")
inc_items = []
iscsinode = ""
ddmembers = []
found = "FALSE"
ddmembers = IsnsServer.readDDMembers(key)
Builtins.foreach(IsnsServer.readISCSI) do |iscsinode2|
found = "FALSE"
Builtins.foreach(ddmembers) do |ddmember|
if Ops.get_string(ddmember, "NODE", "") ==
Ops.get_string(iscsinode2, "NODE", "")
found = "TRUE"
end
end
if found == "FALSE"
inc_items = Builtins.add(
inc_items,
Item(
Id(count),
Ops.get_string(iscsinode2, "NODE", ""),
Ops.get_string(iscsinode2, "TYPE", "")
)
)
count = Ops.add(count, 1)
end
end
UI.ChangeWidget(Id(:members_table), :Items, inc_items)
nil
end
def initDDISCSIMembers(key)
inc_items = []
Builtins.y2milestone("initDDISCSIMembers key is:%1", key)
if key == "dd_display_members"
key = UI.QueryWidget(Id(:dd_table), :CurrentItem)
end
ddid = key
IsnsServer.readDDMembers(ddid).each_with_index do |result, index|
Builtins.y2milestone("iscsiMembers: %1", key)
inc_items << Item(Id(index), result["NODE"], result["TYPE"])
end
UI.ChangeWidget(Id(:dd_members_table), :Items, inc_items)
nil
end
def initDiscoveryDomain(key = nil)
checkISNS
inc_items = []
IsnsServer.readDD.each do |dd|
dd["DD name"] = "default" if dd["DD ID"] == "0"
inc_items << Item(Id(dd["DD ID"]), dd["DD name"])
end
UI.ChangeWidget(Id(:dd_table), :Items, inc_items)
nil
end
def handleISCSI(key, event)
if event["EventReason"] == "Activated"
case event["WidgetID"]
when :delete
@del = UI.QueryWidget(Id(:members_table), :CurrentItem)
if @del != nil
if Popup.ContinueCancel(_("Really delete the selected item?"))
iqn = UI.QueryWidget(Id(:members_table), term(:Item, @del))[1]
IsnsServer.deleteISCSI(iqn)
initISCSI("")
else
Builtins.y2milestone("Delete canceled")
end
end
end
end
nil
end
def handleDiscoveryDomain(key, event)
event = deep_copy(event)
if Ops.get_string(event, "EventReason", "") == "SelectionChanged"
Builtins.y2milestone("selectionChangedEvent")
dd_id = Convert.to_string(UI.QueryWidget(Id(:dd_table), :CurrentItem))
Builtins.y2milestone("selectionChangedEvent - dd-id:%1", dd_id)
initDDISCSIMembers(dd_id)
elsif Ops.get_string(event, "EventReason", "") == "Activated"
Builtins.y2milestone("handleDiscoveryDomainCalled:Activated")
case Ops.get_symbol(event, "WidgetID")
when :delete
@del = Convert.to_string(
UI.QueryWidget(Id(:dd_table), :CurrentItem)
)
if @del != nil
if Popup.ContinueCancel(_("Really delete this domain?"))
IsnsServer.deleteDD(@del)
initDiscoveryDomain
else
Builtins.y2milestone("Delete canceled")
end
end
when :add
@add_map = DiscoveryDomainDetailDialog({ "VALUE" => "" })
initDiscoveryDomain unless @add_map.empty?
end
end
nil
end
def handleDiscoveryDomainMembers(key, event)
event = deep_copy(event)
if Ops.get_string(event, "EventReason", "") == "Activated"
case Ops.get_symbol(event, "WidgetID")
when :delete
# domain deleted, but we get this event so update the members table
dd_id = Convert.to_string(
UI.QueryWidget(Id(:dd_table), :CurrentItem)
)
initDDISCSIMembers(dd_id)
when :remove
iqn = UI.QueryWidget(Id(:dd_members_table), :CurrentItem)
dd_name = Ops.get_string(
Convert.to_term(
UI.QueryWidget(Id(:dd_members_table), term(:Item, iqn))
),
1,
""
)
dd_id = Convert.to_string(
UI.QueryWidget(Id(:dd_table), :CurrentItem)
)
IsnsServer.deleteDDMember(dd_id, dd_name)
initDDISCSIMembers(dd_id)
when :addiscsinode
dd_id = Convert.to_string(
UI.QueryWidget(Id(:dd_table), :CurrentItem)
)
dd_name = Ops.get_string(
Convert.to_term(UI.QueryWidget(Id(:dd_table), term(:Item, dd_id))),
1,
""
)
add_map1 = DisplayAllMembersDialog(dd_name, dd_id)
initDDISCSIMembers(dd_id)
when :createmember
dd_id = Convert.to_string(
UI.QueryWidget(Id(:dd_table), :CurrentItem)
)
dd_name = Ops.get_string(
Convert.to_term(UI.QueryWidget(Id(:dd_table), term(:Item, dd_id))),
1,
""
)
add_map = CreateNode()
if add_map != {}
IsnsServer.addDDMember(
dd_id,
add_map["VALUE"]
)
end
initDDISCSIMembers(dd_id)
end
end
nil
end
def checkISNS
if !IsnsServer.testISNSAccess
# boolean display = true;
# Report::DisplayErrors(display,10);
Report.Error(
_("Unable to connect to iSNS server. Check if iSNS server is running.")
)
return 1
end
0
end
end
end