added changes to api

Co-Authored-By: Digambar Patil <digambarpat@gmail.com>
Co-Authored-By: Steven Dake <sdake@redhat.com>

Change-Id: Ife00527161645aa194d3aaee96413287645b92a3
This commit is contained in:
digambar 2014-10-01 00:38:27 +05:30 committed by Davanum Srinivas (dims)
parent f90f540db4
commit c879329604

View File

@ -20,11 +20,11 @@ from pecan import rest, response
import six import six
state_kind = ["ok", "alarm", "insufficient data"]
state_kind_enum = wtypes.Enum(str, *state_kind) state_kind_enum = wtypes.Enum(str, *state_kind)
operation_kind = ('lt', 'le', 'eq', 'ne', 'ge', 'gt') operation_kind = ('lt', 'le', 'eq', 'ne', 'ge', 'gt')
operation_kind_enum = wtypes.Enum(str, *operation_kind) operation_kind_enum = wtypes.Enum(str, *operation_kind)
class _Base(wtypes.Base): class _Base(wtypes.Base):
@classmethod @classmethod
@ -47,7 +47,9 @@ class _Base(wtypes.Base):
if hasattr(self, k) and if hasattr(self, k) and
getattr(self, k) != wsme.Unset) getattr(self, k) != wsme.Unset)
class Query(_Base): class Query(_Base):
"""Query filter.""" """Query filter."""
# The data types supported by the query. # The data types supported by the query.
@ -103,19 +105,6 @@ class Query(_Base):
def _get_value_as_type(self, forced_type=None): def _get_value_as_type(self, forced_type=None):
"""Convert metadata value to the specified data type. """Convert metadata value to the specified data type.
This method is called during metadata query to help convert the
querying metadata to the data type specified by user. If there is no
data type given, the metadata will be parsed by ast.literal_eval to
try to do a smart converting.
NOTE (flwang) Using "_" as prefix to avoid an InvocationError raised
from wsmeext/sphinxext.py. It's OK to call it outside the Query class.
Because the "public" side of that class is actually the outside of the
API, and the "private" side is the API implementation. The method is
only used in the API implementation, so it's OK.
:returns: metadata value converted with the specified data type.
""" """
type = forced_type or self.type type = forced_type or self.type
try: try:
@ -153,7 +142,6 @@ class Query(_Base):
return converted_value return converted_value
class Container(_Base): class Container(_Base):
container_id = wtypes.text container_id = wtypes.text
""" The ID of the containers.""" """ The ID of the containers."""
@ -168,35 +156,33 @@ class Container(_Base):
@classmethod @classmethod
def sample(cls): def sample(cls):
return cls(id=str(uuid.uuid1(), return cls(id=str(uuid.uuid1(),
name="Docker", name="Docker",
desc='Docker Containers')) desc='Docker Containers'))
class ContainerController(rest.RestController): class ContainerController(rest.RestController):
@wsme_pecan.wsexpose([Container], [Query], int) @wsme_pecan.wsexpose([Container], [Query], int)
def get_all(self, q=None, limit=None): def get_all(self, q=None, limit=None):
# TODO: Returns all the containers # TODO: Returns all the containers
return { response.status = 200
"200": "It returns all the containers." return
}
@wsme_pecan.wsexpose(Container, wtypes.text) @wsme_pecan.wsexpose(Container, wtypes.text)
def get_one(self, container_id): def get_one(self, container_id):
# TODO: Returns all the containers # TODO: Returns all the containers
return { response.status = 200
"200": "It returns all the containers." return
}
@wsme_pecan.wsexpose([Container], body=[Container]) @wsme_pecan.wsexpose([Container], body=[Container])
def post(self, data): def post(self, data):
# TODO: Create a new container # TODO: Create a new container
response.status=201 response.status = 201
return return
@wsme_pecan.wsexpose(None, status_code=204) @wsme_pecan.wsexpose(None, status_code=204)
def delete(self): def delete(self):
# TODO: DELETE the containers # TODO: DELETE the containers
response.status=200 response.status = 204
return return