コード例 #1
0
ファイル: exceptions.py プロジェクト: imkarrer/jumpgate
 def handle(ex, req, resp, params):
     LOG.debug(ex.msg)
     error_handling.error(resp, ex.error_type,
                          "The token is either malformed, expired or not "
                          "valid for the given user/tenant pair",
                          details=ex.details,
                          code=ex.code)
コード例 #2
0
ファイル: volumes.py プロジェクト: ajiang38740/jumpgate
    def on_post(self, req, resp, tenant_id):
        """Create volume (SL Portable storage)."""
        client = req.env['sl_client']

        try:
            body = json.loads(req.stream.read().decode())
            # required field in the create volume payload
            namestr = body['volume'].get("display_name")
            volreq = body['volume']
            # portable storage order cannot have empty name
            name = (config.CONF['volume']['volume_name_prefix'] +
                    (namestr if namestr else ""))

            # size is required option for volume create. Throw type exception
            # if it is invalid
            size = int(volreq['size'])
            # availability_zone is optional, don't throw exception if
            # it is not available
            availability_zone = (
                body['volume'].get('availability_zone')
                or config.CONF['volume']['default_availability_zone'])
            volume_type = body['volume'].get('volume_type')

        except Exception:
            return error_handling.bad_request(resp, 'Malformed request body')

        try:
            volinfo = self._create_volume(tenant_id, client, resp,
                                          size, name=name,
                                          zone=availability_zone,
                                          volume_type=volume_type)

            resp.status = HTTP.ACCEPTED

            if volinfo:
                resp.body = {'volume':
                             format_volume(tenant_id, volinfo, client)}
                resp.body['volume'].update({'status': 'creating'})
            else:
                # Cannot generate a valid response without knowning
                # the volume id when order takes too long to complete.
                # This should be a rare case, but it could break openstack
                # since the volume create caller always expect a volume id
                # uppon successful return. The approach here is to fail
                # the volume create operation and leak one portable storage
                # volume. User can always cancel from SL portal.
                return error_handling.volume_fault(
                    resp, "Portable storage order delayed")

        except SoftLayer.SoftLayerAPIError as e:
            return error_handling.error(resp,
                                        "SoftLayerAPIError",
                                        e.faultString,
                                        code=HTTP.INTERNAL_SERVER_ERROR)
        except Exception as e:
            return error_handling.volume_fault(resp, str(e))
コード例 #3
0
    def on_get(self, req, resp, user_id):
        client = req.sl_client
        account = client['Account'].getObject()
        currentUser = client['Account'].getCurrentUser()
        if currentUser['username'] != user_id:
            return error_handling.error(resp,
                                        'notMatch',
                                        'Invalid user',
                                        details=None,
                                        code=400)

        projects = [{
            'domain_id': str(account['id']),
            'enabled': True,
            'description': None,
            'name': currentUser['username'],
            'id': str(account['id']),
            }]

        resp.body = {'projects': projects, 'tenant_links': []}
コード例 #4
0
    def on_get(self, req, resp, user_id):
        client = req.env['sl_client']
        account = client['Account'].getObject()
        currentUser = client['Account'].getCurrentUser()
        if currentUser['username'] != user_id:
            return error_handling.error(resp,
                                        'notMatch',
                                        'Invalid user',
                                        details=None,
                                        code=400)

        projects = [{
            'domain_id': str(account['id']),
            'enabled': True,
            'description': None,
            'name': currentUser['username'],
            'id': str(account['id']),
            }]

        resp.body = {'projects': projects, 'tenant_links': []}
コード例 #5
0
    def on_get(self, req, resp, user_id):
        client = req.env['sl_client']
        account = client['Account'].getObject()
        currentUser = client['Account'].getCurrentUser()
        if currentUser['username'] != user_id:
            return error(resp,
                         'notMatch',
                         'User provided does not match current user',
                         details=None,
                         code=500)

        projects = [
            {
                'domain_id': str(account['id']),
                'enabled': True,
                'description': None,
                'name': currentUser['username'],
                'id': str(account['id']),
            },
        ]

        resp.body = {'projects': projects, 'tenant_links': []}
コード例 #6
0
ファイル: exceptions.py プロジェクト: imkarrer/jumpgate
 def handle(ex, req, resp, params):
     error_handling.error(resp, ex.error_type, ex.msg,
                          details=ex.details,
                          code=ex.code)
コード例 #7
0
ファイル: volumes.py プロジェクト: imkarrer/jumpgate
    def on_post(self, req, resp, tenant_id):
        """Create volume (SL Portable storage)

        :param req: Falcon request object
        :param resp: Falcon request object
        :param tenant_id: Softlayer tenant_id
        :param return: Falcon response object with openstack response body
        """
        client = req.env['sl_client']
        try:
            v_type_zone = None
            rounding = False
            body = json.loads(req.stream.read().decode())
            if body['volume']['volume_type'] is not None:
                if not self.volume_types['volume_types']:
                    resp.status = HTTP.INTERNAL_SERVER_ERROR
                    return error_handling.volume_fault(resp,
                                                       "Server has no"
                                                       " types to select")
                foundType = False
                for type in self.volume_types['volume_types']:
                    if type['name'] == body['volume']['volume_type']:
                        foundType = True
                        v_type_zone = (
                            type['extra_specs']['capabilities:volume_backend_name']  # noqa
                            )
                        rounding = (
                            type['extra_specs']['drivers:exact_capacity']
                            )
                if not foundType:
                    resp.status = 400
                    raise Exception('Specify a volume with a valid name')

            # required field in the create volume payload
            namestr = body['volume'].get("display_name")
            volreq = body['volume']
            # portable storage order cannot have empty name
            name = (config.CONF['volume']['volume_name_prefix'] +
                    (namestr if namestr else ""))

            # size is required option for volume create. Throw type exception
            # if it is invalid
            size = int(volreq['size'])
            # availability_zone is optional, don't throw exception if
            # it is not available
            availability_zone = (body['volume'].get('availability_zone')
                                 or
                                 v_type_zone
                                 or
                                 config.CONF['volume']['default_availability_zone'])  # noqa
            volume_type = body['volume'].get('volume_type')

        except Exception as e:
            return error_handling.bad_request(resp, str(e))

        try:
            volinfo = self._create_volume(tenant_id, client, resp,
                                          size, name=name,
                                          zone=availability_zone,
                                          volume_type=volume_type,
                                          exact_capacity=rounding)

            resp.status = HTTP.ACCEPTED

            if volinfo:
                resp.body = {'volume':
                             format_volume(tenant_id, volinfo, client)}
                resp.body['volume'].update({'status': 'creating'})
            else:
                # Cannot generate a valid response without knowning
                # the volume id when order takes too long to complete.
                # This should be a rare case, but it could break openstack
                # since the volume create caller always expect a volume id
                # uppon successful return. The approach here is to fail
                # the volume create operation and leak one portable storage
                # volume. User can always cancel from SL portal.

                return error_handling.volume_fault(resp,
                                                   "Portable storage"
                                                   " order delayed")

        except SoftLayer.SoftLayerAPIError as e:
            return error_handling.error(resp,
                                        "SoftLayerAPIError",
                                        e.faultString,
                                        code=e.faultCode)
        except Exception as e:
            return error_handling.volume_fault(resp, str(e))