Skip to content

Commit

Permalink
Merge pull request #26 from gabi2/master
Browse files Browse the repository at this point in the history
bind all IP addresses to a target (if requested by user) bnc #885688
  • Loading branch information
gabi2 committed Jul 28, 2014
2 parents 8f22d42 + dc17e33 commit e4fa51a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 31 deletions.
7 changes: 7 additions & 0 deletions package/yast2-iscsi-lio-server.changes
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Thu Jul 24 11:59:18 CEST 2014 - gs@suse.de

- bind all IP addresses to a target if requested by user
(bnc #885688)
- 3.1.8

-------------------------------------------------------------------
Thu May 15 09:53:44 CEST 2014 - gs@suse.de

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-iscsi-lio-server.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-iscsi-lio-server
Version: 3.1.7
Version: 3.1.8
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
2 changes: 2 additions & 0 deletions src/include/iscsi-lio-server/dialogs.rb
Expand Up @@ -139,6 +139,8 @@ def initialize_iscsi_lio_server_dialogs(include_target)
),
HWeight(1, InputField(Id(:port), _("Port number"), "3260"))
),
VSpacing(0.2),
Left(HBox(CheckBox(Id(:add_ip), _("Bind all IP addresses"), false))),
VSpacing(0.5),
Left(HBox(CheckBox(Id(:auth), _("Use Authentication"), true))),
VSpacing(0.5),
Expand Down
12 changes: 6 additions & 6 deletions src/include/iscsi-lio-server/widgets.rb
Expand Up @@ -1013,14 +1013,14 @@ def storeModify(option_id, option_map)
)
ip = Convert.to_string(UI.QueryWidget(:ipaddr, :Value))
port = Builtins.tointeger(UI.QueryWidget(:port, :Value))
add_all = Convert.to_boolean(UI.QueryWidget(:add_ip, :Value))

Builtins.y2milestone("storeModify ip:%1 port:%2 ipp:%3", ip, port, ipp)
if IP.Check6(ip)
ip = "[#{ip}]" # brackets needed around IPv6
end
np = Builtins.sformat("%1:%2", ip, port)
if !Builtins.isempty(ip) && np != ipp

np = IscsiLioData.FormatIpPort(ip, port)
if (!ip.empty? && np != ipp) || add_all
chg = true
if !IscsiLioData.SetNetworkPortal(@curr_target, @curr_tpg, np)
if !IscsiLioData.SetNetworkPortal(@curr_target, @curr_tpg, np, port, add_all)
txt = Builtins.sformat(_("Problem setting network portal to %1"), np)
Popup.Error(txt)
end
Expand Down
59 changes: 35 additions & 24 deletions src/modules/IscsiLioData.rb
Expand Up @@ -369,15 +369,21 @@ def GetLunList(tgt, tpg)
deep_copy(ret)
end

# format ip and port information for use in commands
def FormatIpPort(ip, port)
# brackets needed around IPv6
ip = "[#{ip}]" if IP.Check6(ip)
return "#{ip}:#{port}"
end

def GetNetworkPortal(tgt, tpg)
Builtins.y2milestone("Data: %1, tgt: %2, tpg: %3", @data, tgt, tpg)
ret = Builtins.maplist(
Ops.get_list(@data, ["tgt", tgt, tpg, "ep", "np"], [])
) do |n|
ip = n["ip"] || ""
ip = "[#{ip}]" if IP.Check6(ip)
port = n["port"] || 1
ipp = Builtins.sformat("%1:%2", ip, port )
port = n["port"] || 3260
ipp = FormatIpPort(ip, port)
end
deep_copy(ret)
end
Expand All @@ -399,28 +405,33 @@ def GetClntLun(tgt, tpg, clnt)
deep_copy(ret)
end

def SetNetworkPortal(tgt, tpg, np)
def SetNetworkPortal(tgt, tpg, np, new_port, add_all)
Builtins.y2milestone("SetNetworkPortal tgt:%1 tpg:%2 np:%3", tgt, tpg, np)
kt = Ops.add(Ops.add(Ops.add(tgt, " "), tpg), " ")
if !Builtins.isempty(
Ops.get_list(@data, ["tgt", tgt, tpg, "ep", "np"], [])
)
LogExecCmd(
Ops.add(
Ops.add("lio_node --delnp ", kt),
Builtins.sformat(
"%1:%2",
Ops.get_string(@data, ["tgt", tgt, tpg, "ep", "np", 0, "ip"], ""),
Ops.get_integer(
@data,
["tgt", tgt, tpg, "ep", "np", 0, "port"],
1
)
)
)
)

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 = LogExecCmd(Ops.add(Ops.add("lio_node --addnp ", kt), np))
ret
end

Expand Down Expand Up @@ -1429,7 +1440,7 @@ def SaveSettings
publish :function => :GetTpgAuth, :type => "boolean (string, integer)"
publish :function => :GetClntList, :type => "list <string> (string, integer)"
publish :function => :GetClntLun, :type => "map <integer, integer> (string, integer, string)"
publish :function => :SetNetworkPortal, :type => "boolean (string, integer, string)"
publish :function => :SetNetworkPortal, :type => "boolean (string, integer, string, string, boolean)"
publish :function => :GetTargets, :type => "list <list> ()"
publish :function => :GetExportLun, :type => "string (integer, map)"
publish :function => :GetExportAuth, :type => "list <map <string, any>> (string, integer)"
Expand Down

0 comments on commit e4fa51a

Please sign in to comment.