Exemplo n.º 1
0
def expose(*args, **kwargs):
    """
    确保返回的数据为Json格式.
    """
    if 'rest_content_types' not in kwargs:
        kwargs['rest_content_types'] = ('json',)
    return wsme_pecan.wsexpose(*args, **kwargs)
Exemplo n.º 2
0
def expose(*args, **kwargs):
    """Ensure that only JSON, and not XML, is supported."""

    if 'rest_content_types' not in kwargs:
        kwargs['rest_content_types'] = ('json', )

    # Set the HTTP Response Content-Type is JSON in header.
    return wsme_pecan.wsexpose(*args, **kwargs)
Exemplo n.º 3
0
def expose(*args, **kwargs):
    """Ensure that only JSON, and not XML, is supported."""
    if 'rest_content_types' not in kwargs:
        kwargs['rest_content_types'] = ('json',)

    return wsme_pecan.wsexpose(*args, **kwargs)
Exemplo n.º 4
0
def expose(*args, **kwargs):
    if 'rest_content_types' not in kwargs:
        kwargs['rest_content_types'] = ('json', )

    return wsme_pecan.wsexpose(*args, **kwargs)
Exemplo n.º 5
0
def expose(*arg, **kwargs):
    """Ensure that only JSON, and not XML, is supported."""
    if 'rest_content_types' not in kwargs:
        kwargs['rest_content_types'] = ('json', )
    return wsme_pecan.wsexpose(*arg, **kwargs)
Exemplo n.º 6
0
        node = Node()
        node.name = 'node1'
        node.console_enabled = True
        node.power_state = 'power-on'
        node.raid_config = dict(name='lucifer')
        node.disks = ['/dev/sda', '/dev/sdb']
        node.update_time = datetime.now()
        return node

    def power_operate(self, nodeid, power_request):
        print power_request.power_action


setattr(NodeController, 'power-operate',
        wsexpose(None, datatypes.uuidtype, body=PowerRequest,
                 status_code=http_client.ACCEPTED,
                 rest_content_type=('json',))(
                     six.get_method_function(NodeController.power_operate)))


class RootController(rest.RestController):
    node = NodeController()

    @expose()
    def _route(self, args, request):
        if len(args) <= 2 and not utils.is_uuid_like(args[0]):
            msg = 'UUID like Project id is required, and the url like follows'\
                  '/{project_id}/resources'
            raise exc.HTTPNotFound(msg)

        if args[0] != request.headers.get('X-Auth-Token'):
            raise exc.HTTPForbidden(
Exemplo n.º 7
0
def expose(*args, **kwargs):
    """Ensure that only JSON, and not XML, is supported."""
    if "rest_content_types" not in kwargs:
        kwargs["rest_content_types"] = ("json",)
    return wsme_pecan.wsexpose(*args, **kwargs)
def wsme_expose(*args, **kwargs):
    """Coerce the content type to json"""

    if 'rest_content_types' not in kwargs:
        kwargs['rest_content_types'] = ('json', )
    return wsme_pecan.wsexpose(*args, **kwargs)