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
3267e416
authored
Aug 22, 2015
by
Czémán Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
firewall: replace --vlan switch to --firewall
parent
0d875b08
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
15 deletions
+15
-15
circle/firewall/management/commands/add_rule.py
+15
-15
No files found.
circle/firewall/management/commands/add_rule.py
View file @
3267e416
...
@@ -17,7 +17,7 @@ from __future__ import unicode_literals, absolute_import
...
@@ -17,7 +17,7 @@ from __future__ import unicode_literals, absolute_import
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.core.management.base
import
BaseCommand
,
CommandError
import
logging
import
logging
from
firewall.models
import
Vlan
,
VlanGroup
,
Rule
from
firewall.models
import
Firewall
,
VlanGroup
,
Rule
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
@@ -64,11 +64,11 @@ class Command(BaseCommand):
...
@@ -64,11 +64,11 @@ class Command(BaseCommand):
choices
=
(
'in'
,
'out'
),
choices
=
(
'in'
,
'out'
),
help
=
'direction of the rule'
)
help
=
'direction of the rule'
)
parser
.
add_argument
(
'--
vlan
'
,
parser
.
add_argument
(
'--
firewall
'
,
action
=
'store'
,
action
=
'store'
,
dest
=
'
vlan
'
,
dest
=
'
firewall
'
,
required
=
True
,
required
=
True
,
help
=
'
vlan name where the port will open
'
)
help
=
'
firewall name which open the given port
'
)
parser
.
add_argument
(
'--vlan-group'
,
parser
.
add_argument
(
'--vlan-group'
,
action
=
'store'
,
action
=
'store'
,
...
@@ -90,17 +90,17 @@ class Command(BaseCommand):
...
@@ -90,17 +90,17 @@ class Command(BaseCommand):
action
=
options
[
'action'
]
action
=
options
[
'action'
]
dir
=
options
[
'dir'
]
dir
=
options
[
'dir'
]
owner
=
options
[
'owner'
]
owner
=
options
[
'owner'
]
vlan
=
options
[
'vlan
'
]
firewall
=
options
[
'firewall
'
]
fnet
=
options
[
'vlan_group'
]
fnet
=
options
[
'vlan_group'
]
try
:
try
:
owner
=
User
.
objects
.
get
(
username
=
owner
)
owner
=
User
.
objects
.
get
(
username
=
owner
)
vlan
=
Vlan
.
objects
.
get
(
name
=
vlan
)
firewall
=
Firewall
.
objects
.
get
(
name
=
firewall
)
fnet
=
VlanGroup
.
objects
.
get
(
name
=
fnet
)
fnet
=
VlanGroup
.
objects
.
get
(
name
=
fnet
)
except
User
.
DoesNotExist
:
except
User
.
DoesNotExist
:
raise
CommandError
(
"User '
%
s' does not exist"
%
owner
)
raise
CommandError
(
"User '
%
s' does not exist"
%
owner
)
except
Vlan
.
DoesNotExist
:
except
Firewall
.
DoesNotExist
:
raise
CommandError
(
"
Vlan '
%
s' does not exist"
%
vlan
)
raise
CommandError
(
"
Firewall '
%
s' does not exist"
%
firewall
)
except
VlanGroup
.
DoesNotExist
:
except
VlanGroup
.
DoesNotExist
:
raise
CommandError
(
"VlanGroup '
%
s' does not exist"
%
fnet
)
raise
CommandError
(
"VlanGroup '
%
s' does not exist"
%
fnet
)
...
@@ -108,7 +108,7 @@ class Command(BaseCommand):
...
@@ -108,7 +108,7 @@ class Command(BaseCommand):
self
.
validate_port
(
port
)
self
.
validate_port
(
port
)
try
:
try
:
rule
=
self
.
make_rule
(
port
,
proto
,
action
,
rule
=
self
.
make_rule
(
port
,
proto
,
action
,
dir
,
owner
,
vlan
,
fnet
)
dir
,
owner
,
firewall
,
fnet
)
rule
.
save
()
rule
.
save
()
except
Warning
as
e
:
except
Warning
as
e
:
logger
.
warning
(
e
)
logger
.
warning
(
e
)
...
@@ -123,19 +123,19 @@ class Command(BaseCommand):
...
@@ -123,19 +123,19 @@ class Command(BaseCommand):
for
port
in
xrange
(
lower
,
higher
+
1
):
for
port
in
xrange
(
lower
,
higher
+
1
):
try
:
try
:
rule
=
self
.
make_rule
(
port
,
proto
,
action
,
dir
,
rule
=
self
.
make_rule
(
port
,
proto
,
action
,
dir
,
owner
,
vlan
,
fnet
)
owner
,
firewall
,
fnet
)
rules
.
append
(
rule
)
rules
.
append
(
rule
)
except
Warning
as
e
:
except
Warning
as
e
:
logger
.
warning
(
e
)
logger
.
warning
(
e
)
Rule
.
objects
.
bulk_create
(
rules
)
Rule
.
objects
.
bulk_create
(
rules
)
def
make_rule
(
self
,
port
,
proto
,
action
,
dir
,
owner
,
vlan
,
fnet
):
def
make_rule
(
self
,
port
,
proto
,
action
,
dir
,
owner
,
firewall
,
fnet
):
rule
=
Rule
(
direction
=
dir
,
dport
=
port
,
proto
=
proto
,
action
=
action
,
rule
=
Rule
(
direction
=
dir
,
dport
=
port
,
proto
=
proto
,
action
=
action
,
vlan
=
vlan
,
foreign_network
=
fnet
,
owner
=
owner
)
firewall
=
firewall
,
foreign_network
=
fnet
,
owner
=
owner
)
if
self
.
is_exist
(
port
,
proto
,
action
,
dir
,
owner
,
vlan
,
fnet
):
if
self
.
is_exist
(
port
,
proto
,
action
,
dir
,
owner
,
firewall
,
fnet
):
raise
Warning
((
'Rule does exist:
%
s'
%
raise
Warning
((
'Rule does exist:
%
s'
%
unicode
(
rule
))
.
encode
(
'utf-8'
))
unicode
(
rule
))
.
encode
(
'utf-8'
))
...
@@ -143,13 +143,13 @@ class Command(BaseCommand):
...
@@ -143,13 +143,13 @@ class Command(BaseCommand):
return
rule
return
rule
def
is_exist
(
self
,
port
,
proto
,
action
,
dir
,
owner
,
vlan
,
fnet
):
def
is_exist
(
self
,
port
,
proto
,
action
,
dir
,
owner
,
firewall
,
fnet
):
rules
=
Rule
.
objects
.
filter
(
direction
=
dir
,
rules
=
Rule
.
objects
.
filter
(
direction
=
dir
,
dport
=
port
,
dport
=
port
,
proto
=
proto
,
proto
=
proto
,
action
=
action
,
action
=
action
,
vlan
=
vlan
,
firewall
=
firewall
,
foreign_network
=
fnet
,
foreign_network
=
fnet
,
owner
=
owner
)
owner
=
owner
)
return
rules
.
exists
()
return
rules
.
exists
()
...
...
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