From d0683bb32a7f87492269e2f86d466f3d8927a3b2 Mon Sep 17 00:00:00 2001 From: Zhenguo Niu Date: Wed, 15 Feb 2017 19:13:04 +0800 Subject: [PATCH] Update disassociate fip API 1. Remove DELETE request body 2. Add API doc Change-Id: I2b86826427bd6d464f4da4c003ef6624a6a354a8 --- api-ref/source/v1/instance_networks.inc | 21 +++++++++++++++++++ api-ref/source/v1/parameters.yaml | 6 ++++++ mogan/api/controllers/v1/instances.py | 11 +++++----- .../controllers/v1/schemas/floating_ips.py | 10 --------- 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/api-ref/source/v1/instance_networks.inc b/api-ref/source/v1/instance_networks.inc index f3bf8274..b9d0ebbe 100644 --- a/api-ref/source/v1/instance_networks.inc +++ b/api-ref/source/v1/instance_networks.inc @@ -66,3 +66,24 @@ Request **Example request to Add (Associate) Floating IP to an instance:** .. literalinclude:: samples/instances/instance-associate-fip-req.json + + +Remove (Disassociate) Floating IP +================================= + +.. rest_method:: DELETE /v1/instances/{instance_uuid}/networks/floatingips/{fip_address} + +Removes, or disassociates, a floating IP address from an instance. + +Normal response codes: 204 + +Error response codes: badRequest(400), unauthorized(401), forbidden(403), +itemNotFound(404), conflict(409) + +Request +------- + +.. rest_parameters:: parameters.yaml + + - instance_uuid: instance_ident + - fip_address: address_path diff --git a/api-ref/source/v1/parameters.yaml b/api-ref/source/v1/parameters.yaml index 210c103d..c1d2d44f 100644 --- a/api-ref/source/v1/parameters.yaml +++ b/api-ref/source/v1/parameters.yaml @@ -9,6 +9,12 @@ openstack-request-id: type: string # variables in path +address_path: + description: | + The floating IP address. + in: path + required: true + type: string api_version: in: path required: true diff --git a/mogan/api/controllers/v1/instances.py b/mogan/api/controllers/v1/instances.py index 0e9d2a44..60248b6e 100644 --- a/mogan/api/controllers/v1/instances.py +++ b/mogan/api/controllers/v1/instances.py @@ -207,17 +207,18 @@ class FloatingIPController(InstanceControllerBase): msg, status_code=http_client.BAD_REQUEST) @policy.authorize_wsgi("mogan:instance", "disassociate_floatingip") - @expose.expose(None, types.uuid, types.jsontype, + @expose.expose(None, types.uuid, wtypes.text, status_code=http_client.NO_CONTENT) - def delete(self, instance_uuid, floatingip): + def delete(self, instance_uuid, address): """Dissociate floating_ip from an instance. :param instance_uuid: UUID of a instance. :param floatingip: The floating IP within the request body. """ - validation.check_schema(floatingip, fip_schemas.remove_floating_ip) - address = floatingip['address'] - + if not netutils.is_valid_ipv4(address): + msg = "Invalid IP address %s" % address + raise wsme.exc.ClientSideError( + msg, status_code=http_client.BAD_REQUEST) # get the floating ip object try: floating_ip = self.network_api.get_floating_ip_by_address( diff --git a/mogan/api/controllers/v1/schemas/floating_ips.py b/mogan/api/controllers/v1/schemas/floating_ips.py index 7064a889..b3429f96 100644 --- a/mogan/api/controllers/v1/schemas/floating_ips.py +++ b/mogan/api/controllers/v1/schemas/floating_ips.py @@ -26,13 +26,3 @@ add_floating_ip = { 'required': ['address'], 'additionalProperties': False } - - -remove_floating_ip = { - 'type': 'object', - 'properties': { - 'address': parameter_types.ip_address, - }, - 'required': ['address'], - 'additionalProperties': False -}