Refactored capability type and namespace dao's
Change-Id: I384d71a9b9067ebb752156f7f8de9dee03b53e9a
This commit is contained in:
parent
313eb511e2
commit
8c0f63f72b
20
config.py
20
config.py
|
@ -92,8 +92,8 @@ cfg.CONF.register_group(keystone_group)
|
|||
cfg.CONF.register_opts(keystone_opts, group=keystone_group)
|
||||
|
||||
# DEFAULT group
|
||||
default_controller_group = cfg.OptGroup('DEFAULT')
|
||||
default_controller_opts = [
|
||||
default_group = cfg.OptGroup('DEFAULT')
|
||||
default_opts = [
|
||||
cfg.StrOpt(
|
||||
'persistence_type',
|
||||
default="memory",
|
||||
|
@ -101,13 +101,13 @@ default_controller_opts = [
|
|||
"values = 'memory' or 'file' or 'db"))
|
||||
]
|
||||
|
||||
cfg.CONF.register_group(default_controller_group)
|
||||
cfg.CONF.register_opts(default_controller_opts,
|
||||
group=default_controller_group)
|
||||
cfg.CONF.register_group(default_group)
|
||||
cfg.CONF.register_opts(default_opts,
|
||||
group=default_group)
|
||||
|
||||
# FILE_PERSISTENCE group
|
||||
file_controller_group = cfg.OptGroup('FILE_PERSISTENCE')
|
||||
file_controller_opts = [
|
||||
file_group = cfg.OptGroup('FILE_PERSISTENCE')
|
||||
file_opts = [
|
||||
cfg.StrOpt(
|
||||
'dictionary_folder',
|
||||
default="/tmp/graffiti-dictionary/",
|
||||
|
@ -115,9 +115,9 @@ file_controller_opts = [
|
|||
)
|
||||
]
|
||||
|
||||
cfg.CONF.register_group(file_controller_group)
|
||||
cfg.CONF.register_opts(file_controller_opts,
|
||||
group=file_controller_group)
|
||||
cfg.CONF.register_group(file_group)
|
||||
cfg.CONF.register_opts(file_opts,
|
||||
group=file_group)
|
||||
|
||||
|
||||
# Used for remote debugging, like pychcharms or pydev
|
||||
|
|
|
@ -18,10 +18,10 @@ from pecan.rest import RestController
|
|||
from wsme.api import Response
|
||||
from wsmeext.pecan import wsexpose
|
||||
|
||||
from graffiti.api.controllers.v1.captype_controller_factory \
|
||||
import CapTypeControllerFactory
|
||||
from graffiti.api.model.v1.capability_type import CapabilityType
|
||||
from ns_controller_factory import NSControllerFactory
|
||||
from graffiti.api.model.v1.dao.captype_dao_factory \
|
||||
import CapabilityTypeDAOFactory
|
||||
from graffiti.api.model.v1.dao.ns_dao_factory import NSDAOFactory
|
||||
from oslo.config import cfg
|
||||
|
||||
|
||||
|
@ -37,9 +37,9 @@ class CapabilityTypeController(RestController):
|
|||
self._load_controller()
|
||||
|
||||
def _load_controller(self):
|
||||
controller_type = cfg.CONF.DEFAULT.persistence_type
|
||||
self._cap_controller = CapTypeControllerFactory.create(controller_type)
|
||||
self._ns_controller = NSControllerFactory.get()
|
||||
dao_type = cfg.CONF.DEFAULT.persistence_type
|
||||
self._cap_controller = CapabilityTypeDAOFactory.create(dao_type)
|
||||
self._ns_controller = NSDAOFactory.get()
|
||||
|
||||
@wsexpose
|
||||
def options():
|
||||
|
|
|
@ -17,8 +17,8 @@ from pecan.rest import RestController
|
|||
|
||||
from wsmeext.pecan import wsexpose
|
||||
|
||||
from graffiti.api.controllers.v1.ns_controller_factory\
|
||||
import NSControllerFactory
|
||||
from graffiti.api.model.v1.dao.ns_dao_factory \
|
||||
import NSDAOFactory
|
||||
from graffiti.api.model.v1.namespace import Namespace
|
||||
from oslo.config import cfg
|
||||
import six
|
||||
|
@ -32,7 +32,7 @@ class NamespaceController(RestController):
|
|||
|
||||
def _load_controller(self):
|
||||
controller_type = cfg.CONF.DEFAULT.persistence_type
|
||||
_controller = NSControllerFactory.create(controller_type)
|
||||
_controller = NSDAOFactory.create(controller_type)
|
||||
return _controller
|
||||
|
||||
@wsexpose
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
# 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 graffiti.api.controllers.v1.ns_db_controller \
|
||||
import DBNSController
|
||||
from graffiti.api.controllers.v1.ns_file_controller \
|
||||
import FileNSController
|
||||
from graffiti.api.controllers.v1.ns_mem_controller \
|
||||
import MemNSController
|
||||
from oslo.config import cfg
|
||||
|
||||
|
||||
class NSControllerFactory(object):
|
||||
|
||||
__controller = None
|
||||
__controller_type = cfg.CONF.DEFAULT.persistence_type
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(NSControllerFactory, self).__init__(**kwargs)
|
||||
|
||||
@staticmethod
|
||||
def create(controller_type, **kwargs):
|
||||
if controller_type.lower() == 'memory':
|
||||
print "Namespace persistence = memory"
|
||||
NSControllerFactory.__controller = MemNSController(**kwargs)
|
||||
return NSControllerFactory.__controller
|
||||
elif controller_type.lower() == "db":
|
||||
print "Namespace persistence = db"
|
||||
NSControllerFactory.__controller = DBNSController(**kwargs)
|
||||
return NSControllerFactory.__controller
|
||||
elif controller_type.lower() == "file":
|
||||
print "Namespace persistence = File"
|
||||
NSControllerFactory.__controller = FileNSController(**kwargs)
|
||||
return NSControllerFactory.__controller
|
||||
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def get():
|
||||
if NSControllerFactory.__controller:
|
||||
return NSControllerFactory.__controller
|
||||
else:
|
||||
return NSControllerFactory.create(
|
||||
NSControllerFactory.__controller_type)
|
|
@ -14,18 +14,18 @@
|
|||
# limitations under the License.
|
||||
|
||||
|
||||
class CapabilityTypeControllerBase(object):
|
||||
class CapabilityTypeDAOBase(object):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(CapabilityTypeControllerBase, self).__init__(**kwargs)
|
||||
self._type = 'None'
|
||||
|
||||
def get_capability_type(self, name, namespace):
|
||||
return None
|
||||
super(CapabilityTypeDAOBase, self).__init__(**kwargs)
|
||||
self._type = "CapabilityTypeDAOBase"
|
||||
|
||||
def get_type(self):
|
||||
return self._type
|
||||
|
||||
def get_capability_type(self, name, namespace):
|
||||
return None
|
||||
|
||||
def find_capability_types(self, query_string):
|
||||
return []
|
||||
|
|
@ -13,30 +13,29 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
from graffiti.api.controllers.v1.captype_db_controller \
|
||||
import DBCapabilityTypeController
|
||||
from graffiti.api.controllers.v1.captype_file_controller \
|
||||
import FileCapabilityTypeController
|
||||
from graffiti.api.controllers.v1.captype_mem_controller \
|
||||
import MemCapabilityTypeController
|
||||
from graffiti.api.model.v1.dao.captype_db_dao \
|
||||
import DBCapabilityTypeDAO
|
||||
from graffiti.api.model.v1.dao.captype_file_dao \
|
||||
import FileCapabilityTypeDAO
|
||||
from graffiti.api.model.v1.dao.captype_mem_dao \
|
||||
import MemCapabilityTypeDAO
|
||||
|
||||
|
||||
class CapTypeControllerFactory(object):
|
||||
class CapabilityTypeDAOFactory(object):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(CapTypeControllerFactory, self).__init__(**kwargs)
|
||||
super(CapabilityTypeDAOFactory, self).__init__(**kwargs)
|
||||
|
||||
@staticmethod
|
||||
def create(controller_type, **kwargs):
|
||||
if controller_type.lower() == 'memory':
|
||||
def create(dao_type, **kwargs):
|
||||
if dao_type.lower() == 'memory':
|
||||
print "Dictionary persistence = memory"
|
||||
return MemCapabilityTypeController(**kwargs)
|
||||
elif controller_type.lower() == "db":
|
||||
return MemCapabilityTypeDAO(**kwargs)
|
||||
elif dao_type.lower() == "db":
|
||||
print "Dictionary persistence = db"
|
||||
return DBCapabilityTypeController(**kwargs)
|
||||
elif controller_type.lower() == "file":
|
||||
return DBCapabilityTypeDAO(**kwargs)
|
||||
elif dao_type.lower() == "file":
|
||||
print "Dictionary persistence = File"
|
||||
return FileCapabilityTypeController(**kwargs)
|
||||
return FileCapabilityTypeDAO(**kwargs)
|
||||
|
||||
return None
|
|
@ -13,8 +13,8 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from captype_controller import CapabilityTypeControllerBase
|
||||
from graffiti.api.model.v1.capability_type import CapabilityType
|
||||
from graffiti.api.model.v1.dao.captype_dao import CapabilityTypeDAOBase
|
||||
from graffiti.api.model.v1.derived_type import DerivedType
|
||||
from graffiti.api.model.v1.property_type import PropertyType
|
||||
from graffiti.db import api as dbapi
|
||||
|
@ -23,11 +23,14 @@ from wsme.rest.json import fromjson
|
|||
from wsme.rest.json import tojson
|
||||
|
||||
|
||||
class DBCapabilityTypeController(CapabilityTypeControllerBase):
|
||||
class DBCapabilityTypeDAO(CapabilityTypeDAOBase):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(DBCapabilityTypeController, self).__init__(**kwargs)
|
||||
self._type = 'DBCapabilityTypeController'
|
||||
super(DBCapabilityTypeDAO, self).__init__(**kwargs)
|
||||
self._type = "DBCapabilityTypeDAO"
|
||||
|
||||
def get_type(self):
|
||||
return self._type
|
||||
|
||||
def _to_model(self, db_captype):
|
||||
model_captype = CapabilityType.to_model(db_captype)
|
|
@ -14,23 +14,26 @@
|
|||
# limitations under the License.
|
||||
|
||||
|
||||
from captype_controller import CapabilityTypeControllerBase
|
||||
from graffiti.api.model.v1.capability_type import CapabilityType
|
||||
from graffiti.api.model.v1.dao.captype_dao import CapabilityTypeDAOBase
|
||||
import json
|
||||
from oslo.config import cfg
|
||||
from wsme.rest.json import fromjson
|
||||
from wsme.rest.json import tojson
|
||||
|
||||
|
||||
class FileCapabilityTypeController(CapabilityTypeControllerBase):
|
||||
class FileCapabilityTypeDAO(CapabilityTypeDAOBase):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(FileCapabilityTypeController, self).__init__(**kwargs)
|
||||
self._type = 'FileCapabilityTypeController'
|
||||
super(FileCapabilityTypeDAO, self).__init__(**kwargs)
|
||||
self._graffiti_folder = cfg.CONF.FILE_PERSISTENCE.dictionary_folder
|
||||
self._filename = "dictionary.json"
|
||||
self._dictionaryfile = self._graffiti_folder + self._filename
|
||||
self._capability_types = self.__file_to_memory()
|
||||
self._type = "FileCapabilityTypeDAO"
|
||||
|
||||
def get_type(self):
|
||||
return self._type
|
||||
|
||||
def get_capability_type(self, name, namespace):
|
||||
id = namespace + ":" + name
|
|
@ -13,15 +13,18 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from captype_controller import CapabilityTypeControllerBase
|
||||
from graffiti.api.model.v1.dao.captype_dao import CapabilityTypeDAOBase
|
||||
|
||||
|
||||
class MemCapabilityTypeController(CapabilityTypeControllerBase):
|
||||
class MemCapabilityTypeDAO(CapabilityTypeDAOBase):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(MemCapabilityTypeController, self).__init__(**kwargs)
|
||||
self._type = 'MemCapabilityTypeController'
|
||||
super(MemCapabilityTypeDAO, self).__init__(**kwargs)
|
||||
self._capability_types = {}
|
||||
self._type = "MemCapabilityTypeDAO"
|
||||
|
||||
def get_type(self):
|
||||
return self._type
|
||||
|
||||
def get_capability_type(self, name, namespace):
|
||||
id = namespace + ":" + name
|
|
@ -14,18 +14,18 @@
|
|||
# limitations under the License.
|
||||
|
||||
|
||||
class NSTypeControllerBase(object):
|
||||
class NSDAOBase(object):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(NSTypeControllerBase, self).__init__(**kwargs)
|
||||
self._type = 'None'
|
||||
|
||||
def get_namespace(self, namespace_name):
|
||||
return None
|
||||
super(NSDAOBase, self).__init__(**kwargs)
|
||||
self._type = "NSDAOBase"
|
||||
|
||||
def get_type(self):
|
||||
return self._type
|
||||
|
||||
def get_namespace(self, namespace_name):
|
||||
return None
|
||||
|
||||
def find_namespaces(self, query_string):
|
||||
return []
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
# 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 graffiti.api.model.v1.dao.ns_db_dao \
|
||||
import DBNSDAO
|
||||
from graffiti.api.model.v1.dao.ns_file_dao \
|
||||
import FileNSDAO
|
||||
from graffiti.api.model.v1.dao.ns_mem_dao \
|
||||
import MemNSDAO
|
||||
from oslo.config import cfg
|
||||
|
||||
|
||||
class NSDAOFactory(object):
|
||||
|
||||
__dao = None
|
||||
__dao_type = cfg.CONF.DEFAULT.persistence_type
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(NSDAOFactory, self).__init__(**kwargs)
|
||||
|
||||
@staticmethod
|
||||
def create(dao_type, **kwargs):
|
||||
if dao_type.lower() == 'memory':
|
||||
print "Namespace persistence = memory"
|
||||
NSDAOFactory.__dao = MemNSDAO(**kwargs)
|
||||
return NSDAOFactory.__dao
|
||||
elif dao_type.lower() == "db":
|
||||
print "Namespace persistence = db"
|
||||
NSDAOFactory.__dao = DBNSDAO(**kwargs)
|
||||
return NSDAOFactory.__dao
|
||||
elif dao_type.lower() == "file":
|
||||
print "Namespace persistence = File"
|
||||
NSDAOFactory.__dao = FileNSDAO(**kwargs)
|
||||
return NSDAOFactory.__dao
|
||||
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def get():
|
||||
if NSDAOFactory.__dao:
|
||||
return NSDAOFactory.__dao
|
||||
else:
|
||||
return NSDAOFactory.create(
|
||||
NSDAOFactory.__dao_type)
|
|
@ -13,16 +13,16 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from graffiti.api.model.v1.dao.ns_dao import NSDAOBase
|
||||
from graffiti.api.model.v1.namespace import Namespace
|
||||
from graffiti.db import api as dbapi
|
||||
from ns_controller import NSTypeControllerBase
|
||||
|
||||
|
||||
class DBNSController(NSTypeControllerBase):
|
||||
class DBNSDAO(NSDAOBase):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(DBNSController, self).__init__(**kwargs)
|
||||
self._type = 'DBNSController'
|
||||
super(DBNSDAO, self).__init__(**kwargs)
|
||||
self._type = "DBNSDAO"
|
||||
|
||||
def get_type(self):
|
||||
return self._type
|
|
@ -14,23 +14,29 @@
|
|||
# limitations under the License.
|
||||
|
||||
|
||||
from graffiti.api.model.v1.dao.ns_dao import NSDAOBase
|
||||
from graffiti.api.model.v1.namespace import Namespace
|
||||
|
||||
import json
|
||||
from ns_controller import NSTypeControllerBase
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from wsme.rest.json import fromjson
|
||||
from wsme.rest.json import tojson
|
||||
|
||||
|
||||
class FileNSController(NSTypeControllerBase):
|
||||
class FileNSDAO(NSDAOBase):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(FileNSController, self).__init__(**kwargs)
|
||||
self._type = 'FileNSController'
|
||||
super(FileNSDAO, self).__init__(**kwargs)
|
||||
self._graffiti_folder = cfg.CONF.FILE_PERSISTENCE.dictionary_folder
|
||||
self._filename = "namespaces.json"
|
||||
self._namespacefile = self._graffiti_folder + self._filename
|
||||
self._namespaces = self.__file_to_memory()
|
||||
self._type = "FileNSDAO"
|
||||
|
||||
def get_type(self):
|
||||
return self._type
|
||||
|
||||
def get_namespace(self, namespace_name):
|
||||
return self._namespaces[namespace_name]
|
|
@ -13,15 +13,15 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from ns_controller import NSTypeControllerBase
|
||||
from graffiti.api.model.v1.dao.ns_dao import NSDAOBase
|
||||
|
||||
|
||||
class MemNSController(NSTypeControllerBase):
|
||||
class MemNSDAO(NSDAOBase):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(MemNSController, self).__init__(**kwargs)
|
||||
self._type = 'MemNSController'
|
||||
super(MemNSDAO, self).__init__(**kwargs)
|
||||
self._namespaces = {}
|
||||
self._type = "MemNSDAO"
|
||||
|
||||
def get_type(self):
|
||||
return self._type
|
|
@ -13,18 +13,24 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from graffiti.api.model.v1.resource_dao import LocalResourceDAO
|
||||
|
||||
|
||||
class ResourceDAOFactory(object):
|
||||
class ResourceDAOBase(object):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(ResourceDAOFactory, self).__init__(**kwargs)
|
||||
super(ResourceDAOBase, self).__init__(**kwargs)
|
||||
self._type = "ResourceDAOBase"
|
||||
|
||||
@staticmethod
|
||||
def create(dao_type, **kwargs):
|
||||
if dao_type.lower() == 'memory':
|
||||
print "Directory persistence = memory"
|
||||
return LocalResourceDAO(**kwargs)
|
||||
def get_type(self):
|
||||
return self._type
|
||||
|
||||
def get_resource(self, id):
|
||||
return None
|
||||
|
||||
def find_resources(self, query_string):
|
||||
return []
|
||||
|
||||
def set_resource(self, id, resource):
|
||||
pass
|
||||
|
||||
def delete_resource(self, id):
|
||||
pass
|
|
@ -0,0 +1,38 @@
|
|||
# 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 graffiti.api.model.v1.dao.resource_db_dao import DBResourceDAO
|
||||
from graffiti.api.model.v1.dao.resource_file_dao import FileResourceDAO
|
||||
from graffiti.api.model.v1.dao.resource_mem_dao import MemResourceDAO
|
||||
|
||||
|
||||
class ResourceDAOFactory(object):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(ResourceDAOFactory, self).__init__(**kwargs)
|
||||
|
||||
@staticmethod
|
||||
def create(dao_type, **kwargs):
|
||||
if dao_type.lower() == 'memory':
|
||||
print "Directory persistence = memory"
|
||||
return MemResourceDAO(**kwargs)
|
||||
elif dao_type.lower() == 'file':
|
||||
print "Directory persistence = file"
|
||||
return FileResourceDAO(**kwargs)
|
||||
elif dao_type.lower() == 'db':
|
||||
print "Directory persistence = db"
|
||||
return DBResourceDAO(**kwargs)
|
||||
|
||||
return None
|
|
@ -0,0 +1,40 @@
|
|||
# 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 graffiti.api.model.v1.dao.resource_dao import ResourceDAOBase
|
||||
|
||||
|
||||
#TODO(Lakshmi): Implement db persistence for resource
|
||||
class DBResourceDAO(ResourceDAOBase):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(DBResourceDAO, self).__init__(**kwargs)
|
||||
self._type = "DBResourceDAO"
|
||||
|
||||
def get_type(self):
|
||||
return self._type
|
||||
|
||||
def get_resource(self, id):
|
||||
pass
|
||||
|
||||
def find_resources(self, query_string):
|
||||
pass
|
||||
|
||||
def set_resource(self, id=None, resource_definition=None):
|
||||
pass
|
||||
|
||||
def delete_resource(self, id):
|
||||
pass
|
|
@ -0,0 +1,42 @@
|
|||
# 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 graffiti.api.model.v1.dao.resource_dao import ResourceDAOBase
|
||||
|
||||
|
||||
class FileResourceDAO(ResourceDAOBase):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(FileResourceDAO, self).__init__(**kwargs)
|
||||
self._type = "FileResourceDAO"
|
||||
|
||||
def get_type(self):
|
||||
return self._type
|
||||
|
||||
def get_resource(self, id):
|
||||
pass
|
||||
|
||||
def find_resources(self, query_string):
|
||||
pass
|
||||
|
||||
def set_resource(self, id=None, resource_definition=None):
|
||||
pass
|
||||
|
||||
def delete_resource(self, id):
|
||||
pass
|
||||
|
||||
def _generate_id(self):
|
||||
pass
|
|
@ -14,49 +14,36 @@
|
|||
# limitations under the License.
|
||||
|
||||
|
||||
class ResourceDAOBase(object):
|
||||
from graffiti.api.model.v1.dao.resource_dao import ResourceDAOBase
|
||||
|
||||
|
||||
class MemResourceDAO(ResourceDAOBase):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(ResourceDAOBase, self).__init__(**kwargs)
|
||||
|
||||
self._type = 'None'
|
||||
|
||||
def get_resource(self, id):
|
||||
return None
|
||||
super(MemResourceDAO, self).__init__(**kwargs)
|
||||
self._resources = dict()
|
||||
self._last_id = 0
|
||||
self._type = "MemResourceDAO"
|
||||
|
||||
def get_type(self):
|
||||
return self._type
|
||||
|
||||
def find_resources(self, query_string):
|
||||
return []
|
||||
|
||||
def set_resource(self, id=None, resource_definition=None):
|
||||
pass
|
||||
|
||||
|
||||
class LocalResourceDAO(ResourceDAOBase):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(LocalResourceDAO, self).__init__(**kwargs)
|
||||
|
||||
self._type = 'LocalResourceDAO'
|
||||
|
||||
self._resources = dict()
|
||||
self._last_id = 0
|
||||
|
||||
def get_resource(self, id):
|
||||
return self._resources[id]
|
||||
|
||||
def find_resources(self, query_string):
|
||||
return self._resources
|
||||
|
||||
def set_resource(self, id=None, resource_definition=None):
|
||||
def set_resource(self, id=None, resource=None):
|
||||
if not id:
|
||||
id = self._generate_id()
|
||||
|
||||
self._resources[id] = resource_definition
|
||||
self._resources[id] = resource
|
||||
return id
|
||||
|
||||
def delete_resource(self, id):
|
||||
pass
|
||||
|
||||
def _generate_id(self):
|
||||
return_value = self._last_id
|
||||
self._last_id += 1
|
|
@ -25,11 +25,11 @@ from graffiti.api.tests import base
|
|||
from graffiti.api.controllers.root import RootController
|
||||
from graffiti.api.controllers.versions import V1Controller
|
||||
|
||||
from graffiti.api.controllers.v1.captype_controller_factory \
|
||||
import CapTypeControllerFactory
|
||||
from graffiti.api.controllers.v1.ns_controller_factory \
|
||||
import NSControllerFactory
|
||||
from graffiti.api.model.v1.resource_dao_factory \
|
||||
from graffiti.api.model.v1.dao.captype_dao_factory \
|
||||
import CapabilityTypeDAOFactory
|
||||
from graffiti.api.model.v1.dao.ns_dao_factory \
|
||||
import NSDAOFactory
|
||||
from graffiti.api.model.v1.dao.resource_dao_factory \
|
||||
import ResourceDAOFactory
|
||||
|
||||
|
||||
|
@ -44,42 +44,50 @@ class TestControllerV1(base.TestCase):
|
|||
self.assertIn(hasattr(v1, 'namespace'), [True])
|
||||
|
||||
def test_v1_namespace_controller_factory__memory(self):
|
||||
rc = NSControllerFactory.create('memory')
|
||||
self.assertEquals(rc.get_type(), 'MemNSController')
|
||||
rc = NSDAOFactory.create('memory')
|
||||
self.assertEquals(rc.get_type(), 'MemNSDAO')
|
||||
|
||||
# TODO(Lakshmi): Create folder before any tests run
|
||||
# def test_v1_namespace_controller_factory__file(self):
|
||||
# rc = NSControllerFactory.create('file')
|
||||
# self.assertEquals(rc.get_type(), 'FileNSController')
|
||||
# self.assertEquals(rc.get_type(), 'FileNSDAO')
|
||||
|
||||
def test_v1_namespace_controller_factory__db(self):
|
||||
rc = NSControllerFactory.create('db')
|
||||
self.assertEquals(rc.get_type(), 'DBNSController')
|
||||
rc = NSDAOFactory.create('db')
|
||||
self.assertEquals(rc.get_type(), 'DBNSDAO')
|
||||
|
||||
def test_v1_capability_type_exists(self):
|
||||
v1 = V1Controller()
|
||||
self.assertIn(hasattr(v1, 'capability_type'), [True])
|
||||
|
||||
def test_v1_capability_type_controller_factory__memory(self):
|
||||
rc = CapTypeControllerFactory.create('memory')
|
||||
self.assertEquals(rc.get_type(), 'MemCapabilityTypeController')
|
||||
def test_v1_capability_type_dao_factory__memory(self):
|
||||
rc = CapabilityTypeDAOFactory.create('memory')
|
||||
self.assertEquals(rc.get_type(), 'MemCapabilityTypeDAO')
|
||||
|
||||
# TODO(Lakshmi): Create folder before any tests run
|
||||
# def test_v1_capability_type_controller_factory__file(self):
|
||||
# rc = CapTypeControllerFactory.create('file')
|
||||
# self.assertEquals(rc.get_type(), 'FileCapabilityTypeController')
|
||||
# def test_v1_capability_type_dao_factory__file(self):
|
||||
# rc = CapabilityTypeDAOFactory.create('file')
|
||||
# self.assertEquals(rc.get_type(), 'FileCapabilityTypeDAO')
|
||||
|
||||
def test_v1_capability_type_controller_factory__db(self):
|
||||
rc = CapTypeControllerFactory.create('db')
|
||||
self.assertEquals(rc.get_type(), 'DBCapabilityTypeController')
|
||||
def test_v1_capability_type_dao_factory__db(self):
|
||||
rc = CapabilityTypeDAOFactory.create('db')
|
||||
self.assertEquals(rc.get_type(), 'DBCapabilityTypeDAO')
|
||||
|
||||
def test_v1_resource_exists(self):
|
||||
v1 = V1Controller()
|
||||
self.assertIn(hasattr(v1, 'resource'), [True])
|
||||
|
||||
def test_v1_resource_controller_factory__local(self):
|
||||
def test_v1_resource_dao_factory__memory(self):
|
||||
rc = ResourceDAOFactory.create('memory')
|
||||
self.assertEquals(rc.get_type(), 'LocalResourceDAO')
|
||||
self.assertEquals(rc.get_type(), 'MemResourceDAO')
|
||||
|
||||
def test_v1_resource_dao_factory__file(self):
|
||||
rc = ResourceDAOFactory.create('file')
|
||||
self.assertEquals(rc.get_type(), 'FileResourceDAO')
|
||||
|
||||
def test_v1_resource_dao_factory__db(self):
|
||||
rc = ResourceDAOFactory.create('db')
|
||||
self.assertEquals(rc.get_type(), 'DBResourceDAO')
|
||||
|
||||
def test_v1_resource_controller_factory__unknown(self):
|
||||
rc = ResourceDAOFactory.create('invalid_controller')
|
||||
|
|
|
@ -13,19 +13,25 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import sys
|
||||
|
||||
from graffiti.openstack.common.gettextutils import _
|
||||
from graffiti.openstack.common.log import logging
|
||||
|
||||
_FATAL_EXCEPTION_FORMAT_ERRORS = False
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class GraffitiException(Exception):
|
||||
"""Base Exception for the project
|
||||
"""Base Graffiti Exception
|
||||
|
||||
To correctly use this class, inherit from it and define
|
||||
the 'message' property.
|
||||
That message will get printf'd
|
||||
a 'msg_fmt' property. That msg_fmt will get printf'd
|
||||
with the keyword arguments provided to the constructor.
|
||||
"""
|
||||
|
||||
message = _("An unknown exception occurred")
|
||||
"""
|
||||
message = _("An unknown exception occurred.")
|
||||
|
||||
def __str__(self):
|
||||
return self.message
|
||||
|
@ -34,34 +40,48 @@ class GraffitiException(Exception):
|
|||
self.kwargs = kwargs
|
||||
|
||||
try:
|
||||
message = self.message % kwargs
|
||||
self.message = self.msg_fmt % kwargs
|
||||
except KeyError:
|
||||
#TODO(Any): print to log
|
||||
pass
|
||||
exc_info = sys.exc_info()
|
||||
#kwargs doesn't match a variable in the message
|
||||
#log the issue and the kwargs
|
||||
logger.exception(_('Exception in string format operation'))
|
||||
for name, value in kwargs.iteritems():
|
||||
logger.error("%s: %s" % (name, value))
|
||||
|
||||
super(GraffitiException, self).__init__(message)
|
||||
if _FATAL_EXCEPTION_FORMAT_ERRORS:
|
||||
raise exc_info[0], exc_info[1], exc_info[2]
|
||||
|
||||
#def __str__(self):
|
||||
# return unicode(self.message).encode('UTF-8')
|
||||
|
||||
def __unicode__(self):
|
||||
return unicode(self.message)
|
||||
|
||||
def __deepcopy__(self, memo):
|
||||
return self.__class__(**self.kwargs)
|
||||
|
||||
|
||||
class NotFound(GraffitiException):
|
||||
message = _("Object not found")
|
||||
msg_fmt = _("Object not found")
|
||||
|
||||
|
||||
class DuplicateEntry(GraffitiException):
|
||||
message = _("Database object already exists")
|
||||
msg_fmt = _("Database object already exists")
|
||||
|
||||
|
||||
class DriverNotFound(NotFound):
|
||||
message = _("Failed to load driver %(driver_name)s.")
|
||||
msg_fmt = _("Failed to load driver %(driver_name)s.")
|
||||
|
||||
|
||||
class DriverLoadError(GraffitiException):
|
||||
message = _("Driver %(driver)s could not be loaded. Reason: %(reason)s.")
|
||||
msg_fmt = _("Driver %(driver)s could not be loaded. Reason: %(reason)s.")
|
||||
|
||||
|
||||
class MethodNotSupported(GraffitiException):
|
||||
message = _("Method %(method)s is not supported by this driver")
|
||||
msg_fmt = _("Method %(method)s is not supported by this driver")
|
||||
|
||||
|
||||
class DriverNotFoundForResourceType(NotFound):
|
||||
message = _("Cannot find a registered driver for the resource "
|
||||
msg_fmt = _("Cannot find a registered driver for the resource "
|
||||
"type %(resource_type)s")
|
||||
|
|
|
@ -64,7 +64,6 @@ class GlanceResourceDriver(base.ResourceInterface):
|
|||
# replace if check with pattern matching
|
||||
if key.count(self.separator) == 2:
|
||||
(namespace, capability_type, prop_name) = key.split(".")
|
||||
image_properties = []
|
||||
image_property = Property()
|
||||
image_property.name = prop_name
|
||||
image_property.value = glance_image_properties[key]
|
||||
|
@ -77,13 +76,12 @@ class GlanceResourceDriver(base.ResourceInterface):
|
|||
|
||||
if not image_capability:
|
||||
image_capability = Capability()
|
||||
image_capability.properties = []
|
||||
image_resource.capabilities.append(image_capability)
|
||||
|
||||
image_capability.capability_type_namespace = namespace
|
||||
image_capability.capability_type = capability_type
|
||||
image_properties.append(image_property)
|
||||
|
||||
image_capability.properties = image_properties
|
||||
image_capability.properties.append(image_property)
|
||||
|
||||
return image_resource
|
||||
|
||||
|
@ -155,10 +153,16 @@ class GlanceResourceDriver(base.ResourceInterface):
|
|||
password=cfg.CONF.keystone.password,
|
||||
tenant_name=cfg.CONF.keystone.tenant_name
|
||||
)
|
||||
self.__endpoint_list = keystone.endpoints.list()
|
||||
for endpoint in self.__endpoint_list:
|
||||
if endpoint.id == endpoint_id:
|
||||
glance_public_url = endpoint.publicurl
|
||||
|
||||
glance_public_url = None
|
||||
for entry in keystone.service_catalog.catalog.get('serviceCatalog'):
|
||||
for endpoint in entry['endpoints']:
|
||||
if endpoint['id'] == endpoint_id:
|
||||
glance_public_url = endpoint['publicURL']
|
||||
break
|
||||
if glance_public_url:
|
||||
break
|
||||
|
||||
glance_client = Client(
|
||||
'1',
|
||||
endpoint=glance_public_url,
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from graffiti.api.model.v1.resource_dao_factory import \
|
||||
from graffiti.api.model.v1.dao.resource_dao_factory import \
|
||||
ResourceDAOFactory
|
||||
|
||||
from graffiti.drivers import base
|
||||
|
@ -26,6 +26,7 @@ class LocalResourceDriver(base.ResourceInterface):
|
|||
def __init__(self):
|
||||
super(LocalResourceDriver, self).__init__()
|
||||
persistence_type = cfg.CONF.DEFAULT.persistence_type
|
||||
|
||||
self._resource_dao = ResourceDAOFactory.create(persistence_type)
|
||||
|
||||
def get_resource(self, resource_id, auth_token, endpoint_id=None,
|
||||
|
@ -66,7 +67,7 @@ class LocalResourceDriver(base.ResourceInterface):
|
|||
"""
|
||||
|
||||
id = resource.id if hasattr(resource, 'id') else None
|
||||
self._resource_dao.set_resource(id, resource_definition=resource)
|
||||
self._resource_dao.set_resource(id, resource=resource)
|
||||
|
||||
return resource
|
||||
|
||||
|
@ -81,7 +82,7 @@ class LocalResourceDriver(base.ResourceInterface):
|
|||
"""
|
||||
self._resource_dao.set_resource(
|
||||
resource_id,
|
||||
resource_definition=resource
|
||||
resource=resource
|
||||
)
|
||||
return resource
|
||||
|
||||
|
|
Loading…
Reference in New Issue