Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
c7fd2925
authored
Mar 03, 2016
by
Czémán Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
firewall: rework make_rule method in add_rule command
parent
3b75446c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
17 deletions
+6
-17
circle/firewall/management/commands/add_rule.py
+6
-17
No files found.
circle/firewall/management/commands/add_rule.py
View file @
c7fd2925
...
@@ -107,8 +107,9 @@ class Command(BaseCommand):
...
@@ -107,8 +107,9 @@ class Command(BaseCommand):
if
port
:
if
port
:
self
.
validate_port
(
port
)
self
.
validate_port
(
port
)
try
:
try
:
rule
=
self
.
make_rule
(
port
,
proto
,
action
,
rule
=
self
.
make_rule
(
dport
=
port
,
proto
=
proto
,
action
=
action
,
dir
,
owner
,
firewall
,
fnet
)
direction
=
dir
,
owner
=
owner
,
firewall
=
firewall
,
foreign_network
=
fnet
)
rule
.
save
()
rule
.
save
()
except
Warning
as
e
:
except
Warning
as
e
:
logger
.
warning
(
e
)
logger
.
warning
(
e
)
...
@@ -130,12 +131,11 @@ class Command(BaseCommand):
...
@@ -130,12 +131,11 @@ class Command(BaseCommand):
Rule
.
objects
.
bulk_create
(
rules
)
Rule
.
objects
.
bulk_create
(
rules
)
def
make_rule
(
self
,
port
,
proto
,
action
,
dir
,
owner
,
firewall
,
fnet
):
def
make_rule
(
self
,
**
kwargs
):
rule
=
Rule
(
direction
=
dir
,
dport
=
port
,
proto
=
proto
,
action
=
action
,
rule
,
created
=
Rule
.
objects
.
get_or_create
(
**
kwargs
)
firewall
=
firewall
,
foreign_network
=
fnet
,
owner
=
owner
)
if
self
.
is_exist
(
port
,
proto
,
action
,
dir
,
owner
,
firewall
,
fnet
)
:
if
not
created
:
raise
Warning
((
'Rule does exist:
%
s'
%
raise
Warning
((
'Rule does exist:
%
s'
%
unicode
(
rule
))
.
encode
(
'utf-8'
))
unicode
(
rule
))
.
encode
(
'utf-8'
))
...
@@ -143,17 +143,6 @@ class Command(BaseCommand):
...
@@ -143,17 +143,6 @@ class Command(BaseCommand):
return
rule
return
rule
def
is_exist
(
self
,
port
,
proto
,
action
,
dir
,
owner
,
firewall
,
fnet
):
rules
=
Rule
.
objects
.
filter
(
direction
=
dir
,
dport
=
port
,
proto
=
proto
,
action
=
action
,
firewall
=
firewall
,
foreign_network
=
fnet
,
owner
=
owner
)
return
rules
.
exists
()
def
validate_port
(
self
,
port
):
def
validate_port
(
self
,
port
):
if
port
<
0
or
port
>
65535
:
if
port
<
0
or
port
>
65535
:
raise
CommandError
(
"Port '
%
i' not in range [0-65535]"
%
port
)
raise
CommandError
(
"Port '
%
i' not in range [0-65535]"
%
port
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment