Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
re2o
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nounous
re2o
Commits
27d68235
Commit
27d68235
authored
Aug 29, 2017
by
Gabriel Detraz
Committed by
root
Aug 29, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Utilise des ranges en lieu et place des slash
parent
81087672
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
16 deletions
+51
-16
machines/forms.py
machines/forms.py
+2
-1
machines/migrations/0052_auto_20170828_2322.py
machines/migrations/0052_auto_20170828_2322.py
+30
-0
machines/models.py
machines/models.py
+15
-11
machines/templates/machines/aff_iptype.html
machines/templates/machines/aff_iptype.html
+4
-4
No files found.
machines/forms.py
View file @
27d68235
...
...
@@ -143,7 +143,8 @@ class DelMachineTypeForm(Form):
class
IpTypeForm
(
ModelForm
):
class
Meta
:
model
=
IpType
fields
=
[
'type'
,
'extension'
,
'need_infra'
,
'domaine_ip'
,
'domaine_range'
,
'vlan'
]
fields
=
[
'type'
,
'extension'
,
'need_infra'
,
'domaine_ip_start'
,
'domaine_ip_stop'
,
'vlan'
]
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
IpTypeForm
,
self
).
__init__
(
*
args
,
**
kwargs
)
...
...
machines/migrations/0052_auto_20170828_2322.py
0 → 100644
View file @
27d68235
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-08-28 21:22
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'machines'
,
'0051_iptype_vlan'
),
]
operations
=
[
migrations
.
RenameField
(
model_name
=
'iptype'
,
old_name
=
'domaine_ip'
,
new_name
=
'domaine_ip_start'
,
),
migrations
.
RemoveField
(
model_name
=
'iptype'
,
name
=
'domaine_range'
,
),
migrations
.
AddField
(
model_name
=
'iptype'
,
name
=
'domaine_ip_stop'
,
field
=
models
.
GenericIPAddressField
(
default
=
'255.255.254.254'
,
protocol
=
'IPv4'
),
preserve_default
=
False
,
),
]
machines/models.py
View file @
27d68235
...
...
@@ -27,7 +27,7 @@ from django.forms import ValidationError
from
django.utils.functional
import
cached_property
from
django.utils
import
timezone
from
macaddress.fields
import
MACAddressField
from
netaddr
import
mac_bare
,
EUI
,
IPSet
,
IP
Network
from
netaddr
import
mac_bare
,
EUI
,
IPSet
,
IP
Range
,
IPNetwork
,
IPAddress
from
django.core.validators
import
MinValueValidator
,
MaxValueValidator
import
re
from
reversion
import
revisions
as
reversion
...
...
@@ -65,21 +65,17 @@ class IpType(models.Model):
type
=
models
.
CharField
(
max_length
=
255
)
extension
=
models
.
ForeignKey
(
'Extension'
,
on_delete
=
models
.
PROTECT
)
need_infra
=
models
.
BooleanField
(
default
=
False
)
domaine_ip
=
models
.
GenericIPAddressField
(
protocol
=
'IPv4'
)
domaine_
range
=
models
.
IntegerField
(
validators
=
[
MinValueValidator
(
16
),
MaxValueValidator
(
32
)]
)
domaine_ip
_start
=
models
.
GenericIPAddressField
(
protocol
=
'IPv4'
)
domaine_
ip_stop
=
models
.
GenericIPAddressField
(
protocol
=
'IPv4'
)
vlan
=
models
.
ForeignKey
(
'Vlan'
,
on_delete
=
models
.
PROTECT
,
blank
=
True
,
null
=
True
)
@
cached_property
def
network
(
self
):
return
str
(
self
.
domaine_ip
)
+
'/'
+
str
(
self
.
domaine_range
)
@
cached_property
def
ip_network
(
self
):
return
IPNetwork
(
self
.
network
)
def
ip_range
(
self
):
return
IPRange
(
self
.
domaine_ip_start
,
end
=
self
.
domaine_ip_stop
)
@
cached_property
def
ip_set
(
self
):
return
IPSet
(
self
.
ip_
network
)
return
IPSet
(
self
.
ip_
range
)
@
cached_property
def
ip_set_as_str
(
self
):
...
...
@@ -93,7 +89,10 @@ class IpType(models.Model):
def
gen_ip_range
(
self
):
# Creation du range d'ip dans les objets iplist
ip_obj
=
[
IpList
(
ip_type
=
self
,
ipv4
=
str
(
ip
))
for
ip
in
self
.
ip_network
.
iter_hosts
()]
networks
=
[]
for
net
in
self
.
ip_range
.
cidrs
():
networks
+=
net
.
iter_hosts
()
ip_obj
=
[
IpList
(
ip_type
=
self
,
ipv4
=
str
(
ip
))
for
ip
in
networks
]
IpList
.
objects
.
bulk_create
(
ip_obj
)
return
...
...
@@ -105,6 +104,11 @@ class IpType(models.Model):
ip
.
delete
()
def
clean
(
self
):
if
IPAddress
(
self
.
domaine_ip_start
)
>
IPAddress
(
self
.
domaine_ip_stop
):
raise
ValidationError
(
"Domaine end doit être après start..."
)
# On ne crée pas plus grand qu'un /16
if
self
.
ip_range
.
size
>
65536
:
raise
ValidationError
(
"Le range est trop gros, vous ne devez pas créer plus grand qu'un /16"
)
# On check que les / ne se recoupent pas
for
element
in
IpType
.
objects
.
all
().
exclude
(
pk
=
self
.
pk
):
if
not
self
.
ip_set
.
isdisjoint
(
element
.
ip_set
):
...
...
machines/templates/machines/aff_iptype.html
View file @
27d68235
...
...
@@ -28,8 +28,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<th>
Type d'ip
</th>
<th>
Extension
</th>
<th>
Nécessite l'autorisation infra
</th>
<th>
D
omaine d'ip
</th>
<th>
Range
</th>
<th>
D
ébut
</th>
<th>
Fin
</th>
<th>
Sur vlan
</th>
<th></th>
<th></th>
...
...
@@ -40,8 +40,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<td>
{{ type.type }}
</td>
<td>
{{ type.extension }}
</td>
<td>
{{ type.need_infra }}
</td>
<td>
{{ type.domaine_ip }}
</td>
<td>
{{ type.domaine_
range
}}
</td>
<td>
{{ type.domaine_ip
_start
}}
</td>
<td>
{{ type.domaine_
ip_stop
}}
</td>
<td>
{{ type.vlan }}
</td>
<td
class=
"text-right"
>
{% if is_infra %}
...
...
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