Merge "Removes fixed ips extension from V3 API"
This commit is contained in:
@@ -90,8 +90,6 @@
|
||||
"compute_extension:v3:os-extended-volumes:attach": "",
|
||||
"compute_extension:v3:os-extended-volumes:detach": "",
|
||||
"compute_extension:fixed_ips": "rule:admin_api",
|
||||
"compute_extension:v3:os-fixed-ips:discoverable": "",
|
||||
"compute_extension:v3:os-fixed-ips": "rule:admin_api",
|
||||
"compute_extension:flavor_access": "",
|
||||
"compute_extension:v3:os-flavor-access": "",
|
||||
"compute_extension:flavor_disabled": "",
|
||||
|
@@ -1,105 +0,0 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2012, 2013 IBM Corp.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import webob.exc
|
||||
|
||||
from nova.api.openstack import extensions
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova.openstack.common.gettextutils import _
|
||||
from nova.openstack.common import log as logging
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
ALIAS = "os-fixed-ips"
|
||||
authorize = extensions.extension_authorizer('compute', 'v3:' + ALIAS)
|
||||
|
||||
|
||||
class FixedIPController(object):
|
||||
@extensions.expected_errors(404)
|
||||
def show(self, req, id):
|
||||
"""Return data about the given fixed ip."""
|
||||
context = req.environ['nova.context']
|
||||
authorize(context)
|
||||
|
||||
try:
|
||||
fixed_ip = db.fixed_ip_get_by_address_detailed(context, id)
|
||||
except (exception.FixedIpNotFoundForAddress,
|
||||
exception.FixedIpInvalid) as ex:
|
||||
raise webob.exc.HTTPNotFound(explanation=ex.format_message())
|
||||
|
||||
fixed_ip_info = {"fixed_ip": {}}
|
||||
if not fixed_ip[1]:
|
||||
msg = _("Fixed IP %s has been deleted") % id
|
||||
raise webob.exc.HTTPNotFound(explanation=msg)
|
||||
|
||||
fixed_ip_info['fixed_ip']['cidr'] = fixed_ip[1]['cidr']
|
||||
fixed_ip_info['fixed_ip']['address'] = fixed_ip[0]['address']
|
||||
|
||||
if fixed_ip[2]:
|
||||
fixed_ip_info['fixed_ip']['hostname'] = fixed_ip[2]['hostname']
|
||||
fixed_ip_info['fixed_ip']['host'] = fixed_ip[2]['host']
|
||||
else:
|
||||
fixed_ip_info['fixed_ip']['hostname'] = None
|
||||
fixed_ip_info['fixed_ip']['host'] = None
|
||||
|
||||
return fixed_ip_info
|
||||
|
||||
@extensions.expected_errors((400, 404))
|
||||
def action(self, req, id, body):
|
||||
context = req.environ['nova.context']
|
||||
authorize(context)
|
||||
if 'reserve' in body:
|
||||
LOG.debug(_("Reserving IP address %s") % id)
|
||||
return self._set_reserved(context, id, True)
|
||||
elif 'unreserve' in body:
|
||||
LOG.debug(_("Unreserving IP address %s") % id)
|
||||
return self._set_reserved(context, id, False)
|
||||
else:
|
||||
raise webob.exc.HTTPBadRequest(
|
||||
explanation="No valid action specified")
|
||||
|
||||
def _set_reserved(self, context, address, reserved):
|
||||
try:
|
||||
fixed_ip = db.fixed_ip_get_by_address(context, address)
|
||||
db.fixed_ip_update(context, fixed_ip['address'],
|
||||
{'reserved': reserved})
|
||||
except (exception.FixedIpNotFoundForAddress,
|
||||
exception.FixedIpInvalid) as ex:
|
||||
msg = _("Fixed IP %s not found") % address
|
||||
raise webob.exc.HTTPNotFound(explanation=msg)
|
||||
|
||||
return webob.exc.HTTPAccepted()
|
||||
|
||||
|
||||
class FixedIPs(extensions.V3APIExtensionBase):
|
||||
"""Fixed IPs support."""
|
||||
|
||||
name = "FixedIPs"
|
||||
alias = ALIAS
|
||||
namespace = "http://docs.openstack.org/compute/ext/fixed_ips/api/v3"
|
||||
version = 1
|
||||
|
||||
def get_resources(self):
|
||||
member_actions = {'action': 'POST'}
|
||||
resources = [
|
||||
extensions.ResourceExtension('os-fixed-ips',
|
||||
FixedIPController(),
|
||||
member_actions=member_actions)]
|
||||
return resources
|
||||
|
||||
def get_controller_extensions(self):
|
||||
return []
|
@@ -1,205 +0,0 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2012 IBM Corp.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import webob
|
||||
|
||||
from nova.api.openstack.compute.plugins.v3 import fixed_ips
|
||||
from nova import context
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova import test
|
||||
from nova.tests.api.openstack import fakes
|
||||
|
||||
|
||||
fake_fixed_ips = [{'id': 1,
|
||||
'address': '192.168.1.1',
|
||||
'network_id': 1,
|
||||
'virtual_interface_id': 1,
|
||||
'instance_uuid': '1',
|
||||
'allocated': False,
|
||||
'leased': False,
|
||||
'reserved': False,
|
||||
'host': None,
|
||||
'deleted': False},
|
||||
{'id': 2,
|
||||
'address': '192.168.1.2',
|
||||
'network_id': 1,
|
||||
'virtual_interface_id': 2,
|
||||
'instance_uuid': '2',
|
||||
'allocated': False,
|
||||
'leased': False,
|
||||
'reserved': False,
|
||||
'host': None,
|
||||
'deleted': False},
|
||||
{'id': 3,
|
||||
'address': '10.0.0.2',
|
||||
'network_id': 1,
|
||||
'virtual_interface_id': 3,
|
||||
'instance_uuid': '3',
|
||||
'allocated': False,
|
||||
'leased': False,
|
||||
'reserved': False,
|
||||
'host': None,
|
||||
'deleted': True},
|
||||
]
|
||||
|
||||
|
||||
def fake_fixed_ip_get_by_address(context, address):
|
||||
for fixed_ip in fake_fixed_ips:
|
||||
if fixed_ip['address'] == address and not fixed_ip['deleted']:
|
||||
return fixed_ip
|
||||
raise exception.FixedIpNotFoundForAddress(address=address)
|
||||
|
||||
|
||||
def fake_fixed_ip_get_by_address_detailed(context, address):
|
||||
network = {'id': 1,
|
||||
'cidr': "192.168.1.0/24"}
|
||||
for fixed_ip in fake_fixed_ips:
|
||||
if fixed_ip['address'] == address and not fixed_ip['deleted']:
|
||||
return (fixed_ip, FakeModel(network), None)
|
||||
raise exception.FixedIpNotFoundForAddress(address=address)
|
||||
|
||||
|
||||
def fake_fixed_ip_update(context, address, values):
|
||||
fixed_ip = fake_fixed_ip_get_by_address(context, address)
|
||||
if fixed_ip is None:
|
||||
raise exception.FixedIpNotFoundForAddress(address=address)
|
||||
else:
|
||||
for key in values:
|
||||
fixed_ip[key] = values[key]
|
||||
|
||||
|
||||
class FakeModel(object):
|
||||
"""Stubs out for model."""
|
||||
def __init__(self, values):
|
||||
self.values = values
|
||||
|
||||
def __getattr__(self, name):
|
||||
return self.values[name]
|
||||
|
||||
def __getitem__(self, key):
|
||||
if key in self.values:
|
||||
return self.values[key]
|
||||
else:
|
||||
raise NotImplementedError()
|
||||
|
||||
def __repr__(self):
|
||||
return '<FakeModel: %s>' % self.values
|
||||
|
||||
|
||||
def fake_network_get_all(context):
|
||||
network = {'id': 1,
|
||||
'cidr': "192.168.1.0/24"}
|
||||
return [FakeModel(network)]
|
||||
|
||||
|
||||
class FixedIpTest(test.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(FixedIpTest, self).setUp()
|
||||
|
||||
self.stubs.Set(db, "fixed_ip_get_by_address",
|
||||
fake_fixed_ip_get_by_address)
|
||||
self.stubs.Set(db, "fixed_ip_get_by_address_detailed",
|
||||
fake_fixed_ip_get_by_address_detailed)
|
||||
self.stubs.Set(db, "fixed_ip_update", fake_fixed_ip_update)
|
||||
|
||||
self.context = context.get_admin_context()
|
||||
self.controller = fixed_ips.FixedIPController()
|
||||
|
||||
def test_fixed_ips_get(self):
|
||||
req = fakes.HTTPRequest.blank('/v3/fake/os-fixed-ips/192.168.1.1')
|
||||
res_dict = self.controller.show(req, '192.168.1.1')
|
||||
response = {'fixed_ip': {'cidr': '192.168.1.0/24',
|
||||
'hostname': None,
|
||||
'host': None,
|
||||
'address': '192.168.1.1'}}
|
||||
self.assertEqual(response, res_dict)
|
||||
|
||||
def test_fixed_ips_get_bad_ip_fail(self):
|
||||
req = fakes.HTTPRequest.blank('/v3/fake/os-fixed-ips/10.0.0.1')
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.show, req,
|
||||
'10.0.0.1')
|
||||
|
||||
def test_fixed_ips_get_invalid_ip_address(self):
|
||||
req = fakes.HTTPRequest.blank('/v3/os-fixed-ips/inv.ali.d.ip')
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.show, req,
|
||||
'inv.ali.d.ip')
|
||||
|
||||
def test_fixed_ips_get_deleted_ip_fail(self):
|
||||
req = fakes.HTTPRequest.blank('/v3/fake/os-fixed-ips/10.0.0.2')
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.show, req,
|
||||
'10.0.0.2')
|
||||
|
||||
def test_fixed_ip_reserve(self):
|
||||
fake_fixed_ips[0]['reserved'] = False
|
||||
body = {'reserve': None}
|
||||
req = fakes.HTTPRequest.blank(
|
||||
'/v3/fake/os-fixed-ips/192.168.1.1/action')
|
||||
result = self.controller.action(req, "192.168.1.1", body)
|
||||
|
||||
self.assertEqual('202 Accepted', result.status)
|
||||
self.assertEqual(fake_fixed_ips[0]['reserved'], True)
|
||||
|
||||
def test_fixed_ip_reserve_bad_ip(self):
|
||||
body = {'reserve': None}
|
||||
req = fakes.HTTPRequest.blank(
|
||||
'/v3/fake/os-fixed-ips/10.0.0.1/action')
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.action, req,
|
||||
'10.0.0.1', body)
|
||||
|
||||
def test_fixed_ip_reserve_invalid_ip_address(self):
|
||||
body = {'reserve': None}
|
||||
req = fakes.HTTPRequest.blank('/v3/os-fixed-ips/inv.ali.d.ip/action')
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.controller.action, req, 'inv.ali.d.ip', body)
|
||||
|
||||
def test_fixed_ip_reserve_deleted_ip(self):
|
||||
body = {'reserve': None}
|
||||
req = fakes.HTTPRequest.blank(
|
||||
'/v3/fake/os-fixed-ips/10.0.0.2/action')
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.action, req,
|
||||
'10.0.0.2', body)
|
||||
|
||||
def test_fixed_ip_unreserve(self):
|
||||
fake_fixed_ips[0]['reserved'] = True
|
||||
body = {'unreserve': None}
|
||||
req = fakes.HTTPRequest.blank(
|
||||
'/v3/fake/os-fixed-ips/192.168.1.1/action')
|
||||
result = self.controller.action(req, "192.168.1.1", body)
|
||||
|
||||
self.assertEqual('202 Accepted', result.status)
|
||||
self.assertEqual(fake_fixed_ips[0]['reserved'], False)
|
||||
|
||||
def test_fixed_ip_unreserve_bad_ip(self):
|
||||
body = {'unreserve': None}
|
||||
req = fakes.HTTPRequest.blank(
|
||||
'/v3/fake/os-fixed-ips/10.0.0.1/action')
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.action, req,
|
||||
'10.0.0.1', body)
|
||||
|
||||
def test_fixed_ip_unreserve_invalid_ip_address(self):
|
||||
body = {'unreserve': None}
|
||||
req = fakes.HTTPRequest.blank('/v3/os-fixed-ips/inv.ali.d.ip/action')
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.controller.action, req, 'inv.ali.d.ip', body)
|
||||
|
||||
def test_fixed_ip_unreserve_deleted_ip(self):
|
||||
body = {'unreserve': None}
|
||||
req = fakes.HTTPRequest.blank(
|
||||
'/v3/fake/os-fixed-ips/10.0.0.2/action')
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.action, req,
|
||||
'10.0.0.2', body)
|
@@ -72,10 +72,10 @@ class ExtensionLoadingTestCase(test.TestCase):
|
||||
|
||||
def test_extensions_blacklist(self):
|
||||
app = compute.APIRouterV3()
|
||||
self.assertIn('os-fixed-ips', app._loaded_extension_info.extensions)
|
||||
CONF.set_override('extensions_blacklist', ['os-fixed-ips'], 'osapi_v3')
|
||||
self.assertIn('os-hosts', app._loaded_extension_info.extensions)
|
||||
CONF.set_override('extensions_blacklist', ['os-hosts'], 'osapi_v3')
|
||||
app = compute.APIRouterV3()
|
||||
self.assertNotIn('os-fixed-ips', app._loaded_extension_info.extensions)
|
||||
self.assertNotIn('os-hosts', app._loaded_extension_info.extensions)
|
||||
|
||||
def test_extensions_whitelist_accept(self):
|
||||
# NOTE(maurosr): just to avoid to get an exception raised for not
|
||||
@@ -85,11 +85,11 @@ class ExtensionLoadingTestCase(test.TestCase):
|
||||
self.addCleanup(self._set_v3_core, v3_core)
|
||||
|
||||
app = compute.APIRouterV3()
|
||||
self.assertIn('os-fixed-ips', app._loaded_extension_info.extensions)
|
||||
CONF.set_override('extensions_whitelist', ['servers', 'os-fixed-ips'],
|
||||
self.assertIn('os-hosts', app._loaded_extension_info.extensions)
|
||||
CONF.set_override('extensions_whitelist', ['servers', 'os-hosts'],
|
||||
'osapi_v3')
|
||||
app = compute.APIRouterV3()
|
||||
self.assertIn('os-fixed-ips', app._loaded_extension_info.extensions)
|
||||
self.assertIn('os-hosts', app._loaded_extension_info.extensions)
|
||||
|
||||
def test_extensions_whitelist_block(self):
|
||||
# NOTE(maurosr): just to avoid to get an exception raised for not
|
||||
@@ -99,10 +99,10 @@ class ExtensionLoadingTestCase(test.TestCase):
|
||||
self.addCleanup(self._set_v3_core, v3_core)
|
||||
|
||||
app = compute.APIRouterV3()
|
||||
self.assertIn('os-fixed-ips', app._loaded_extension_info.extensions)
|
||||
self.assertIn('os-hosts', app._loaded_extension_info.extensions)
|
||||
CONF.set_override('extensions_whitelist', ['servers'], 'osapi_v3')
|
||||
app = compute.APIRouterV3()
|
||||
self.assertNotIn('os-fixed-ips', app._loaded_extension_info.extensions)
|
||||
self.assertNotIn('os-hosts', app._loaded_extension_info.extensions)
|
||||
|
||||
def test_blacklist_overrides_whitelist(self):
|
||||
# NOTE(maurosr): just to avoid to get an exception raised for not
|
||||
@@ -112,12 +112,12 @@ class ExtensionLoadingTestCase(test.TestCase):
|
||||
self.addCleanup(self._set_v3_core, v3_core)
|
||||
|
||||
app = compute.APIRouterV3()
|
||||
self.assertIn('os-fixed-ips', app._loaded_extension_info.extensions)
|
||||
CONF.set_override('extensions_whitelist', ['servers', 'os-fixed-ips'],
|
||||
self.assertIn('os-hosts', app._loaded_extension_info.extensions)
|
||||
CONF.set_override('extensions_whitelist', ['servers', 'os-hosts'],
|
||||
'osapi_v3')
|
||||
CONF.set_override('extensions_blacklist', ['os-fixed-ips'], 'osapi_v3')
|
||||
CONF.set_override('extensions_blacklist', ['os-hosts'], 'osapi_v3')
|
||||
app = compute.APIRouterV3()
|
||||
self.assertNotIn('os-fixed-ips', app._loaded_extension_info.extensions)
|
||||
self.assertNotIn('os-hosts', app._loaded_extension_info.extensions)
|
||||
self.assertIn('servers', app._loaded_extension_info.extensions)
|
||||
self.assertEqual(len(app._loaded_extension_info.extensions), 1)
|
||||
|
||||
|
@@ -170,7 +170,6 @@ policy_data = """
|
||||
"compute_extension:v3:os-extended-volumes:attach": "",
|
||||
"compute_extension:v3:os-extended-volumes:detach": "",
|
||||
"compute_extension:fixed_ips": "",
|
||||
"compute_extension:v3:os-fixed-ips": "",
|
||||
"compute_extension:flavor_access": "",
|
||||
"compute_extension:v3:os-flavor-access": "",
|
||||
"compute_extension:flavor_disabled": "",
|
||||
|
@@ -77,7 +77,6 @@ nova.api.v3.extensions =
|
||||
extended_status = nova.api.openstack.compute.plugins.v3.extended_status:ExtendedStatus
|
||||
extended_volumes = nova.api.openstack.compute.plugins.v3.extended_volumes:ExtendedVolumes
|
||||
extension_info = nova.api.openstack.compute.plugins.v3.extension_info:ExtensionInfo
|
||||
fixed_ips = nova.api.openstack.compute.plugins.v3.fixed_ips:FixedIPs
|
||||
flavors = nova.api.openstack.compute.plugins.v3.flavors:Flavors
|
||||
flavors_extraspecs = nova.api.openstack.compute.plugins.v3.flavors_extraspecs:FlavorsExtraSpecs
|
||||
flavor_access = nova.api.openstack.compute.plugins.v3.flavor_access:FlavorAccess
|
||||
|
Reference in New Issue
Block a user