octavia 12.0.0.0rc2__py3-none-any.whl → 13.0.0.0rc1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. octavia/amphorae/backends/agent/api_server/osutils.py +1 -0
  2. octavia/amphorae/backends/agent/api_server/plug.py +21 -7
  3. octavia/amphorae/backends/agent/api_server/templates/amphora-netns.systemd.j2 +2 -2
  4. octavia/amphorae/backends/agent/api_server/util.py +21 -0
  5. octavia/amphorae/backends/health_daemon/health_daemon.py +9 -3
  6. octavia/amphorae/backends/health_daemon/health_sender.py +2 -0
  7. octavia/amphorae/backends/utils/interface.py +14 -6
  8. octavia/amphorae/backends/utils/interface_file.py +6 -3
  9. octavia/amphorae/backends/utils/keepalivedlvs_query.py +8 -9
  10. octavia/amphorae/drivers/driver_base.py +1 -2
  11. octavia/amphorae/drivers/haproxy/rest_api_driver.py +11 -25
  12. octavia/amphorae/drivers/health/heartbeat_udp.py +34 -24
  13. octavia/amphorae/drivers/keepalived/jinja/jinja_cfg.py +3 -12
  14. octavia/amphorae/drivers/noop_driver/driver.py +3 -5
  15. octavia/api/common/pagination.py +4 -4
  16. octavia/api/drivers/amphora_driver/v2/driver.py +11 -5
  17. octavia/api/drivers/driver_agent/driver_get.py +22 -14
  18. octavia/api/drivers/driver_agent/driver_updater.py +8 -4
  19. octavia/api/drivers/utils.py +4 -2
  20. octavia/api/healthcheck/healthcheck_plugins.py +4 -2
  21. octavia/api/root_controller.py +4 -1
  22. octavia/api/v2/controllers/amphora.py +35 -38
  23. octavia/api/v2/controllers/availability_zone_profiles.py +43 -33
  24. octavia/api/v2/controllers/availability_zones.py +22 -18
  25. octavia/api/v2/controllers/flavor_profiles.py +37 -28
  26. octavia/api/v2/controllers/flavors.py +19 -15
  27. octavia/api/v2/controllers/health_monitor.py +44 -33
  28. octavia/api/v2/controllers/l7policy.py +52 -40
  29. octavia/api/v2/controllers/l7rule.py +68 -55
  30. octavia/api/v2/controllers/listener.py +88 -61
  31. octavia/api/v2/controllers/load_balancer.py +52 -34
  32. octavia/api/v2/controllers/member.py +63 -52
  33. octavia/api/v2/controllers/pool.py +55 -42
  34. octavia/api/v2/controllers/quotas.py +5 -3
  35. octavia/api/v2/types/listener.py +15 -0
  36. octavia/cmd/octavia_worker.py +0 -3
  37. octavia/cmd/status.py +1 -4
  38. octavia/common/clients.py +25 -45
  39. octavia/common/config.py +64 -22
  40. octavia/common/constants.py +3 -2
  41. octavia/common/data_models.py +7 -1
  42. octavia/common/jinja/haproxy/combined_listeners/jinja_cfg.py +12 -1
  43. octavia/common/jinja/haproxy/combined_listeners/templates/macros.j2 +5 -2
  44. octavia/common/jinja/lvs/jinja_cfg.py +4 -2
  45. octavia/common/keystone.py +58 -5
  46. octavia/common/validate.py +35 -0
  47. octavia/compute/drivers/noop_driver/driver.py +6 -0
  48. octavia/controller/healthmanager/health_manager.py +3 -6
  49. octavia/controller/housekeeping/house_keeping.py +36 -37
  50. octavia/controller/worker/amphora_rate_limit.py +5 -4
  51. octavia/controller/worker/task_utils.py +57 -41
  52. octavia/controller/worker/v2/controller_worker.py +160 -103
  53. octavia/controller/worker/v2/flows/listener_flows.py +3 -0
  54. octavia/controller/worker/v2/flows/load_balancer_flows.py +9 -14
  55. octavia/controller/worker/v2/tasks/amphora_driver_tasks.py +152 -91
  56. octavia/controller/worker/v2/tasks/compute_tasks.py +4 -2
  57. octavia/controller/worker/v2/tasks/database_tasks.py +542 -400
  58. octavia/controller/worker/v2/tasks/network_tasks.py +119 -79
  59. octavia/db/api.py +26 -23
  60. octavia/db/base_models.py +2 -2
  61. octavia/db/healthcheck.py +2 -1
  62. octavia/db/migration/alembic_migrations/versions/632152d2d32e_add_http_strict_transport_security_.py +42 -0
  63. octavia/db/models.py +12 -2
  64. octavia/db/prepare.py +2 -0
  65. octavia/db/repositories.py +462 -482
  66. octavia/hacking/checks.py +1 -1
  67. octavia/network/base.py +0 -14
  68. octavia/network/drivers/neutron/allowed_address_pairs.py +92 -135
  69. octavia/network/drivers/neutron/base.py +65 -77
  70. octavia/network/drivers/neutron/utils.py +69 -85
  71. octavia/network/drivers/noop_driver/driver.py +0 -7
  72. octavia/statistics/drivers/update_db.py +10 -10
  73. octavia/tests/common/constants.py +91 -84
  74. octavia/tests/common/sample_data_models.py +13 -1
  75. octavia/tests/fixtures.py +32 -0
  76. octavia/tests/functional/amphorae/backend/agent/api_server/test_server.py +9 -10
  77. octavia/tests/functional/api/drivers/driver_agent/test_driver_agent.py +260 -15
  78. octavia/tests/functional/api/test_root_controller.py +3 -28
  79. octavia/tests/functional/api/v2/base.py +5 -3
  80. octavia/tests/functional/api/v2/test_amphora.py +18 -5
  81. octavia/tests/functional/api/v2/test_availability_zone_profiles.py +1 -0
  82. octavia/tests/functional/api/v2/test_listener.py +51 -19
  83. octavia/tests/functional/api/v2/test_load_balancer.py +10 -1
  84. octavia/tests/functional/db/base.py +31 -16
  85. octavia/tests/functional/db/test_models.py +27 -28
  86. octavia/tests/functional/db/test_repositories.py +407 -50
  87. octavia/tests/unit/amphorae/backends/agent/api_server/test_amphora_info.py +2 -0
  88. octavia/tests/unit/amphorae/backends/agent/api_server/test_osutils.py +1 -1
  89. octavia/tests/unit/amphorae/backends/agent/api_server/test_plug.py +54 -6
  90. octavia/tests/unit/amphorae/backends/agent/api_server/test_util.py +35 -0
  91. octavia/tests/unit/amphorae/backends/health_daemon/test_health_daemon.py +8 -0
  92. octavia/tests/unit/amphorae/backends/health_daemon/test_health_sender.py +18 -0
  93. octavia/tests/unit/amphorae/backends/utils/test_interface.py +81 -0
  94. octavia/tests/unit/amphorae/backends/utils/test_interface_file.py +2 -0
  95. octavia/tests/unit/amphorae/backends/utils/test_keepalivedlvs_query.py +129 -5
  96. octavia/tests/unit/amphorae/drivers/haproxy/test_rest_api_driver_1_0.py +42 -20
  97. octavia/tests/unit/amphorae/drivers/health/test_heartbeat_udp.py +18 -20
  98. octavia/tests/unit/amphorae/drivers/keepalived/jinja/test_jinja_cfg.py +4 -4
  99. octavia/tests/unit/amphorae/drivers/noop_driver/test_driver.py +4 -1
  100. octavia/tests/unit/api/drivers/driver_agent/test_driver_get.py +3 -3
  101. octavia/tests/unit/api/drivers/driver_agent/test_driver_updater.py +11 -13
  102. octavia/tests/unit/base.py +6 -0
  103. octavia/tests/unit/cmd/test_interface.py +2 -2
  104. octavia/tests/unit/cmd/test_status.py +2 -2
  105. octavia/tests/unit/common/jinja/haproxy/combined_listeners/test_jinja_cfg.py +152 -1
  106. octavia/tests/unit/common/sample_configs/sample_configs_combined.py +10 -3
  107. octavia/tests/unit/common/test_clients.py +0 -39
  108. octavia/tests/unit/common/test_keystone.py +54 -0
  109. octavia/tests/unit/common/test_validate.py +67 -0
  110. octavia/tests/unit/controller/healthmanager/test_health_manager.py +8 -22
  111. octavia/tests/unit/controller/housekeeping/test_house_keeping.py +3 -64
  112. octavia/tests/unit/controller/worker/test_amphora_rate_limit.py +1 -1
  113. octavia/tests/unit/controller/worker/test_task_utils.py +44 -24
  114. octavia/tests/unit/controller/worker/v2/flows/test_load_balancer_flows.py +0 -1
  115. octavia/tests/unit/controller/worker/v2/tasks/test_amphora_driver_tasks.py +49 -26
  116. octavia/tests/unit/controller/worker/v2/tasks/test_database_tasks.py +399 -196
  117. octavia/tests/unit/controller/worker/v2/tasks/test_database_tasks_quota.py +37 -64
  118. octavia/tests/unit/controller/worker/v2/tasks/test_network_tasks.py +3 -14
  119. octavia/tests/unit/controller/worker/v2/test_controller_worker.py +2 -2
  120. octavia/tests/unit/network/drivers/neutron/test_allowed_address_pairs.py +456 -561
  121. octavia/tests/unit/network/drivers/neutron/test_base.py +181 -194
  122. octavia/tests/unit/network/drivers/neutron/test_utils.py +14 -30
  123. octavia/tests/unit/statistics/drivers/test_update_db.py +7 -5
  124. {octavia-12.0.0.0rc2.data → octavia-13.0.0.0rc1.data}/data/share/octavia/README.rst +1 -1
  125. {octavia-12.0.0.0rc2.dist-info → octavia-13.0.0.0rc1.dist-info}/AUTHORS +4 -0
  126. {octavia-12.0.0.0rc2.dist-info → octavia-13.0.0.0rc1.dist-info}/METADATA +4 -4
  127. {octavia-12.0.0.0rc2.dist-info → octavia-13.0.0.0rc1.dist-info}/RECORD +141 -189
  128. {octavia-12.0.0.0rc2.dist-info → octavia-13.0.0.0rc1.dist-info}/entry_points.txt +1 -2
  129. octavia-13.0.0.0rc1.dist-info/pbr.json +1 -0
  130. octavia/api/drivers/amphora_driver/v1/__init__.py +0 -11
  131. octavia/api/drivers/amphora_driver/v1/driver.py +0 -547
  132. octavia/controller/queue/v1/__init__.py +0 -11
  133. octavia/controller/queue/v1/consumer.py +0 -64
  134. octavia/controller/queue/v1/endpoints.py +0 -160
  135. octavia/controller/worker/v1/__init__.py +0 -11
  136. octavia/controller/worker/v1/controller_worker.py +0 -1157
  137. octavia/controller/worker/v1/flows/__init__.py +0 -11
  138. octavia/controller/worker/v1/flows/amphora_flows.py +0 -610
  139. octavia/controller/worker/v1/flows/health_monitor_flows.py +0 -105
  140. octavia/controller/worker/v1/flows/l7policy_flows.py +0 -94
  141. octavia/controller/worker/v1/flows/l7rule_flows.py +0 -100
  142. octavia/controller/worker/v1/flows/listener_flows.py +0 -128
  143. octavia/controller/worker/v1/flows/load_balancer_flows.py +0 -692
  144. octavia/controller/worker/v1/flows/member_flows.py +0 -230
  145. octavia/controller/worker/v1/flows/pool_flows.py +0 -127
  146. octavia/controller/worker/v1/tasks/__init__.py +0 -11
  147. octavia/controller/worker/v1/tasks/amphora_driver_tasks.py +0 -453
  148. octavia/controller/worker/v1/tasks/cert_task.py +0 -51
  149. octavia/controller/worker/v1/tasks/compute_tasks.py +0 -335
  150. octavia/controller/worker/v1/tasks/database_tasks.py +0 -2756
  151. octavia/controller/worker/v1/tasks/lifecycle_tasks.py +0 -173
  152. octavia/controller/worker/v1/tasks/model_tasks.py +0 -41
  153. octavia/controller/worker/v1/tasks/network_tasks.py +0 -970
  154. octavia/controller/worker/v1/tasks/retry_tasks.py +0 -74
  155. octavia/tests/unit/api/drivers/amphora_driver/v1/__init__.py +0 -11
  156. octavia/tests/unit/api/drivers/amphora_driver/v1/test_driver.py +0 -824
  157. octavia/tests/unit/controller/queue/v1/__init__.py +0 -11
  158. octavia/tests/unit/controller/queue/v1/test_consumer.py +0 -61
  159. octavia/tests/unit/controller/queue/v1/test_endpoints.py +0 -189
  160. octavia/tests/unit/controller/worker/v1/__init__.py +0 -11
  161. octavia/tests/unit/controller/worker/v1/flows/__init__.py +0 -11
  162. octavia/tests/unit/controller/worker/v1/flows/test_amphora_flows.py +0 -474
  163. octavia/tests/unit/controller/worker/v1/flows/test_health_monitor_flows.py +0 -72
  164. octavia/tests/unit/controller/worker/v1/flows/test_l7policy_flows.py +0 -67
  165. octavia/tests/unit/controller/worker/v1/flows/test_l7rule_flows.py +0 -67
  166. octavia/tests/unit/controller/worker/v1/flows/test_listener_flows.py +0 -91
  167. octavia/tests/unit/controller/worker/v1/flows/test_load_balancer_flows.py +0 -431
  168. octavia/tests/unit/controller/worker/v1/flows/test_member_flows.py +0 -106
  169. octavia/tests/unit/controller/worker/v1/flows/test_pool_flows.py +0 -77
  170. octavia/tests/unit/controller/worker/v1/tasks/__init__.py +0 -11
  171. octavia/tests/unit/controller/worker/v1/tasks/test_amphora_driver_tasks.py +0 -792
  172. octavia/tests/unit/controller/worker/v1/tasks/test_cert_task.py +0 -46
  173. octavia/tests/unit/controller/worker/v1/tasks/test_compute_tasks.py +0 -634
  174. octavia/tests/unit/controller/worker/v1/tasks/test_database_tasks.py +0 -2615
  175. octavia/tests/unit/controller/worker/v1/tasks/test_database_tasks_quota.py +0 -415
  176. octavia/tests/unit/controller/worker/v1/tasks/test_lifecycle_tasks.py +0 -401
  177. octavia/tests/unit/controller/worker/v1/tasks/test_model_tasks.py +0 -44
  178. octavia/tests/unit/controller/worker/v1/tasks/test_network_tasks.py +0 -1788
  179. octavia/tests/unit/controller/worker/v1/tasks/test_retry_tasks.py +0 -47
  180. octavia/tests/unit/controller/worker/v1/test_controller_worker.py +0 -2096
  181. octavia-12.0.0.0rc2.dist-info/pbr.json +0 -1
  182. {octavia-12.0.0.0rc2.data → octavia-13.0.0.0rc1.data}/data/share/octavia/LICENSE +0 -0
  183. {octavia-12.0.0.0rc2.data → octavia-13.0.0.0rc1.data}/data/share/octavia/diskimage-create/README.rst +0 -0
  184. {octavia-12.0.0.0rc2.data → octavia-13.0.0.0rc1.data}/data/share/octavia/diskimage-create/diskimage-create.sh +0 -0
  185. {octavia-12.0.0.0rc2.data → octavia-13.0.0.0rc1.data}/data/share/octavia/diskimage-create/image-tests.sh +0 -0
  186. {octavia-12.0.0.0rc2.data → octavia-13.0.0.0rc1.data}/data/share/octavia/diskimage-create/requirements.txt +0 -0
  187. {octavia-12.0.0.0rc2.data → octavia-13.0.0.0rc1.data}/data/share/octavia/diskimage-create/test-requirements.txt +0 -0
  188. {octavia-12.0.0.0rc2.data → octavia-13.0.0.0rc1.data}/data/share/octavia/diskimage-create/tox.ini +0 -0
  189. {octavia-12.0.0.0rc2.data → octavia-13.0.0.0rc1.data}/data/share/octavia/diskimage-create/version.txt +0 -0
  190. {octavia-12.0.0.0rc2.data → octavia-13.0.0.0rc1.data}/scripts/octavia-wsgi +0 -0
  191. {octavia-12.0.0.0rc2.dist-info → octavia-13.0.0.0rc1.dist-info}/LICENSE +0 -0
  192. {octavia-12.0.0.0rc2.dist-info → octavia-13.0.0.0rc1.dist-info}/WHEEL +0 -0
  193. {octavia-12.0.0.0rc2.dist-info → octavia-13.0.0.0rc1.dist-info}/top_level.txt +0 -0
