Initial Dictionary service API
Change-Id: If0a6febe0cc0edc91375b3275eceda09c3191207
This commit is contained in:
parent
18f8484739
commit
d53d910b98
56
graffiti/api/controllers/v1/capability_type.py
Normal file
56
graffiti/api/controllers/v1/capability_type.py
Normal file
@ -0,0 +1,56 @@
|
||||
# Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
# implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from pecan.rest import RestController
|
||||
|
||||
from wsmeext.pecan import wsexpose
|
||||
|
||||
from graffiti.api.model.v1.capability_type import CapabilityType
|
||||
|
||||
import six
|
||||
|
||||
capability_types = []
|
||||
|
||||
|
||||
class CapabilityTypeController(RestController):
|
||||
def __init__(self):
|
||||
super(RestController, self).__init__()
|
||||
self.status = 200
|
||||
|
||||
@wsexpose
|
||||
def options():
|
||||
pass
|
||||
|
||||
@wsexpose(CapabilityType, six.text_type)
|
||||
def get_one(self, name):
|
||||
global capability_types
|
||||
|
||||
for capability_type in capability_types:
|
||||
if capability_type.name.lower() == name.lower():
|
||||
return capability_type
|
||||
|
||||
res = CapabilityType(CapabilityType(), status_code=404,
|
||||
error="CapabilityType Not Found")
|
||||
return res
|
||||
|
||||
@wsexpose([CapabilityType])
|
||||
def get_all(self):
|
||||
global capability_types
|
||||
return capability_types
|
||||
|
||||
@wsexpose(CapabilityType, body=CapabilityType)
|
||||
def post(self, capability_type):
|
||||
global capability_types
|
||||
capability_types.append(capability_type)
|
56
graffiti/api/controllers/v1/namespace.py
Normal file
56
graffiti/api/controllers/v1/namespace.py
Normal file
@ -0,0 +1,56 @@
|
||||
# Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
# implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from pecan.rest import RestController
|
||||
|
||||
from wsmeext.pecan import wsexpose
|
||||
|
||||
from graffiti.api.model.v1.namespace import Namespace
|
||||
|
||||
import six
|
||||
|
||||
namespaces = []
|
||||
|
||||
|
||||
class NamespaceController(RestController):
|
||||
def __init__(self):
|
||||
super(RestController, self).__init__()
|
||||
self.status = 200
|
||||
|
||||
@wsexpose
|
||||
def options():
|
||||
pass
|
||||
|
||||
@wsexpose(Namespace, six.text_type)
|
||||
def get_one(self, name):
|
||||
global namespaces
|
||||
|
||||
for namespace in namespaces:
|
||||
if namespace.name.lower() == name.lower():
|
||||
return namespace
|
||||
|
||||
res = Namespace(Namespace(), status_code=404,
|
||||
error="Namespace Not Found")
|
||||
return res
|
||||
|
||||
@wsexpose([Namespace])
|
||||
def get_all(self):
|
||||
global namespaces
|
||||
return namespaces
|
||||
|
||||
@wsexpose(Namespace, body=Namespace)
|
||||
def post(self, namespace):
|
||||
global namespaces
|
||||
namespaces.append(namespace)
|
@ -13,9 +13,13 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from graffiti.api.controllers.v1.capability_type import \
|
||||
CapabilityTypeController
|
||||
from graffiti.api.controllers.v1.namespace import NamespaceController
|
||||
from graffiti.api.controllers.v1.resource import ResourceController
|
||||
|
||||
|
||||
class V1Controller(object):
|
||||
|
||||
namespace = NamespaceController()
|
||||
capability_type = CapabilityTypeController()
|
||||
resource = ResourceController()
|
||||
|
26
graffiti/api/model/v1/capability_type.py
Normal file
26
graffiti/api/model/v1/capability_type.py
Normal file
@ -0,0 +1,26 @@
|
||||
# Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
# implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import wsme
|
||||
from wsme import types
|
||||
|
||||
|
||||
class CapabilityType(types.Base):
|
||||
name = wsme.wsattr(types.text, mandatory=True)
|
||||
namespace = wsme.wsattr(types.text, mandatory=True)
|
||||
description = wsme.wsattr(types.text, mandatory=False)
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(CapabilityType, self).__init__(**kwargs)
|
26
graffiti/api/model/v1/namespace.py
Normal file
26
graffiti/api/model/v1/namespace.py
Normal file
@ -0,0 +1,26 @@
|
||||
# Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
# implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import wsme
|
||||
from wsme import types
|
||||
|
||||
|
||||
class Namespace(types.Base):
|
||||
name = wsme.wsattr(types.text, mandatory=True)
|
||||
scope = wsme.wsattr(types.text, mandatory=True)
|
||||
owner = wsme.wsattr(types.text, mandatory=True)
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(Namespace, self).__init__(**kwargs)
|
Loading…
Reference in New Issue
Block a user