Quand un switch n'existe pas, il faut planter.
This commit is contained in:
parent
4205d73132
commit
b65466de08
2 changed files with 9 additions and 2 deletions
|
@ -3,7 +3,7 @@
|
|||
|
||||
import os
|
||||
|
||||
from .switch import HPSwitch
|
||||
from .switch import HPSwitch, SwitchNotFound
|
||||
from .tools import trace_mac
|
||||
|
||||
import gestion.config.snmp as config_snmp
|
||||
|
|
|
@ -10,6 +10,10 @@ from .snmp import SNMPClient
|
|||
from .mac import format_mac, MACFactory
|
||||
from .defaults import OPERSTATUS, ADMINSTATUS, ETHSPEED, REV_ETHSPEED
|
||||
|
||||
class SwitchNotFound(Exception):
|
||||
"""Erreur basique quand le switch n'est pas trouvé"""
|
||||
pass
|
||||
|
||||
class HPSwitchFactory(object):
|
||||
"""Factory stockant les switches"""
|
||||
|
||||
|
@ -44,7 +48,10 @@ class HPSwitch(object):
|
|||
try:
|
||||
__switch = socket.gethostbyname_ex(switch)[0]
|
||||
except socket.gaierror:
|
||||
__switch = switch
|
||||
try:
|
||||
netaddr.IPAddress(switch)
|
||||
except netaddr.AddrFormatError:
|
||||
raise SwitchNotFound
|
||||
|
||||
switch_object = HPSwitchFactory.get_switch(__switch)
|
||||
if switch_object is None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue