Class: Yast::IscsiLioDataClass
- Inherits:
-
Module
- Object
- Module
- Yast::IscsiLioDataClass
- Defined in:
- ../../src/modules/IscsiLioData.rb
Instance Method Summary (collapse)
- - (Object) ActivateConfigIetd(dat)
- - (Object) ActivateLun(tgt, tpg, lun, lm)
- - (Object) AddIncoming(tgt, val)
- - (Object) AddLun(tgt, val)
- - (Object) AddNewTarget(name, tpg, lun)
- - (Object) AddOutgoing(tgt, val)
- - (Object) AddTarget(tgt, tpg)
- - (Object) CheckPath(p)
- - (Object) ClearData
- - (Object) CreateLunName(used, p)
- - (Object) CreateTcmDev(p)
- - (Object) CreateTcmKey(tcm, base, p)
- - (Object) DelTarget(tgt, tpg)
- - (Object) DoCreateClnt(tgt, tpg, clnt)
- - (Object) DoCreateClntLun(tgt, tpg, clnt, lun, tlun)
- - (Object) DoRemoveClnt(tgt, tpg, clnt)
- - (Object) DoRemoveClntLun(tgt, tpg, clnt, lun)
- - (Object) DoRemoveLun(tgt, tpg, l)
- - (Object) DoUpdateLun(tgt, tpg, lm)
- - (Object) EnableTpg(tgt, tpg)
- - (Object) FindTcmKey(p)
-
- (Object) FormatIpPort(ip, port)
format ip and port information for use in commands.
- - (Object) GetAuth(tgt, tpg, clnt)
- - (Object) GetChanges
- - (Object) GetClntList(tgt, tpg)
- - (Object) GetClntLun(tgt, tpg, clnt)
- - (Object) GetConfig
- - (Object) GetConnected
- - (Object) GetData
- - (Object) GetExportAuth(tgt, tpg)
- - (Object) GetExportLun(l, m)
- - (Object) GetExportTargets
-
- (Array) GetIpAddr
Get list of IP addresses (filters stdout of 'ip addr show').
- - (Object) GetIpAndPort(np)
- - (Object) GetLun(tgt, tpg)
- - (Object) GetLunList(tgt, tpg)
-
- (Object) GetNetConfig
Get information about network interfaces from 'ip addr show'.
- - (Object) GetNetworkPortal(tgt, tpg)
- - (Object) GetTargets
- - (Object) GetTgt(data, tgt, tpg)
- - (Object) GetTpgAuth(tgt, tpg)
- - (Object) HasAuth(tgt, tpg, clnt)
- - (Object) HasIncomingAuth(tgt, tpg, clnt)
- - (Object) HasOutgoingAuth(tgt, tpg, clnt)
- - (Object) HasTarget(tgt, tpg)
- - (Object) IsTpgActive(tgt, tpg)
-
- (Hash) LogExecCmd(cmd, do_log: true)
Execute given command (using SCR.Execute) and return result.
- - (Object) main
- - (Object) MyFind(s, pat)
- - (Object) NeedUpdateLun(tgt, tpg, lm)
- - (Object) ParseAuthData(tgt, tpg, clnt, chap, mutual)
- - (Object) ParseConfigIetd(rv)
- - (Object) ParseConfigLio
- - (Object) ReplaceSlashUs(i)
- - (Object) SaveSettings
- - (Object) SetAuth(tgt, tpg, clnt, incoming, outgoing)
- - (Object) SetData(dat)
- - (Object) SetIetdAuth(tgt, tpg, incom, outgo)
- - (Object) SetNetworkPortal(tgt, tpg, np, new_port, add_all)
- - (Object) SetTgt(data, tgt, tpg, m)
- - (Object) SetTpgAuth(tgt, tpg, value)
- - (Object) SplitStringNE(str, delim)
- - (Object) UpdateConfig
Instance Method Details
- (Object) ActivateConfigIetd(dat)
1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 |
# File '../../src/modules/IscsiLioData.rb', line 1189 def ActivateConfigIetd(dat) dat = deep_copy(dat) cmd = "" ok = true Builtins.y2milestone("ActivateConfigIetd start") Builtins.foreach(Ops.get_map(dat, "tgt", {})) do |key, m| Builtins.foreach(m) do |tpg, d| kt = Ops.add(Ops.add(key, " "), tpg) Builtins.foreach(Ops.get_map(d, ["ep", "lun"], {})) do |l, lun| ok = ActivateLun(key, tpg, l, lun) && ok end ok = EnableTpg(key, tpg) && ok if !IsTpgActive(key, tpg) end end Builtins.y2milestone("ActivateConfigIetd ok:%1", ok) @data = ParseConfigLio() ok end |
- (Object) ActivateLun(tgt, tpg, lun, lm)
1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 |
# File '../../src/modules/IscsiLioData.rb', line 1133 def ActivateLun(tgt, tpg, lun, lm) lm = deep_copy(lm) Builtins.y2milestone("ActivateLun tgt:%1 tpg:%2 lun:%3", tgt, tpg, lun) kt = Ops.add(Ops.add(Ops.add(Ops.add(tgt, " "), tpg), " "), lun) ok = true done = false if Builtins.haskey( Ops.get_map(@data, ["tgt", tgt, tpg, "ep", "lun"], {}), lun ) if Ops.get_string( @data, ["tgt", tgt, tpg, "ep", "lun", lun, "tcm_key"], "" ) != Ops.get_string(lm, "tcm_key", "") || Ops.get_string(@data, ["tgt", tgt, tpg, "ep", "lun", lun, "nm"], "") != Ops.get_string(lm, "nm", "") ok = DoRemoveLun(tgt, tpg, lun) else done = true end end if !done && ok && Builtins.isempty(Ops.get_string(lm, "tcm_key", "")) key = CreateTcmDev(Ops.get_string(lm, "path", "")) if Builtins.isempty(key) ok = false else Ops.set(lm, "tcm_key", key) end end if !done && ok ok = LogExecCmd( Ops.add( Ops.add( Ops.add( Ops.add(Ops.add("lio_node --addlun ", kt), " "), Ops.get_string(lm, "nm", "") ), " " ), Ops.get_string(lm, "tcm_key", "") ) ) end Builtins.y2milestone("ActivateLun ok:%1 done:%2 lm:%3", ok, done, lm) ok end |
- (Object) AddIncoming(tgt, val)
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File '../../src/modules/IscsiLioData.rb', line 194 def AddIncoming(tgt, val) tgt = deep_copy(tgt) sl = SplitStringNE(val, " \t") if !Builtins.isempty(Ops.get(sl, 0, "")) && !Builtins.isempty(Ops.get(sl, 1, "")) Ops.set( tgt, "incoming", Builtins.add( Ops.get_list(tgt, "incoming", []), [Ops.get(sl, 0, ""), Ops.get(sl, 1, "")] ) ) end deep_copy(tgt) end |
- (Object) AddLun(tgt, val)
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 |
# File '../../src/modules/IscsiLioData.rb', line 135 def AddLun(tgt, val) tgt = deep_copy(tgt) Ops.set(tgt, "ep", { "lun" => {} }) if !Builtins.haskey(tgt, "ep") sl = SplitStringNE(val, " \t") Builtins.y2milestone("AddLun sl:%1", sl) if !Builtins.isempty(Ops.get(sl, 0, "")) && !Builtins.isempty(Ops.get(sl, 1, "")) l = Builtins.tointeger(Ops.get(sl, 0, "")) if l != nil && !Builtins.haskey(Ops.get_map(tgt, ["ep", "lun"], {}), l) Ops.set(tgt, ["ep", "lun", l], {}) end if Builtins.haskey(Ops.get_map(tgt, ["ep", "lun"], {}), l) tmps = SplitStringNE(Ops.get(sl, 1, ""), ",") sl = [] Builtins.foreach(tmps) do |s| sl = Convert.convert( Builtins.merge(sl, Builtins.splitstring(s, "=")), :from => "list", :to => "list <string>" ) end Builtins.y2milestone("AddLun sl:%1", sl) while !Builtins.isempty(sl) if Ops.get(sl, 0, "") == "Path" && Ops.greater_than(Builtins.size(sl), 1) tk = FindTcmKey(Ops.get(sl, 1, "")) if !Builtins.isempty(tk) Ops.set(tgt, ["ep", "lun", l, "tcm_key"], tk) else Ops.set(tgt, ["ep", "lun", l, "path"], Ops.get(sl, 1, "")) end used = Builtins.maplist(Ops.get_map(tgt, ["ep", "lun"], {})) do |i, m| Ops.get_string(m, "nm", "") end Builtins.y2milestone("AddLun used:%1", used) Ops.set( tgt, ["ep", "lun", l, "nm"], CreateLunName(used, Ops.get(sl, 1, "")) ) sl = Builtins.remove(sl, 0) end sl = Builtins.remove(sl, 0) end end if Builtins.isempty(Ops.get_string(tgt, ["ep", "lun", l, "path"], "")) && Builtins.isempty( Ops.get_string(tgt, ["ep", "lun", l, "tcm_key"], "") ) Ops.set( tgt, ["ep", "lun"], Builtins.remove(Ops.get_map(tgt, ["ep", "lun"], {}), l) ) end end deep_copy(tgt) end |
- (Object) AddNewTarget(name, tpg, lun)
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File '../../src/modules/IscsiLioData.rb', line 287 def AddNewTarget(name, tpg, lun) lun = deep_copy(lun) Builtins.y2milestone("AddNewTarget name:%1 tpg:%2", name, tpg) Ops.set(@data, "tgt", {}) if !Builtins.haskey(@data, "tgt") Ops.set(@data, ["tgt", name], { tpg => {} }) Builtins.foreach(lun) do |s| Ops.set( @data, ["tgt", name, tpg], AddLun(Ops.get_map(@data, ["tgt", name, tpg], {}), s) ) end nil end |
- (Object) AddOutgoing(tgt, val)
211 212 213 214 215 216 217 218 219 |
# File '../../src/modules/IscsiLioData.rb', line 211 def AddOutgoing(tgt, val) tgt = deep_copy(tgt) sl = SplitStringNE(val, " \t") if !Builtins.isempty(Ops.get(sl, 0, "")) && !Builtins.isempty(Ops.get(sl, 1, "")) Ops.set(tgt, "outgoing", [Ops.get(sl, 0, ""), Ops.get(sl, 1, "")]) end deep_copy(tgt) end |
- (Object) AddTarget(tgt, tpg)
1239 1240 1241 1242 1243 1244 1245 1246 |
# File '../../src/modules/IscsiLioData.rb', line 1239 def AddTarget(tgt, tpg) ret = LogExecCmd( Ops.add(Ops.add(Ops.add("lio_node --addtpg ", tgt), " "), tpg) ) ret = EnableTpg(tgt, tpg) if ret Builtins.y2milestone("AddTarget tgt:%1 tpg:%2 ret:%3", tgt, tpg, ret) ret end |
- (Object) CheckPath(p)
1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 |
# File '../../src/modules/IscsiLioData.rb', line 1062 def CheckPath(p) ret = [false, false, 0] stat = Convert.to_map(SCR.Read(path(".target.stat"), p)) Ops.set( ret, 0, Ops.get_boolean(stat, "isblock", false) || Ops.get_boolean(stat, "isreg", false) ) Ops.set( ret, 1, Ops.get_boolean(ret, 0, false) && Ops.get_boolean(stat, "isblock", false) ) if Ops.get_boolean(ret, 0, false) Ops.set(ret, 2, Ops.get_integer(stat, "size", 0)) end Builtins.y2milestone("CheckPath p:%1 ret:%2", p, ret) deep_copy(ret) end |
- (Object) ClearData
554 555 556 557 558 |
# File '../../src/modules/IscsiLioData.rb', line 554 def ClearData @data = {} nil end |
- (Object) CreateLunName(used, p)
109 110 111 112 113 114 115 116 117 118 119 120 |
# File '../../src/modules/IscsiLioData.rb', line 109 def CreateLunName(used, p) used = deep_copy(used) ret = ReplaceSlashUs(p) base = ret count = 0 while !Builtins.isempty(Builtins.filter(used) { |s| s == ret }) count = Ops.add(count, 1) ret = Ops.add(Ops.add(base, "_"), count) end Builtins.y2milestone("CreateLunName p:%1 ret:%2", p, ret) ret end |
- (Object) CreateTcmDev(p)
1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 |
# File '../../src/modules/IscsiLioData.rb', line 1084 def CreateTcmDev(p) ret = "" cmd = "tcm_node " bl = CheckPath(p) file = !Ops.get_boolean(bl, 1, false) if Ops.get_boolean(bl, 0, false) ret = Ops.get_boolean(bl, 1, false) ? "iblock_0/" : "fileio_0/" cmd = Ops.add( cmd, Ops.get_boolean(bl, 1, false) ? "--block " : "--fileio " ) end if !Builtins.isempty(ret) ret = CreateTcmKey(Ops.get_map(@data, "tcm", {}), ret, p) cmd = Ops.add(Ops.add(Ops.add(cmd, ret), " "), p) cmd = Ops.add(Ops.add(cmd, " "), Ops.get_integer(bl, 2, 1)) if file end if !Builtins.isempty(ret) && !LogExecCmd(cmd) ret = "" else Ops.set( @data, ["tcm", ret], { "path" => p, "type" => file ? :fileio : :iblock } ) end Builtins.y2milestone("CreateTcmDev path:%1 ret:%2", p, ret) if !Builtins.isempty(ret) Builtins.y2milestone( "CreateTcmDev new tcm:%1", Ops.get_map(@data, ["tcm", ret], {}) ) end ret end |
- (Object) CreateTcmKey(tcm, base, p)
122 123 124 125 126 127 128 129 130 131 132 133 |
# File '../../src/modules/IscsiLioData.rb', line 122 def CreateTcmKey(tcm, base, p) tcm = deep_copy(tcm) ret = Ops.add(base, ReplaceSlashUs(p)) base = ret count = 0 while Builtins.haskey(tcm, ret) count = Ops.add(count, 1) ret = Ops.add(Ops.add(base, "_"), count) end Builtins.y2milestone("CreateTcmKey base:%1 p:%2 ret:%3", base, p, ret) ret end |
- (Object) DelTarget(tgt, tpg)
1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 |
# File '../../src/modules/IscsiLioData.rb', line 1248 def DelTarget(tgt, tpg) ret = LogExecCmd( Ops.add(Ops.add(Ops.add("lio_node --deltpg ", tgt), " "), tpg) ) if ret && Ops.less_or_equal( Builtins.size(Ops.get_map(@data, ["tgt", tgt], {})), 1 ) ret = LogExecCmd(Ops.add("lio_node --deliqn ", tgt)) end Builtins.y2milestone("DelTarget tgt:%1 tpg:%2 ret:%3", tgt, tpg, ret) ret end |
- (Object) DoCreateClnt(tgt, tpg, clnt)
1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 |
# File '../../src/modules/IscsiLioData.rb', line 1352 def DoCreateClnt(tgt, tpg, clnt) kt = Ops.add(Ops.add(Ops.add(Ops.add(tgt, " "), tpg), " "), clnt) ret = LogExecCmd(Ops.add("lio_node --addnodeacl ", kt)) Builtins.y2milestone( "DoCreateClnt tgt:%1 tpg:%2 clnt:%3 ret:%4", tgt, tpg, clnt, ret ) ret end |
- (Object) DoCreateClntLun(tgt, tpg, clnt, lun, tlun)
1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 |
# File '../../src/modules/IscsiLioData.rb', line 1387 def DoCreateClntLun(tgt, tpg, clnt, lun, tlun) kt = Ops.add( Ops.add( Ops.add( Ops.add( Ops.add(Ops.add(Ops.add(Ops.add(tgt, " "), tpg), " "), clnt), " " ), tlun ), " " ), lun ) ret = LogExecCmd(Ops.add("lio_node --addlunacl ", kt)) Builtins.y2milestone( "DoCreateClntLun tgt:%1 tpg:%2 clnt:%3 lun:%4:%5 ret:%6", tgt, tpg, clnt, lun, tlun, ret ) ret end |
- (Object) DoRemoveClnt(tgt, tpg, clnt)
1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 |
# File '../../src/modules/IscsiLioData.rb', line 1339 def DoRemoveClnt(tgt, tpg, clnt) kt = Ops.add(Ops.add(Ops.add(Ops.add(tgt, " "), tpg), " "), clnt) ret = LogExecCmd(Ops.add("lio_node --delnodeacl ", kt)) Builtins.y2milestone( "DoRemoveClnt tgt:%1 tpg:%2 clnt:%3 ret:%4", tgt, tpg, clnt, ret ) ret end |
- (Object) DoRemoveClntLun(tgt, tpg, clnt, lun)
1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 |
# File '../../src/modules/IscsiLioData.rb', line 1366 def DoRemoveClntLun(tgt, tpg, clnt, lun) kt = Ops.add( Ops.add( Ops.add(Ops.add(Ops.add(Ops.add(tgt, " "), tpg), " "), clnt), " " ), lun ) ret = LogExecCmd(Ops.add("lio_node --dellunacl ", kt)) Builtins.y2milestone( "DoRemoveClntLun tgt:%1 tpg:%2 clnt:%3 lun:%4 ret:%5", tgt, tpg, clnt, lun, ret ) ret end |
- (Object) DoRemoveLun(tgt, tpg, l)
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 |
# File '../../src/modules/IscsiLioData.rb', line 1120 def DoRemoveLun(tgt, tpg, l) kt = Ops.add(Ops.add(Ops.add(Ops.add(tgt, " "), tpg), " "), l) ret = LogExecCmd(Ops.add("lio_node --dellun ", kt)) Builtins.y2milestone( "DoRemoveLun tgt:%1 tpg:%2 l:%3 ret:%4", tgt, tpg, l, ret ) ret end |
- (Object) DoUpdateLun(tgt, tpg, lm)
1230 1231 1232 1233 1234 1235 1236 1237 |
# File '../../src/modules/IscsiLioData.rb', line 1230 def DoUpdateLun(tgt, tpg, lm) lm = deep_copy(lm) Builtins.y2milestone("DoUpdateLun tgt:%1 tpg:%2 lm:%3", tgt, tpg, lm) lun = Ops.get_integer(lm, "lun", -1) ret = ActivateLun(tgt, tpg, lun, lm) Builtins.y2milestone("DoUpdateLun ret:%1", ret) ret end |
- (Object) EnableTpg(tgt, tpg)
1182 1183 1184 1185 1186 1187 |
# File '../../src/modules/IscsiLioData.rb', line 1182 def EnableTpg(tgt, tpg) ret = LogExecCmd( Ops.add(Ops.add(Ops.add("lio_node --enabletpg ", tgt), " "), tpg) ) ret end |
- (Object) FindTcmKey(p)
86 87 88 89 90 91 92 93 94 95 96 |
# File '../../src/modules/IscsiLioData.rb', line 86 def FindTcmKey(p) ret = Ops.get( Builtins.maplist(Builtins.filter(Ops.get_map(@data, "tcm", {})) do |k, m| Ops.get_string(m, "path", "") == p end) { |key, du| key }, 0, "" ) Builtins.y2milestone("FindTcmKey p:%1 ret:%2", p, ret) ret end |
- (Object) FormatIpPort(ip, port)
format ip and port information for use in commands
379 380 381 382 383 |
# File '../../src/modules/IscsiLioData.rb', line 379 def FormatIpPort(ip, port) # brackets needed around IPv6 ip = "[#{ip}]" if IP.Check6(ip) return "#{ip}:#{port}" end |
- (Object) GetAuth(tgt, tpg, clnt)
346 347 348 349 350 351 352 353 |
# File '../../src/modules/IscsiLioData.rb', line 346 def GetAuth(tgt, tpg, clnt) m = GetTgt(@data, tgt, tpg) m = Ops.get_map(m, ["clnt", clnt], {}) if !Builtins.isempty(tgt) { "incoming" => Ops.get_list(m, ["incoming", 0], []), "outgoing" => Ops.get_list(m, "outgoing", []) } end |
- (Object) GetChanges
560 561 562 |
# File '../../src/modules/IscsiLioData.rb', line 560 def GetChanges {} end |
- (Object) GetClntList(tgt, tpg)
404 405 406 407 408 409 |
# File '../../src/modules/IscsiLioData.rb', line 404 def GetClntList(tgt, tpg) ret = Builtins.maplist(Ops.get_map(@data, ["tgt", tgt, tpg, "clnt"], {})) do |s, m| s end deep_copy(ret) end |
- (Object) GetClntLun(tgt, tpg, clnt)
411 412 413 414 |
# File '../../src/modules/IscsiLioData.rb', line 411 def GetClntLun(tgt, tpg, clnt) ret = Ops.get_map(@data, ["tgt", tgt, tpg, "clnt", clnt, "lun"], {}) deep_copy(ret) end |
- (Object) GetConfig
564 565 566 |
# File '../../src/modules/IscsiLioData.rb', line 564 def GetConfig {} end |
- (Object) GetConnected
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 |
# File '../../src/modules/IscsiLioData.rb', line 614 def GetConnected cmd = "find /sys/kernel/config/target/iscsi -name info" ret = Convert.convert( SCR.Execute(path(".target.bash_output"), cmd), :from => "any", :to => "map <string, any>" ) ls = SplitStringNE(Ops.get_string(ret, "stdout", ""), "\n") Builtins.y2milestone("GetConnected ls:%1", ls) state = {} inact = "No active iSCSI Session " act = "InitiatorName: " Builtins.foreach(ls) do |f| cmd = Ops.add("head -1 ", f) ret = Convert.convert( SCR.Execute(path(".target.bash_output"), cmd), :from => "any", :to => "map <string, any>" ) if Ops.get_integer(ret, "exit", -1) == 0 if Builtins.substring( Ops.get_string(ret, "stdout", ""), 0, Builtins.size(inact) ) == inact Ops.set(state, f, false) elsif Builtins.substring( Ops.get_string(ret, "stdout", ""), 0, Builtins.size(act) ) == act Ops.set(state, f, true) end end end Builtins.y2milestone("GetConnected state:%1", state) state = Builtins.mapmap(state) do |s, b| ls = Builtins.splitstring(s, "/") { Ops.add( Ops.add( Ops.add( Ops.add(Ops.get(ls, 6, ""), " "), Builtins.substring(Ops.get(ls, 7, ""), 5) ), " " ), Ops.get(ls, 9, "") ) => b } end Builtins.y2milestone("GetConnected state:%1", state) ls = Builtins.maplist(Builtins.filter(state) { |s, b| b }) { |s, b| s } Builtins.y2milestone("GetConnected ret:%1", ls) deep_copy(ls) end |
- (Object) GetData
543 544 545 |
# File '../../src/modules/IscsiLioData.rb', line 543 def GetData deep_copy(@data) end |
- (Object) GetExportAuth(tgt, tpg)
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 |
# File '../../src/modules/IscsiLioData.rb', line 476 def GetExportAuth(tgt, tpg) ret = [] m = GetTgt(@data, tgt, tpg) Builtins.foreach(Ops.get_list(m, "incoming", [])) do |s| ret = Builtins.add( ret, { "KEY" => "IncomingUser", "VALUE" => Ops.add( Ops.add(Ops.get_string(s, 0, ""), " "), Ops.get_string(s, 1, "") ) } ) end if Ops.greater_than(Builtins.size(Ops.get_list(m, "outgoing", [])), 1) ret = Builtins.add( ret, { "KEY" => "OutgoingUser", "VALUE" => Ops.add( Ops.add(Ops.get_string(m, ["outgoing", 0], ""), " "), Ops.get_string(m, ["outgoing", 1], "") ) } ) end deep_copy(ret) end |
- (Object) GetExportLun(l, m)
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 |
# File '../../src/modules/IscsiLioData.rb', line 459 def GetExportLun(l, m) m = deep_copy(m) p = Ops.get_string(m, "path", "") if Builtins.isempty(p) p = Ops.get_string( @data, ["tcm", Ops.get_string(m, "tcm_key", ""), "path"], "" ) end ret = Ops.add( Ops.add(Ops.add(Builtins.tostring(l), " Path="), p), ",Type=fileio" ) ret end |
- (Object) GetExportTargets
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 |
# File '../../src/modules/IscsiLioData.rb', line 506 def GetExportTargets ret = {} Builtins.foreach(GetTargets()) do |s| tgt = [ { "KEY" => "Target", "VALUE" => Ops.get_string(s, 0, "") }, { "KEY" => "Tpg", "VALUE" => Builtins.tostring(Ops.get_integer(s, 1, 1)) } ] Builtins.foreach( Ops.get_map( @data, [ "tgt", Ops.get_string(s, 0, ""), Ops.get_integer(s, 1, 1), "ep", "lun" ], {} ) ) do |i, m| tgt = Builtins.add( tgt, { "KEY" => "Lun", "VALUE" => GetExportLun(i, m) } ) end tgt = Builtins.union( tgt, GetExportAuth(Ops.get_string(s, 0, ""), Ops.get_integer(s, 1, 1)) ) Ops.set(ret, Ops.get_string(s, 0, ""), tgt) end deep_copy(ret) end |
- (Array) GetIpAddr
Get list of IP addresses (filters stdout of 'ip addr show')
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 |
# File '../../src/modules/IscsiLioData.rb', line 585 def GetIpAddr ip_list = GetNetConfig() ip_list.select! do |line| line.include?("inet") && !line.include?("deprecated") # don't show deprecated IPs end ip_list = ip_list.map do |ip| ip.lstrip! case ip when /^inet *([.\d]+)\/.*/ $1 when /^inet6 *([.:\w]+)\/.*/ $1 else ip end end ip_list.reject! do |address| address.start_with?("127.") || # local IPv4 address.start_with?("::1") || # local IPv6 address.start_with?("fe80:") # scope link IPv6 end ip_list = [""] if ip_list.empty? Builtins.y2milestone("GetIpAddr: %1", ip_list) deep_copy(ip_list) end |
- (Object) GetIpAndPort(np)
49 50 51 52 53 54 55 56 57 58 59 60 |
# File '../../src/modules/IscsiLioData.rb', line 49 def GetIpAndPort(np) return [] if !np || np.empty? if !np.start_with?("[") ret = Builtins.splitstring(np, ":") elsif match_data = np.match(/\[([:\w]+)\]:(\d+)/) ret = [match_data[1] || "", match_data[2] || ""] else ret = [] end ret end |
- (Object) GetLun(tgt, tpg)
356 357 358 359 |
# File '../../src/modules/IscsiLioData.rb', line 356 def GetLun(tgt, tpg) ret = Ops.get_map(@data, ["tgt", tgt, tpg, "ep", "lun"], {}) deep_copy(ret) end |
- (Object) GetLunList(tgt, tpg)
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
# File '../../src/modules/IscsiLioData.rb', line 361 def GetLunList(tgt, tpg) ret = Builtins.maplist( Ops.get_map(@data, ["tgt", tgt, tpg, "ep", "lun"], {}) ) do |l, m| [ l, Ops.get_string(m, "nm", ""), Ops.get_string( @data, ["tcm", Ops.get_string(m, "tcm_key", ""), "path"], "" ) ] end deep_copy(ret) end |
- (Object) GetNetConfig
Get information about network interfaces from 'ip addr show'
571 572 573 574 575 576 577 |
# File '../../src/modules/IscsiLioData.rb', line 571 def GetNetConfig out = Convert.to_map( SCR.Execute(path(".target.bash_output"), "LC_ALL=POSIX ip addr show") ) ls = out.fetch("stdout", "").split("\n") deep_copy(ls) end |
- (Object) GetNetworkPortal(tgt, tpg)
385 386 387 388 389 390 391 392 393 394 395 396 397 |
# File '../../src/modules/IscsiLioData.rb', line 385 def GetNetworkPortal(tgt, tpg) Builtins.y2milestone("target: %1, target portal group: %2", tgt, tpg) # log complete data only for debugging purposes (contains password/user info) Builtins.y2debug("Data: %1", @data) ret = Builtins.maplist( Ops.get_list(@data, ["tgt", tgt, tpg, "ep", "np"], []) ) do |n| ip = n["ip"] || "" port = n["port"] || 3260 ipp = FormatIpPort(ip, port) end deep_copy(ret) end |
- (Object) GetTargets
446 447 448 449 450 451 452 453 454 455 456 457 |
# File '../../src/modules/IscsiLioData.rb', line 446 def GetTargets ret = [] Builtins.foreach(Ops.get_map(@data, "tgt", {})) do |key, m| Builtins.foreach(m) do |tpg, dummy| ret = Builtins.add(ret, [key, tpg]) Builtins.y2milestone("GetTargets key:%1 tpg:%2", key, tpg) Builtins.y2milestone("GetTargets ret:%1", ret) end end Builtins.y2milestone("GetTargets ret:%1", ret) deep_copy(ret) end |
- (Object) GetTgt(data, tgt, tpg)
68 69 70 71 72 73 |
# File '../../src/modules/IscsiLioData.rb', line 68 def GetTgt(data, tgt, tpg) data = deep_copy(data) m = Ops.get_map(data, ["tgt", tgt, tpg], {}) m = deep_copy(data) if Builtins.isempty(tgt) deep_copy(m) end |
- (Object) GetTpgAuth(tgt, tpg)
399 400 401 402 |
# File '../../src/modules/IscsiLioData.rb', line 399 def GetTpgAuth(tgt, tpg) ret = Ops.get_boolean(@data, ["tgt", tgt, tpg, "auth"], true) ret end |
- (Object) HasAuth(tgt, tpg, clnt)
342 343 344 |
# File '../../src/modules/IscsiLioData.rb', line 342 def HasAuth(tgt, tpg, clnt) HasIncomingAuth(tgt, tpg, clnt) || HasOutgoingAuth(tgt, tpg, clnt) end |
- (Object) HasIncomingAuth(tgt, tpg, clnt)
320 321 322 323 324 325 326 327 328 329 |
# File '../../src/modules/IscsiLioData.rb', line 320 def HasIncomingAuth(tgt, tpg, clnt) m = GetTgt(@data, tgt, tpg) m = Ops.get_map(m, ["clnt", clnt], {}) if !Builtins.isempty(clnt) ret = !Builtins.isempty(Ops.get_list(m, "incoming", [])) Builtins.y2milestone( "HasIncomingAuth ret:%1", ret ) ret end |
- (Object) HasOutgoingAuth(tgt, tpg, clnt)
331 332 333 334 335 336 337 338 339 340 |
# File '../../src/modules/IscsiLioData.rb', line 331 def HasOutgoingAuth(tgt, tpg, clnt) m = GetTgt(@data, tgt, tpg) m = Ops.get_map(m, ["clnt", clnt], {}) if !Builtins.isempty(clnt) ret = Ops.greater_than(Builtins.size(Ops.get_list(m, "outgoing", [])), 1) Builtins.y2milestone( "HasOutgoingAuth ret:%1", ret ) ret end |
- (Object) HasTarget(tgt, tpg)
315 316 317 318 |
# File '../../src/modules/IscsiLioData.rb', line 315 def HasTarget(tgt, tpg) Builtins.haskey(Ops.get_map(@data, "tgt", {}), tgt) && Builtins.haskey(Ops.get_map(@data, ["tgt", tgt], {}), tpg) end |
- (Object) IsTpgActive(tgt, tpg)
260 261 262 |
# File '../../src/modules/IscsiLioData.rb', line 260 def IsTpgActive(tgt, tpg) Ops.get_boolean(@data, ["tgt", tgt, tpg, "ep", "enabled"], false) end |
- (Hash) LogExecCmd(cmd, do_log: true)
Execute given command (using SCR.Execute) and return result. Logs the command to YaST log-file if allowed.
272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File '../../src/modules/IscsiLioData.rb', line 272 def LogExecCmd(cmd, do_log: true) Builtins.y2milestone("Executing cmd:%1", cmd) if do_log ret = Convert.convert( SCR.Execute(path(".target.bash_output"), cmd), :from => "any", :to => "map <string, any>" ) if Ops.get_integer(ret, "exit", -1) != 0 Builtins.y2error("Error ret:%1", ret) else Builtins.y2milestone("Ret:%1", ret) end Ops.get_integer(ret, "exit", -1) == 0 end |
- (Object) main
36 37 38 39 40 41 |
# File '../../src/modules/IscsiLioData.rb', line 36 def main textdomain "iscsi-lio-server" @data = {} end |
- (Object) MyFind(s, pat)
62 63 64 65 66 |
# File '../../src/modules/IscsiLioData.rb', line 62 def MyFind(s, pat) ret = Builtins.search(s, pat) ret = -1 if ret == nil ret end |
- (Object) NeedUpdateLun(tgt, tpg, lm)
1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 |
# File '../../src/modules/IscsiLioData.rb', line 1208 def NeedUpdateLun(tgt, tpg, lm) lun = Ops.get_integer(lm.value, "lun", -1) ret = !Builtins.haskey( Ops.get_map(@data, ["tgt", tgt, tpg, "ep", "lun"], {}), lun ) tk = FindTcmKey(Ops.get_string(lm.value, "path", "")) Ops.set(lm.value, "tcm_key", tk) if !Builtins.isempty(tk) if !ret ret = Ops.get_string( @data, ["tgt", tgt, tpg, "ep", "lun", lun, "tcm_key"], "" ) != Ops.get_string(lm.value, "tcm_key", "") || Ops.get_string(@data, ["tgt", tgt, tpg, "ep", "lun", lun, "nm"], "") != Ops.get_string(lm.value, "nm", "") end Builtins.y2milestone("NeedUpdateLun ret:%1 lm:%2", ret, lm.value) ret end |
- (Object) ParseAuthData(tgt, tpg, clnt, chap, mutual)
672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 |
# File '../../src/modules/IscsiLioData.rb', line 672 def ParseAuthData(tgt, tpg, clnt, chap, mutual) Builtins.y2milestone( "ParseAuthData tgt:%1 tpg:%2 clnt:%3", tgt, tpg, clnt ) cmd = "" if !Builtins.isempty(tgt) cmd = Ops.add( Ops.add( Ops.add(Ops.add(Ops.add("lio_node --showchapauth ", tgt), " "), tpg), " " ), clnt ) else cmd = "lio_node --showchapdiscauth" end cmd = Ops.add("LC_ALL=POSIX ", cmd) out = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd)) ls = SplitStringNE(Ops.get_string(out, "stdout", ""), "\n") i = 0 while Ops.less_than(i, Builtins.size(ls)) if Builtins.search(Ops.get(ls, i, ""), "password_mutual:") != nil Ops.set( mutual.value, 1, Ops.get(SplitStringNE(Ops.get(ls, i, ""), " "), 1, "") ) end if Builtins.search(Ops.get(ls, i, ""), "userid_mutual:") != nil Ops.set( mutual.value, 0, Ops.get(SplitStringNE(Ops.get(ls, i, ""), " "), 1, "") ) end if Builtins.search(Ops.get(ls, i, ""), "password:") != nil Ops.set( chap.value, 1, Ops.get(SplitStringNE(Ops.get(ls, i, ""), " "), 1, "") ) end if Builtins.search(Ops.get(ls, i, ""), "userid:") != nil Ops.set( chap.value, 0, Ops.get(SplitStringNE(Ops.get(ls, i, ""), " "), 1, "") ) end i = Ops.add(i, 1) end nil end |
- (Object) ParseConfigIetd(rv)
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 |
# File '../../src/modules/IscsiLioData.rb', line 221 def ParseConfigIetd(rv) rv = deep_copy(rv) data = {} target = "" tpg = 1 Builtins.foreach(Ops.get_list(rv, "value", [])) do |v| name = Builtins.toupper(Ops.get_string(v, "name", "")) val = Ops.get_string(v, "value", "") if Builtins.contains(["ISNSSERVER", "ISNSACCESSCONTROL"], name) Ops.set(data, name, val) elsif name == "TARGET" Ops.set(data, "tgt", {}) if !Builtins.haskey(data, "tgt") if !Builtins.haskey(Ops.get_map(data, "tgt", {}), val) Ops.set(data, ["tgt", val], { tpg => {} }) end target = val elsif name == "LUN" && !Builtins.isempty(target) Ops.set( data, ["tgt", target, tpg], AddLun(Ops.get_map(data, ["tgt", target, tpg], {}), val) ) elsif name == "INCOMINGUSER" m = GetTgt(data, target, tpg) m = AddIncoming(m, val) data_ref = arg_ref(data) SetTgt(data_ref, target, tpg, m) data = data_ref.value elsif name == "OUTGOINGUSER" m = GetTgt(data, target, tpg) m = AddOutgoing(m, val) data_ref = arg_ref(data) SetTgt(data_ref, target, tpg, m) data = data_ref.value end end deep_copy(data) end |
- (Object) ParseConfigLio
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 |
# File '../../src/modules/IscsiLioData.rb', line 730 def ParseConfigLio tcm = {} out = Convert.to_map( SCR.Execute( path(".target.bash_output"), "LC_ALL=POSIX tcm_node --listhbas" ) ) ls = SplitStringNE(Ops.get_string(out, "stdout", ""), "\n") i = 0 while Ops.less_than(i, Builtins.size(ls)) while Ops.less_than(i, Builtins.size(ls)) && Builtins.search(Ops.get(ls, i, ""), "\\---") != 0 i = Ops.add(i, 1) end hba = Ops.get(Builtins.splitstring(Ops.get(ls, i, ""), " "), 1, "") nm = "" i = Ops.add(i, 1) pos = MyFind(Ops.get(ls, i, ""), "\\---") while Ops.less_than(i, Builtins.size(ls)) && pos != 0 if Ops.greater_than(pos, 0) nm = Ops.get(SplitStringNE(Ops.get(ls, i, ""), " "), 1, "") Builtins.y2milestone("ParseConfigLio nm=%1", nm) end if Builtins.search(Ops.get(ls, i, ""), "TCM FILEIO") != nil pos = Builtins.search(Ops.get(ls, i, ""), "File:") if pos != nil p = Ops.get( SplitStringNE(Builtins.substring(Ops.get(ls, i, ""), pos), " "), 1, "" ) key = Ops.add(Ops.add(hba, "/"), nm) if !Builtins.isempty(p) Ops.set(tcm, key, { "path" => p, "type" => :fileio }) end Builtins.y2milestone( "ParseConfigLio hba[%1]:%2", key, Ops.get_map(tcm, key, {}) ) end end if Builtins.search(Ops.get(ls, i, ""), "iBlock device:") != nil pos = Builtins.search(Ops.get(ls, i, ""), "UDEV PATH:") if pos != nil p = Ops.get( SplitStringNE(Builtins.substring(Ops.get(ls, i, ""), pos), " "), 2, "" ) key = Ops.add(Ops.add(hba, "/"), nm) if !Builtins.isempty(p) Ops.set(tcm, key, { "path" => p, "type" => :iblock }) end Builtins.y2milestone( "ParseConfigLio hba[%1]:%2", key, Ops.get_map(tcm, key, {}) ) end end i = Ops.add(i, 1) pos = MyFind(Ops.get(ls, i, ""), "\\---") end end endp = {} out = Convert.to_map( SCR.Execute( path(".target.bash_output"), "LC_ALL=POSIX lio_node --listendpoints" ) ) ls = SplitStringNE(Ops.get_string(out, "stdout", ""), "\n") i = 0 while Ops.less_than(i, Builtins.size(ls)) while Ops.less_than(i, Builtins.size(ls)) && Builtins.search(Ops.get(ls, i, ""), "\\---") != 0 i = Ops.add(i, 1) end tgt = Ops.get(Builtins.splitstring(Ops.get(ls, i, ""), " "), 1, "") ts = "" Ops.set(endp, tgt, {}) i = Ops.add(i, 1) pos = MyFind(Ops.get(ls, i, ""), "\\---") tpg = 0 while Ops.less_than(i, Builtins.size(ls)) && pos != 0 if Builtins.search(Ops.get(ls, i, ""), "-> tpgt") != nil tpg = Builtins.tointeger( Builtins.substring( Ops.get(SplitStringNE(Ops.get(ls, i, ""), " "), 1, ""), 5 ) ) if tpg != nil Ops.set(endp, [tgt, tpg], {}) else tpg = 0 end Builtins.y2milestone("ParseConfigLio tpg:%1", tpg) end if Ops.greater_than(tpg, 0) && Builtins.search(Ops.get(ls, i, ""), "TPG Status:") != nil ts = Ops.get(SplitStringNE(Ops.get(ls, i, ""), " "), 2, "") Ops.set(endp, [tgt, tpg, "enabled"], ts == "ENABLED") Builtins.y2milestone( "ParseConfigLio enabled:%1", Ops.get_boolean(endp, [tgt, tpg, "enabled"], false) ) end if Ops.greater_than(tpg, 0) && Builtins.search(Ops.get(ls, i, ""), "TPG Network Portals:") != nil i = Ops.add(i, 1) while Ops.greater_than(MyFind(Ops.get(ls, i, ""), "-> "), 0) np = Ops.get(SplitStringNE(Ops.get(ls, i, ""), " "), 1, "") tls = GetIpAndPort(np) port = Builtins.tointeger(Ops.get(tls, 1, "")) if port != nil Ops.set( endp, [tgt, tpg, "np"], Builtins.add( Ops.get_list(endp, [tgt, tpg, "np"], []), { "ip" => Ops.get(tls, 0, ""), "port" => port } ) ) Builtins.y2milestone("Set ip to: %1", Ops.get(tls, 0, "")) end i = Ops.add(i, 1) end i = Ops.subtract(i, 1) Builtins.y2milestone( "ParseConfigLio np:%1", Ops.get_list(endp, [tgt, tpg, "np"], []) ) end if Ops.greater_than(tpg, 0) && Builtins.search(Ops.get(ls, i, ""), "-> lun") != nil tls = SplitStringNE(Ops.get(ls, i, ""), " ") ti = Builtins.tointeger( Builtins.substring( Ops.get(SplitStringNE(Ops.get(tls, 1, ""), "/"), 0, ""), 4 ) ) if ti != nil if !Builtins.haskey(Ops.get_map(endp, [tgt, tpg], {}), "lun") Ops.set(endp, [tgt, tpg, "lun"], {}) end lun = {} Ops.set( lun, "nm", Ops.get(SplitStringNE(Ops.get(tls, 1, ""), "/"), 1, "") ) Ops.set( lun, "tcm_key", Builtins.substring(Ops.get(tls, 3, ""), 12) ) Ops.set(endp, [tgt, tpg, "lun", ti], lun) Builtins.y2milestone("ParseConfigLio lun[%1]:%2", ti, lun) if !Builtins.haskey(tcm, Ops.get_string(lun, "tcm_key", "")) Builtins.y2warning( "tcm key %1 should exist", Ops.get_string(lun, "tcm_key", "") ) end end end i = Ops.add(i, 1) pos = MyFind(Ops.get(ls, i, ""), "\\---") end end ret = { "tcm" => tcm } tgmap = {} mutual = ["", ""] chap = ["", ""] chap_ref = arg_ref(chap) mutual_ref = arg_ref(mutual) ParseAuthData("", 0, "", chap_ref, mutual_ref) chap = chap_ref.value mutual = mutual_ref.value if !Builtins.isempty(Ops.get(mutual, 0, "")) && !Builtins.isempty(Ops.get(mutual, 1, "")) Ops.set(ret, "outgoing", mutual) end if !Builtins.isempty(Ops.get(chap, 0, "")) && !Builtins.isempty(Ops.get(chap, 1, "")) Ops.set(ret, "incoming", [chap]) end Builtins.foreach(endp) do |tgt, m| Ops.set(tgmap, tgt, {}) Builtins.foreach( Convert.convert(m, :from => "map", :to => "map <integer, map>") ) do |tpg, tp| Ops.set( tgmap, [tgt, tpg], { "ep" => Ops.get_map(endp, [tgt, tpg], {}), "clnt" => {} } ) Builtins.y2milestone("ParseConfigLio tgt:%1 tpg:%2", tgt, tpg) cmd = Ops.add( Ops.add(Ops.add("LC_ALL=POSIX lio_node --listlunacls ", tgt), " "), tpg ) out = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd)) ls = SplitStringNE(Ops.get_string(out, "stdout", ""), "\n") i = 0 nm = "" while Ops.less_than(i, Builtins.size(ls)) if Builtins.search(Ops.get(ls, i, ""), "InitiatorName ACL:") != nil nm = Ops.get(SplitStringNE(Ops.get(ls, i, ""), " "), 3, "") if !Builtins.isempty(nm) Ops.set(tgmap, [tgt, tpg, "clnt", nm], {}) end Builtins.y2milestone("ParseConfigLio nm:%1", nm) end if !Builtins.isempty(nm) && Builtins.search(Ops.get(ls, i, ""), "-> lun") != nil tls = SplitStringNE(Ops.get(ls, i, ""), " ") ti = Builtins.tointeger( Builtins.substring( Ops.get(SplitStringNE(Ops.get(tls, 1, ""), "/"), 0, ""), 4 ) ) lun = Builtins.tointeger( Builtins.substring( Ops.get(SplitStringNE(Ops.get(tls, 3, ""), "/"), 5, ""), 4 ) ) if ti != nil && lun != nil if !Builtins.haskey( Ops.get_map(tgmap, [tgt, tpg, "clnt", nm], {}), "lun" ) Ops.set(tgmap, [tgt, tpg, "clnt", nm, "lun"], {}) end Ops.set(tgmap, [tgt, tpg, "clnt", nm, "lun", ti], lun) Builtins.y2milestone("ParseConfigLio lun[%1]:%2", ti, lun) if !Builtins.haskey( Ops.get_map(tgmap, [tgt, tpg, "ep", "lun"], {}), lun ) Builtins.y2warning("lun %1 should exist in endpoints", lun) end end end i = Ops.add(i, 1) end Builtins.foreach(Ops.get_map(tgmap, [tgt, tpg, "clnt"], {})) do |clnt, m2| mutual = ["", ""] chap = ["", ""] chap_ref = arg_ref(chap) mutual_ref = arg_ref(mutual) ParseAuthData(tgt, tpg, clnt, chap_ref, mutual_ref) chap = chap_ref.value mutual = mutual_ref.value if !Builtins.isempty(Ops.get(mutual, 0, "")) && !Builtins.isempty(Ops.get(mutual, 1, "")) Ops.set(tgmap, [tgt, tpg, "clnt", clnt, "outgoing"], mutual) end if !Builtins.isempty(Ops.get(chap, 0, "")) && !Builtins.isempty(Ops.get(chap, 1, "")) Ops.set(tgmap, [tgt, tpg, "clnt", clnt, "incoming"], [chap]) end end cmd = Ops.add( Ops.add(Ops.add("LC_ALL=POSIX lio_node --listtpgattr ", tgt), " "), tpg ) out = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd)) ls = SplitStringNE(Ops.get_string(out, "stdout", ""), "\n") i = 0 while Ops.less_than(i, Builtins.size(ls)) if Builtins.search(Ops.get(ls, i, ""), "authentication=") != nil val = Ops.get(SplitStringNE(Ops.get(ls, i, ""), "="), 1, "") Ops.set(tgmap, [tgt, tpg, "auth"], val == "1") end i = Ops.add(i, 1) end end end cl = GetConnected() Builtins.foreach(cl) do |s| ls2 = SplitStringNE(s, " ") Ops.set(ls2, 1, Builtins.tointeger(Ops.get_string(ls2, 1, "-1"))) Builtins.y2milestone("ParseConfigLio conn:%1", ls2) if Builtins.haskey( Ops.get_map(tgmap, Ops.get_string(ls2, 0, ""), {}), Ops.get_integer(ls2, 1, -1) ) Ops.set( tgmap, [Ops.get_string(ls2, 0, ""), Ops.get_integer(ls2, 1, -1), "conn"], Ops.add( Ops.get_integer( tgmap, [Ops.get_string(ls2, 0, ""), Ops.get_integer(ls2, 1, -1), "conn"], 0 ), 1 ) ) end if Builtins.haskey( Ops.get_map( tgmap, [Ops.get_string(ls2, 0, ""), Ops.get_integer(ls2, 1, -1), "clnt"], {} ), Ops.get_string(ls2, 2, "") ) Ops.set( tgmap, [ Ops.get_string(ls2, 0, ""), Ops.get_integer(ls2, 1, -1), "clnt", Ops.get_string(ls2, 2, ""), "connected" ], true ) end end Ops.set(ret, "tgt", tgmap) deep_copy(ret) end |
- (Object) ReplaceSlashUs(i)
98 99 100 101 102 103 104 105 106 107 |
# File '../../src/modules/IscsiLioData.rb', line 98 def ReplaceSlashUs(i) ret = "" count = 0 Builtins.foreach(SplitStringNE(i, "/")) do |s| ret = Ops.add(ret, "_") if Ops.greater_than(count, 0) ret = Ops.add(ret, s) count = Ops.add(count, 1) end ret end |
- (Object) SaveSettings
1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 |
# File '../../src/modules/IscsiLioData.rb', line 1421 def SaveSettings dump_cmd = "/usr/sbin/lio_dump --file /etc/target/lio_setup.sh" if !LogExecCmd(dump_cmd) Report.Error(_("Cannot save lio setup")) end setup_cmd = "/usr/sbin/tcm_dump --file /etc/target/tcm_setup.sh" if !LogExecCmd(setup_cmd) Report.Error(_("Cannot save tcm setup")) end end |
- (Object) SetAuth(tgt, tpg, clnt, incoming, outgoing)
1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 |
# File '../../src/modules/IscsiLioData.rb', line 1263 def SetAuth(tgt, tpg, clnt, incoming, outgoing) incoming = deep_copy(incoming) if incoming.empty? log_incoming = [] else log_incoming = ["*****", "*****"] end outgoing = deep_copy(outgoing) if outgoing.empty? log_outgoing = [] else log_outgoing = ["*****", "*****"] end Builtins.y2milestone( "SetAuth tgt:%1 tpg:%2 clnt:%3 in:%4 out:%5", tgt, tpg, clnt, log_incoming, log_outgoing ) cmd = "" ret = true if Builtins.isempty(tgt) cmd = "lio_node --setchapdiscauth" if !Builtins.isempty(incoming) ret = LogExecCmd("#{cmd} #{incoming[0]} #{incoming[1]}", do_log: false) && ret Builtins.y2milestone("Executing cmd: #{cmd} ***** *****") elsif HasIncomingAuth("", 0, "") ret = LogExecCmd("#{cmd} \"\" \"\" ") && ret end cmd = "lio_node --setchapdiscmutualauth" if !Builtins.isempty(outgoing) ret = LogExecCmd("#{cmd} #{outgoing[0]} #{outgoing[1]}", do_log: false) && ret Builtins.y2milestone("Executing cmd: #{cmd} ***** *****") elsif HasOutgoingAuth("", 0, "") ret = LogExecCmd("#{cmd} \"\" \"\" ") && ret end else param = "#{tgt} #{tpg} #{clnt}" cmd = "lio_node --setchapauth #{param}" if !Builtins.isempty(incoming) ret = LogExecCmd("#{cmd} #{incoming[0]} #{incoming[1]}", do_log: false) && ret Builtins.y2milestone("Executing cmd: #{cmd} ***** *****") elsif HasIncomingAuth(tgt, tpg, clnt) ret = LogExecCmd("#{cmd} \"\" \"\" ") && ret end cmd = "lio_node --setchapmutualauth #{param}" if !Builtins.isempty(outgoing) ret = LogExecCmd("#{cmd} #{outgoing[0]} #{outgoing[1]}", do_log: false) && ret Builtins.y2milestone("Executing cmd: #{cmd} ***** *****") elsif HasOutgoingAuth(tgt, tpg, clnt) ret = LogExecCmd("#{cmd} \"\" \"\" ") && ret end end Builtins.y2milestone("SetAuth ret:%1", ret) ret end |
- (Object) SetData(dat)
547 548 549 550 551 552 |
# File '../../src/modules/IscsiLioData.rb', line 547 def SetData(dat) dat = deep_copy(dat) @data = deep_copy(dat) nil end |
- (Object) SetIetdAuth(tgt, tpg, incom, outgo)
303 304 305 306 307 308 309 310 311 312 313 |
# File '../../src/modules/IscsiLioData.rb', line 303 def SetIetdAuth(tgt, tpg, incom, outgo) incom = deep_copy(incom) m = GetTgt(@data, tgt, tpg) Builtins.foreach(incom) { |s| m = AddIncoming(m, s) } m = AddOutgoing(m, outgo) if !Builtins.isempty(outgo) data_ref = arg_ref(@data) SetTgt(data_ref, tgt, tpg, m) @data = data_ref.value nil end |
- (Object) SetNetworkPortal(tgt, tpg, np, new_port, add_all)
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 |
# File '../../src/modules/IscsiLioData.rb', line 416 def SetNetworkPortal(tgt, tpg, np, new_port, add_all) Builtins.y2milestone("SetNetworkPortal tgt:%1 tpg:%2 np:%3", tgt, tpg, np) target_info = "#{tgt} #{tpg}" ip_list = Ops.get_list(@data, ["tgt", tgt, tpg, "ep", "np"], []) if !ip_list.empty? && !add_all ip_list.each do |ipp| ip = ipp["ip"] port = ipp["port"] || 3260 if ip LogExecCmd("lio_node --delnp #{target_info} #{FormatIpPort(ip, port)}") else Builtins.y2error("IP address missing in data #{ipp}") end end end if add_all ret = true IscsiLioData.GetIpAddr.each do |ip| success = LogExecCmd("lio_node --addnp #{target_info} #{FormatIpPort(ip, new_port)}") ret = false if !success end else ret = LogExecCmd("lio_node --addnp #{target_info} #{np}") end ret end |
- (Object) SetTgt(data, tgt, tpg, m)
75 76 77 78 79 80 81 82 83 84 |
# File '../../src/modules/IscsiLioData.rb', line 75 def SetTgt(data, tgt, tpg, m) m = deep_copy(m) if Builtins.isempty(tgt) data.value = deep_copy(m) else Ops.set(data.value, ["tgt", tgt], { tpg => m }) end nil end |
- (Object) SetTpgAuth(tgt, tpg, value)
1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 |
# File '../../src/modules/IscsiLioData.rb', line 1322 def SetTpgAuth(tgt, tpg, value) ret = true tgt_auth_info = GetTgt(@data, tgt, tpg) current_value = tgt_auth_info.fetch("auth", false) Builtins.y2milestone("SetTpgAuth tgt:%1 tpg:%2 auth:%3 current auth:%4", tgt, tpg, value, current_value) value_changed = value != current_value if value_changed || tgt_auth_info.empty? auth = value ? "--enableauth" : "--disableauth" cmd = "lio_node #{auth} #{tgt} #{tpg}" ret = LogExecCmd(cmd) end Builtins.y2milestone("SetTpgAuth ret:%1", ret) ret end |
- (Object) SplitStringNE(str, delim)
43 44 45 46 47 |
# File '../../src/modules/IscsiLioData.rb', line 43 def SplitStringNE(str, delim) Builtins.filter(Builtins.splitstring(str, delim)) do |s| !Builtins.isempty(s) end end |
- (Object) UpdateConfig
1414 1415 1416 1417 1418 1419 |
# File '../../src/modules/IscsiLioData.rb', line 1414 def UpdateConfig @data = ParseConfigLio() Builtins.y2milestone("UpdateConfig done") nil end |