diff --git a/magnum/api/controllers/v1/baymodel.py b/magnum/api/controllers/v1/baymodel.py index df35cb72df..73fbf9339c 100644 --- a/magnum/api/controllers/v1/baymodel.py +++ b/magnum/api/controllers/v1/baymodel.py @@ -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), diff --git a/magnum/api/controllers/v1/types.py b/magnum/api/controllers/v1/types.py index ace920b505..c5540d507d 100644 --- a/magnum/api/controllers/v1/types.py +++ b/magnum/api/controllers/v1/types.py @@ -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)) diff --git a/requirements.txt b/requirements.txt index f68a91649c..8ccc0d3401 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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