コード例 #1
0
ファイル: __init__.py プロジェクト: YouthSun/nova
 def __call__(self, req):
     context = req.environ['nova.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)
         return self._error(req, context, type(ex).__name__, ex.message)
     except exception.VolumeNotFound as ex:
         LOG.info(_('VolumeNotFound raised: %s'), unicode(ex),
                  context=context)
         ec2_id = ec2utils.id_to_ec2_vol_id(ex.volume_id)
         message = _('Volume %s not found') % 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.snapshot_id)
         message = _('Snapshot %s not found') % 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 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
コード例 #2
0
 def __call__(self, req):
     context = req.environ['nova.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)
         return self._error(req, context, type(ex).__name__, ex.message)
     except exception.VolumeNotFound as ex:
         LOG.info(_('VolumeNotFound raised: %s'),
                  unicode(ex),
                  context=context)
         ec2_id = ec2utils.id_to_ec2_vol_id(ex.volume_id)
         message = _('Volume %s not found') % 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.snapshot_id)
         message = _('Snapshot %s not found') % 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 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
コード例 #3
0
ファイル: __init__.py プロジェクト: dido18/nova
 def __call__(self, req):
     context = req.environ["nova.context"]
     api_request = req.environ["ec2.request"]
     try:
         result = api_request.invoke(context)
     except exception.InstanceNotFound as ex:
         ec2_id = ec2utils.id_to_ec2_inst_id(ex.kwargs["instance_id"])
         message = ex.msg_fmt % {"instance_id": ec2_id}
         return ec2_error_ex(ex, req, message=message)
     except exception.VolumeNotFound as ex:
         ec2_id = ec2utils.id_to_ec2_vol_id(ex.kwargs["volume_id"])
         message = ex.msg_fmt % {"volume_id": ec2_id}
         return ec2_error_ex(ex, req, message=message)
     except exception.SnapshotNotFound as ex:
         ec2_id = ec2utils.id_to_ec2_snap_id(ex.kwargs["snapshot_id"])
         message = ex.msg_fmt % {"snapshot_id": ec2_id}
         return ec2_error_ex(ex, req, message=message)
     except (
         exception.CannotDisassociateAutoAssignedFloatingIP,
         exception.FloatingIpAssociated,
         exception.FloatingIpNotFound,
         exception.FloatingIpBadRequest,
         exception.ImageNotActive,
         exception.InvalidInstanceIDMalformed,
         exception.InvalidVolumeIDMalformed,
         exception.InvalidKeypair,
         exception.InvalidParameterValue,
         exception.InvalidPortRange,
         exception.InvalidVolume,
         exception.KeyPairExists,
         exception.KeypairNotFound,
         exception.MissingParameter,
         exception.NoFloatingIpInterface,
         exception.NoMoreFixedIps,
         exception.Forbidden,
         exception.QuotaError,
         exception.SecurityGroupExists,
         exception.SecurityGroupLimitExceeded,
         exception.SecurityGroupRuleExists,
         exception.VolumeUnattached,
         # Following aren't translated to valid EC2 errors.
         exception.ImageNotFound,
         exception.ImageNotFoundEC2,
         exception.InvalidAttribute,
         exception.InvalidRequest,
         exception.NotFound,
     ) as ex:
         return ec2_error_ex(ex, req)
     except Exception as ex:
         return ec2_error_ex(ex, req, unexpected=True)
     else:
         resp = webob.Response()
         resp.status = 200
         resp.headers["Content-Type"] = "text/xml"
         resp.body = str(result)
         return resp
