~ubuntu-branches/ubuntu/vivid/neutron-lbaas/vivid

« back to all changes in this revision

Viewing changes to neutron_lbaas/services/loadbalancer/drivers/driver_mixins.py

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2015-02-16 09:24:28 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20150216092428-xj2eg6134f65core
Tags: 1:2015.1~b2-0ubuntu1
* New upstream release.
  - d/control: Update/align with upstream dependency changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
#    under the License.
14
14
 
15
15
import abc
 
16
from neutron.plugins.common import constants
16
17
import six
17
18
 
18
 
from neutron.plugins.common import constants
 
19
from neutron_lbaas.db.loadbalancer import models
 
20
from neutron_lbaas.services.loadbalancer import constants as lb_const
 
21
from neutron_lbaas.services.loadbalancer import data_models
19
22
 
20
23
 
21
24
@six.add_metaclass(abc.ABCMeta)
24
27
    def __init__(self, driver):
25
28
        self.driver = driver
26
29
 
 
30
    @abc.abstractproperty
 
31
    def db_delete_method(self):
 
32
        pass
 
33
 
27
34
    @abc.abstractmethod
28
35
    def create(self, context, obj):
29
36
        pass
36
43
    def delete(self, context, obj):
37
44
        pass
38
45
 
 
46
    def successful_completion(self, context, obj, delete=False):
 
47
        """
 
48
        Sets the provisioning_status of the load balancer and obj to
 
49
        ACTIVE.  Also sets the operating status of obj to ONLINE.  Should be
 
50
        called last in the implementor's BaseManagerMixin methods for
 
51
        successful runs.
 
52
 
 
53
        :param context: neutron context
 
54
        :param obj: instance of a
 
55
                    neutron_lbaas.services.loadbalancer.data_model
 
56
        :param delete: set True if being called from a delete method.  Will
 
57
                       most likely result in the obj being deleted from the db.
 
58
        """
 
59
        # TODO(blogan): Will need to decide what to do with all operating
 
60
        # statuses.  Update to ONLINE here, or leave the operating status
 
61
        # alone and let health checks update
 
62
        obj_sa_cls = data_models.DATA_MODEL_TO_SA_MODEL_MAP[obj.__class__]
 
63
        if delete:
 
64
            self.db_delete_method(context, obj.id)
 
65
        if obj == obj.root_loadbalancer and delete:
 
66
            # Load balancer was deleted and no longer exists
 
67
            return
 
68
        lb_op_status = obj.root_loadbalancer.operating_status
 
69
        if obj == obj.root_loadbalancer:
 
70
            lb_op_status = lb_const.ONLINE
 
71
        self.driver.plugin.db.update_status(
 
72
            context, models.LoadBalancer, obj.root_loadbalancer.id,
 
73
            provisioning_status=constants.ACTIVE,
 
74
            operating_status=lb_op_status)
 
75
        if obj == obj.root_loadbalancer or delete:
 
76
            # Do not want to update the status of the load balancer again
 
77
            # Or the obj was deleted from the db so no need to update the
 
78
            # statuses
 
79
            return
 
80
        obj_op_status = lb_const.ONLINE
 
81
        if isinstance(obj, data_models.HealthMonitor):
 
82
            # Health Monitor does not have an operating status
 
83
            obj_op_status = None
 
84
        self.driver.plugin.db.update_status(
 
85
            context, obj_sa_cls, obj.id,
 
86
            provisioning_status=constants.ACTIVE,
 
87
            operating_status=obj_op_status)
 
88
 
 
89
    def failed_completion(self, context, obj):
 
90
        """
 
91
        Sets the provisioning status of the load balancer and obj to
 
92
        ERROR.  Should be called whenever something goes wrong (raised
 
93
        exception) in an implementor's BaseManagerMixin methods.
 
94
 
 
95
        :param context: neutron context
 
96
        :param obj: instance of a
 
97
                    neutron_lbaas.services.loadbalancer.data_model
 
98
        """
 
99
        # TODO(blogan): Will need to decide what to do with all operating
 
100
        # statuses.  Update to ONLINE here, or leave the operating status
 
101
        # alone and let health checks update
 
102
        self.driver.plugin.db.update_status(
 
103
            context, models.LoadBalancer, obj.root_loadbalancer.id,
 
104
            provisioning_status=constants.ERROR)
 
105
        if obj == obj.root_loadbalancer:
 
106
            # Do not want to update the status of the load balancer again
 
107
            return
 
108
        obj_sa_cls = data_models.DATA_MODEL_TO_SA_MODEL_MAP[obj.__class__]
 
109
        self.driver.plugin.db.update_status(
 
110
            context, obj_sa_cls, obj.id,
 
111
            provisioning_status=constants.ERROR,
 
112
            operating_status=lb_const.OFFLINE)
 
113
 
39
114
 
40
115
@six.add_metaclass(abc.ABCMeta)
41
116
class BaseRefreshMixin(object):
51
126
    @abc.abstractmethod
52
127
    def stats(self, context, obj):
53
128
        pass
54
 
 
55
 
 
56
 
class BaseStatusUpdateMixin(object):
57
 
 
58
 
    # Status update helpers
59
 
    # Note: You must set self.model_class to an appropriate neutron model
60
 
    # in your base manager class.
61
 
 
62
 
    def active(self, context, model_id):
63
 
        if self.model_class is not None:
64
 
            self.driver.plugin.update_status(context, self.model_class,
65
 
                                             model_id, constants.ACTIVE)
66
 
 
67
 
    def failed(self, context, model_id):
68
 
        if self.model_class is not None:
69
 
            self.driver.plugin.update_status(context, self.model_class,
70
 
                                             model_id, constants.ERROR)
71
 
 
72
 
 
73
 
class BaseHealthMonitorStatusUpdateMixin(object):
74
 
 
75
 
    def active(self, context, health_monitor_id, pool_id):
76
 
        self.driver.plugin.update_pool_health_monitor(context,
77
 
                                                      health_monitor_id,
78
 
                                                      pool_id,
79
 
                                                      constants.ACTIVE)
80
 
 
81
 
    def failed(self, context, health_monitor_id, pool_id):
82
 
        self.driver.plugin.update_pool_health_monitor(context,
83
 
                                                      health_monitor_id,
84
 
                                                      pool_id,
85
 
                                                      constants.ERROR)