~ubuntu-branches/ubuntu/raring/nova/raring-proposed

« back to all changes in this revision

Viewing changes to nova/api/openstack/compute/contrib/floating_ips.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Adam Gandelman, Chuck Short
  • Date: 2012-11-23 09:04:58 UTC
  • mfrom: (1.1.66)
  • Revision ID: package-import@ubuntu.com-20121123090458-91565o7aev1i1h71
Tags: 2013.1~g1-0ubuntu1
[ Adam Gandelman ]
* debian/control: Ensure novaclient is upgraded with nova,
  require python-keystoneclient >= 1:2.9.0. (LP: #1073289)
* debian/patches/{ubuntu/*, rbd-security.patch}: Dropped, applied
  upstream.
* debian/control: Add python-testtools to Build-Depends.

[ Chuck Short ]
* New upstream version.
* Refreshed debian/patches/avoid_setuptools_git_dependency.patch.
* debian/rules: FTBFS if missing binaries.
* debian/nova-scheudler.install: Add missing rabbit-queues and
  nova-rpc-zmq-receiver.
* Remove nova-volume since it doesnt exist anymore, transition to cinder-*.
* debian/rules: install apport hook in the right place.
* debian/patches/ubuntu-show-tests.patch: Display test failures.
* debian/control: Add depends on genisoimage
* debian/control: Suggest guestmount.
* debian/control: Suggest websockify. (LP: #1076442)
* debian/nova.conf: Disable nova-volume service.
* debian/control: Depend on xen-system-* rather than the hypervisor.
* debian/control, debian/mans/nova-conductor.8, debian/nova-conductor.init,
  debian/nova-conductor.install, debian/nova-conductor.logrotate
  debian/nova-conductor.manpages, debian/nova-conductor.postrm
  debian/nova-conductor.upstart.in: Add nova-conductor service.
* debian/control: Add python-fixtures as a build deps.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
from nova import exception
28
28
from nova import network
29
29
from nova.openstack.common import log as logging
30
 
from nova import utils
 
30
from nova.openstack.common import uuidutils
31
31
 
32
32
 
33
33
LOG = logging.getLogger(__name__)
92
92
    try:
93
93
        self.network_api.disassociate_floating_ip(context, instance, address)
94
94
    except exception.NotAuthorized:
95
 
        raise webob.exc.HTTPUnauthorized()
 
95
        raise webob.exc.HTTPForbidden()
96
96
    except exception.FloatingIpNotAssociated:
97
97
        msg = _('Floating ip is not associated')
98
98
        raise webob.exc.HTTPBadRequest(explanation=msg)
 
99
    except exception.CannotDisassociateAutoAssignedFloatingIP:
 
100
        msg = _('Cannot disassociate auto assigned floating ip')
 
101
        raise webob.exc.HTTPForbidden(explanation=msg)
99
102
 
100
103
 
101
104
class FloatingIPController(object):
118
121
        return self.compute_api.get(context, instance_id)
119
122
 
120
123
    def _set_metadata(self, context, floating_ip):
121
 
        fixed_ip_id = floating_ip['fixed_ip_id']
122
 
        floating_ip['fixed_ip'] = self._get_fixed_ip(context,
123
 
                                                     fixed_ip_id)
124
 
        instance_uuid = None
125
 
        if floating_ip['fixed_ip']:
126
 
            instance_uuid = floating_ip['fixed_ip']['instance_uuid']
127
 
 
128
 
        if instance_uuid:
129
 
            floating_ip['instance'] = self._get_instance(context,
130
 
                                                         instance_uuid)
131
 
        else:
132
 
            floating_ip['instance'] = None
 
124
        # When Quantum v2 API is used, 'fixed_ip' and 'instance' are
 
125
        # already set. In this case we don't need to update the fields.
 
126
 
 
127
        if 'fixed_ip' not in floating_ip:
 
128
            fixed_ip_id = floating_ip['fixed_ip_id']
 
129
            floating_ip['fixed_ip'] = self._get_fixed_ip(context,
 
130
                                                         fixed_ip_id)
 
131
        if 'instance' not in floating_ip:
 
132
            instance_uuid = None
 
133
            if floating_ip['fixed_ip']:
 
134
                instance_uuid = floating_ip['fixed_ip']['instance_uuid']
 
135
 
 
136
            if instance_uuid:
 
137
                floating_ip['instance'] = self._get_instance(context,
 
138
                                                             instance_uuid)
 
139
            else:
 
140
                floating_ip['instance'] = None
133
141
 
134
142
    @wsgi.serializers(xml=FloatingIPTemplate)
135
143
    def show(self, req, id):
140
148
        try:
141
149
            floating_ip = self.network_api.get_floating_ip(context, id)
142
150
        except exception.NotFound:
143
 
            raise webob.exc.HTTPNotFound()
 
151
            msg = _("Floating ip not found for id %s") % id
 
152
            raise webob.exc.HTTPNotFound(explanation=msg)
144
153
 
145
154
        self._set_metadata(context, floating_ip)
146
155
 
175
184
                nmfi.message = _("No more floating ips in pool %s.") % pool
176
185
            else:
177
186
                nmfi.message = _("No more floating ips available.")
178
 
            raise nmfi
 
187
            raise
179
188
 
180
189
        return _translate_floating_ip_view(ip)
181
190
 
184
193
        authorize(context)
185
194
 
186
195
        # get the floating ip object
187
 
        floating_ip = self.network_api.get_floating_ip(context, id)
 
196
        try:
 
197
            floating_ip = self.network_api.get_floating_ip(context, id)
 
198
        except exception.NotFound:
 
199
            msg = _("Floating ip not found for id %s") % id
 
200
            raise webob.exc.HTTPNotFound(explanation=msg)
188
201
        address = floating_ip['address']
189
202
 
190
203
        # get the associated instance object (if any)
254
267
        except exception.NoFloatingIpInterface:
255
268
            msg = _('l3driver call to add floating ip failed')
256
269
            raise webob.exc.HTTPBadRequest(explanation=msg)
 
270
        except (exception.FloatingIpNotFoundForAddress,
 
271
                exception.NotAuthorized):
 
272
            msg = _('floating ip not found')
 
273
            raise webob.exc.HTTPNotFound(explanation=msg)
257
274
        except Exception:
258
275
            msg = _('Error. Unable to associate floating ip')
259
276
            LOG.exception(msg)
277
294
            raise webob.exc.HTTPBadRequest(explanation=msg)
278
295
 
279
296
        # get the floating ip object
280
 
        floating_ip = self.network_api.get_floating_ip_by_address(context,
281
 
                                                                  address)
 
297
        try:
 
298
            floating_ip = self.network_api.get_floating_ip_by_address(context,
 
299
                                                                      address)
 
300
        except exception.FloatingIpNotFoundForAddress:
 
301
            msg = _("floating ip not found")
 
302
            raise webob.exc.HTTPNotFound(explanation=msg)
 
303
 
282
304
        # get the associated instance object (if any)
283
305
        instance = get_instance_by_floating_ip_addr(self, context, address)
284
306
 
285
307
        # disassociate if associated
286
308
        if (instance and
287
309
            floating_ip.get('fixed_ip_id') and
288
 
            (utils.is_uuid_like(id) and
 
310
            (uuidutils.is_uuid_like(id) and
289
311
             [instance['uuid'] == id] or
290
312
             [instance['id'] == id])[0]):
291
313
            disassociate_floating_ip(self, context, instance, address)