コード例 #4
0
 def __call__(self, req):
     context = req.environ['nova.context']
     api_request = req.environ['ec2.request']
     result = None
     try:
         result = api_request.invoke(context)
     except exception.InstanceNotFound as ex:
         ec2_id = ec2utils.id_to_ec2_inst_id(ex.kwargs['instance_id'])
         message = ex.msg_fmt % {'instance_id': ec2_id}
         return ec2_error_ex(ex, req, message=message)
     except exception.VolumeNotFound as ex:
         ec2_id = ec2utils.id_to_ec2_vol_id(ex.kwargs['volume_id'])
         message = ex.msg_fmt % {'volume_id': ec2_id}
         return ec2_error_ex(ex, req, message=message)
     except exception.SnapshotNotFound as ex:
         ec2_id = ec2utils.id_to_ec2_snap_id(ex.kwargs['snapshot_id'])
         message = ex.msg_fmt % {'snapshot_id': ec2_id}
         return ec2_error_ex(ex, req, message=message)
     except (
             exception.CannotDisassociateAutoAssignedFloatingIP,
             exception.FloatingIpAssociated,
             exception.FloatingIpNotFound,
             exception.ImageNotActive,
             exception.InvalidInstanceIDMalformed,
             exception.InvalidKeypair,
             exception.InvalidParameterValue,
             exception.InvalidPortRange,
             exception.InvalidVolume,
             exception.KeyPairExists,
             exception.KeypairNotFound,
             exception.MissingParameter,
             exception.NoFloatingIpInterface,
             exception.NoMoreFixedIps,
             exception.NotAuthorized,
             exception.QuotaError,
             exception.QuotaError,
             exception.SecurityGroupExists,
             exception.SecurityGroupLimitExceeded,
             exception.SecurityGroupLimitExceeded,
             exception.SecurityGroupRuleExists,
             exception.VolumeUnattached,
             # Following aren't translated to valid EC2 errors.
             exception.ImageNotFound,
             exception.ImageNotFoundEC2,
             exception.InvalidAttribute,
             exception.InvalidRequest,
             exception.NotFound) as ex:
         return ec2_error_ex(ex, req)
     except Exception as ex:
         return ec2_error_ex(ex, req, unexpected=True)
     else:
         resp = webob.Response()
         resp.status = 200
         resp.headers['Content-Type'] = 'text/xml'
         resp.body = str(result)
         return resp
コード例 #5
0
ファイル: __init__.py プロジェクト: ainiaa/nova
 def __call__(self, req):
     context = req.environ['nova.context']
     api_request = req.environ['ec2.request']
     result = None
     try:
         result = api_request.invoke(context)
     except exception.InstanceNotFound as ex:
         ec2_id = ec2utils.id_to_ec2_inst_id(ex.kwargs['instance_id'])
         message = ex.msg_fmt % {'instance_id': ec2_id}
         return ec2_error_ex(ex, req, message=message)
     except exception.VolumeNotFound as ex:
         ec2_id = ec2utils.id_to_ec2_vol_id(ex.kwargs['volume_id'])
         message = ex.msg_fmt % {'volume_id': ec2_id}
         return ec2_error_ex(ex, req, message=message)
     except exception.SnapshotNotFound as ex:
         ec2_id = ec2utils.id_to_ec2_snap_id(ex.kwargs['snapshot_id'])
         message = ex.msg_fmt % {'snapshot_id': ec2_id}
         return ec2_error_ex(ex, req, message=message)
     except exception.KeyPairExists as ex:
         code = 'InvalidKeyPair.Duplicate'
         return ec2_error_ex(ex, req, code=code)
     except exception.InvalidKeypair as ex:
         code = 'InvalidKeyPair.Format'
         return ec2_error_ex(ex, req, code=code)
     except (exception.EC2APIError,
             exception.NotFound,
             exception.KeypairNotFound,
             exception.SecurityGroupExists,
             exception.InvalidParameterValue,
             exception.InvalidPortRange,
             exception.NotAuthorized,
             exception.InvalidRequest,
             exception.InvalidAttribute,
             exception.InvalidPortRange,
             exception.QuotaError,
             exception.MissingParameter,
             exception.InvalidInstanceIDMalformedEC2) as ex:
         return ec2_error_ex(ex, req)
     except Exception as ex:
         return ec2_error_ex(ex, req, unexpected=True)
     else:
         resp = webob.Response()
         resp.status = 200
         resp.headers['Content-Type'] = 'text/xml'
         resp.body = str(result)
         return resp
コード例 #6
0
ファイル: __init__.py プロジェクト: jziub/nova
 def __call__(self, req):
     context = req.environ["nova.context"]
     api_request = req.environ["ec2.request"]
     result = None
     try:
         result = api_request.invoke(context)
     except exception.InstanceNotFound as ex:
         ec2_id = ec2utils.id_to_ec2_inst_id(ex.kwargs["instance_id"])
         message = ex.msg_fmt % {"instance_id": ec2_id}
         return ec2_error_ex(ex, req, message=message)
     except exception.VolumeNotFound as ex:
         ec2_id = ec2utils.id_to_ec2_vol_id(ex.kwargs["volume_id"])
         message = ex.msg_fmt % {"volume_id": ec2_id}
         return ec2_error_ex(ex, req, message=message)
     except exception.SnapshotNotFound as ex:
         ec2_id = ec2utils.id_to_ec2_snap_id(ex.kwargs["snapshot_id"])
         message = ex.msg_fmt % {"snapshot_id": ec2_id}
         return ec2_error_ex(ex, req, message=message)
     except exception.KeyPairExists as ex:
         code = "InvalidKeyPair.Duplicate"
         return ec2_error_ex(ex, req, code=code)
     except exception.InvalidKeypair as ex:
         code = "InvalidKeyPair.Format"
         return ec2_error_ex(ex, req, code=code)
     except (
         exception.EC2APIError,
         exception.NotFound,
         exception.InvalidParameterValue,
         exception.InvalidPortRange,
         exception.NotAuthorized,
         exception.InvalidRequest,
         exception.QuotaError,
         exception.InvalidInstanceIDMalformed,
     ) as ex:
         return ec2_error_ex(ex, req)
     except Exception as ex:
         return ec2_error_ex(ex, req, unexpected=True)
     else:
         resp = webob.Response()
         resp.status = 200
         resp.headers["Content-Type"] = "text/xml"
         resp.body = str(result)
         return resp
