Fix the ipaddress validate issue

Right now the jenkins jobs all failed with ipv4address validate.
We make ipaddress check logic use netaddr

If wsme have better IPv4AddressType changes or magnum api types usage
was not right, we can change latter. Right now, we should
make magnum work.

For netaddr it has been include in global-requirements

For wsme IPv4AddressType, check
ttps://github.com/stackforge/wsme/blob/master/wsme/types.py

Closes-Bug: #1455405
Co-Authored-By: Davanum Srinivas <davanum@gmail.com>
Change-Id: I67e6c9e0377103bf5b0cd4d120c146ef2366f440
This commit is contained in:
Kai Qiang Wu(Kennan) 2015-05-15 17:22:11 +08:00 committed by Davanum Srinivas
parent ed5b34a1a9
commit 426a9e9b67
3 changed files with 18 additions and 1 deletions

View File

@ -72,7 +72,7 @@ class BayModel(base.APIBase):
master_flavor_id = wtypes.StringType(min_length=1, max_length=255)
"""The flavor of the master node for this bay model"""
dns_nameserver = wtypes.IPv4AddressType()
dns_nameserver = types.IPv4AddressType()
"""The DNS nameserver address"""
keypair_id = wsme.wsattr(wtypes.StringType(min_length=1, max_length=255),

View File

@ -15,7 +15,9 @@
# License for the specific language governing permissions and limitations
# under the License.
import netaddr
from oslo_utils import strutils
import six
import wsme
from wsme import types as wtypes
@ -203,3 +205,17 @@ class JsonPatchType(wtypes.Base):
if patch.value:
ret['value'] = patch.value
return ret
class IPv4AddressType(wtypes.UserType):
"""A simple IPv4 type."""
basetype = six.string_types
name = "ipv4address"
@staticmethod
def validate(value):
try:
netaddr.IPAddress(value, version=4, flags=netaddr.INET_PTON)
except netaddr.AddrFormatError as e:
raise ValueError(six.text_type(e))

View File

@ -27,3 +27,4 @@ taskflow>=0.7.1
WSME>=0.6
docker-py>=1.1.0 # Apache-2.0
jsonpatch>=1.1
netaddr>=0.7.12