Skip to content

Commit

Permalink
Fate318391, add firewall ports.
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-wang committed May 15, 2015
1 parent 00cd23e commit 33eb0cc
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 25 deletions.
18 changes: 18 additions & 0 deletions package/drbd-cluster.fwd
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Name: Drbd
## Description: Opens ports for DRBD.
## Port 7788 and higher is recommend.

# space separated list of allowed TCP ports
TCP="7788"

# space separated list of allowed UDP ports
UDP=""

# space separated list of allowed RPC services
RPC=""

# space separated list of allowed IP protocols
IP=""

# space separated list of allowed UDP broadcast ports
BROADCAST=""
6 changes: 6 additions & 0 deletions package/yast2-drbd.spec
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ Name: yast2-drbd
Version: 3.1.11
Release: 0

%define _fwdefdir /etc/sysconfig/SuSEfirewall2.d/services
BuildRoot: %{_tmppath}/%{name}-%{version}-build
Source0: %{name}-%{version}.tar.bz2
Source1: drbd-cluster.fwd

BuildRequires: perl-XML-Writer
BuildRequires: ruby
Expand Down Expand Up @@ -57,6 +59,9 @@ Authors:
%install
%yast_install

mkdir -p $RPM_BUILD_ROOT/%{_fwdefdir}
install -m 644 %{S:1} $RPM_BUILD_ROOT/%{_fwdefdir}/drbd

%files
%defattr(-,root,root)
%{yast_yncludedir}/drbd/
Expand All @@ -68,5 +73,6 @@ Authors:
%{yast_agentdir}/ag_drbd
%{yast_agentdir}/drbd.rb.yy
%doc %{yast_docdir}
%config %{_fwdefdir}/drbd

%changelog
40 changes: 33 additions & 7 deletions src/include/drbd/startup_conf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def initialize_drbd_startup_conf(include_target)
Yast.import "Wizard"
Yast.import "Service"
Yast.import "Drbd"
Yast.import "CWMFirewallInterfaces"

Yast.include include_target, "drbd/helps.rb"
Yast.include include_target, "drbd/common.rb"
Expand All @@ -33,7 +34,7 @@ def ConfigureStartUpDialog
Left(
RadioButton(
Id("on"),
_("On -- Start DRBD Server Now and when Booting")
_("On -- Start DRBD Server when Booting")
)
),
Left(
Expand Down Expand Up @@ -70,6 +71,20 @@ def ConfigureStartUpDialog
)
)

# Just a dialog
firewall_widget = CWMFirewallInterfaces.CreateOpenFirewallWidget(
{
#servie:drbd is the name of /etc/sysconfig/SuSEfirewall2.d/services/drbd
"services" => [
"service:drbd"
],
"display_details" => true
}
)
Builtins.y2milestone("%1", firewall_widget)
# firewall_layout is just a dialog
firewall_layout = Ops.get_term(firewall_widget, "custom_widget", VBox())

_Tpropagate = Frame(
_("Propagate Configuration"),
Left(
Expand Down Expand Up @@ -98,6 +113,8 @@ def ConfigureStartUpDialog
VSpacing(1),
_Tonoff,
VSpacing(1),
firewall_layout,
VSpacing(1),
_Tpropagate,
VStretch()
)
Expand All @@ -107,6 +124,8 @@ def ConfigureStartUpDialog
my_SetContents("startup_conf", contents)

UI.ChangeWidget(Id("server_type"), :CurrentButton, boot ? "on" : "off")
CWMFirewallInterfaces.OpenFirewallInit(firewall_widget, "")
event = {}

ret = nil
while true
Expand All @@ -124,7 +143,9 @@ def ConfigureStartUpDialog
)
)

ret = UI.UserInput
# add event
event = UI.WaitForEvent
ret = Ops.get(event, "ID")

if ret == :abort || ret == :cancel
if ReallyAbort()
Expand All @@ -134,7 +155,10 @@ def ConfigureStartUpDialog
end
end

break if ret == :next || ret == :back
if ret == :next || ret == :back
CWMFirewallInterfaces.OpenFirewallStore(firewall_widget, "", event)
break
end

if ret == "start_now"
if !Service.Start("drbd")
Expand All @@ -152,10 +176,10 @@ def ConfigureStartUpDialog
next
end

