Merge "Protectable module code framework"

This commit is contained in:
Jenkins 2016-02-18 10:00:28 +00:00 committed by Gerrit Code Review
commit bf9f046665
5 changed files with 125 additions and 9 deletions

15
smaug/resource.py Normal file
View File

@ -0,0 +1,15 @@
# 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 collections import namedtuple
Resource = namedtuple("Resource", ('type', 'id'))

View File

@ -0,0 +1,54 @@
# 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 abc
import six
@six.add_metaclass(abc.ABCMeta)
class ProtectablePlugin(object):
"""Base abstract class for protectable plugin.
"""
@abc.abstractmethod
def get_resource_type(self):
"""Return the resource type that this plugin supports.
Subclasses can implement as a classmethod
"""
pass
@abc.abstractmethod
def get_parent_resource_types(self):
"""Return the possible parent resource types.
Subclasses can implement as a classmethod
"""
pass
@abc.abstractmethod
def list_resources(self):
"""List resource instances of resource_type.
:return: The list of resource instance.
"""
pass
@abc.abstractmethod
def fetch_child_resources(self, parent_resource):
"""List child resources of resource_type under given parent resource.
:param parent_resource: The parent resource to list child resources.
:return: The list of child resources of resource_type.
"""
pass

View File

@ -0,0 +1,56 @@
# 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.
class ProtectableRegistry(object):
_protectable_map = {}
@classmethod
def load_plugins(cls, conf):
"""Load all protectable plugins configured and register them.
:param conf: The plugin list to load.
"""
# TODO(yingzhe)
pass
@classmethod
def register_plugin(cls, plugin):
# TODO(saggi)
pass
@classmethod
def list_resource_types(cls):
"""List all resource types supported by protectables.
:return: The list of supported resource types.
"""
# TODO(saggi)
pass
@classmethod
def list_resources(cls, resource_type):
"""List resource instances of given type.
:param resource_type: The resource type to list instance.
:return: The list of resource instance.
"""
pass
@classmethod
def fetch_dependent_resources(cls, resource):
"""List dependent resources under given parent resource.
:param resource: The parent resource to list dependent resources.
:return: The list of dependent resources.
"""
pass

View File

@ -22,15 +22,6 @@ CONF = cfg.CONF
LOG = logging.getLogger(__name__)
class ProtectionData(object):
def __init__(self):
super(ProtectionData, self).__init__()
self.protection_id = None
self.protection_target = None
self.status = None
# TODO(wangliuan)
@six.add_metaclass(abc.ABCMeta)
class ProtectionPlugin(object):