Ejemplo n.º 1
0
 def test_id_to_ec2_id(self):
     self.assertEqual(ec2utils.id_to_ec2_id(30), 'i-0000001e')
     self.assertEqual(ec2utils.id_to_ec2_id(29, 'ami-%08x'), 'ami-0000001d')
     self.assertEqual(ec2utils.id_to_ec2_snap_id(28), 'snap-0000001c')
     self.assertEqual(ec2utils.id_to_ec2_vol_id(27), 'vol-0000001b')
Ejemplo n.º 2
0
 def __call__(self, req):
     context = req.environ['engine.context']
     api_request = req.environ['ec2.request']
     result = None
     try:
         result = api_request.invoke(context)
     except exception.InstanceNotFound as ex:
         LOG.info(_('InstanceNotFound raised: %s'), unicode(ex),
                  context=context)
         ec2_id = ec2utils.id_to_ec2_id(ex.kwargs['instance_id'])
         message = ex.message % {'instance_id': ec2_id}
         return self._error(req, context, type(ex).__name__, message)
     except exception.VolumeNotFound as ex:
         LOG.info(_('VolumeNotFound raised: %s'), unicode(ex),
                  context=context)
         ec2_id = ec2utils.id_to_ec2_vol_id(ex.kwargs['volume_id'])
         message = ex.message % {'volume_id': ec2_id}
         return self._error(req, context, type(ex).__name__, message)
     except exception.SnapshotNotFound as ex:
         LOG.info(_('SnapshotNotFound raised: %s'), unicode(ex),
                  context=context)
         ec2_id = ec2utils.id_to_ec2_snap_id(ex.kwargs['snapshot_id'])
         message = ex.message % {'snapshot_id': ec2_id}
         return self._error(req, context, type(ex).__name__, message)
     except exception.NotFound as ex:
         LOG.info(_('NotFound raised: %s'), unicode(ex), context=context)
         return self._error(req, context, type(ex).__name__, unicode(ex))
     except exception.ApiError as ex:
         LOG.exception(_('ApiError raised: %s'), unicode(ex),
                       context=context)
         if ex.code:
             return self._error(req, context, ex.code, unicode(ex))
         else:
             return self._error(req, context, type(ex).__name__,
                                unicode(ex))
     except exception.KeyPairExists as ex:
         LOG.debug(_('KeyPairExists raised: %s'), unicode(ex),
                  context=context)
         return self._error(req, context, type(ex).__name__, unicode(ex))
     except exception.InvalidParameterValue as ex:
         LOG.debug(_('InvalidParameterValue raised: %s'), unicode(ex),
                  context=context)
         return self._error(req, context, type(ex).__name__, unicode(ex))
     except exception.InvalidPortRange as ex:
         LOG.debug(_('InvalidPortRange raised: %s'), unicode(ex),
                  context=context)
         return self._error(req, context, type(ex).__name__, unicode(ex))
     except exception.NotAuthorized as ex:
         LOG.info(_('NotAuthorized raised: %s'), unicode(ex),
                 context=context)
         return self._error(req, context, type(ex).__name__, unicode(ex))
     except exception.InvalidRequest as ex:
         LOG.debug(_('InvalidRequest raised: %s'), unicode(ex),
                  context=context)
         return self._error(req, context, type(ex).__name__, unicode(ex))
     except Exception as ex:
         extra = {'environment': req.environ}
         LOG.exception(_('Unexpected error raised: %s'), unicode(ex),
                       extra=extra, context=context)
         return self._error(req,
                            context,
                            'UnknownError',
                            _('An unknown error has occurred. '
                            'Please try your request again.'))
     else:
         resp = webob.Response()
         resp.status = 200
         resp.headers['Content-Type'] = 'text/xml'
         resp.body = str(result)
         return resp