-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge "Port floating_ip_pools extention to v2.1"
- Loading branch information
Showing
8 changed files
with
146 additions
and
8 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
doc/v3/api_samples/os-floating-ip-pools/floatingippools-list-resp.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"floating_ip_pools": [ | ||
{ | ||
"name": "pool1" | ||
}, | ||
{ | ||
"name": "pool2" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
nova/api/openstack/compute/plugins/v3/floating_ip_pools.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Copyright (c) 2011 X.commerce, a business unit of eBay Inc. | ||
# | ||
# 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. | ||
|
||
from nova.api.openstack import extensions | ||
from nova import network | ||
|
||
|
||
ALIAS = 'os-floating-ip-pools' | ||
authorize = extensions.extension_authorizer('compute', 'v3:' + ALIAS) | ||
|
||
|
||
def _translate_floating_ip_view(pool_name): | ||
return { | ||
'name': pool_name, | ||
} | ||
|
||
|
||
def _translate_floating_ip_pools_view(pools): | ||
return { | ||
'floating_ip_pools': [_translate_floating_ip_view(pool_name) | ||
for pool_name in pools] | ||
} | ||
|
||
|
||
class FloatingIPPoolsController(object): | ||
"""The Floating IP Pool API controller for the OpenStack API.""" | ||
|
||
def __init__(self): | ||
self.network_api = network.API() | ||
super(FloatingIPPoolsController, self).__init__() | ||
|
||
@extensions.expected_errors(()) | ||
def index(self, req): | ||
"""Return a list of pools.""" | ||
context = req.environ['nova.context'] | ||
authorize(context) | ||
pools = self.network_api.get_floating_ip_pools(context) | ||
return _translate_floating_ip_pools_view(pools) | ||
|
||
|
||
class FloatingIpPools(extensions.V3APIExtensionBase): | ||
"""Floating IPs support.""" | ||
|
||
name = "FloatingIpPools" | ||
alias = ALIAS | ||
version = 1 | ||
|
||
def get_resources(self): | ||
resource = [extensions.ResourceExtension(ALIAS, | ||
FloatingIPPoolsController())] | ||
return resource | ||
|
||
def get_controller_extensions(self): | ||
"""It's an abstract function V3APIExtensionBase and the extension | ||
will not be loaded without it. | ||
""" | ||
return [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
nova/tests/integrated/v3/api_samples/os-floating-ip-pools/floatingippools-list-resp.json.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"floating_ip_pools": [ | ||
{ | ||
"name": "%(pool1)s" | ||
}, | ||
{ | ||
"name": "%(pool2)s" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Copyright 2014 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. | ||
|
||
from nova.network import api as network_api | ||
from nova.tests.integrated.v3 import api_sample_base | ||
|
||
|
||
class FloatingIPPoolsSampleTests(api_sample_base.ApiSampleTestBaseV3): | ||
extension_name = "os-floating-ip-pools" | ||
|
||
def test_list_floatingippools(self): | ||
pool_list = ["pool1", "pool2"] | ||
|
||
def fake_get_floating_ip_pools(self, context): | ||
return pool_list | ||
|
||
self.stubs.Set(network_api.API, "get_floating_ip_pools", | ||
fake_get_floating_ip_pools) | ||
response = self._do_get('os-floating-ip-pools') | ||
subs = { | ||
'pool1': pool_list[0], | ||
'pool2': pool_list[1] | ||
} | ||
self._verify_response('floatingippools-list-resp', subs, response, 200) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters