예제 #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
예제 #2
0
파일: __init__.py 프로젝트: hsluoyz/patron
 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
예제 #3
0
파일: manager.py 프로젝트: hsluoyz/patron
    def get_ec2_ids(self, context, instance):
        ec2_ids = {}

        ec2_ids["instance-id"] = ec2utils.id_to_ec2_inst_id(instance["uuid"])
        ec2_ids["ami-id"] = ec2utils.glance_id_to_ec2_id(context, instance["image_ref"])
        for image_type in ["kernel", "ramdisk"]:
            image_id = instance.get("%s_id" % image_type)
            if image_id is not None:
                ec2_image_type = ec2utils.image_type(image_type)
                ec2_id = ec2utils.glance_id_to_ec2_id(context, image_id, ec2_image_type)
                ec2_ids["%s-id" % image_type] = ec2_id

        return ec2_ids
예제 #4
0
    def get_ec2_ids(self, context, instance):
        ec2_ids = {}

        ec2_ids['instance-id'] = ec2utils.id_to_ec2_inst_id(instance['uuid'])
        ec2_ids['ami-id'] = ec2utils.glance_id_to_ec2_id(context,
                                                         instance['image_ref'])
        for image_type in ['kernel', 'ramdisk']:
            image_id = instance.get('%s_id' % image_type)
            if image_id is not None:
                ec2_image_type = ec2utils.image_type(image_type)
                ec2_id = ec2utils.glance_id_to_ec2_id(context, image_id,
                                                      ec2_image_type)
                ec2_ids['%s-id' % image_type] = ec2_id

        return ec2_ids