Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FoD
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Schmitz
FoD
Commits
478173ac
Commit
478173ac
authored
13 years ago
by
Leonidas Poulopoulos
Browse files
Options
Downloads
Patches
Plain Diff
Added clean method to netwrork address. 'then' statement is obligatory
parent
a24fbf37
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
flowspec/models.py
+46
-3
46 additions, 3 deletions
flowspec/models.py
with
46 additions
and
3 deletions
flowspec/models.py
+
46
−
3
View file @
478173ac
# -*- coding: utf-8 -*- vim:encoding=utf-8:
# vim: tabstop=4:shiftwidth=4:softtabstop=4:expandtab
from
django.db
import
models
from
django.db
import
models
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
...
@@ -5,6 +8,7 @@ import nxpy as np
...
@@ -5,6 +8,7 @@ import nxpy as np
from
ncclient
import
manager
from
ncclient
import
manager
from
ncclient.transport.errors
import
AuthenticationError
,
SSHError
from
ncclient.transport.errors
import
AuthenticationError
,
SSHError
from
lxml
import
etree
as
ET
from
lxml
import
etree
as
ET
from
ipaddr
import
*
FRAGMENT_CODES
=
(
FRAGMENT_CODES
=
(
(
"
dont-fragment
"
,
"
Don
'
t fragment
"
),
(
"
dont-fragment
"
,
"
Don
'
t fragment
"
),
...
@@ -27,9 +31,17 @@ THEN_CHOICES = (
...
@@ -27,9 +31,17 @@ THEN_CHOICES = (
class
MatchAddress
(
models
.
Model
):
class
MatchAddress
(
models
.
Model
):
address
=
models
.
CharField
(
max_length
=
255
)
address
=
models
.
CharField
(
max_length
=
255
,
help_text
=
u
"
Network address. Use address/CIDR notation
"
)
def
__unicode__
(
self
):
def
__unicode__
(
self
):
return
self
.
address
return
self
.
address
def
clean
(
self
,
*
args
,
**
kwargs
):
from
django.core.exceptions
import
ValidationError
try
:
assert
(
IPNetwork
(
self
.
address
))
except
Exception
:
raise
ValidationError
(
'
Invalid network address format
'
)
class
Meta
:
class
Meta
:
db_table
=
u
'
match_address
'
db_table
=
u
'
match_address
'
...
@@ -94,7 +106,7 @@ class ThenAction(models.Model):
...
@@ -94,7 +106,7 @@ class ThenAction(models.Model):
db_table
=
u
'
then_action
'
db_table
=
u
'
then_action
'
class
ThenStatement
(
models
.
Model
):
class
ThenStatement
(
models
.
Model
):
thenaction
=
models
.
ManyToManyField
(
ThenAction
,
blank
=
True
,
null
=
True
)
thenaction
=
models
.
ManyToManyField
(
ThenAction
)
class
Meta
:
class
Meta
:
db_table
=
u
'
then
'
db_table
=
u
'
then
'
...
@@ -111,6 +123,37 @@ class MatchStatement(models.Model):
...
@@ -111,6 +123,37 @@ class MatchStatement(models.Model):
matchSource
=
models
.
ForeignKey
(
MatchAddress
,
blank
=
True
,
null
=
True
,
related_name
=
"
matchSource
"
)
matchSource
=
models
.
ForeignKey
(
MatchAddress
,
blank
=
True
,
null
=
True
,
related_name
=
"
matchSource
"
)
matchSourcePort
=
models
.
ManyToManyField
(
MatchPort
,
blank
=
True
,
null
=
True
,
related_name
=
"
matchSourcePort
"
)
matchSourcePort
=
models
.
ManyToManyField
(
MatchPort
,
blank
=
True
,
null
=
True
,
related_name
=
"
matchSourcePort
"
)
matchTcpFlag
=
models
.
ForeignKey
(
MatchTcpFlag
,
blank
=
True
,
null
=
True
)
matchTcpFlag
=
models
.
ForeignKey
(
MatchTcpFlag
,
blank
=
True
,
null
=
True
)
# def clean(self, *args, **kwargs):
# clean_error = True
# from django.core.exceptions import ValidationError
# if not (self.matchDestination or self.matchfragmenttype or self.matchicmpcode or self.matchicmptype
# or self.matchpacketlength or self.matchprotocol or self.matchSource or self.matchTcpFlag):
# clean_error = False
# try:
# assert(self.matchDestinationPort)
# clean_error = False
# except:
# pass
# try:
# assert(self.matchSourcePort)
# clean_error = False
# except:
# pass
# try:
# assert(self.matchport)
# clean_error = False
# except:
# pass
# try:
# print self.matchdscp
# assert(self.matchdscp)
# clean_error = False
# except:
# pass
# if clean_error:
# raise ValidationError('At least one match statement has to be declared')
class
Meta
:
class
Meta
:
db_table
=
u
'
match
'
db_table
=
u
'
match
'
...
@@ -127,7 +170,7 @@ class Route(models.Model):
...
@@ -127,7 +170,7 @@ class Route(models.Model):
class
Meta
:
class
Meta
:
db_table
=
u
'
route
'
db_table
=
u
'
route
'
def
save
(
self
,
*
args
,
**
kwargs
):
def
save
(
self
,
*
args
,
**
kwargs
):
# Begin translation to device xml configuration
# Begin translation to device xml configuration
device
=
np
.
Device
()
device
=
np
.
Device
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment