Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Re2o
re2o
Commits
a12a5196
Commit
a12a5196
authored
Nov 07, 2017
by
Gabriel Detraz
Committed by
root
Nov 07, 2017
Browse files
Affichage constructeur
parent
0e9baa60
Changes
2
Hide whitespace changes
Inline
Side-by-side
machines/models.py
View file @
a12a5196
...
...
@@ -445,6 +445,13 @@ class Interface(models.Model):
""" Renvoie l'ipv6 en str. Mise en cache et propriété de l'objet"""
return
str
(
self
.
ipv6_object
)
def
manufacturer
(
self
):
try
:
manufacturer_self
=
str
(
self
.
mac_address
.
oui
.
registration
().
org
)
except
:
manufacturer_self
=
None
return
manufacturer_self
def
mac_bare
(
self
):
""" Formatage de la mac type mac_bare"""
return
str
(
EUI
(
self
.
mac_address
,
dialect
=
mac_bare
)).
lower
()
...
...
@@ -457,24 +464,6 @@ class Interface(models.Model):
except
:
raise
ValidationError
(
"La mac donnée est invalide"
)
def
clean
(
self
,
*
args
,
**
kwargs
):
""" Formate l'addresse mac en mac_bare (fonction filter_mac)
et assigne une ipv4 dans le bon range si inexistante ou incohérente"""
# If type was an invalid value, django won't create an attribute type
# but try clean() as we may be able to create it from another value
# so even if the error as yet been detected at this point, django
# continues because the error might not prevent us from creating the
# instance.
# But in our case, it's impossible to create a type value so we raise
# the error.
if
not
hasattr
(
self
,
'type'
)
:
raise
ValidationError
(
"Le type d'ip choisi n'est pas valide"
)
self
.
filter_macaddress
()
self
.
mac_address
=
str
(
EUI
(
self
.
mac_address
))
or
None
if
not
self
.
ipv4
or
self
.
type
.
ip_type
!=
self
.
ipv4
.
ip_type
:
self
.
assign_ipv4
()
super
(
Interface
,
self
).
clean
(
*
args
,
**
kwargs
)
def
assign_ipv4
(
self
):
""" Assigne une ip à l'interface """
free_ips
=
self
.
type
.
ip_type
.
free_ip
()
...
...
@@ -494,6 +483,37 @@ class Interface(models.Model):
self
.
clean
()
self
.
save
()
def
has_private_ip
(
self
):
""" True si l'ip associée est privée"""
if
self
.
ipv4
:
return
IPAddress
(
str
(
self
.
ipv4
)).
is_private
()
else
:
return
False
def
may_have_port_open
(
self
):
""" True si l'interface a une ip et une ip publique.
Permet de ne pas exporter des ouvertures sur des ip privées
(useless)"""
return
self
.
ipv4
and
not
self
.
has_private_ip
()
def
clean
(
self
,
*
args
,
**
kwargs
):
""" Formate l'addresse mac en mac_bare (fonction filter_mac)
et assigne une ipv4 dans le bon range si inexistante ou incohérente"""
# If type was an invalid value, django won't create an attribute type
# but try clean() as we may be able to create it from another value
# so even if the error as yet been detected at this point, django
# continues because the error might not prevent us from creating the
# instance.
# But in our case, it's impossible to create a type value so we raise
# the error.
if
not
hasattr
(
self
,
'type'
)
:
raise
ValidationError
(
"Le type d'ip choisi n'est pas valide"
)
self
.
filter_macaddress
()
self
.
mac_address
=
str
(
EUI
(
self
.
mac_address
))
or
None
if
not
self
.
ipv4
or
self
.
type
.
ip_type
!=
self
.
ipv4
.
ip_type
:
self
.
assign_ipv4
()
super
(
Interface
,
self
).
clean
(
*
args
,
**
kwargs
)
def
save
(
self
,
*
args
,
**
kwargs
):
self
.
filter_macaddress
()
# On verifie la cohérence en forçant l'extension par la méthode
...
...
@@ -510,19 +530,6 @@ class Interface(models.Model):
domain
=
None
return
str
(
domain
)
def
has_private_ip
(
self
):
""" True si l'ip associée est privée"""
if
self
.
ipv4
:
return
IPAddress
(
str
(
self
.
ipv4
)).
is_private
()
else
:
return
False
def
may_have_port_open
(
self
):
""" True si l'interface a une ip et une ip publique.
Permet de ne pas exporter des ouvertures sur des ip privées
(useless)"""
return
self
.
ipv4
and
not
self
.
has_private_ip
()
class
Domain
(
models
.
Model
):
""" Objet domain. Enregistrement A et CNAME en même temps : permet de
...
...
machines/templates/machines/aff_machines.html
View file @
a12a5196
...
...
@@ -83,6 +83,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
</td>
<td>
{{ interface.mac_address }}
<br>
{{ interface.manufacturer }}
</td>
<td>
<b>
IPv4
</b>
{{ interface.ipv4 }}
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment