Protectable module code framework
Closes-Bug: #1536494 Change-Id: I846caddca46e8b4c738abddc972f756229f7cd26
This commit is contained in:
parent
94a5581983
commit
5f250af4f6
15
smaug/resource.py
Normal file
15
smaug/resource.py
Normal 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'))
|
0
smaug/services/protection/plugins/__init__.py
Normal file
0
smaug/services/protection/plugins/__init__.py
Normal file
54
smaug/services/protection/protectable_plugin.py
Normal file
54
smaug/services/protection/protectable_plugin.py
Normal 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
|
56
smaug/services/protection/protectable_registry.py
Normal file
56
smaug/services/protection/protectable_registry.py
Normal 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
|
@ -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):
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user