From d53d910b98124dbcf843e3e229637ad026f75c87 Mon Sep 17 00:00:00 2001 From: Lakshmi N Sampath Date: Fri, 14 Mar 2014 13:26:57 -0700 Subject: [PATCH] Initial Dictionary service API Change-Id: If0a6febe0cc0edc91375b3275eceda09c3191207 --- .../api/controllers/v1/capability_type.py | 56 +++++++++++++++++++ graffiti/api/controllers/v1/namespace.py | 56 +++++++++++++++++++ graffiti/api/controllers/versions.py | 6 +- graffiti/api/model/v1/capability_type.py | 26 +++++++++ graffiti/api/model/v1/namespace.py | 26 +++++++++ 5 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 graffiti/api/controllers/v1/capability_type.py create mode 100644 graffiti/api/controllers/v1/namespace.py create mode 100644 graffiti/api/model/v1/capability_type.py create mode 100644 graffiti/api/model/v1/namespace.py diff --git a/graffiti/api/controllers/v1/capability_type.py b/graffiti/api/controllers/v1/capability_type.py new file mode 100644 index 0000000..75dae40 --- /dev/null +++ b/graffiti/api/controllers/v1/capability_type.py @@ -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) diff --git a/graffiti/api/controllers/v1/namespace.py b/graffiti/api/controllers/v1/namespace.py new file mode 100644 index 0000000..ac13643 --- /dev/null +++ b/graffiti/api/controllers/v1/namespace.py @@ -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) diff --git a/graffiti/api/controllers/versions.py b/graffiti/api/controllers/versions.py index 1e5e2f1..85f1eb6 100644 --- a/graffiti/api/controllers/versions.py +++ b/graffiti/api/controllers/versions.py @@ -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() diff --git a/graffiti/api/model/v1/capability_type.py b/graffiti/api/model/v1/capability_type.py new file mode 100644 index 0000000..e392729 --- /dev/null +++ b/graffiti/api/model/v1/capability_type.py @@ -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) diff --git a/graffiti/api/model/v1/namespace.py b/graffiti/api/model/v1/namespace.py new file mode 100644 index 0000000..599c3be --- /dev/null +++ b/graffiti/api/model/v1/namespace.py @@ -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)