# 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 PolicyBase(object):
    '''
    Base class for policies.
    '''
    def __init__(self, name, type_name, **kwargs):
        self.name = name
        self.type_name = type_name
        self.cooldown = 0
        self.enabled = True
        self.uuid = None
        self.spec = {}

    def pre_op(self, cluster_id, action):
        '''
        Force all subclasses to implement an operation that will be invoked
        before an action.
        '''
        return NotImplemented

    def post_op(self, cluster_id, action):
        '''
        Force all subclasses to implement an operation that will be performed
        after an action.
        '''
        return NotImplemented

    def to_dict(self):
        pb_dict = {
            'name': self.name,
            'type': self.type_name,
            'uuid': self.uuid,
            'spec': self.spec,
            'cooldown': self.cooldown,
        }
        return pb_dict

    @classmethod
    def from_dict(self, **kwargs):
        pb = PolicyBase(**kwargs)
        return pb

Add pre_op and post_op methods to PolicyBase
Add pre_op and post_op methods to PolicyBase

For all policies to be enforced, they may need a hooks that perform some
operations on the targeted clusters.
