summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorAnthony Young <sleepsonthefloor@gmail.com>2011-08-19 13:15:42 -0700
committerAnthony Young <sleepsonthefloor@gmail.com>2011-08-19 13:15:42 -0700
commit5366332a84b89bc5a056bd7f43e528a908e8d188 (patch)
tree4851977e134b120d699549930bc7533ba2a5cba1 /nova/api
parent65d7db1136557b7af1f0b9413bacc8fc59e7211f (diff)
downloadnova-5366332a84b89bc5a056bd7f43e528a908e8d188.tar.gz
nova-5366332a84b89bc5a056bd7f43e528a908e8d188.tar.xz
nova-5366332a84b89bc5a056bd7f43e528a908e8d188.zip
incorporate feedback from brian waldon and brian lamar. Move associate/disassociate to server actions
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/contrib/floating_ips.py69
1 files changed, 45 insertions, 24 deletions
diff --git a/nova/api/openstack/contrib/floating_ips.py b/nova/api/openstack/contrib/floating_ips.py
index 2f5fdd001..b305ebdcb 100644
--- a/nova/api/openstack/contrib/floating_ips.py
+++ b/nova/api/openstack/contrib/floating_ips.py
@@ -15,8 +15,9 @@
# 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 webob import exc
+import webob
+from nova import compute
from nova import exception
from nova import log as logging
from nova import network
@@ -71,7 +72,7 @@ class FloatingIPController(object):
try:
floating_ip = self.network_api.get_floating_ip(context, id)
except exception.NotFound:
- return faults.Fault(exc.HTTPNotFound())
+ return faults.Fault(webob.exc.HTTPNotFound())
return _translate_floating_ip_view(floating_ip)
@@ -110,40 +111,49 @@ class FloatingIPController(object):
self.network_api.release_floating_ip(context,
address=floating_ip['address'])
- return exc.HTTPAccepted()
+ return webob.exc.HTTPAccepted()
- def associate(self, req, id, body):
- """PUT /floating_ips/{id}/associate fixed ip in body """
+ def _get_ip_by_id(self, context, value):
+ """Checks that value is id and then returns its address."""
+ return self.network_api.get_floating_ip(context, value)['address']
+
+
+class Floating_ips(extensions.ExtensionDescriptor):
+ def __init__(self):
+ self.compute_api = compute.API()
+ self.network_api = network.API()
+ super(Floating_ips, self).__init__()
+
+ def _add_floating_ip(self, input_dict, req, instance_id):
+ """Associate floating_ip to an instance."""
context = req.environ['nova.context']
- floating_ip = self._get_ip_by_id(context, id)
- fixed_ip = body['floating_ip']['fixed_ip']
+ try:
+ address = input_dict['addFloatingIp']['address']
+ except KeyError:
+ msg = _("Address not specified")
+ raise webob.exc.HTTPBadRequest(explanation=msg)
- self.network_api.associate_floating_ip(context,
- floating_ip, fixed_ip)
+ self.compute_api.associate_floating_ip(context, instance_id, address)
- floating_ip = self.network_api.get_floating_ip(context, id)
- return _translate_floating_ip_view(floating_ip)
+ return webob.Response(status_int=202)
- def disassociate(self, req, id, body=None):
- """PUT /floating_ips/{id}/disassociate """
+ def _remove_floating_ip(self, input_dict, req, instance_id):
+ """Dissociate floating_ip from an instance."""
context = req.environ['nova.context']
- floating_ip = self.network_api.get_floating_ip(context, id)
- address = floating_ip['address']
- # no-op if this ip is already disassociated
+ try:
+ address = input_dict['removeFloatingIp']['address']
+ except KeyError:
+ msg = _("Address not specified")
+ raise webob.exc.HTTPBadRequest(explanation=msg)
+
+ floating_ip = self.network_api.get_floating_ip_by_ip(context, address)
if 'fixed_ip' in floating_ip:
self.network_api.disassociate_floating_ip(context, address)
- floating_ip = self.network_api.get_floating_ip(context, id)
-
- return _translate_floating_ip_view(floating_ip)
-
- def _get_ip_by_id(self, context, value):
- """Checks that value is id and then returns its address."""
- return self.network_api.get_floating_ip(context, value)['address']
+ return webob.Response(status_int=202)
-class Floating_ips(extensions.ExtensionDescriptor):
def get_name(self):
return "Floating_ips"
@@ -170,3 +180,14 @@ class Floating_ips(extensions.ExtensionDescriptor):
resources.append(res)
return resources
+
+ def get_actions(self):
+ """Return the actions the extension adds, as required by contract."""
+ actions = [
+ extensions.ActionExtension("servers", "addFloatingIp",
+ self._add_floating_ip),
+ extensions.ActionExtension("servers", "removeFloatingIp",
+ self._remove_floating_ip),
+ ]
+
+ return actions