@@ -1,2756 +0,0 @@
1
- # Copyright 2015 Hewlett-Packard Development Company, L.P.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License"); you may
4
- # not use this file except in compliance with the License. You may obtain
5
- # a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
- # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
- # License for the specific language governing permissions and limitations
13
- # under the License.
14
- #
15
-
16
- from cryptography import fernet
17
- from oslo_config import cfg
18
- from oslo_db import exception as odb_exceptions
19
- from oslo_log import log as logging
20
- from oslo_utils import excutils
21
- from oslo_utils import uuidutils
22
- import sqlalchemy
23
- from sqlalchemy.orm import exc
24
- from taskflow import task
25
- from taskflow.types import failure
26
-
27
- from octavia.common import constants
28
- from octavia.common import data_models
29
- from octavia.common.tls_utils import cert_parser
30
- from octavia.common import utils
31
- from octavia.controller.worker import task_utils as task_utilities
32
- from octavia.db import api as db_apis
33
- from octavia.db import repositories as repo
34
-
35
- CONF = cfg.CONF
36
- LOG = logging.getLogger(__name__)
37
-
38
-
39
- class BaseDatabaseTask(task.Task):
40
- """Base task to load drivers common to the tasks."""
41
-
42
- def __init__(self, **kwargs):
43
- self.repos = repo.Repositories()
44
- self.amphora_repo = repo.AmphoraRepository()
45
- self.health_mon_repo = repo.HealthMonitorRepository()
46
- self.listener_repo = repo.ListenerRepository()
47
- self.loadbalancer_repo = repo.LoadBalancerRepository()
48
- self.vip_repo = repo.VipRepository()
49
- self.member_repo = repo.MemberRepository()
50
- self.pool_repo = repo.PoolRepository()
51
- self.amp_health_repo = repo.AmphoraHealthRepository()
52
- self.l7policy_repo = repo.L7PolicyRepository()
53
- self.l7rule_repo = repo.L7RuleRepository()
54
- self.task_utils = task_utilities.TaskUtils()
55
- super().__init__(**kwargs)
56
-
57
- def _delete_from_amp_health(self, amphora_id):
58
- """Delete the amphora_health record for an amphora.
59
-
60
- :param amphora_id: The amphora id to delete
61
- """
62
- LOG.debug('Disabling health monitoring on amphora: %s', amphora_id)
63
- try:
64
- self.amp_health_repo.delete(db_apis.get_session(),
65
- amphora_id=amphora_id)
66
- except (sqlalchemy.orm.exc.NoResultFound,
67
- sqlalchemy.orm.exc.UnmappedInstanceError):
68
- LOG.debug('No existing amphora health record to delete '
69
- 'for amphora: %s, skipping.', amphora_id)
70
-
71
- def _mark_amp_health_busy(self, amphora_id):
72
- """Mark the amphora_health record busy for an amphora.
73
-
74
- :param amphora_id: The amphora id to mark busy
75
- """
76
- LOG.debug('Marking health monitoring busy on amphora: %s', amphora_id)
77
- try:
78
- self.amp_health_repo.update(db_apis.get_session(),
79
- amphora_id=amphora_id,
80
- busy=True)
81
- except (sqlalchemy.orm.exc.NoResultFound,
82
- sqlalchemy.orm.exc.UnmappedInstanceError):
83
- LOG.debug('No existing amphora health record to mark busy '
84
- 'for amphora: %s, skipping.', amphora_id)
85
-
86
-
87
- class CreateAmphoraInDB(BaseDatabaseTask):
88
- """Task to create an initial amphora in the Database."""
89
-
90
- def execute(self, *args, loadbalancer_id=None, **kwargs):
91
- """Creates an pending create amphora record in the database.
92
-
93
- :returns: The created amphora object
94
- """
95
-
96
- amphora = self.amphora_repo.create(db_apis.get_session(),
97
- id=uuidutils.generate_uuid(),
98
- load_balancer_id=loadbalancer_id,
99
- status=constants.PENDING_CREATE,
100
- cert_busy=False)
101
- if loadbalancer_id:
102
- LOG.info("Created Amphora %s in DB for load balancer %s",
103
- amphora.id, loadbalancer_id)
104
- else:
105
- LOG.info("Created Amphora %s in DB", amphora.id)
106
- return amphora.id
107
-
108
- def revert(self, result, *args, **kwargs):
109
- """Revert by storing the amphora in error state in the DB
110
-
111
- In a future version we might change the status to DELETED
112
- if deleting the amphora was successful
113
-
114
- :param result: Id of created amphora.
115
- :returns: None
116
- """
117
-
118
- if isinstance(result, failure.Failure):
119
- # This task's execute failed, so nothing needed to be done to
120
- # revert
121
- return
122
-
123
- # At this point the revert is being called because another task
124
- # executed after this failed so we will need to do something and
125
- # result is the amphora's id
126
-
127
- LOG.warning("Reverting create amphora in DB for amp id %s ", result)
128
-
129
- # Delete the amphora for now. May want to just update status later
130
- try:
131
- self.amphora_repo.delete(db_apis.get_session(), id=result)
132
- except Exception as e:
133
- LOG.error("Failed to delete amphora %(amp)s "
134
- "in the database due to: "
135
- "%(except)s", {'amp': result, 'except': str(e)})
136
-
137
-
138
- class MarkLBAmphoraeDeletedInDB(BaseDatabaseTask):
139
- """Task to mark a list of amphora deleted in the Database."""
140
-
141
- def execute(self, loadbalancer):
142
- """Update load balancer's amphorae statuses to DELETED in the database.
143
-
144
- :param loadbalancer: The load balancer which amphorae should be
145
- marked DELETED.
146
- :returns: None
147
- """
148
- for amp in loadbalancer.amphorae:
149
- LOG.debug("Marking amphora %s DELETED ", amp.id)
150
- self.amphora_repo.update(db_apis.get_session(),
151
- id=amp.id, status=constants.DELETED)
152
-
153
-
154
- class DeleteHealthMonitorInDB(BaseDatabaseTask):
155
- """Delete the health monitor in the DB.
156
-
157
- Since sqlalchemy will likely retry by itself always revert if it fails
158
- """
159
-
160
- def execute(self, health_mon):
161
- """Delete the health monitor in DB
162
-
163
- :param health_mon: The health monitor which should be deleted
164
- :returns: None
165
- """
166
-
167
- LOG.debug("DB delete health monitor: %s ", health_mon.id)
168
- try:
169
- self.health_mon_repo.delete(db_apis.get_session(),
170
- id=health_mon.id)
171
- except exc.NoResultFound:
172
- # ignore if the HealthMonitor was not found
173
- pass
174
-
175
- def revert(self, health_mon, *args, **kwargs):
176
- """Mark the health monitor ERROR since the mark active couldn't happen
177
-
178
- :param health_mon: The health monitor which couldn't be deleted
179
- :returns: None
180
- """
181
-
182
- LOG.warning("Reverting mark health monitor delete in DB "
183
- "for health monitor with id %s", health_mon.id)
184
- self.health_mon_repo.update(db_apis.get_session(), id=health_mon.id,
185
- provisioning_status=constants.ERROR)
186
-
187
-
188
- class DeleteHealthMonitorInDBByPool(DeleteHealthMonitorInDB):
189
- """Delete the health monitor in the DB.
190
-
191
- Since sqlalchemy will likely retry by itself always revert if it fails
192
- """
193
-
194
- def execute(self, pool):
195
- """Delete the health monitor in the DB.
196
-
197
- :param pool: A pool which health monitor should be deleted.
198
- :returns: None
199
- """
200
- super().execute(
201
- pool.health_monitor)
202
-
203
- def revert(self, pool, *args, **kwargs):
204
- """Mark the health monitor ERROR since the mark active couldn't happen
205
-
206
- :param pool: A pool which health monitor couldn't be deleted
207
- :returns: None
208
- """
209
- super().revert(
210
- pool.health_monitor, *args, **kwargs)
211
-
212
-
213
- class DeleteMemberInDB(BaseDatabaseTask):
214
- """Delete the member in the DB.
215
-
216
- Since sqlalchemy will likely retry by itself always revert if it fails
217
- """
218
-
219
- def execute(self, member):
220
- """Delete the member in the DB
221
-
222
- :param member: The member to be deleted
223
- :returns: None
224
- """
225
-
226
- LOG.debug("DB delete member for id: %s ", member.id)
227
- self.member_repo.delete(db_apis.get_session(), id=member.id)
228
-
229
- def revert(self, member, *args, **kwargs):
230
- """Mark the member ERROR since the delete couldn't happen
231
-
232
- :param member: Member that failed to get deleted
233
- :returns: None
234
- """
235
-
236
- LOG.warning("Reverting delete in DB for member id %s", member.id)
237
- try:
238
- self.member_repo.update(db_apis.get_session(), member.id,
239
- provisioning_status=constants.ERROR)
240
- except Exception as e:
241
- LOG.error("Failed to update member %(mem)s "
242
- "provisioning_status to ERROR due to: %(except)s",
243
- {'mem': member.id, 'except': str(e)})
244
-
245
-
246
- class DeleteListenerInDB(BaseDatabaseTask):
247
- """Delete the listener in the DB."""
248
-
249
- def execute(self, listener):
250
- """Delete the listener in DB
251
-
252
- :param listener: The listener to delete
253
- :returns: None
254
- """
255
- LOG.debug("Delete in DB for listener id: %s", listener.id)
256
- self.listener_repo.delete(db_apis.get_session(), id=listener.id)
257
-
258
- def revert(self, listener, *args, **kwargs):
259
- """Mark the listener ERROR since the listener didn't delete
260
-
261
- :param listener: Listener that failed to get deleted
262
- :returns: None
263
- """
264
-
265
- LOG.warning("Reverting mark listener delete in DB for listener id %s",
266
- listener.id)
267
-
268
-
269
- class DeletePoolInDB(BaseDatabaseTask):
270
- """Delete the pool in the DB.
271
-
272
- Since sqlalchemy will likely retry by itself always revert if it fails
273
- """
274
-
275
- def execute(self, pool):
276
- """Delete the pool in DB
277
-
278
- :param pool: The pool to be deleted
279
- :returns: None
280
- """
281
-
282
- LOG.debug("Delete in DB for pool id: %s ", pool.id)
283
- self.pool_repo.delete(db_apis.get_session(), id=pool.id)
284
-
285
- def revert(self, pool, *args, **kwargs):
286
- """Mark the pool ERROR since the delete couldn't happen
287
-
288
- :param pool: Pool that failed to get deleted
289
- :returns: None
290
- """
291
-
292
- LOG.warning("Reverting delete in DB for pool id %s", pool.id)
293
- try:
294
- self.pool_repo.update(db_apis.get_session(), pool.id,
295
- provisioning_status=constants.ERROR)
296
- except Exception as e:
297
- LOG.error("Failed to update pool %(pool)s "
298
- "provisioning_status to ERROR due to: %(except)s",
299
- {'pool': pool.id, 'except': str(e)})
300
-
301
-
302
- class DeleteL7PolicyInDB(BaseDatabaseTask):
303
- """Delete the L7 policy in the DB.
304
-
305
- Since sqlalchemy will likely retry by itself always revert if it fails
306
- """
307
-
308
- def execute(self, l7policy):
309
- """Delete the l7policy in DB
310
-
311
- :param l7policy: The l7policy to be deleted
312
- :returns: None
313
- """
314
-
315
- LOG.debug("Delete in DB for l7policy id: %s ", l7policy.id)
316
- self.l7policy_repo.delete(db_apis.get_session(), id=l7policy.id)
317
-
318
- def revert(self, l7policy, *args, **kwargs):
319
- """Mark the l7policy ERROR since the delete couldn't happen
320
-
321
- :param l7policy: L7 policy that failed to get deleted
322
- :returns: None
323
- """
324
-
325
- LOG.warning("Reverting delete in DB for l7policy id %s", l7policy.id)
326
- try:
327
- self.l7policy_repo.update(db_apis.get_session(), l7policy.id,
328
- provisioning_status=constants.ERROR)
329
- except Exception as e:
330
- LOG.error("Failed to update l7policy %(l7policy)s "
331
- "provisioning_status to ERROR due to: %(except)s",
332
- {'l7policy': l7policy.id, 'except': str(e)})
333
-
334
-
335
- class DeleteL7RuleInDB(BaseDatabaseTask):
336
- """Delete the L7 rule in the DB.
337
-
338
- Since sqlalchemy will likely retry by itself always revert if it fails
339
- """
340
-
341
- def execute(self, l7rule):
342
- """Delete the l7rule in DB
343
-
344
- :param l7rule: The l7rule to be deleted
345
- :returns: None
346
- """
347
-
348
- LOG.debug("Delete in DB for l7rule id: %s ", l7rule.id)
349
- self.l7rule_repo.delete(db_apis.get_session(), id=l7rule.id)
350
-
351
- def revert(self, l7rule, *args, **kwargs):
352
- """Mark the l7rule ERROR since the delete couldn't happen
353
-
354
- :param l7rule: L7 rule that failed to get deleted
355
- :returns: None
356
- """
357
-
358
- LOG.warning("Reverting delete in DB for l7rule id %s", l7rule.id)
359
- try:
360
- self.l7rule_repo.update(db_apis.get_session(), l7rule.id,
361
- provisioning_status=constants.ERROR)
362
- except Exception as e:
363
- LOG.error("Failed to update l7rule %(l7rule)s "
364
- "provisioning_status to ERROR due to: %(except)s",
365
- {'l7rule': l7rule.id, 'except': str(e)})
366
-
367
-
368
- class ReloadAmphora(BaseDatabaseTask):
369
- """Get an amphora object from the database."""
370
-
371
- def execute(self, amphora_id):
372
- """Get an amphora object from the database.
373
-
374
- :param amphora_id: The amphora ID to lookup
375
- :returns: The amphora object
376
- """
377
-
378
- LOG.debug("Get amphora from DB for amphora id: %s ", amphora_id)
379
- return self.amphora_repo.get(db_apis.get_session(), id=amphora_id)
380
-
381
-
382
- class ReloadLoadBalancer(BaseDatabaseTask):
383
- """Get an load balancer object from the database."""
384
-
385
- def execute(self, loadbalancer_id, *args, **kwargs):
386
- """Get an load balancer object from the database.
387
-
388
- :param loadbalancer_id: The load balancer ID to lookup
389
- :returns: The load balancer object
390
- """
391
-
392
- LOG.debug("Get load balancer from DB for load balancer id: %s ",
393
- loadbalancer_id)
394
- return self.loadbalancer_repo.get(db_apis.get_session(),
395
- id=loadbalancer_id)
396
-
397
-
398
- class UpdateVIPAfterAllocation(BaseDatabaseTask):
399
- """Update a VIP associated with a given load balancer."""
400
-
401
- def execute(self, loadbalancer_id, vip):
402
- """Update a VIP associated with a given load balancer.
403
-
404
- :param loadbalancer_id: Id of a load balancer which VIP should be
405
- updated.
406
- :param vip: data_models.Vip object with update data.
407
- :returns: The load balancer object.
408
- """
409
- self.repos.vip.update(db_apis.get_session(), loadbalancer_id,
410
- port_id=vip.port_id, subnet_id=vip.subnet_id,
411
- ip_address=vip.ip_address)
412
- lb = self.repos.load_balancer.get(db_apis.get_session(),
413
- id=loadbalancer_id)
414
- LOG.info("Updated vip with port id %s, subnet id %s, ip address %s "
415
- "for load balancer %s",
416
- vip.port_id,
417
- vip.subnet_id,
418
- vip.ip_address,
419
- loadbalancer_id)
420
- return lb
421
-
422
-
423
- class UpdateAmphoraeVIPData(BaseDatabaseTask):
424
- """Update amphorae VIP data."""
425
-
426
- def execute(self, amps_data):
427
- """Update amphorae VIP data.
428
-
429
- :param amps_data: Amphorae update dicts.
430
- :returns: None
431
- """
432
- for amp_data in amps_data:
433
- self.repos.amphora.update(db_apis.get_session(), amp_data.id,
434
- vrrp_ip=amp_data.vrrp_ip,
435
- ha_ip=amp_data.ha_ip,
436
- vrrp_port_id=amp_data.vrrp_port_id,
437
- ha_port_id=amp_data.ha_port_id,
438
- vrrp_id=1)
439
-
440
-
441
- class UpdateAmphoraVIPData(BaseDatabaseTask):
442
- """Update amphorae VIP data."""
443
-
444
- def execute(self, amp_data):
445
- """Update amphorae VIP data.
446
-
447
- :param amps_data: Amphorae update dicts.
448
- :returns: None
449
- """
450
- self.repos.amphora.update(db_apis.get_session(), amp_data.id,
451
- vrrp_ip=amp_data.vrrp_ip,
452
- ha_ip=amp_data.ha_ip,
453
- vrrp_port_id=amp_data.vrrp_port_id,
454
- ha_port_id=amp_data.ha_port_id,
455
- vrrp_id=1)
456
-
457
-
458
- class UpdateAmpFailoverDetails(BaseDatabaseTask):
459
- """Update amphora failover details in the database."""
460
-
461
- def execute(self, amphora, vip, base_port):
462
- """Update amphora failover details in the database.
463
-
464
- :param amphora: The amphora to update
465
- :param vip: The VIP object associated with this amphora.
466
- :param base_port: The base port object associated with the amphora.
467
- :returns: None
468
- """
469
- # role and vrrp_priority will be updated later.
470
- self.repos.amphora.update(db_apis.get_session(), amphora.id,
471
- vrrp_ip=base_port.fixed_ips[0].ip_address,
472
- ha_ip=vip.ip_address,
473
- vrrp_port_id=base_port.id,
474
- ha_port_id=vip.port_id,
475
- vrrp_id=1)
476
-
477
-
478
- class AssociateFailoverAmphoraWithLBID(BaseDatabaseTask):
479
- """Associate failover amphora with loadbalancer in the database."""
480
-
481
- def execute(self, amphora_id, loadbalancer_id):
482
- """Associate failover amphora with loadbalancer in the database.
483
-
484
- :param amphora_id: Id of an amphora to update
485
- :param loadbalancer_id: Id of a load balancer to be associated with
486
- a given amphora.
487
- :returns: None
488
- """
489
- self.repos.amphora.associate(db_apis.get_session(),
490
- load_balancer_id=loadbalancer_id,
491
- amphora_id=amphora_id)
492
-
493
- def revert(self, amphora_id, *args, **kwargs):
494
- """Remove amphora-load balancer association.
495
-
496
- :param amphora_id: Id of an amphora that couldn't be associated
497
- with a load balancer.
498
- :returns: None
499
- """
500
- try:
501
- self.repos.amphora.update(db_apis.get_session(), amphora_id,
502
- loadbalancer_id=None)
503
- except Exception as e:
504
- LOG.error("Failed to update amphora %(amp)s "
505
- "load balancer id to None due to: "
506
- "%(except)s", {'amp': amphora_id, 'except': str(e)})
507
-
508
-
509
- class _MarkAmphoraRoleAndPriorityInDB(BaseDatabaseTask):
510
- """Alter the amphora role and priority in DB."""
511
-
512
- def _execute(self, amphora, amp_role, vrrp_priority):
513
- """Alter the amphora role and priority in DB.
514
-
515
- :param amphora: Amphora to update.
516
- :param amp_role: Amphora role to be set.
517
- :param vrrp_priority: VRRP priority to set.
518
- :returns: None
519
- """
520
- LOG.debug("Mark %(role)s in DB for amphora: %(amp)s",
521
- {'role': amp_role, 'amp': amphora.id})
522
- self.amphora_repo.update(db_apis.get_session(), amphora.id,
523
- role=amp_role,
524
- vrrp_priority=vrrp_priority)
525
-
526
- def _revert(self, result, amphora, *args, **kwargs):
527
- """Removes role and vrrp_priority association.
528
-
529
- :param result: Result of the association.
530
- :param amphora: Amphora which role/vrrp_priority association
531
- failed.
532
- :returns: None
533
- """
534
-
535
- if isinstance(result, failure.Failure):
536
- return
537
-
538
- LOG.warning("Reverting amphora role in DB for amp id %(amp)s",
539
- {'amp': amphora.id})
540
- try:
541
- self.amphora_repo.update(db_apis.get_session(), amphora.id,
542
- role=None,
543
- vrrp_priority=None)
544
- except Exception as e:
545
- LOG.error("Failed to update amphora %(amp)s "
546
- "role and vrrp_priority to None due to: "
547
- "%(except)s", {'amp': amphora.id, 'except': str(e)})
548
-
549
-
550
- class MarkAmphoraMasterInDB(_MarkAmphoraRoleAndPriorityInDB):
551
- """Alter the amphora role to: MASTER."""
552
-
553
- def execute(self, amphora):
554
- """Mark amphora as MASTER in db.
555
-
556
- :param amphora: Amphora to update role.
557
- :returns: None
558
- """
559
- amp_role = constants.ROLE_MASTER
560
- self._execute(amphora, amp_role, constants.ROLE_MASTER_PRIORITY)
561
-
562
- def revert(self, result, amphora, *args, **kwargs):
563
- """Removes amphora role association.
564
-
565
- :param amphora: Amphora to update role.
566
- :returns: None
567
- """
568
- self._revert(result, amphora, *args, **kwargs)
569
-
570
-
571
- class MarkAmphoraBackupInDB(_MarkAmphoraRoleAndPriorityInDB):
572
- """Alter the amphora role to: Backup."""
573
-
574
- def execute(self, amphora):
575
- """Mark amphora as BACKUP in db.
576
-
577
- :param amphora: Amphora to update role.
578
- :returns: None
579
- """
580
- amp_role = constants.ROLE_BACKUP
581
- self._execute(amphora, amp_role, constants.ROLE_BACKUP_PRIORITY)
582
-
583
- def revert(self, result, amphora, *args, **kwargs):
584
- """Removes amphora role association.
585
-
586
- :param amphora: Amphora to update role.
587
- :returns: None
588
- """
589
- self._revert(result, amphora, *args, **kwargs)
590
-
591
-
592
- class MarkAmphoraStandAloneInDB(_MarkAmphoraRoleAndPriorityInDB):
593
- """Alter the amphora role to: Standalone."""
594
-
595
- def execute(self, amphora):
596
- """Mark amphora as STANDALONE in db.
597
-
598
- :param amphora: Amphora to update role.
599
- :returns: None
600
- """
601
- amp_role = constants.ROLE_STANDALONE
602
- self._execute(amphora, amp_role, None)
603
-
604
- def revert(self, result, amphora, *args, **kwargs):
605
- """Removes amphora role association.
606
-
607
- :param amphora: Amphora to update role.
608
- :returns: None
609
- """
610
- self._revert(result, amphora, *args, **kwargs)
611
-
612
-
613
- class MarkAmphoraAllocatedInDB(BaseDatabaseTask):
614
- """Will mark an amphora as allocated to a load balancer in the database.
615
-
616
- Assume sqlalchemy made sure the DB got
617
- retried sufficiently - so just abort
618
- """
619
-
620
- def execute(self, amphora, loadbalancer_id):
621
- """Mark amphora as allocated to a load balancer in DB.
622
-
623
- :param amphora: Amphora to be updated.
624
- :param loadbalancer_id: Id of a load balancer to which an amphora
625
- should be allocated.
626
- :returns: None
627
- """
628
-
629
- LOG.info('Mark ALLOCATED in DB for amphora: %(amp)s with '
630
- 'compute id: %(comp)s for load balancer: %(lb)s',
631
- {
632
- 'amp': amphora.id,
633
- 'comp': amphora.compute_id,
634
- 'lb': loadbalancer_id
635
- })
636
- self.amphora_repo.update(db_apis.get_session(), amphora.id,
637
- status=constants.AMPHORA_ALLOCATED,
638
- compute_id=amphora.compute_id,
639
- lb_network_ip=amphora.lb_network_ip,
640
- load_balancer_id=loadbalancer_id)
641
-
642
- def revert(self, result, amphora, loadbalancer_id, *args, **kwargs):
643
- """Mark the amphora as broken and ready to be cleaned up.
644
-
645
- :param result: Execute task result
646
- :param amphora: Amphora that was updated.
647
- :param loadbalancer_id: Id of a load balancer to which an amphora
648
- failed to be allocated.
649
- :returns: None
650
- """
651
-
652
- if isinstance(result, failure.Failure):
653
- return
654
-
655
- LOG.warning("Reverting mark amphora ready in DB for amp "
656
- "id %(amp)s and compute id %(comp)s",
657
- {'amp': amphora.id, 'comp': amphora.compute_id})
658
- self.task_utils.mark_amphora_status_error(amphora.id)
659
-
660
-
661
- class MarkAmphoraBootingInDB(BaseDatabaseTask):
662
- """Mark the amphora as booting in the database."""
663
-
664
- def execute(self, amphora_id, compute_id):
665
- """Mark amphora booting in DB.
666
-
667
- :param amphora_id: Id of the amphora to update
668
- :param compute_id: Id of a compute on which an amphora resides
669
- :returns: None
670
- """
671
-
672
- LOG.debug("Mark BOOTING in DB for amphora: %(amp)s with "
673
- "compute id %(id)s", {'amp': amphora_id, 'id': compute_id})
674
- self.amphora_repo.update(db_apis.get_session(), amphora_id,
675
- status=constants.AMPHORA_BOOTING,
676
- compute_id=compute_id)
677
-
678
- def revert(self, result, amphora_id, compute_id, *args, **kwargs):
679
- """Mark the amphora as broken and ready to be cleaned up.
680
-
681
- :param result: Execute task result
682
- :param amphora_id: Id of the amphora that failed to update
683
- :param compute_id: Id of a compute on which an amphora resides
684
- :returns: None
685
- """
686
-
687
- if isinstance(result, failure.Failure):
688
- return
689
-
690
- LOG.warning("Reverting mark amphora booting in DB for amp "
691
- "id %(amp)s and compute id %(comp)s",
692
- {'amp': amphora_id, 'comp': compute_id})
693
- try:
694
- self.amphora_repo.update(db_apis.get_session(), amphora_id,
695
- status=constants.ERROR,
696
- compute_id=compute_id)
697
- except Exception as e:
698
- LOG.error("Failed to update amphora %(amp)s "
699
- "status to ERROR due to: "
700
- "%(except)s", {'amp': amphora_id, 'except': str(e)})
701
-
702
-
703
- class MarkAmphoraDeletedInDB(BaseDatabaseTask):
704
- """Mark the amphora deleted in the DB.
705
-
706
- Since sqlalchemy will likely retry by itself always revert if it fails
707
- """
708
-
709
- def execute(self, amphora):
710
- """Mark the amphora as deleted in DB.
711
-
712
- :param amphora: Amphora to be updated.
713
- :returns: None
714
- """
715
-
716
- LOG.debug("Mark DELETED in DB for amphora: %(amp)s with "
717
- "compute id %(comp)s",
718
- {'amp': amphora.id, 'comp': amphora.compute_id})
719
- self.amphora_repo.update(db_apis.get_session(), amphora.id,
720
- status=constants.DELETED)
721
-
722
- def revert(self, amphora, *args, **kwargs):
723
- """Mark the amphora as broken and ready to be cleaned up.
724
-
725
- :param amphora: Amphora that was updated.
726
- :returns: None
727
- """
728
-
729
- LOG.warning("Reverting mark amphora deleted in DB "
730
- "for amp id %(amp)s and compute id %(comp)s",
731
- {'amp': amphora.id, 'comp': amphora.compute_id})
732
- self.task_utils.mark_amphora_status_error(amphora.id)
733
-
734
-
735
- class MarkAmphoraPendingDeleteInDB(BaseDatabaseTask):
736
- """Mark the amphora pending delete in the DB.
737
-
738
- Since sqlalchemy will likely retry by itself always revert if it fails
739
- """
740
-
741
- def execute(self, amphora):
742
- """Mark the amphora as pending delete in DB.
743
-
744
- :param amphora: Amphora to be updated.
745
- :returns: None
746
- """
747
-
748
- LOG.debug("Mark PENDING DELETE in DB for amphora: %(amp)s "
749
- "with compute id %(id)s",
750
- {'amp': amphora.id, 'id': amphora.compute_id})
751
- self.amphora_repo.update(db_apis.get_session(), amphora.id,
752
- status=constants.PENDING_DELETE)
753
-
754
- def revert(self, amphora, *args, **kwargs):
755
- """Mark the amphora as broken and ready to be cleaned up.
756
-
757
- :param amphora: Amphora that was updated.
758
- :returns: None
759
- """
760
-
761
- LOG.warning("Reverting mark amphora pending delete in DB "
762
- "for amp id %(amp)s and compute id %(comp)s",
763
- {'amp': amphora.id, 'comp': amphora.compute_id})
764
- self.task_utils.mark_amphora_status_error(amphora.id)
765
-
766
-
767
- class MarkAmphoraPendingUpdateInDB(BaseDatabaseTask):
768
- """Mark the amphora pending update in the DB.
769
-
770
- Since sqlalchemy will likely retry by itself always revert if it fails
771
- """
772
-
773
- def execute(self, amphora):
774
- """Mark the amphora as pending update in DB.
775
-
776
- :param amphora: Amphora to be updated.
777
- :returns: None
778
- """
779
-
780
- LOG.debug("Mark PENDING UPDATE in DB for amphora: %(amp)s "
781
- "with compute id %(id)s",
782
- {'amp': amphora.id, 'id': amphora.compute_id})
783
- self.amphora_repo.update(db_apis.get_session(), amphora.id,
784
- status=constants.PENDING_UPDATE)
785
-
786
- def revert(self, amphora, *args, **kwargs):
787
- """Mark the amphora as broken and ready to be cleaned up.
788
-
789
- :param amphora: Amphora that was updated.
790
- :returns: None
791
- """
792
-
793
- LOG.warning("Reverting mark amphora pending update in DB "
794
- "for amp id %(amp)s and compute id %(comp)s",
795
- {'amp': amphora.id, 'comp': amphora.compute_id})
796
- self.task_utils.mark_amphora_status_error(amphora.id)
797
-
798
-
799
- class MarkAmphoraReadyInDB(BaseDatabaseTask):
800
- """This task will mark an amphora as ready in the database.
801
-
802
- Assume sqlalchemy made sure the DB got
803
- retried sufficiently - so just abort
804
- """
805
-
806
- def execute(self, amphora):
807
- """Mark amphora as ready in DB.
808
-
809
- :param amphora: Amphora to be updated.
810
- :returns: None
811
- """
812
-
813
- LOG.info("Mark READY in DB for amphora: %(amp)s with compute "
814
- "id %(comp)s",
815
- {"amp": amphora.id, "comp": amphora.compute_id})
816
- self.amphora_repo.update(db_apis.get_session(), amphora.id,
817
- status=constants.AMPHORA_READY,
818
- compute_id=amphora.compute_id,
819
- lb_network_ip=amphora.lb_network_ip)
820
-
821
- def revert(self, amphora, *args, **kwargs):
822
- """Mark the amphora as broken and ready to be cleaned up.
823
-
824
- :param amphora: Amphora that was updated.
825
- :returns: None
826
- """
827
-
828
- LOG.warning("Reverting mark amphora ready in DB for amp "
829
- "id %(amp)s and compute id %(comp)s",
830
- {'amp': amphora.id, 'comp': amphora.compute_id})
831
- try:
832
- self.amphora_repo.update(db_apis.get_session(), amphora.id,
833
- status=constants.ERROR,
834
- compute_id=amphora.compute_id,
835
- lb_network_ip=amphora.lb_network_ip)
836
- except Exception as e:
837
- LOG.error("Failed to update amphora %(amp)s "
838
- "status to ERROR due to: "
839
- "%(except)s", {'amp': amphora.id, 'except': str(e)})
840
-
841
-
842
- class UpdateAmphoraComputeId(BaseDatabaseTask):
843
- """Associate amphora with a compute in DB."""
844
-
845
- def execute(self, amphora_id, compute_id):
846
- """Associate amphora with a compute in DB.
847
-
848
- :param amphora_id: Id of the amphora to update
849
- :param compute_id: Id of a compute on which an amphora resides
850
- :returns: None
851
- """
852
-
853
- self.amphora_repo.update(db_apis.get_session(), amphora_id,
854
- compute_id=compute_id)
855
-
856
-
857
- class UpdateAmphoraInfo(BaseDatabaseTask):
858
- """Update amphora with compute instance details."""
859
-
860
- def execute(self, amphora_id, compute_obj):
861
- """Update amphora with compute instance details.
862
-
863
- :param amphora_id: Id of the amphora to update
864
- :param compute_obj: Compute on which an amphora resides
865
- :returns: Updated amphora object
866
- """
867
- self.amphora_repo.update(
868
- db_apis.get_session(), amphora_id,
869
- lb_network_ip=compute_obj.lb_network_ip,
870
- cached_zone=compute_obj.cached_zone,
871
- image_id=compute_obj.image_id,
872
- compute_flavor=compute_obj.compute_flavor)
873
- return self.amphora_repo.get(db_apis.get_session(), id=amphora_id)
874
-
875
-
876
- class UpdateAmphoraDBCertExpiration(BaseDatabaseTask):
877
- """Update the amphora expiration date with new cert file date."""
878
-
879
- def execute(self, amphora_id, server_pem):
880
- """Update the amphora expiration date with new cert file date.
881
-
882
- :param amphora_id: Id of the amphora to update
883
- :param server_pem: Certificate in PEM format
884
- :returns: None
885
- """
886
-
887
- LOG.debug("Update DB cert expiry date of amphora id: %s", amphora_id)
888
-
889
- key = utils.get_compatible_server_certs_key_passphrase()
890
- fer = fernet.Fernet(key)
891
- cert_expiration = cert_parser.get_cert_expiration(
892
- fer.decrypt(server_pem))
893
- LOG.debug("Certificate expiration date is %s ", cert_expiration)
894
- self.amphora_repo.update(db_apis.get_session(), amphora_id,
895
- cert_expiration=cert_expiration)
896
-
897
-
898
- class UpdateAmphoraCertBusyToFalse(BaseDatabaseTask):
899
- """Update the amphora cert_busy flag to be false."""
900
-
901
- def execute(self, amphora):
902
- """Update the amphora cert_busy flag to be false.
903
-
904
- :param amphora: Amphora to be updated.
905
- :returns: None
906
- """
907
-
908
- LOG.debug("Update cert_busy flag of amphora id %s to False",
909
- amphora.id)
910
- self.amphora_repo.update(db_apis.get_session(), amphora.id,
911
- cert_busy=False)
912
-
913
-
914
- class MarkLBActiveInDB(BaseDatabaseTask):
915
- """Mark the load balancer active in the DB.
916
-
917
- Since sqlalchemy will likely retry by itself always revert if it fails
918
- """
919
-
920
- def __init__(self, mark_subobjects=False, **kwargs):
921
- super().__init__(**kwargs)
922
- self.mark_subobjects = mark_subobjects
923
-
924
- def execute(self, loadbalancer):
925
- """Mark the load balancer as active in DB.
926
-
927
- This also marks ACTIVE all sub-objects of the load balancer if
928
- self.mark_subobjects is True.
929
-
930
- :param loadbalancer: Load balancer object to be updated
931
- :returns: None
932
- """
933
-
934
- if self.mark_subobjects:
935
- LOG.debug("Marking all listeners of loadbalancer %s ACTIVE",
936
- loadbalancer.id)
937
- for listener in loadbalancer.listeners:
938
- self._mark_listener_status(listener, constants.ACTIVE)
939
-
940
- LOG.info("Mark ACTIVE in DB for load balancer id: %s",
941
- loadbalancer.id)
942
- self.loadbalancer_repo.update(db_apis.get_session(),
943
- loadbalancer.id,
944
- provisioning_status=constants.ACTIVE)
945
-
946
- def _mark_listener_status(self, listener, status):
947
- self.listener_repo.update(db_apis.get_session(),
948
- listener.id,
949
- provisioning_status=status)
950
- LOG.debug("Marking all l7policies of listener %s %s",
951
- listener.id, status)
952
- for l7policy in listener.l7policies:
953
- self._mark_l7policy_status(l7policy, status)
954
-
955
- if listener.default_pool:
956
- LOG.debug("Marking default pool of listener %s %s",
957
- listener.id, status)
958
- self._mark_pool_status(listener.default_pool, status)
959
-
960
- def _mark_l7policy_status(self, l7policy, status):
961
- self.l7policy_repo.update(
962
- db_apis.get_session(), l7policy.id,
963
- provisioning_status=status)
964
-
965
- LOG.debug("Marking all l7rules of l7policy %s %s",
966
- l7policy.id, status)
967
- for l7rule in l7policy.l7rules:
968
- self._mark_l7rule_status(l7rule, status)
969
-
970
- if l7policy.redirect_pool:
971
- LOG.debug("Marking redirect pool of l7policy %s %s",
972
- l7policy.id, status)
973
- self._mark_pool_status(l7policy.redirect_pool, status)
974
-
975
- def _mark_l7rule_status(self, l7rule, status):
976
- self.l7rule_repo.update(
977
- db_apis.get_session(), l7rule.id,
978
- provisioning_status=status)
979
-
980
- def _mark_pool_status(self, pool, status):
981
- self.pool_repo.update(
982
- db_apis.get_session(), pool.id,
983
- provisioning_status=status)
984
- if pool.health_monitor:
985
- LOG.debug("Marking health monitor of pool %s %s", pool.id, status)
986
- self._mark_hm_status(pool.health_monitor, status)
987
-
988
- LOG.debug("Marking all members of pool %s %s", pool.id, status)
989
- for member in pool.members:
990
- self._mark_member_status(member, status)
991
-
992
- def _mark_hm_status(self, hm, status):
993
- self.health_mon_repo.update(
994
- db_apis.get_session(), hm.id,
995
- provisioning_status=status)
996
-
997
- def _mark_member_status(self, member, status):
998
- self.member_repo.update(
999
- db_apis.get_session(), member.id,
1000
- provisioning_status=status)
1001
-
1002
- def revert(self, loadbalancer, *args, **kwargs):
1003
- """Mark the load balancer as broken and ready to be cleaned up.
1004
-
1005
- This also puts all sub-objects of the load balancer to ERROR state if
1006
- self.mark_subobjects is True
1007
-
1008
- :param loadbalancer: Load balancer object that failed to update
1009
- :returns: None
1010
- """
1011
-
1012
- if self.mark_subobjects:
1013
- LOG.debug("Marking all listeners of loadbalancer %s ERROR",
1014
- loadbalancer.id)
1015
- for listener in loadbalancer.listeners:
1016
- try:
1017
- self._mark_listener_status(listener, constants.ERROR)
1018
- except Exception:
1019
- LOG.warning("Error updating listener %s provisioning "
1020
- "status", listener.id)
1021
-
1022
-
1023
- class UpdateLBServerGroupInDB(BaseDatabaseTask):
1024
- """Update the server group id info for load balancer in DB."""
1025
-
1026
- def execute(self, loadbalancer_id, server_group_id):
1027
- """Update the server group id info for load balancer in DB.
1028
-
1029
- :param loadbalancer_id: Id of a load balancer to update
1030
- :param server_group_id: Id of a server group to associate with
1031
- the load balancer
1032
- :returns: None
1033
- """
1034
-
1035
- LOG.debug("Server Group updated with id: %s for load balancer id: %s:",
1036
- server_group_id, loadbalancer_id)
1037
- self.loadbalancer_repo.update(db_apis.get_session(),
1038
- id=loadbalancer_id,
1039
- server_group_id=server_group_id)
1040
-
1041
- def revert(self, loadbalancer_id, server_group_id, *args, **kwargs):
1042
- """Remove server group information from a load balancer in DB.
1043
-
1044
- :param loadbalancer_id: Id of a load balancer that failed to update
1045
- :param server_group_id: Id of a server group that couldn't be
1046
- associated with the load balancer
1047
- :returns: None
1048
- """
1049
- LOG.warning('Reverting Server Group updated with id: %(s1)s for '
1050
- 'load balancer id: %(s2)s ',
1051
- {'s1': server_group_id, 's2': loadbalancer_id})
1052
- try:
1053
- self.loadbalancer_repo.update(db_apis.get_session(),
1054
- id=loadbalancer_id,
1055
- server_group_id=None)
1056
- except Exception as e:
1057
- LOG.error("Failed to update load balancer %(lb)s "
1058
- "server_group_id to None due to: "
1059
- "%(except)s", {'lb': loadbalancer_id, 'except': str(e)})
1060
-
1061
-
1062
- class MarkLBDeletedInDB(BaseDatabaseTask):
1063
- """Mark the load balancer deleted in the DB.
1064
-
1065
- Since sqlalchemy will likely retry by itself always revert if it fails
1066
- """
1067
-
1068
- def execute(self, loadbalancer):
1069
- """Mark the load balancer as deleted in DB.
1070
-
1071
- :param loadbalancer: Load balancer object to be updated
1072
- :returns: None
1073
- """
1074
-
1075
- LOG.debug("Mark DELETED in DB for load balancer id: %s",
1076
- loadbalancer.id)
1077
- self.loadbalancer_repo.update(db_apis.get_session(),
1078
- loadbalancer.id,
1079
- provisioning_status=constants.DELETED)
1080
-
1081
-
1082
- class MarkLBPendingDeleteInDB(BaseDatabaseTask):
1083
- """Mark the load balancer pending delete in the DB.
1084
-
1085
- Since sqlalchemy will likely retry by itself always revert if it fails
1086
- """
1087
-
1088
- def execute(self, loadbalancer):
1089
- """Mark the load balancer as pending delete in DB.
1090
-
1091
- :param loadbalancer: Load balancer object to be updated
1092
- :returns: None
1093
- """
1094
-
1095
- LOG.debug("Mark PENDING DELETE in DB for load balancer id: %s",
1096
- loadbalancer.id)
1097
- self.loadbalancer_repo.update(db_apis.get_session(),
1098
- loadbalancer.id,
1099
- provisioning_status=(constants.
1100
- PENDING_DELETE))
1101
-
1102
-
1103
- class MarkLBAndListenersActiveInDB(BaseDatabaseTask):
1104
- """Mark the load balancer and specified listeners active in the DB.
1105
-
1106
- Since sqlalchemy will likely retry by itself always revert if it fails
1107
- """
1108
-
1109
- def execute(self, loadbalancer, listeners):
1110
- """Mark the load balancer and listeners as active in DB.
1111
-
1112
- :param loadbalancer: Load balancer object to be updated
1113
- :param listeners: Listener objects to be updated
1114
- :returns: None
1115
- """
1116
-
1117
- LOG.debug("Mark ACTIVE in DB for load balancer id: %s "
1118
- "and updating status for listener ids: %s", loadbalancer.id,
1119
- ', '.join([listener.id for listener in listeners]))
1120
- self.loadbalancer_repo.update(db_apis.get_session(),
1121
- loadbalancer.id,
1122
- provisioning_status=constants.ACTIVE)
1123
- for listener in listeners:
1124
- self.listener_repo.prov_status_active_if_not_error(
1125
- db_apis.get_session(), listener.id)
1126
-
1127
- def revert(self, loadbalancer, listeners, *args, **kwargs):
1128
- """Mark the load balancer and listeners as broken.
1129
-
1130
- :param loadbalancer: Load balancer object that failed to update
1131
- :param listeners: Listener objects that failed to update
1132
- :returns: None
1133
- """
1134
-
1135
- LOG.warning("Reverting mark listeners active in DB "
1136
- "for listener ids: %(list)s",
1137
- {'list': ', '.join([listener.id
1138
- for listener in listeners])})
1139
- for listener in listeners:
1140
- self.task_utils.mark_listener_prov_status_error(listener.id)
1141
-
1142
-
1143
- class MarkListenerDeletedInDB(BaseDatabaseTask):
1144
- """Mark the listener deleted in the DB.
1145
-
1146
- Since sqlalchemy will likely retry by itself always revert if it fails
1147
- """
1148
-
1149
- def execute(self, listener):
1150
- """Mark the listener as deleted in DB
1151
-
1152
- :param listener: The listener to be marked deleted
1153
- :returns: None
1154
- """
1155
-
1156
- LOG.debug("Mark DELETED in DB for listener id: %s ", listener.id)
1157
- self.listener_repo.update(db_apis.get_session(), listener.id,
1158
- provisioning_status=constants.DELETED)
1159
-
1160
- def revert(self, listener, *args, **kwargs):
1161
- """Mark the listener ERROR since the delete couldn't happen
1162
-
1163
- :param listener: The listener that couldn't be updated
1164
- :returns: None
1165
- """
1166
-
1167
- LOG.warning("Reverting mark listener deleted in DB "
1168
- "for listener id %s", listener.id)
1169
- self.task_utils.mark_listener_prov_status_error(listener.id)
1170
-
1171
-
1172
- class MarkListenerPendingDeleteInDB(BaseDatabaseTask):
1173
- """Mark the listener pending delete in the DB.
1174
-
1175
- Since sqlalchemy will likely retry by itself always revert if it fails
1176
- """
1177
-
1178
- def execute(self, listener):
1179
- """Mark the listener as pending delete in DB.
1180
-
1181
- :param listener: The listener to be updated
1182
- :returns: None
1183
- """
1184
-
1185
- LOG.debug("Mark PENDING DELETE in DB for listener id: %s",
1186
- listener.id)
1187
- self.listener_repo.update(db_apis.get_session(), listener.id,
1188
- provisioning_status=constants.PENDING_DELETE)
1189
-
1190
- def revert(self, listener, *args, **kwargs):
1191
- """Mark the listener as broken and ready to be cleaned up.
1192
-
1193
- :param listener: The listener that couldn't be updated
1194
- :returns: None
1195
- """
1196
-
1197
- LOG.warning("Reverting mark listener pending delete in DB "
1198
- "for listener id %s", listener.id)
1199
- self.task_utils.mark_listener_prov_status_error(listener.id)
1200
-
1201
-
1202
- class UpdateLoadbalancerInDB(BaseDatabaseTask):
1203
- """Update the loadbalancer in the DB.
1204
-
1205
- Since sqlalchemy will likely retry by itself always revert if it fails
1206
- """
1207
-
1208
- def execute(self, loadbalancer, update_dict):
1209
- """Update the loadbalancer in the DB
1210
-
1211
- :param loadbalancer: The load balancer to be updated
1212
- :param update_dict: The dictionary of updates to apply
1213
- :returns: None
1214
- """
1215
-
1216
- LOG.debug("Update DB for loadbalancer id: %s ", loadbalancer.id)
1217
- if update_dict.get('vip'):
1218
- vip_dict = update_dict.pop('vip')
1219
- self.vip_repo.update(db_apis.get_session(),
1220
- loadbalancer.vip.load_balancer_id,
1221
- **vip_dict)
1222
- self.loadbalancer_repo.update(db_apis.get_session(), loadbalancer.id,
1223
- **update_dict)
1224
-
1225
-
1226
- class UpdateHealthMonInDB(BaseDatabaseTask):
1227
- """Update the health monitor in the DB.
1228
-
1229
- Since sqlalchemy will likely retry by itself always revert if it fails
1230
- """
1231
-
1232
- def execute(self, health_mon, update_dict):
1233
- """Update the health monitor in the DB
1234
-
1235
- :param health_mon: The health monitor to be updated
1236
- :param update_dict: The dictionary of updates to apply
1237
- :returns: None
1238
- """
1239
-
1240
- LOG.debug("Update DB for health monitor id: %s ", health_mon.id)
1241
- self.health_mon_repo.update(db_apis.get_session(), health_mon.id,
1242
- **update_dict)
1243
-
1244
- def revert(self, health_mon, *args, **kwargs):
1245
- """Mark the health monitor ERROR since the update couldn't happen
1246
-
1247
- :param health_mon: The health monitor that couldn't be updated
1248
- :returns: None
1249
- """
1250
-
1251
- LOG.warning("Reverting update health monitor in DB "
1252
- "for health monitor id %s", health_mon.id)
1253
- try:
1254
- self.health_mon_repo.update(db_apis.get_session(),
1255
- health_mon.id,
1256
- provisioning_status=constants.ERROR)
1257
- except Exception as e:
1258
- LOG.error("Failed to update health monitor %(hm)s "
1259
- "provisioning_status to ERROR due to: %(except)s",
1260
- {'hm': health_mon.id, 'except': str(e)})
1261
-
1262
-
1263
- class UpdateListenerInDB(BaseDatabaseTask):
1264
- """Update the listener in the DB.
1265
-
1266
- Since sqlalchemy will likely retry by itself always revert if it fails
1267
- """
1268
-
1269
- def execute(self, listener, update_dict):
1270
- """Update the listener in the DB
1271
-
1272
- :param listener: The listener to be updated
1273
- :param update_dict: The dictionary of updates to apply
1274
- :returns: None
1275
- """
1276
-
1277
- LOG.debug("Update DB for listener id: %s ", listener.id)
1278
- self.listener_repo.update(db_apis.get_session(), listener.id,
1279
- **update_dict)
1280
-
1281
- def revert(self, listener, *args, **kwargs):
1282
- """Mark the listener ERROR since the update couldn't happen
1283
-
1284
- :param listener: The listener that couldn't be updated
1285
- :returns: None
1286
- """
1287
-
1288
- LOG.warning("Reverting update listener in DB "
1289
- "for listener id %s", listener.id)
1290
- self.task_utils.mark_listener_prov_status_error(listener.id)
1291
-
1292
-
1293
- class UpdateMemberInDB(BaseDatabaseTask):
1294
- """Update the member in the DB.
1295
-
1296
- Since sqlalchemy will likely retry by itself always revert if it fails
1297
- """
1298
-
1299
- def execute(self, member, update_dict):
1300
- """Update the member in the DB
1301
-
1302
- :param member: The member to be updated
1303
- :param update_dict: The dictionary of updates to apply
1304
- :returns: None
1305
- """
1306
-
1307
- LOG.debug("Update DB for member id: %s ", member.id)
1308
- self.member_repo.update(db_apis.get_session(), member.id,
1309
- **update_dict)
1310
-
1311
- def revert(self, member, *args, **kwargs):
1312
- """Mark the member ERROR since the update couldn't happen
1313
-
1314
- :param member: The member that couldn't be updated
1315
- :returns: None
1316
- """
1317
-
1318
- LOG.warning("Reverting update member in DB "
1319
- "for member id %s", member.id)
1320
- try:
1321
- self.member_repo.update(db_apis.get_session(), member.id,
1322
- provisioning_status=constants.ERROR)
1323
- except Exception as e:
1324
- LOG.error("Failed to update member %(member)s provisioning_status "
1325
- "to ERROR due to: %(except)s", {'member': member.id,
1326
- 'except': str(e)})
1327
-
1328
-
1329
- class UpdatePoolInDB(BaseDatabaseTask):
1330
- """Update the pool in the DB.
1331
-
1332
- Since sqlalchemy will likely retry by itself always revert if it fails
1333
- """
1334
-
1335
- def execute(self, pool, update_dict):
1336
- """Update the pool in the DB
1337
-
1338
- :param pool: The pool to be updated
1339
- :param update_dict: The dictionary of updates to apply
1340
- :returns: None
1341
- """
1342
-
1343
- LOG.debug("Update DB for pool id: %s ", pool.id)
1344
- self.repos.update_pool_and_sp(db_apis.get_session(), pool.id,
1345
- update_dict)
1346
-
1347
- def revert(self, pool, *args, **kwargs):
1348
- """Mark the pool ERROR since the update couldn't happen
1349
-
1350
- :param pool: The pool that couldn't be updated
1351
- :returns: None
1352
- """
1353
-
1354
- LOG.warning("Reverting update pool in DB for pool id %s", pool.id)
1355
- try:
1356
- self.repos.update_pool_and_sp(
1357
- db_apis.get_session(), pool.id,
1358
- {'provisioning_status': constants.ERROR})
1359
- except Exception as e:
1360
- LOG.error("Failed to update pool %(pool)s provisioning_status to "
1361
- "ERROR due to: %(except)s", {'pool': pool.id,
1362
- 'except': str(e)})
1363
-
1364
-
1365
- class UpdateL7PolicyInDB(BaseDatabaseTask):
1366
- """Update the L7 policy in the DB.
1367
-
1368
- Since sqlalchemy will likely retry by itself always revert if it fails
1369
- """
1370
-
1371
- def execute(self, l7policy, update_dict):
1372
- """Update the L7 policy in the DB
1373
-
1374
- :param l7policy: The L7 policy to be updated
1375
- :param update_dict: The dictionary of updates to apply
1376
- :returns: None
1377
- """
1378
-
1379
- LOG.debug("Update DB for l7policy id: %s ", l7policy.id)
1380
- self.l7policy_repo.update(db_apis.get_session(), l7policy.id,
1381
- **update_dict)
1382
-
1383
- def revert(self, l7policy, *args, **kwargs):
1384
- """Mark the l7policy ERROR since the update couldn't happen
1385
-
1386
- :param l7policy: L7 policy that couldn't be updated
1387
- :returns: None
1388
- """
1389
-
1390
- LOG.warning("Reverting update l7policy in DB "
1391
- "for l7policy id %s", l7policy.id)
1392
- try:
1393
- self.l7policy_repo.update(db_apis.get_session(), l7policy.id,
1394
- provisioning_status=constants.ERROR)
1395
- except Exception as e:
1396
- LOG.error("Failed to update l7policy %(l7p)s provisioning_status "
1397
- "to ERROR due to: %(except)s", {'l7p': l7policy.id,
1398
- 'except': str(e)})
1399
-
1400
-
1401
- class UpdateL7RuleInDB(BaseDatabaseTask):
1402
- """Update the L7 rule in the DB.
1403
-
1404
- Since sqlalchemy will likely retry by itself always revert if it fails
1405
- """
1406
-
1407
- def execute(self, l7rule, update_dict):
1408
- """Update the L7 rule in the DB
1409
-
1410
- :param l7rule: The L7 rule to be updated
1411
- :param update_dict: The dictionary of updates to apply
1412
- :returns: None
1413
- """
1414
-
1415
- LOG.debug("Update DB for l7rule id: %s ", l7rule.id)
1416
- self.l7rule_repo.update(db_apis.get_session(), l7rule.id,
1417
- **update_dict)
1418
-
1419
- def revert(self, l7rule, *args, **kwargs):
1420
- """Mark the L7 rule ERROR since the update couldn't happen
1421
-
1422
- :param l7rule: L7 rule that couldn't be updated
1423
- :returns: None
1424
- """
1425
-
1426
- LOG.warning("Reverting update l7rule in DB "
1427
- "for l7rule id %s", l7rule.id)
1428
- try:
1429
- self.l7policy_repo.update(db_apis.get_session(),
1430
- l7rule.l7policy.id,
1431
- provisioning_status=constants.ERROR)
1432
- except Exception as e:
1433
- LOG.error("Failed to update L7rule %(l7r)s provisioning_status to "
1434
- "ERROR due to: %(except)s", {'l7r': l7rule.l7policy.id,
1435
- 'except': str(e)})
1436
-
1437
-
1438
- class GetAmphoraDetails(BaseDatabaseTask):
1439
- """Task to retrieve amphora network details."""
1440
-
1441
- def execute(self, amphora):
1442
- """Retrieve amphora network details.
1443
-
1444
- :param amphora: Amphora which network details are required
1445
- :returns: data_models.Amphora object
1446
- """
1447
- return data_models.Amphora(id=amphora.id,
1448
- vrrp_ip=amphora.vrrp_ip,
1449
- ha_ip=amphora.ha_ip,
1450
- vrrp_port_id=amphora.vrrp_port_id,
1451
- ha_port_id=amphora.ha_port_id,
1452
- role=amphora.role,
1453
- vrrp_id=amphora.vrrp_id,
1454
- vrrp_priority=amphora.vrrp_priority)
1455
-
1456
-
1457
- class GetAmphoraeFromLoadbalancer(BaseDatabaseTask):
1458
- """Task to pull the amphorae from a loadbalancer."""
1459
-
1460
- def execute(self, loadbalancer_id):
1461
- """Pull the amphorae from a loadbalancer.
1462
-
1463
- :param loadbalancer_id: Load balancer ID to get amphorae from
1464
- :returns: A list of Listener objects
1465
- """
1466
- amphorae = []
1467
- loadbalancer = self.loadbalancer_repo.get(db_apis.get_session(),
1468
- id=loadbalancer_id)
1469
- for amp in loadbalancer.amphorae:
1470
- a = self.amphora_repo.get(db_apis.get_session(), id=amp.id,
1471
- show_deleted=False)
1472
- if a is None:
1473
- continue
1474
- amphorae.append(a)
1475
- return amphorae
1476
-
1477
-
1478
- class GetListenersFromLoadbalancer(BaseDatabaseTask):
1479
- """Task to pull the listeners from a loadbalancer."""
1480
-
1481
- def execute(self, loadbalancer):
1482
- """Pull the listeners from a loadbalancer.
1483
-
1484
- :param loadbalancer: Load balancer which listeners are required
1485
- :returns: A list of Listener objects
1486
- """
1487
- listeners = []
1488
- for listener in loadbalancer.listeners:
1489
- lb = self.listener_repo.get(db_apis.get_session(), id=listener.id)
1490
- lb.load_balancer = loadbalancer
1491
- listeners.append(lb)
1492
- return listeners
1493
-
1494
-
1495
- class GetLoadBalancer(BaseDatabaseTask):
1496
- """Get an load balancer object from the database."""
1497
-
1498
- def execute(self, loadbalancer_id, *args, **kwargs):
1499
- """Get an load balancer object from the database.
1500
-
1501
- :param loadbalancer_id: The load balancer ID to lookup
1502
- :returns: The load balancer object
1503
- """
1504
-
1505
- LOG.debug("Get load balancer from DB for load balancer id: %s",
1506
- loadbalancer_id)
1507
- return self.loadbalancer_repo.get(db_apis.get_session(),
1508
- id=loadbalancer_id)
1509
-
1510
-
1511
- class GetVipFromLoadbalancer(BaseDatabaseTask):
1512
- """Task to pull the vip from a loadbalancer."""
1513
-
1514
- def execute(self, loadbalancer):
1515
- """Pull the vip from a loadbalancer.
1516
-
1517
- :param loadbalancer: Load balancer which VIP is required
1518
- :returns: VIP associated with a given load balancer
1519
- """
1520
- return loadbalancer.vip
1521
-
1522
-
1523
- class CreateVRRPGroupForLB(BaseDatabaseTask):
1524
- """Create a VRRP group for a load balancer."""
1525
-
1526
- def execute(self, loadbalancer_id):
1527
- """Create a VRRP group for a load balancer.
1528
-
1529
- :param loadbalancer_id: Load balancer ID for which a VRRP group
1530
- should be created
1531
- """
1532
- try:
1533
- self.repos.vrrpgroup.create(
1534
- db_apis.get_session(),
1535
- load_balancer_id=loadbalancer_id,
1536
- vrrp_group_name=str(loadbalancer_id).replace('-', ''),
1537
- vrrp_auth_type=constants.VRRP_AUTH_DEFAULT,
1538
- vrrp_auth_pass=uuidutils.generate_uuid().replace('-', '')[0:7],
1539
- advert_int=CONF.keepalived_vrrp.vrrp_advert_int)
1540
- except odb_exceptions.DBDuplicateEntry:
1541
- LOG.debug('VRRP_GROUP entry already exists for load balancer, '
1542
- 'skipping create.')
1543
-
1544
-
1545
- class DisableAmphoraHealthMonitoring(BaseDatabaseTask):
1546
- """Disable amphora health monitoring.
1547
-
1548
- This disables amphora health monitoring by removing it from
1549
- the amphora_health table.
1550
- """
1551
-
1552
- def execute(self, amphora):
1553
- """Disable health monitoring for an amphora
1554
-
1555
- :param amphora: The amphora to disable health monitoring for
1556
- :returns: None
1557
- """
1558
- self._delete_from_amp_health(amphora.id)
1559
-
1560
-
1561
- class DisableLBAmphoraeHealthMonitoring(BaseDatabaseTask):
1562
- """Disable health monitoring on the LB amphorae.
1563
-
1564
- This disables amphora health monitoring by removing it from
1565
- the amphora_health table for each amphora on a load balancer.
1566
- """
1567
-
1568
- def execute(self, loadbalancer):
1569
- """Disable health monitoring for amphora on a load balancer
1570
-
1571
- :param loadbalancer: The load balancer to disable health monitoring on
1572
- :returns: None
1573
- """
1574
- for amphora in loadbalancer.amphorae:
1575
- self._delete_from_amp_health(amphora.id)
1576
-
1577
-
1578
- class MarkAmphoraHealthBusy(BaseDatabaseTask):
1579
- """Mark amphora health monitoring busy.
1580
-
1581
- This prevents amphora failover by marking the amphora busy in
1582
- the amphora_health table.
1583
- """
1584
-
1585
- def execute(self, amphora):
1586
- """Mark amphora health monitoring busy
1587
-
1588
- :param amphora: The amphora to mark amphora health busy
1589
- :returns: None
1590
- """
1591
- self._mark_amp_health_busy(amphora.id)
1592
-
1593
-
1594
- class MarkLBAmphoraeHealthBusy(BaseDatabaseTask):
1595
- """Mark amphorae health monitoring busy for the LB.
1596
-
1597
- This prevents amphorae failover by marking each amphora of a given
1598
- load balancer busy in the amphora_health table.
1599
- """
1600
-
1601
- def execute(self, loadbalancer):
1602
- """Marks amphorae health busy for each amphora on a load balancer
1603
-
1604
- :param loadbalancer: The load balancer to mark amphorae health busy
1605
- :returns: None
1606
- """
1607
- for amphora in loadbalancer.amphorae:
1608
- self._mark_amp_health_busy(amphora.id)
1609
-
1610
-
1611
- class MarkHealthMonitorActiveInDB(BaseDatabaseTask):
1612
- """Mark the health monitor ACTIVE in the DB.
1613
-
1614
- Since sqlalchemy will likely retry by itself always revert if it fails
1615
- """
1616
-
1617
- def execute(self, health_mon):
1618
- """Mark the health monitor ACTIVE in DB.
1619
-
1620
- :param health_mon: Health Monitor object to be updated
1621
- :returns: None
1622
- """
1623
-
1624
- LOG.debug("Mark ACTIVE in DB for health monitor id: %s",
1625
- health_mon.id)
1626
-
1627
- op_status = (constants.ONLINE if health_mon.enabled
1628
- else constants.OFFLINE)
1629
- self.health_mon_repo.update(db_apis.get_session(),
1630
- health_mon.id,
1631
- provisioning_status=constants.ACTIVE,
1632
- operating_status=op_status)
1633
-
1634
- def revert(self, health_mon, *args, **kwargs):
1635
- """Mark the health monitor as broken
1636
-
1637
- :param health_mon: Health Monitor object that failed to update
1638
- :returns: None
1639
- """
1640
-
1641
- LOG.warning("Reverting mark health montor ACTIVE in DB "
1642
- "for health monitor id %s", health_mon.id)
1643
- self.task_utils.mark_health_mon_prov_status_error(health_mon.id)
1644
-
1645
-
1646
- class MarkHealthMonitorPendingCreateInDB(BaseDatabaseTask):
1647
- """Mark the health monitor pending create in the DB.
1648
-
1649
- Since sqlalchemy will likely retry by itself always revert if it fails
1650
- """
1651
-
1652
- def execute(self, health_mon):
1653
- """Mark the health monitor as pending create in DB.
1654
-
1655
- :param health_mon: Health Monitor object to be updated
1656
- :returns: None
1657
- """
1658
-
1659
- LOG.debug("Mark PENDING CREATE in DB for health monitor id: %s",
1660
- health_mon.id)
1661
- self.health_mon_repo.update(db_apis.get_session(),
1662
- health_mon.id,
1663
- provisioning_status=(constants.
1664
- PENDING_CREATE))
1665
-
1666
- def revert(self, health_mon, *args, **kwargs):
1667
- """Mark the health monitor as broken
1668
-
1669
- :param health_mon: Health Monitor object that failed to update
1670
- :returns: None
1671
- """
1672
-
1673
- LOG.warning("Reverting mark health monitor pending create in DB "
1674
- "for health monitor id %s", health_mon.id)
1675
- self.task_utils.mark_health_mon_prov_status_error(health_mon.id)
1676
-
1677
-
1678
- class MarkHealthMonitorPendingDeleteInDB(BaseDatabaseTask):
1679
- """Mark the health monitor pending delete in the DB.
1680
-
1681
- Since sqlalchemy will likely retry by itself always revert if it fails
1682
- """
1683
-
1684
- def execute(self, health_mon):
1685
- """Mark the health monitor as pending delete in DB.
1686
-
1687
- :param health_mon: Health Monitor object to be updated
1688
- :returns: None
1689
- """
1690
-
1691
- LOG.debug("Mark PENDING DELETE in DB for health monitor id: %s",
1692
- health_mon.id)
1693
- self.health_mon_repo.update(db_apis.get_session(),
1694
- health_mon.id,
1695
- provisioning_status=(constants.
1696
- PENDING_DELETE))
1697
-
1698
- def revert(self, health_mon, *args, **kwargs):
1699
- """Mark the health monitor as broken
1700
-
1701
- :param health_mon: Health Monitor object that failed to update
1702
- :returns: None
1703
- """
1704
-
1705
- LOG.warning("Reverting mark health monitor pending delete in DB "
1706
- "for health monitor id %s", health_mon.id)
1707
- self.task_utils.mark_health_mon_prov_status_error(health_mon.id)
1708
-
1709
-
1710
- class MarkHealthMonitorPendingUpdateInDB(BaseDatabaseTask):
1711
- """Mark the health monitor pending update in the DB.
1712
-
1713
- Since sqlalchemy will likely retry by itself always revert if it fails
1714
- """
1715
-
1716
- def execute(self, health_mon):
1717
- """Mark the health monitor as pending update in DB.
1718
-
1719
- :param health_mon: Health Monitor object to be updated
1720
- :returns: None
1721
- """
1722
-
1723
- LOG.debug("Mark PENDING UPDATE in DB for health monitor id: %s",
1724
- health_mon.id)
1725
- self.health_mon_repo.update(db_apis.get_session(),
1726
- health_mon.id,
1727
- provisioning_status=(constants.
1728
- PENDING_UPDATE))
1729
-
1730
- def revert(self, health_mon, *args, **kwargs):
1731
- """Mark the health monitor as broken
1732
-
1733
- :param health_mon: Health Monitor object that failed to update
1734
- :returns: None
1735
- """
1736
-
1737
- LOG.warning("Reverting mark health monitor pending update in DB "
1738
- "for health monitor id %s", health_mon.id)
1739
- self.task_utils.mark_health_mon_prov_status_error(health_mon.id)
1740
-
1741
-
1742
- class MarkL7PolicyActiveInDB(BaseDatabaseTask):
1743
- """Mark the l7policy ACTIVE in the DB.
1744
-
1745
- Since sqlalchemy will likely retry by itself always revert if it fails
1746
- """
1747
-
1748
- def execute(self, l7policy):
1749
- """Mark the l7policy ACTIVE in DB.
1750
-
1751
- :param l7policy: L7Policy object to be updated
1752
- :returns: None
1753
- """
1754
-
1755
- LOG.debug("Mark ACTIVE in DB for l7policy id: %s",
1756
- l7policy.id)
1757
-
1758
- op_status = constants.ONLINE if l7policy.enabled else constants.OFFLINE
1759
- self.l7policy_repo.update(db_apis.get_session(),
1760
- l7policy.id,
1761
- provisioning_status=constants.ACTIVE,
1762
- operating_status=op_status)
1763
-
1764
- def revert(self, l7policy, *args, **kwargs):
1765
- """Mark the l7policy as broken
1766
-
1767
- :param l7policy: L7Policy object that failed to update
1768
- :returns: None
1769
- """
1770
-
1771
- LOG.warning("Reverting mark l7policy ACTIVE in DB "
1772
- "for l7policy id %s", l7policy.id)
1773
- self.task_utils.mark_l7policy_prov_status_error(l7policy.id)
1774
-
1775
-
1776
- class MarkL7PolicyPendingCreateInDB(BaseDatabaseTask):
1777
- """Mark the l7policy pending create in the DB.
1778
-
1779
- Since sqlalchemy will likely retry by itself always revert if it fails
1780
- """
1781
-
1782
- def execute(self, l7policy):
1783
- """Mark the l7policy as pending create in DB.
1784
-
1785
- :param l7policy: L7Policy object to be updated
1786
- :returns: None
1787
- """
1788
-
1789
- LOG.debug("Mark PENDING CREATE in DB for l7policy id: %s",
1790
- l7policy.id)
1791
- self.l7policy_repo.update(db_apis.get_session(),
1792
- l7policy.id,
1793
- provisioning_status=constants.PENDING_CREATE)
1794
-
1795
- def revert(self, l7policy, *args, **kwargs):
1796
- """Mark the l7policy as broken
1797
-
1798
- :param l7policy: L7Policy object that failed to update
1799
- :returns: None
1800
- """
1801
-
1802
- LOG.warning("Reverting mark l7policy pending create in DB "
1803
- "for l7policy id %s", l7policy.id)
1804
- self.task_utils.mark_l7policy_prov_status_error(l7policy.id)
1805
-
1806
-
1807
- class MarkL7PolicyPendingDeleteInDB(BaseDatabaseTask):
1808
- """Mark the l7policy pending delete in the DB.
1809
-
1810
- Since sqlalchemy will likely retry by itself always revert if it fails
1811
- """
1812
-
1813
- def execute(self, l7policy):
1814
- """Mark the l7policy as pending delete in DB.
1815
-
1816
- :param l7policy: L7Policy object to be updated
1817
- :returns: None
1818
- """
1819
-
1820
- LOG.debug("Mark PENDING DELETE in DB for l7policy id: %s",
1821
- l7policy.id)
1822
- self.l7policy_repo.update(db_apis.get_session(),
1823
- l7policy.id,
1824
- provisioning_status=constants.PENDING_DELETE)
1825
-
1826
- def revert(self, l7policy, *args, **kwargs):
1827
- """Mark the l7policy as broken
1828
-
1829
- :param l7policy: L7Policy object that failed to update
1830
- :returns: None
1831
- """
1832
-
1833
- LOG.warning("Reverting mark l7policy pending delete in DB "
1834
- "for l7policy id %s", l7policy.id)
1835
- self.task_utils.mark_l7policy_prov_status_error(l7policy.id)
1836
-
1837
-
1838
- class MarkL7PolicyPendingUpdateInDB(BaseDatabaseTask):
1839
- """Mark the l7policy pending update in the DB.
1840
-
1841
- Since sqlalchemy will likely retry by itself always revert if it fails
1842
- """
1843
-
1844
- def execute(self, l7policy):
1845
- """Mark the l7policy as pending update in DB.
1846
-
1847
- :param l7policy: L7Policy object to be updated
1848
- :returns: None
1849
- """
1850
-
1851
- LOG.debug("Mark PENDING UPDATE in DB for l7policy id: %s",
1852
- l7policy.id)
1853
- self.l7policy_repo.update(db_apis.get_session(),
1854
- l7policy.id,
1855
- provisioning_status=(constants.
1856
- PENDING_UPDATE))
1857
-
1858
- def revert(self, l7policy, *args, **kwargs):
1859
- """Mark the l7policy as broken
1860
-
1861
- :param l7policy: L7Policy object that failed to update
1862
- :returns: None
1863
- """
1864
-
1865
- LOG.warning("Reverting mark l7policy pending update in DB "
1866
- "for l7policy id %s", l7policy.id)
1867
- self.task_utils.mark_l7policy_prov_status_error(l7policy.id)
1868
-
1869
-
1870
- class MarkL7RuleActiveInDB(BaseDatabaseTask):
1871
- """Mark the l7rule ACTIVE in the DB.
1872
-
1873
- Since sqlalchemy will likely retry by itself always revert if it fails
1874
- """
1875
-
1876
- def execute(self, l7rule):
1877
- """Mark the l7rule ACTIVE in DB.
1878
-
1879
- :param l7rule: L7Rule object to be updated
1880
- :returns: None
1881
- """
1882
-
1883
- LOG.debug("Mark ACTIVE in DB for l7rule id: %s",
1884
- l7rule.id)
1885
- op_status = constants.ONLINE if l7rule.enabled else constants.OFFLINE
1886
- self.l7rule_repo.update(db_apis.get_session(),
1887
- l7rule.id,
1888
- provisioning_status=constants.ACTIVE,
1889
- operating_status=op_status)
1890
-
1891
- def revert(self, l7rule, *args, **kwargs):
1892
- """Mark the l7rule as broken
1893
-
1894
- :param l7rule: L7Rule object that failed to update
1895
- :returns: None
1896
- """
1897
-
1898
- LOG.warning("Reverting mark l7rule ACTIVE in DB "
1899
- "for l7rule id %s", l7rule.id)
1900
- self.task_utils.mark_l7rule_prov_status_error(l7rule.id)
1901
-
1902
-
1903
- class MarkL7RulePendingCreateInDB(BaseDatabaseTask):
1904
- """Mark the l7rule pending create in the DB.
1905
-
1906
- Since sqlalchemy will likely retry by itself always revert if it fails
1907
- """
1908
-
1909
- def execute(self, l7rule):
1910
- """Mark the l7rule as pending create in DB.
1911
-
1912
- :param l7rule: L7Rule object to be updated
1913
- :returns: None
1914
- """
1915
-
1916
- LOG.debug("Mark PENDING CREATE in DB for l7rule id: %s",
1917
- l7rule.id)
1918
- self.l7rule_repo.update(db_apis.get_session(),
1919
- l7rule.id,
1920
- provisioning_status=constants.PENDING_CREATE)
1921
-
1922
- def revert(self, l7rule, *args, **kwargs):
1923
- """Mark the l7rule as broken
1924
-
1925
- :param l7rule: L7Rule object that failed to update
1926
- :returns: None
1927
- """
1928
-
1929
- LOG.warning("Reverting mark l7rule pending create in DB "
1930
- "for l7rule id %s", l7rule.id)
1931
- self.task_utils.mark_l7rule_prov_status_error(l7rule.id)
1932
-
1933
-
1934
- class MarkL7RulePendingDeleteInDB(BaseDatabaseTask):
1935
- """Mark the l7rule pending delete in the DB.
1936
-
1937
- Since sqlalchemy will likely retry by itself always revert if it fails
1938
- """
1939
-
1940
- def execute(self, l7rule):
1941
- """Mark the l7rule as pending delete in DB.
1942
-
1943
- :param l7rule: L7Rule object to be updated
1944
- :returns: None
1945
- """
1946
-
1947
- LOG.debug("Mark PENDING DELETE in DB for l7rule id: %s",
1948
- l7rule.id)
1949
- self.l7rule_repo.update(db_apis.get_session(),
1950
- l7rule.id,
1951
- provisioning_status=constants.PENDING_DELETE)
1952
-
1953
- def revert(self, l7rule, *args, **kwargs):
1954
- """Mark the l7rule as broken
1955
-
1956
- :param l7rule: L7Rule object that failed to update
1957
- :returns: None
1958
- """
1959
-
1960
- LOG.warning("Reverting mark l7rule pending delete in DB "
1961
- "for l7rule id %s", l7rule.id)
1962
- self.task_utils.mark_l7rule_prov_status_error(l7rule.id)
1963
-
1964
-
1965
- class MarkL7RulePendingUpdateInDB(BaseDatabaseTask):
1966
- """Mark the l7rule pending update in the DB.
1967
-
1968
- Since sqlalchemy will likely retry by itself always revert if it fails
1969
- """
1970
-
1971
- def execute(self, l7rule):
1972
- """Mark the l7rule as pending update in DB.
1973
-
1974
- :param l7rule: L7Rule object to be updated
1975
- :returns: None
1976
- """
1977
-
1978
- LOG.debug("Mark PENDING UPDATE in DB for l7rule id: %s",
1979
- l7rule.id)
1980
- self.l7rule_repo.update(db_apis.get_session(),
1981
- l7rule.id,
1982
- provisioning_status=constants.PENDING_UPDATE)
1983
-
1984
- def revert(self, l7rule, *args, **kwargs):
1985
- """Mark the l7rule as broken
1986
-
1987
- :param l7rule: L7Rule object that failed to update
1988
- :returns: None
1989
- """
1990
-
1991
- LOG.warning("Reverting mark l7rule pending update in DB "
1992
- "for l7rule id %s", l7rule.id)
1993
- self.task_utils.mark_l7rule_prov_status_error(l7rule.id)
1994
-
1995
-
1996
- class MarkMemberActiveInDB(BaseDatabaseTask):
1997
- """Mark the member ACTIVE in the DB.
1998
-
1999
- Since sqlalchemy will likely retry by itself always revert if it fails
2000
- """
2001
-
2002
- def execute(self, member):
2003
- """Mark the member ACTIVE in DB.
2004
-
2005
- :param member: Member object to be updated
2006
- :returns: None
2007
- """
2008
-
2009
- LOG.debug("Mark ACTIVE in DB for member id: %s", member.id)
2010
- self.member_repo.update(db_apis.get_session(),
2011
- member.id,
2012
- provisioning_status=constants.ACTIVE)
2013
-
2014
- def revert(self, member, *args, **kwargs):
2015
- """Mark the member as broken
2016
-
2017
- :param member: Member object that failed to update
2018
- :returns: None
2019
- """
2020
-
2021
- LOG.warning("Reverting mark member ACTIVE in DB "
2022
- "for member id %s", member.id)
2023
- self.task_utils.mark_member_prov_status_error(member.id)
2024
-
2025
-
2026
- class MarkMemberPendingCreateInDB(BaseDatabaseTask):
2027
- """Mark the member pending create in the DB.
2028
-
2029
- Since sqlalchemy will likely retry by itself always revert if it fails
2030
- """
2031
-
2032
- def execute(self, member):
2033
- """Mark the member as pending create in DB.
2034
-
2035
- :param member: Member object to be updated
2036
- :returns: None
2037
- """
2038
-
2039
- LOG.debug("Mark PENDING CREATE in DB for member id: %s", member.id)
2040
- self.member_repo.update(db_apis.get_session(),
2041
- member.id,
2042
- provisioning_status=constants.PENDING_CREATE)
2043
-
2044
- def revert(self, member, *args, **kwargs):
2045
- """Mark the member as broken
2046
-
2047
- :param member: Member object that failed to update
2048
- :returns: None
2049
- """
2050
-
2051
- LOG.warning("Reverting mark member pending create in DB "
2052
- "for member id %s", member.id)
2053
- self.task_utils.mark_member_prov_status_error(member.id)
2054
-
2055
-
2056
- class MarkMemberPendingDeleteInDB(BaseDatabaseTask):
2057
- """Mark the member pending delete in the DB.
2058
-
2059
- Since sqlalchemy will likely retry by itself always revert if it fails
2060
- """
2061
-
2062
- def execute(self, member):
2063
- """Mark the member as pending delete in DB.
2064
-
2065
- :param member: Member object to be updated
2066
- :returns: None
2067
- """
2068
-
2069
- LOG.debug("Mark PENDING DELETE in DB for member id: %s", member.id)
2070
- self.member_repo.update(db_apis.get_session(),
2071
- member.id,
2072
- provisioning_status=constants.PENDING_DELETE)
2073
-
2074
- def revert(self, member, *args, **kwargs):
2075
- """Mark the member as broken
2076
-
2077
- :param member: Member object that failed to update
2078
- :returns: None
2079
- """
2080
-
2081
- LOG.warning("Reverting mark member pending delete in DB "
2082
- "for member id %s", member.id)
2083
- self.task_utils.mark_member_prov_status_error(member.id)
2084
-
2085
-
2086
- class MarkMemberPendingUpdateInDB(BaseDatabaseTask):
2087
- """Mark the member pending update in the DB.
2088
-
2089
- Since sqlalchemy will likely retry by itself always revert if it fails
2090
- """
2091
-
2092
- def execute(self, member):
2093
- """Mark the member as pending update in DB.
2094
-
2095
- :param member: Member object to be updated
2096
- :returns: None
2097
- """
2098
-
2099
- LOG.debug("Mark PENDING UPDATE in DB for member id: %s",
2100
- member.id)
2101
- self.member_repo.update(db_apis.get_session(),
2102
- member.id,
2103
- provisioning_status=constants.PENDING_UPDATE)
2104
-
2105
- def revert(self, member, *args, **kwargs):
2106
- """Mark the member as broken
2107
-
2108
- :param member: Member object that failed to update
2109
- :returns: None
2110
- """
2111
-
2112
- LOG.warning("Reverting mark member pending update in DB "
2113
- "for member id %s", member.id)
2114
- self.task_utils.mark_member_prov_status_error(member.id)
2115
-
2116
-
2117
- class MarkPoolActiveInDB(BaseDatabaseTask):
2118
- """Mark the pool ACTIVE in the DB.
2119
-
2120
- Since sqlalchemy will likely retry by itself always revert if it fails
2121
- """
2122
-
2123
- def execute(self, pool):
2124
- """Mark the pool ACTIVE in DB.
2125
-
2126
- :param pool: Pool object to be updated
2127
- :returns: None
2128
- """
2129
-
2130
- LOG.debug("Mark ACTIVE in DB for pool id: %s",
2131
- pool.id)
2132
- self.pool_repo.update(db_apis.get_session(),
2133
- pool.id,
2134
- provisioning_status=constants.ACTIVE)
2135
-
2136
- def revert(self, pool, *args, **kwargs):
2137
- """Mark the pool as broken
2138
-
2139
- :param pool: Pool object that failed to update
2140
- :returns: None
2141
- """
2142
-
2143
- LOG.warning("Reverting mark pool ACTIVE in DB for pool id %s", pool.id)
2144
- self.task_utils.mark_pool_prov_status_error(pool.id)
2145
-
2146
-
2147
- class MarkPoolPendingCreateInDB(BaseDatabaseTask):
2148
- """Mark the pool pending create in the DB.
2149
-
2150
- Since sqlalchemy will likely retry by itself always revert if it fails
2151
- """
2152
-
2153
- def execute(self, pool):
2154
- """Mark the pool as pending create in DB.
2155
-
2156
- :param pool: Pool object to be updated
2157
- :returns: None
2158
- """
2159
-
2160
- LOG.debug("Mark PENDING CREATE in DB for pool id: %s",
2161
- pool.id)
2162
- self.pool_repo.update(db_apis.get_session(),
2163
- pool.id,
2164
- provisioning_status=constants.PENDING_CREATE)
2165
-
2166
- def revert(self, pool, *args, **kwargs):
2167
- """Mark the pool as broken
2168
-
2169
- :param pool: Pool object that failed to update
2170
- :returns: None
2171
- """
2172
-
2173
- LOG.warning("Reverting mark pool pending create in DB "
2174
- "for pool id %s", pool.id)
2175
- self.task_utils.mark_pool_prov_status_error(pool.id)
2176
-
2177
-
2178
- class MarkPoolPendingDeleteInDB(BaseDatabaseTask):
2179
- """Mark the pool pending delete in the DB.
2180
-
2181
- Since sqlalchemy will likely retry by itself always revert if it fails
2182
- """
2183
-
2184
- def execute(self, pool):
2185
- """Mark the pool as pending delete in DB.
2186
-
2187
- :param pool: Pool object to be updated
2188
- :returns: None
2189
- """
2190
-
2191
- LOG.debug("Mark PENDING DELETE in DB for pool id: %s",
2192
- pool.id)
2193
- self.pool_repo.update(db_apis.get_session(),
2194
- pool.id,
2195
- provisioning_status=constants.PENDING_DELETE)
2196
-
2197
- def revert(self, pool, *args, **kwargs):
2198
- """Mark the pool as broken
2199
-
2200
- :param pool: Pool object that failed to update
2201
- :returns: None
2202
- """
2203
-
2204
- LOG.warning("Reverting mark pool pending delete in DB "
2205
- "for pool id %s", pool.id)
2206
- self.task_utils.mark_pool_prov_status_error(pool.id)
2207
-
2208
-
2209
- class MarkPoolPendingUpdateInDB(BaseDatabaseTask):
2210
- """Mark the pool pending update in the DB.
2211
-
2212
- Since sqlalchemy will likely retry by itself always revert if it fails
2213
- """
2214
-
2215
- def execute(self, pool):
2216
- """Mark the pool as pending update in DB.
2217
-
2218
- :param pool: Pool object to be updated
2219
- :returns: None
2220
- """
2221
-
2222
- LOG.debug("Mark PENDING UPDATE in DB for pool id: %s",
2223
- pool.id)
2224
- self.pool_repo.update(db_apis.get_session(),
2225
- pool.id,
2226
- provisioning_status=constants.PENDING_UPDATE)
2227
-
2228
- def revert(self, pool, *args, **kwargs):
2229
- """Mark the pool as broken
2230
-
2231
- :param pool: Pool object that failed to update
2232
- :returns: None
2233
- """
2234
-
2235
- LOG.warning("Reverting mark pool pending update in DB "
2236
- "for pool id %s", pool.id)
2237
- self.task_utils.mark_pool_prov_status_error(pool.id)
2238
-
2239
-
2240
- class DecrementHealthMonitorQuota(BaseDatabaseTask):
2241
- """Decrements the health monitor quota for a project.
2242
-
2243
- Since sqlalchemy will likely retry by itself always revert if it fails
2244
- """
2245
-
2246
- def execute(self, health_mon):
2247
- """Decrements the health monitor quota.
2248
-
2249
- :param health_mon: The health monitor to decrement the quota on.
2250
- :returns: None
2251
- """
2252
-
2253
- LOG.debug("Decrementing health monitor quota for "
2254
- "project: %s ", health_mon.project_id)
2255
-
2256
- lock_session = db_apis.get_session(autocommit=False)
2257
- try:
2258
- self.repos.decrement_quota(lock_session,
2259
- data_models.HealthMonitor,
2260
- health_mon.project_id)
2261
- lock_session.commit()
2262
- except Exception:
2263
- with excutils.save_and_reraise_exception():
2264
- LOG.error('Failed to decrement health monitor quota for '
2265
- 'project: %(proj)s the project may have excess '
2266
- 'quota in use.', {'proj': health_mon.project_id})
2267
- lock_session.rollback()
2268
-
2269
- def revert(self, health_mon, result, *args, **kwargs):
2270
- """Re-apply the quota
2271
-
2272
- :param health_mon: The health monitor to decrement the quota on.
2273
- :returns: None
2274
- """
2275
-
2276
- LOG.warning('Reverting decrement quota for health monitor on project'
2277
- ' %(proj)s Project quota counts may be incorrect.',
2278
- {'proj': health_mon.project_id})
2279
-
2280
- # Increment the quota back if this task wasn't the failure
2281
- if not isinstance(result, failure.Failure):
2282
-
2283
- try:
2284
- session = db_apis.get_session()
2285
- lock_session = db_apis.get_session(autocommit=False)
2286
- try:
2287
- self.repos.check_quota_met(session,
2288
- lock_session,
2289
- data_models.HealthMonitor,
2290
- health_mon.project_id)
2291
- lock_session.commit()
2292
- except Exception:
2293
- lock_session.rollback()
2294
- except Exception:
2295
- # Don't fail the revert flow
2296
- pass
2297
-
2298
-
2299
- class DecrementListenerQuota(BaseDatabaseTask):
2300
- """Decrements the listener quota for a project.
2301
-
2302
- Since sqlalchemy will likely retry by itself always revert if it fails
2303
- """
2304
-
2305
- def execute(self, listener):
2306
- """Decrements the listener quota.
2307
-
2308
- :param listener: The listener to decrement the quota on.
2309
- :returns: None
2310
- """
2311
-
2312
- LOG.debug("Decrementing listener quota for "
2313
- "project: %s ", listener.project_id)
2314
-
2315
- lock_session = db_apis.get_session(autocommit=False)
2316
- try:
2317
- self.repos.decrement_quota(lock_session,
2318
- data_models.Listener,
2319
- listener.project_id)
2320
- lock_session.commit()
2321
- except Exception:
2322
- with excutils.save_and_reraise_exception():
2323
- LOG.error('Failed to decrement listener quota for project: '
2324
- '%(proj)s the project may have excess quota in use.',
2325
- {'proj': listener.project_id})
2326
- lock_session.rollback()
2327
-
2328
- def revert(self, listener, result, *args, **kwargs):
2329
- """Re-apply the quota
2330
-
2331
- :param listener: The listener to decrement the quota on.
2332
- :returns: None
2333
- """
2334
-
2335
- LOG.warning('Reverting decrement quota for listener on project '
2336
- '%(proj)s Project quota counts may be incorrect.',
2337
- {'proj': listener.project_id})
2338
-
2339
- # Increment the quota back if this task wasn't the failure
2340
- if not isinstance(result, failure.Failure):
2341
-
2342
- try:
2343
- session = db_apis.get_session()
2344
- lock_session = db_apis.get_session(autocommit=False)
2345
- try:
2346
- self.repos.check_quota_met(session,
2347
- lock_session,
2348
- data_models.Listener,
2349
- listener.project_id)
2350
- lock_session.commit()
2351
- except Exception:
2352
- lock_session.rollback()
2353
- except Exception:
2354
- # Don't fail the revert flow
2355
- pass
2356
-
2357
-
2358
- class DecrementLoadBalancerQuota(BaseDatabaseTask):
2359
- """Decrements the load balancer quota for a project.
2360
-
2361
- Since sqlalchemy will likely retry by itself always revert if it fails
2362
- """
2363
-
2364
- def execute(self, loadbalancer):
2365
- """Decrements the load balancer quota.
2366
-
2367
- :param loadbalancer: The load balancer to decrement the quota on.
2368
- :returns: None
2369
- """
2370
-
2371
- LOG.debug("Decrementing load balancer quota for "
2372
- "project: %s ", loadbalancer.project_id)
2373
-
2374
- lock_session = db_apis.get_session(autocommit=False)
2375
- try:
2376
- self.repos.decrement_quota(lock_session,
2377
- data_models.LoadBalancer,
2378
- loadbalancer.project_id)
2379
- lock_session.commit()
2380
- except Exception:
2381
- with excutils.save_and_reraise_exception():
2382
- LOG.error('Failed to decrement load balancer quota for '
2383
- 'project: %(proj)s the project may have excess '
2384
- 'quota in use.', {'proj': loadbalancer.project_id})
2385
- lock_session.rollback()
2386
-
2387
- def revert(self, loadbalancer, result, *args, **kwargs):
2388
- """Re-apply the quota
2389
-
2390
- :param loadbalancer: The load balancer to decrement the quota on.
2391
- :returns: None
2392
- """
2393
-
2394
- LOG.warning('Reverting decrement quota for load balancer on project '
2395
- '%(proj)s Project quota counts may be incorrect.',
2396
- {'proj': loadbalancer.project_id})
2397
-
2398
- # Increment the quota back if this task wasn't the failure
2399
- if not isinstance(result, failure.Failure):
2400
-
2401
- try:
2402
- session = db_apis.get_session()
2403
- lock_session = db_apis.get_session(autocommit=False)
2404
- try:
2405
- self.repos.check_quota_met(session,
2406
- lock_session,
2407
- data_models.LoadBalancer,
2408
- loadbalancer.project_id)
2409
- lock_session.commit()
2410
- except Exception:
2411
- lock_session.rollback()
2412
- except Exception:
2413
- # Don't fail the revert flow
2414
- pass
2415
-
2416
-
2417
- class DecrementMemberQuota(BaseDatabaseTask):
2418
- """Decrements the member quota for a project.
2419
-
2420
- Since sqlalchemy will likely retry by itself always revert if it fails
2421
- """
2422
-
2423
- def execute(self, member):
2424
- """Decrements the member quota.
2425
-
2426
- :param member: The member to decrement the quota on.
2427
- :returns: None
2428
- """
2429
-
2430
- LOG.debug("Decrementing member quota for "
2431
- "project: %s ", member.project_id)
2432
-
2433
- lock_session = db_apis.get_session(autocommit=False)
2434
- try:
2435
- self.repos.decrement_quota(lock_session,
2436
- data_models.Member,
2437
- member.project_id)
2438
- lock_session.commit()
2439
- except Exception:
2440
- with excutils.save_and_reraise_exception():
2441
- LOG.error('Failed to decrement member quota for project: '
2442
- '%(proj)s the project may have excess quota in use.',
2443
- {'proj': member.project_id})
2444
- lock_session.rollback()
2445
-
2446
- def revert(self, member, result, *args, **kwargs):
2447
- """Re-apply the quota
2448
-
2449
- :param member: The member to decrement the quota on.
2450
- :returns: None
2451
- """
2452
-
2453
- LOG.warning('Reverting decrement quota for member on project %(proj)s '
2454
- 'Project quota counts may be incorrect.',
2455
- {'proj': member.project_id})
2456
-
2457
- # Increment the quota back if this task wasn't the failure
2458
- if not isinstance(result, failure.Failure):
2459
-
2460
- try:
2461
- session = db_apis.get_session()
2462
- lock_session = db_apis.get_session(autocommit=False)
2463
- try:
2464
- self.repos.check_quota_met(session,
2465
- lock_session,
2466
- data_models.Member,
2467
- member.project_id)
2468
- lock_session.commit()
2469
- except Exception:
2470
- lock_session.rollback()
2471
- except Exception:
2472
- # Don't fail the revert flow
2473
- pass
2474
-
2475
-
2476
- class DecrementPoolQuota(BaseDatabaseTask):
2477
- """Decrements the pool quota for a project.
2478
-
2479
- Since sqlalchemy will likely retry by itself always revert if it fails
2480
- """
2481
-
2482
- def execute(self, pool, pool_child_count):
2483
- """Decrements the pool quota.
2484
-
2485
- :param pool: The pool to decrement the quota on
2486
- :returns: None
2487
- """
2488
-
2489
- LOG.debug("Decrementing pool quota for "
2490
- "project: %s ", pool.project_id)
2491
-
2492
- lock_session = db_apis.get_session(autocommit=False)
2493
- try:
2494
- self.repos.decrement_quota(lock_session,
2495
- data_models.Pool,
2496
- pool.project_id)
2497
-
2498
- # Pools cascade delete members and health monitors
2499
- # update the quota for those items as well.
2500
- if pool_child_count['HM'] > 0:
2501
- self.repos.decrement_quota(lock_session,
2502
- data_models.HealthMonitor,
2503
- pool.project_id)
2504
- if pool_child_count['member'] > 0:
2505
- self.repos.decrement_quota(
2506
- lock_session, data_models.Member,
2507
- pool.project_id, quantity=pool_child_count['member'])
2508
-
2509
- lock_session.commit()
2510
- except Exception:
2511
- with excutils.save_and_reraise_exception():
2512
- LOG.error('Failed to decrement pool quota for project: '
2513
- '%(proj)s the project may have excess quota in use.',
2514
- {'proj': pool.project_id})
2515
- lock_session.rollback()
2516
-
2517
- def revert(self, pool, pool_child_count, result, *args, **kwargs):
2518
- """Re-apply the quota
2519
-
2520
- :param project_id: The id of project to decrement the quota on
2521
- :returns: None
2522
- """
2523
-
2524
- LOG.warning('Reverting decrement quota for pool on project %(proj)s '
2525
- 'Project quota counts may be incorrect.',
2526
- {'proj': pool.project_id})
2527
-
2528
- # Increment the quota back if this task wasn't the failure
2529
- if not isinstance(result, failure.Failure):
2530
-
2531
- # These are all independent to maximize the correction
2532
- # in case other quota actions have occurred
2533
- try:
2534
- session = db_apis.get_session()
2535
- lock_session = db_apis.get_session(autocommit=False)
2536
- try:
2537
- self.repos.check_quota_met(session,
2538
- lock_session,
2539
- data_models.Pool,
2540
- pool.project_id)
2541
- lock_session.commit()
2542
- except Exception:
2543
- lock_session.rollback()
2544
-
2545
- # Attempt to increment back the health monitor quota
2546
- if pool_child_count['HM'] > 0:
2547
- lock_session = db_apis.get_session(autocommit=False)
2548
- try:
2549
- self.repos.check_quota_met(session,
2550
- lock_session,
2551
- data_models.HealthMonitor,
2552
- pool.project_id)
2553
- lock_session.commit()
2554
- except Exception:
2555
- lock_session.rollback()
2556
-
2557
- # Attempt to increment back the member quota
2558
- # This is separate calls to maximize the correction
2559
- # should other factors have increased the in use quota
2560
- # before this point in the revert flow
2561
- for i in range(pool_child_count['member']):
2562
- lock_session = db_apis.get_session(autocommit=False)
2563
- try:
2564
- self.repos.check_quota_met(session,
2565
- lock_session,
2566
- data_models.Member,
2567
- pool.project_id)
2568
- lock_session.commit()
2569
- except Exception:
2570
- lock_session.rollback()
2571
- except Exception:
2572
- # Don't fail the revert flow
2573
- pass
2574
-
2575
-
2576
- class CountPoolChildrenForQuota(BaseDatabaseTask):
2577
- """Counts the pool child resources for quota management.
2578
-
2579
- Since the children of pools are cleaned up by the sqlalchemy
2580
- cascade delete settings, we need to collect the quota counts
2581
- for the child objects early.
2582
-
2583
- """
2584
-
2585
- def execute(self, pool):
2586
- """Count the pool child resources for quota management
2587
-
2588
- :param pool: The pool to count children on
2589
- :returns: None
2590
- """
2591
-
2592
- LOG.debug("Counting pool children for "
2593
- "project: %s ", pool.project_id)
2594
-
2595
- health_mon_count = 1 if pool.health_monitor else 0
2596
- member_count = len(pool.members)
2597
-
2598
- return {'HM': health_mon_count, 'member': member_count}
2599
-
2600
-
2601
- class DecrementL7policyQuota(BaseDatabaseTask):
2602
- """Decrements the l7policy quota for a project.
2603
-
2604
- Since sqlalchemy will likely retry by itself always revert if it fails
2605
- """
2606
-
2607
- def execute(self, l7policy):
2608
- """Decrements the l7policy quota.
2609
-
2610
- :param l7policy: The l7policy to decrement the quota on.
2611
- :returns: None
2612
- """
2613
-
2614
- LOG.debug("Decrementing l7policy quota for "
2615
- "project: %s ", l7policy.project_id)
2616
-
2617
- lock_session = db_apis.get_session(autocommit=False)
2618
- try:
2619
- self.repos.decrement_quota(lock_session,
2620
- data_models.L7Policy,
2621
- l7policy.project_id)
2622
-
2623
- if l7policy.l7rules:
2624
- self.repos.decrement_quota(lock_session,
2625
- data_models.L7Rule,
2626
- l7policy.project_id,
2627
- quantity=len(l7policy.l7rules))
2628
- lock_session.commit()
2629
- except Exception:
2630
- with excutils.save_and_reraise_exception():
2631
- LOG.error('Failed to decrement l7policy quota for project: '
2632
- '%(proj)s the project may have excess quota in use.',
2633
- {'proj': l7policy.project_id})
2634
- lock_session.rollback()
2635
-
2636
- def revert(self, l7policy, result, *args, **kwargs):
2637
- """Re-apply the quota
2638
-
2639
- :param l7policy: The l7policy to decrement the quota on.
2640
- :returns: None
2641
- """
2642
-
2643
- LOG.warning('Reverting decrement quota for l7policy on project'
2644
- ' %(proj)s Project quota counts may be incorrect.',
2645
- {'proj': l7policy.project_id})
2646
-
2647
- # Increment the quota back if this task wasn't the failure
2648
- if not isinstance(result, failure.Failure):
2649
-
2650
- try:
2651
- session = db_apis.get_session()
2652
- lock_session = db_apis.get_session(autocommit=False)
2653
- try:
2654
- self.repos.check_quota_met(session,
2655
- lock_session,
2656
- data_models.L7Policy,
2657
- l7policy.project_id)
2658
- lock_session.commit()
2659
- except Exception:
2660
- lock_session.rollback()
2661
-
2662
- # Attempt to increment back the L7Rule quota
2663
- for i in range(len(l7policy.l7rules)):
2664
- lock_session = db_apis.get_session(autocommit=False)
2665
- try:
2666
- self.repos.check_quota_met(session,
2667
- lock_session,
2668
- data_models.L7Rule,
2669
- l7policy.project_id)
2670
- lock_session.commit()
2671
- except Exception:
2672
- lock_session.rollback()
2673
- except Exception:
2674
- # Don't fail the revert flow
2675
- pass
2676
-
2677
-
2678
- class DecrementL7ruleQuota(BaseDatabaseTask):
2679
- """Decrements the l7rule quota for a project.
2680
-
2681
- Since sqlalchemy will likely retry by itself always revert if it fails
2682
- """
2683
-
2684
- def execute(self, l7rule):
2685
- """Decrements the l7rule quota.
2686
-
2687
- :param l7rule: The l7rule to decrement the quota on.
2688
- :returns: None
2689
- """
2690
-
2691
- LOG.debug("Decrementing l7rule quota for "
2692
- "project: %s ", l7rule.project_id)
2693
-
2694
- lock_session = db_apis.get_session(autocommit=False)
2695
- try:
2696
- self.repos.decrement_quota(lock_session,
2697
- data_models.L7Rule,
2698
- l7rule.project_id)
2699
- lock_session.commit()
2700
- except Exception:
2701
- with excutils.save_and_reraise_exception():
2702
- LOG.error('Failed to decrement l7rule quota for project: '
2703
- '%(proj)s the project may have excess quota in use.',
2704
- {'proj': l7rule.project_id})
2705
- lock_session.rollback()
2706
-
2707
- def revert(self, l7rule, result, *args, **kwargs):
2708
- """Re-apply the quota
2709
-
2710
- :param l7rule: The l7rule to decrement the quota on.
2711
- :returns: None
2712
- """
2713
-
2714
- LOG.warning('Reverting decrement quota for l7rule on project %(proj)s '
2715
- 'Project quota counts may be incorrect.',
2716
- {'proj': l7rule.project_id})
2717
-
2718
- # Increment the quota back if this task wasn't the failure
2719
- if not isinstance(result, failure.Failure):
2720
-
2721
- try:
2722
- session = db_apis.get_session()
2723
- lock_session = db_apis.get_session(autocommit=False)
2724
- try:
2725
- self.repos.check_quota_met(session,
2726
- lock_session,
2727
- data_models.L7Rule,
2728
- l7rule.project_id)
2729
- lock_session.commit()
2730
- except Exception:
2731
- lock_session.rollback()
2732
- except Exception:
2733
- # Don't fail the revert flow
2734
- pass
2735
-
2736
-
2737
- class UpdatePoolMembersOperatingStatusInDB(BaseDatabaseTask):
2738
- """Updates the members of a pool operating status.
2739
-
2740
- Since sqlalchemy will likely retry by itself always revert if it fails
2741
- """
2742
-
2743
- def execute(self, pool, operating_status):
2744
- """Update the members of a pool operating status in DB.
2745
-
2746
- :param pool: Pool object to be updated
2747
- :param operating_status: Operating status to set
2748
- :returns: None
2749
- """
2750
-
2751
- LOG.debug("Updating member operating status to %(status)s in DB for "
2752
- "pool id: %(pool)s", {'status': operating_status,
2753
- 'pool': pool.id})
2754
- self.member_repo.update_pool_members(db_apis.get_session(),
2755
- pool.id,
2756
- operating_status=operating_status)