Exemple #1
0
 def __call__(self, req):
     context = req.environ['patron.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.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
Exemple #2
0
 def __call__(self, req):
     context = req.environ['patron.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.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
Exemple #3
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')
Exemple #4
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')