コード例 #7
0
ファイル: __init__.py プロジェクト: bopopescu/plumgrid-nova
 def __call__(self, req):
     context = req.environ['nova.context']
     api_request = req.environ['ec2.request']
     result = None
     try:
         result = api_request.invoke(context)
     except exception.InstanceNotFound as ex:
         ec2_id = ec2utils.id_to_ec2_inst_id(ex.kwargs['instance_id'])
         message = ex.msg_fmt % {'instance_id': ec2_id}
         return ec2_error_ex(ex, req, message=message)
     except exception.VolumeNotFound as ex:
         ec2_id = ec2utils.id_to_ec2_vol_id(ex.kwargs['volume_id'])
         message = ex.msg_fmt % {'volume_id': ec2_id}
         return ec2_error_ex(ex, req, message=message)
     except exception.SnapshotNotFound as ex:
         ec2_id = ec2utils.id_to_ec2_snap_id(ex.kwargs['snapshot_id'])
         message = ex.msg_fmt % {'snapshot_id': ec2_id}
         return ec2_error_ex(ex, req, message=message)
     except exception.KeyPairExists as ex:
         code = 'InvalidKeyPair.Duplicate'
         return ec2_error_ex(ex, req, code=code)
     except exception.InvalidKeypair as ex:
         code = 'InvalidKeyPair.Format'
         return ec2_error_ex(ex, req, code=code)
     except (exception.EC2APIError, exception.NotFound,
             exception.InvalidParameterValue, exception.InvalidPortRange,
             exception.NotAuthorized, exception.InvalidRequest,
             exception.QuotaError,
             exception.InvalidInstanceIDMalformed) as ex:
         return ec2_error_ex(ex, req)
     except Exception as ex:
         return ec2_error_ex(ex, req, unexpected=True)
     else:
         resp = webob.Response()
         resp.status = 200
         resp.headers['Content-Type'] = 'text/xml'
         resp.body = str(result)
         return resp
コード例 #8
0
ファイル: test_api.py プロジェクト: renuka-apte/nova
 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")