if ret == :help
myHelp("startup_conf")
next
end
#if ret == :help
# myHelp("startup_conf")
# next
#end

if ret == :wizardTree
ret = Convert.to_string(UI.QueryWidget(Id(:wizardTree), :CurrentItem))
Expand All @@ -166,6 +190,8 @@ def ConfigureStartUpDialog
break
end

CWMFirewallInterfaces.OpenFirewallHandle(firewall_widget, "", event)

Builtins.y2error("unexpected retcode: %1", ret)
end

Expand Down
62 changes: 44 additions & 18 deletions src/modules/Drbd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def main
Yast.import "Report"
Yast.import "Summary"
Yast.import "Service"
Yast.import "SuSEFirewall"
Yast.import "SuSEFirewallServices"

Yast.import "Mode"
Yast.import "PackageSystem"
Expand Down Expand Up @@ -134,7 +136,7 @@ def prepare_conf_file
true
end

def finding_local()
def finding_local(section)
# Get hostname to find out the local disk/port/IP
out = Convert.to_map(
SCR.Execute(
Expand All @@ -153,24 +155,25 @@ def finding_local()

resconfig["on"].each do |nodename, conf|
if @local_hostname == nodename
disk = conf["disk"]
Builtins.y2debug("Using local disk %1 for DRBD.", disk)
if !@local_disks_ori.include?(disk)
@local_disks_ori.push(disk)
end
if section == "disk"
disk = conf["disk"]
Builtins.y2debug("Using local disk %1 for DRBD.", disk)
if !@local_disks_ori.include?(disk)
@local_disks_ori.push(disk)
end

port = conf["address"].split(":")[1]
Builtins.y2debug("Using port %1 for disk %2 for DRBD.", port, disk)
if !@local_ports.include?(port)
@local_ports.push(port)
elsif section == "port"
port = conf["address"].split(":")[1]
Builtins.y2debug("Using port %1 for DRBD.", port)
if !@local_ports.include?(port)
@local_ports.push(port)
end
end

break
end
end

Builtins.y2debug("Local disks list is %1.", @local_disks_ori)
Builtins.y2debug("TCP ports list is %1.", @local_ports)
end

nil
Expand All @@ -184,18 +187,20 @@ def Read
Progress.New(
caption,
" ",
4,
5,
[
_("Read global settings"),
_("Read resources"),
_("Read LVM configurations"),
_("Read daemon status")
_("Read daemon status"),
_("Read SuSEFirewall Settings")
],
[
_("Reading global settings..."),
_("Reading resources..."),
_("Reading LVM configurations..."),
_("Reading daemon status..."),
_("Read SuSEFirewall Settings"),
_("Finished")
],
""
Expand Down Expand Up @@ -416,14 +421,20 @@ def Read

Builtins.y2milestone("read resource_config=%1", @resource_config)

# Find all info like disks/ports belong to local node
finding_local
# Find all info like disks belong to local node
finding_local("disk")

Progress.NextStage
@start_daemon = Service.Enabled("drbd")

Progress.NextStage

# read the SuSEfirewall2
SuSEFirewall.Read

# Progress finished
Progress.NextStage

Progress.Finish
@modified = false
true
Expand Down Expand Up @@ -617,18 +628,20 @@ def Write
Progress.New(
caption,
" ",
4,
5,
[
_("Write global settings"),
_("Write resources"),
_("Write LVM configurations"),
_("Set daemon status")
_("Set daemon status"),
_("Write the SuSEfirewall settings")
],
[
_("Writing global settings..."),
_("Writing resources..."),
_("Writing LVM configurations..."),
_("Setting daemon status..."),
_("Writing the SuSEFirewall settings"),
_("Finished")
],
""
Expand Down Expand Up @@ -729,6 +742,19 @@ def Write
end
Progress.NextStage

# open all local ports
finding_local("port")

# DRBD only use TCP port
SuSEFirewallServices.SetNeededPortsAndProtocols(
"service:drbd",
{ "tcp_ports" => @local_ports }
)

SuSEFirewall.Write

# Progress finished
Progress.NextStage
Progress.Finish
true
end
Expand Down

0 comments on commit 33eb0cc

Please sign in to comment.