diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-03-05 13:26:37 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-03-05 13:26:37 +0000 |
| commit | 1a83c02299dc9331ec5e973145ff22ebb6efcd22 (patch) | |
| tree | dcef42c5f44ea3ea9c731ec1a9bb6f4ba300cc5a /nova/api | |
| parent | 899d518aec818bc7609f523baa6bc1dfd45d2ece (diff) | |
| parent | 481c314d6a54965fe6e0972995c6ad9afa86a908 (diff) | |
Merge "Standarize ip validation along the code"
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/ec2/__init__.py | 2 | ||||
| -rw-r--r-- | nova/api/openstack/compute/contrib/floating_ip_dns.py | 11 | ||||
| -rw-r--r-- | nova/api/openstack/compute/servers.py | 9 | ||||
| -rw-r--r-- | nova/api/validator.py | 9 |
4 files changed, 5 insertions, 26 deletions
diff --git a/nova/api/ec2/__init__.py b/nova/api/ec2/__init__.py index e094cf0b3..7ce18685b 100644 --- a/nova/api/ec2/__init__.py +++ b/nova/api/ec2/__init__.py @@ -442,7 +442,7 @@ class Validator(wsgi.Middleware): 'image_id': validator.validate_ec2_id, 'attribute': validator.validate_str(), 'image_location': validator.validate_image_path, - 'public_ip': validator.validate_ipv4, + 'public_ip': utils.is_valid_ipv4, 'region_name': validator.validate_str(), 'group_name': validator.validate_str(max_length=255), 'group_description': validator.validate_str(max_length=255), diff --git a/nova/api/openstack/compute/contrib/floating_ip_dns.py b/nova/api/openstack/compute/contrib/floating_ip_dns.py index bddf3580c..5caea9ffa 100644 --- a/nova/api/openstack/compute/contrib/floating_ip_dns.py +++ b/nova/api/openstack/compute/contrib/floating_ip_dns.py @@ -14,7 +14,6 @@ # License for the specific language governing permissions and limitations # under the License -import socket import urllib import webob @@ -25,6 +24,7 @@ from nova.api.openstack import xmlutil from nova import exception from nova import network from nova.openstack.common import log as logging +from nova import utils LOG = logging.getLogger(__name__) @@ -210,15 +210,8 @@ class FloatingIPDNSEntryController(object): floating_ip = None # Check whether id is a valid ipv4/ipv6 address. - try: - socket.inet_pton(socket.AF_INET, id) + if utils.is_valid_ipv4(id) or utils.is_valid_ipv6(id): floating_ip = id - except socket.error: - try: - socket.inet_pton(socket.AF_INET6, id) - floating_ip = id - except socket.error: - pass if floating_ip: entries = self.network_api.get_dns_entries_by_address(context, diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py index 05aa7b238..532c5b0fa 100644 --- a/nova/api/openstack/compute/servers.py +++ b/nova/api/openstack/compute/servers.py @@ -17,7 +17,6 @@ import base64 import os import re -import socket from oslo.config import cfg import webob @@ -704,16 +703,12 @@ class Controller(wsgi.Controller): raise exc.HTTPBadRequest(explanation=expl) def _validate_access_ipv4(self, address): - try: - socket.inet_aton(address) - except socket.error: + if not utils.is_valid_ipv4(address): expl = _('accessIPv4 is not proper IPv4 format') raise exc.HTTPBadRequest(explanation=expl) def _validate_access_ipv6(self, address): - try: - socket.inet_pton(socket.AF_INET6, address) - except socket.error: + if not utils.is_valid_ipv6(address): expl = _('accessIPv6 is not proper IPv6 format') raise exc.HTTPBadRequest(explanation=expl) diff --git a/nova/api/validator.py b/nova/api/validator.py index 9304387fd..2e7356391 100644 --- a/nova/api/validator.py +++ b/nova/api/validator.py @@ -18,7 +18,6 @@ import base64 import re -import socket from nova.openstack.common import log as logging @@ -94,14 +93,6 @@ def validate_image_path(val): return True -def validate_ipv4(addr): - try: - socket.inet_aton(addr) - except (socket.error, TypeError): - return False - return True - - def validate_user_data(user_data): """Check if the user_data is encoded properly.""" try: |
