projects
/
contrib
/
cloudeebus.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
9a24e83
)
customize netmask error messages, factorize code
author
Luc Yriarte
<luc.yriarte@intel.com>
Thu, 28 Mar 2013 14:21:23 +0000
(15:21 +0100)
committer
Luc Yriarte
<luc.yriarte@intel.com>
Thu, 28 Mar 2013 14:21:23 +0000
(15:21 +0100)
cloudeebus/cloudeebus.py
patch
|
blob
|
history
diff --git
a/cloudeebus/cloudeebus.py
b/cloudeebus/cloudeebus.py
index
7209aea
..
6224847
100755
(executable)
--- a/
cloudeebus/cloudeebus.py
+++ b/
cloudeebus/cloudeebus.py
@@
-56,7
+56,6
@@
NETMASK = []
###############################################################################
def ipV4ToHex(mask):
## Convert an ip or an IP mask (such as ip/24 or ip/255.255.255.0) in hex value (32bits)
###############################################################################
def ipV4ToHex(mask):
## Convert an ip or an IP mask (such as ip/24 or ip/255.255.255.0) in hex value (32bits)
- invalidMask = False
maskHex = 0
byte = 0
if mask.rfind(".") == -1:
maskHex = 0
byte = 0
if mask.rfind(".") == -1:
@@
-64,23
+63,20
@@
def ipV4ToHex(mask):
maskHex = (2**(int(mask))-1)
maskHex = maskHex << (32-int(mask))
else:
maskHex = (2**(int(mask))-1)
maskHex = maskHex << (32-int(mask))
else:
- invalidMask = invalidMask or True
+ raise Exception("Illegal mask (larger than 32 bits) " + mask)
else:
maskField = mask.split(".")
# Check if mask has four fields (byte)
else:
maskField = mask.split(".")
# Check if mask has four fields (byte)
- invalidMask = invalidMask or len(maskField) != 4
+ if len(maskField) != 4:
+ raise Exception("Illegal ip address / mask (should be 4 bytes) " + mask)
for maskQuartet in maskField:
byte = int(maskQuartet)
# Check if each field is really a byte
if byte > 255:
for maskQuartet in maskField:
byte = int(maskQuartet)
# Check if each field is really a byte
if byte > 255:
- invalidMask = invalidMask or True
+ raise Exception("Illegal ip address / mask (digit larger than a byte) " + mask)
maskHex += byte
maskHex = maskHex << 8
maskHex = maskHex >> 8
maskHex += byte
maskHex = maskHex << 8
maskHex = maskHex >> 8
- if invalidMask:
- msg = "Illegal mask (or IP address) " + mask
- log.msg(msg)
- raise Exception(msg)
return maskHex
###############################################################################
return maskHex
###############################################################################