コード例 #9
0
ファイル: __init__.py プロジェクト: isolosun/nova
    def __call__(self, req):
        context = req.environ['nova.context']
        request_id = context.request_id
        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_inst_id(ex.kwargs['instance_id'])
            message = ex.message % {'instance_id': ec2_id}
            return ec2_error(req, request_id, 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 ec2_error(req, request_id, 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 ec2_error(req, request_id, type(ex).__name__, message)
        except exception.NotFound as ex:
            LOG.info(_('NotFound raised: %s'), unicode(ex), context=context)
            return ec2_error(req, request_id, type(ex).__name__, unicode(ex))
        except exception.EC2APIError as ex:
            LOG.exception(_('EC2APIError raised: %s'), unicode(ex),
                          context=context)
            if ex.code:
                return ec2_error(req, request_id, ex.code, unicode(ex))
            else:
                return ec2_error(req, request_id, type(ex).__name__,
                                   unicode(ex))
        except exception.KeyPairExists as ex:
            LOG.debug(_('KeyPairExists raised: %s'), unicode(ex),
                     context=context)
            return ec2_error(req, request_id, type(ex).__name__, unicode(ex))
        except exception.InvalidParameterValue as ex:
            LOG.debug(_('InvalidParameterValue raised: %s'), unicode(ex),
                     context=context)
            return ec2_error(req, request_id, type(ex).__name__, unicode(ex))
        except exception.InvalidPortRange as ex:
            LOG.debug(_('InvalidPortRange raised: %s'), unicode(ex),
                     context=context)
            return ec2_error(req, request_id, type(ex).__name__, unicode(ex))
        except exception.NotAuthorized as ex:
            LOG.info(_('NotAuthorized raised: %s'), unicode(ex),
                    context=context)
            return ec2_error(req, request_id, type(ex).__name__, unicode(ex))
        except exception.InvalidRequest as ex:
            LOG.debug(_('InvalidRequest raised: %s'), unicode(ex),
                     context=context)
            return ec2_error(req, request_id, type(ex).__name__, unicode(ex))
        except exception.QuotaError as ex:
            LOG.debug(_('QuotaError raised: %s'), unicode(ex),
                      context=context)
            return ec2_error(req, request_id, type(ex).__name__, unicode(ex))
        except exception.InvalidInstanceIDMalformed as ex:
            LOG.debug(_('Invalid id: bogus (expecting "i-..."): %s'),
                        unicode(ex), context=context)
            return ec2_error(req, request_id, type(ex).__name__, unicode(ex))
        except Exception as ex:
            env = req.environ.copy()
            for k in env.keys():
                if not isinstance(env[k], basestring):
                    env.pop(k)

            LOG.exception(_('Unexpected error raised: %s'), unicode(ex))
            LOG.error(_('Environment: %s') % jsonutils.dumps(env))
            return ec2_error(req, request_id, '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
コード例 #10
0
ファイル: test_api.py プロジェクト: uruddarraju/nova
 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')
コード例 #11
0
ファイル: test_api.py プロジェクト: derekhiggins/nova
 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')
コード例 #12
0
ファイル: __init__.py プロジェクト: JacobMulero/nova
    def __call__(self, req):
        context = req.environ["nova.context"]
        request_id = context.request_id
        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_inst_id(ex.kwargs["instance_id"])
            message = ex.message % {"instance_id": ec2_id}
            return ec2_error(req, request_id, 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 ec2_error(req, request_id, 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 ec2_error(req, request_id, type(ex).__name__, message)
        except exception.NotFound as ex:
            LOG.info(_("NotFound raised: %s"), unicode(ex), context=context)
            return ec2_error(req, request_id, type(ex).__name__, unicode(ex))
        except exception.EC2APIError as ex:
            if ex.code:
                return ec2_error(req, request_id, ex.code, unicode(ex))
            else:
                return ec2_error(req, request_id, type(ex).__name__, unicode(ex))
        except exception.KeyPairExists as ex:
            LOG.debug(_("KeyPairExists raised: %s"), unicode(ex), context=context)
            code = "InvalidKeyPair.Duplicate"
            return ec2_error(req, request_id, code, unicode(ex))
        except exception.InvalidKeypair as ex:
            LOG.debug(_("InvalidKeypair raised: %s"), unicode(ex), context)
            code = "InvalidKeyPair.Format"
            return ec2_error(req, request_id, code, unicode(ex))
        except exception.InvalidParameterValue as ex:
            LOG.debug(_("InvalidParameterValue raised: %s"), unicode(ex), context=context)
            return ec2_error(req, request_id, type(ex).__name__, unicode(ex))
        except exception.InvalidPortRange as ex:
            LOG.debug(_("InvalidPortRange raised: %s"), unicode(ex), context=context)
            return ec2_error(req, request_id, type(ex).__name__, unicode(ex))
        except exception.NotAuthorized as ex:
            LOG.info(_("NotAuthorized raised: %s"), unicode(ex), context=context)
            return ec2_error(req, request_id, type(ex).__name__, unicode(ex))
        except exception.InvalidRequest as ex:
            LOG.debug(_("InvalidRequest raised: %s"), unicode(ex), context=context)
            return ec2_error(req, request_id, type(ex).__name__, unicode(ex))
        except exception.QuotaError as ex:
            LOG.debug(_("QuotaError raised: %s"), unicode(ex), context=context)
            return ec2_error(req, request_id, type(ex).__name__, unicode(ex))
        except exception.InvalidInstanceIDMalformed as ex:
            LOG.debug(_('Invalid id: bogus (expecting "i-..."): %s'), unicode(ex), context=context)
            return ec2_error(req, request_id, type(ex).__name__, unicode(ex))
        except Exception as ex:
            env = req.environ.copy()
            for k in env.keys():
                if not isinstance(env[k], basestring):
                    env.pop(k)

            LOG.exception(_("Unexpected error raised: %s"), unicode(ex))
            LOG.error(_("Environment: %s") % jsonutils.dumps(env))
            return ec2_error(
                req, request_id, "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