Merge lp:~allenap/maas/non-django-database-test into lp:~maas-committers/maas/trunk
- non-django-database-test
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Gavin Panella |
Approved revision: | no longer in the source branch. |
Merged at revision: | 5626 |
Proposed branch: | lp:~allenap/maas/non-django-database-test |
Merge into: | lp:~maas-committers/maas/trunk |
Diff against target: |
16279 lines (+14478/-311) 56 files modified
Makefile (+13/-1) buildout.cfg (+52/-6) src/maasserver/__main__.py (+9/-0) src/maasserver/api/tests/test_discoveries.py (+0/-7) src/maasserver/api/tests/test_events.py (+0/-1) src/maasserver/api/tests/test_interfaces.py (+0/-2) src/maasserver/api/tests/test_ipaddresses.py (+0/-10) src/maasserver/api/tests/test_machine.py (+4/-7) src/maasserver/clusterrpc/tests/test_boot_images.py (+1/-2) src/maasserver/dns/tests/test_config.py (+3/-3) src/maasserver/dns/tests/test_zonegenerator.py (+3/-8) src/maasserver/management/commands/dbupgrade.py (+4/-3) src/maasserver/models/tests/test_config.py (+32/-1) src/maasserver/models/tests/test_discovery.py (+0/-5) src/maasserver/models/tests/test_dnspublication.py (+5/-0) src/maasserver/models/tests/test_interface.py (+0/-14) src/maasserver/models/tests/test_managers.py (+3/-3) src/maasserver/models/tests/test_node.py (+0/-10) src/maasserver/models/tests/test_staticipaddress.py (+0/-7) src/maasserver/models/tests/test_subnet.py (+0/-18) src/maasserver/models/tests/test_timestampedmodel.py (+3/-3) src/maasserver/regiondservices/tests/test_ntp.py (+0/-6) src/maasserver/static/js/angular/factories/events.js (+1/-1) src/maasserver/static/js/angular/factories/tests/test_events.js (+1/-1) src/maasserver/testing/api.py (+0/-1) src/maasserver/testing/initial.maas_test.sql (+13837/-0) src/maasserver/testing/resources.py (+261/-0) src/maasserver/testing/testcase.py (+110/-13) src/maasserver/testing/tests/test_sampledata.py (+0/-5) src/maasserver/tests/test_auth.py (+0/-5) src/maasserver/tests/test_commands_dbupgrade.py (+3/-1) src/maasserver/tests/test_dbviews.py (+0/-5) src/maasserver/tests/test_eventloop.py (+2/-1) src/maasserver/tests/test_fields.py (+10/-7) src/maasserver/tests/test_forms_helpers.py (+2/-2) src/maasserver/tests/test_forms_interface_link.py (+3/-43) src/maasserver/tests/test_ntp.py (+0/-13) src/maasserver/tests/test_preseed.py (+7/-6) src/maasserver/tests/test_routablepairs.py (+0/-5) src/maasserver/triggers/system.py (+2/-1) src/maasserver/triggers/tests/test_system_listener.py (+34/-25) src/maasserver/triggers/websocket.py (+5/-1) src/maasserver/utils/tests/test_signals.py (+2/-2) src/maasserver/utils/tests/test_threads.py (+3/-2) src/maasserver/views/tests/test_account.py (+7/-4) src/maasserver/views/tests/test_general.py (+4/-0) src/maasserver/websockets/handlers/tests/test_device.py (+0/-6) src/maasserver/websockets/handlers/tests/test_discovery.py (+0/-5) src/maastesting/djangotestcase.py (+14/-2) src/maastesting/testcase.py (+10/-19) src/maastesting/twisted.py (+19/-0) src/metadataserver/nodeinituser.py (+5/-12) src/metadataserver/tests/test_fields.py (+2/-2) src/metadataserver/tests/test_vendor_data.py (+0/-2) src/metadataserver/user_data/disk_erasing.py (+1/-1) src/metadataserver/user_data/tests/test_disk_erasing.py (+1/-1) |
To merge this branch: | bzr merge lp:~allenap/maas/non-django-database-test |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Blake Rouse (community) | Approve | ||
Review via email: mp+313777@code.launchpad.net |
Commit message
Run database tests without needing Django's test cases, mostly.
Previously Django's test cases did set-up and tear-down of the test database. In migrations mode this was teeth-grindingly slow; in legacy mode it was much quicker, but the database was not the same as would have been produced by migrations. Now a template database is constructed using migrations (with some cheats to make it much quicker) which is then used to prepare the database that tests use. In other words it combines the correctness of migrations with the speed of Django's legacy approach.
Description of the change
Fear not! Most of this diff is an SQL dump that's used to speed up the application of migrations:
$ bzr diff -r submit: | diffstat
Using submit branch /home/gavin/
Makefile | 14
buildout.cfg | 58
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maasserver
src/maastestin
src/maastestin
src/maastestin
src/metadatase
src/metadatase
src/metadatase
src/metadatase
src/metadatase
56 files changed, 14375 insertions(+), 296 deletions(-)
Gavin Panella (allenap) wrote : | # |
> Looked through the code and I am still some what confused? What is
> legacy tests? I assume those must run as well when doing "make test"?
>
> Looking at the code it was hard to see the difference between a legacy
> test and a none legacy test. Also no documentation on when legacy
> should be used over a standard test type. Is this something where we
> need to do work on tests that use legacy to remove this new
> "test.region-
I've done some work to whittle down the set of remaining legacy tests,
and it now stands at 71 tests. A legacy test is one that still needs to
run with the old Django test case and django_nose. 69 of those 71 need
it because they define `apps`, e.g.:
class TestMAASModelFo
apps = ['maasserver.
There will be a way around this, but I haven't figured it out yet.
The other 2 tests that I haven't figured out yet are:
test_
test_
I haven't tried much to fix them, just put them aside for now.
The goal is definitely to eliminate these tests. For now, `make test`
will run bin/test.
legacy tests.
Blake Rouse (blake-rouse) wrote : | # |
Okay thanks for the information.
Preview Diff
1 | === modified file 'Makefile' |
2 | --- Makefile 2016-12-07 12:46:14 +0000 |
3 | +++ Makefile 2017-01-05 16:20:57 +0000 |
4 | @@ -63,6 +63,7 @@ |
5 | bin/test.rack \ |
6 | bin/test.config \ |
7 | bin/test.region \ |
8 | + bin/test.region.legacy \ |
9 | bin/test.testing \ |
10 | bin/test.js \ |
11 | bin/test.e2e \ |
12 | @@ -122,6 +123,11 @@ |
13 | $(buildout) install region-test |
14 | @touch --no-create $@ |
15 | |
16 | +bin/test.region.legacy: \ |
17 | + bin/buildout buildout.cfg versions.cfg setup.py $(js_enums) |
18 | + $(buildout) install region-test-legacy |
19 | + @touch --no-create $@ |
20 | + |
21 | bin/maas: bin/buildout buildout.cfg versions.cfg setup.py |
22 | $(buildout) install cli |
23 | @touch --no-create $@ |
24 | @@ -213,6 +219,7 @@ |
25 | bin/test.rack |
26 | bin/test.config |
27 | bin/test.region |
28 | + bin/test.region.legacy |
29 | bin/test.testing |
30 | bin/test.js |
31 | endef |
32 | @@ -239,6 +246,11 @@ |
33 | clean-failed: |
34 | $(RM) .noseids |
35 | |
36 | +src/maasserver/testing/initial.maas_test.sql: bin/database syncdb |
37 | + bin/database --preserve run -- pg_dump maas --format=plain > $@ |
38 | + |
39 | +test-initial-data: src/maasserver/testing/initial.maas_test.sql |
40 | + |
41 | define test-template |
42 | $(test) --with-xunit --xunit-file=xunit.$(notdir $(test)).xml || touch .failed |
43 | endef |
44 | @@ -475,7 +487,7 @@ |
45 | test+coverage |
46 | test+lxd |
47 | test-failed |
48 | - test-migrations |
49 | + test-initial-data |
50 | endef |
51 | |
52 | # |
53 | |
54 | === modified file 'buildout.cfg' |
55 | --- buildout.cfg 2016-12-07 12:46:14 +0000 |
56 | +++ buildout.cfg 2017-01-05 16:20:57 +0000 |
57 | @@ -9,6 +9,7 @@ |
58 | rack-test |
59 | region |
60 | region-test |
61 | + region-test-legacy |
62 | repl |
63 | sphinx |
64 | testing-test |
65 | @@ -115,8 +116,54 @@ |
66 | recipe = zc.recipe.egg |
67 | eggs = |
68 | ${region:eggs} |
69 | -entry-points = |
70 | - test.region=maasserver:execute_from_command_line |
71 | + ${common:test-eggs} |
72 | +entry-points = |
73 | + test.region=maastesting.noseplug:main |
74 | +initialization = |
75 | + ${region:initialization} |
76 | + options = [ |
77 | + "--with-crochet", |
78 | + "--with-resources", |
79 | + "--with-scenarios", |
80 | + "--with-select", |
81 | + "--select-dir=src/maasserver", |
82 | + "--select-dir=src/metadataserver", |
83 | + "--cover-package=maas,maasserver,metadataserver", |
84 | + "--cover-branches", |
85 | + # Reduce the logging level to INFO here as |
86 | + # DebuggingLoggerMiddleware logs the content of all the |
87 | + # requests at DEBUG level: we don't want this in the |
88 | + # tests as it's too verbose. |
89 | + "--logging-level=INFO", |
90 | + "--logging-clear-handlers", |
91 | + # Do not run tests tagged "legacy". |
92 | + "-a", "!legacy", |
93 | + ] |
94 | + ${common:inject-test-options} |
95 | + # Configure logging. TODO: Do this in a plugin. |
96 | + from provisioningserver import logger |
97 | + logger.configure(mode=logger.LoggingMode.COMMAND) |
98 | + # Limit concurrency in all thread-pools to ONE. |
99 | + from maasserver.utils import threads |
100 | + threads.install_default_pool(maxthreads=1) |
101 | + threads.install_database_unpool(maxthreads=1) |
102 | + # Disable all database connections in the reactor. |
103 | + from maasserver.utils import orm |
104 | + from twisted.internet import reactor |
105 | + assert not reactor.running, "The reactor has been started too early." |
106 | + reactor.callFromThread(orm.disable_all_database_connections) |
107 | + # Last and least, configure Django. |
108 | + import django; django.setup() |
109 | +scripts = test.region |
110 | +extra-paths = |
111 | + ${region:extra-paths} |
112 | + |
113 | +[region-test-legacy] |
114 | +recipe = zc.recipe.egg |
115 | +eggs = |
116 | + ${region:eggs} |
117 | +entry-points = |
118 | + test.region.legacy=maasserver:execute_from_command_line |
119 | initialization = |
120 | ${region:initialization} |
121 | environ.setdefault("MAAS_PREVENT_MIGRATIONS", "1") |
122 | @@ -124,9 +171,6 @@ |
123 | "test", |
124 | "--noinput", |
125 | "--with-crochet", |
126 | - # Disable resources in the region for now because of suspected bad |
127 | - # interactions with django_nose. |
128 | - # "--with-resources", |
129 | "--with-scenarios", |
130 | "--with-select", |
131 | "--select-dir=src/maasserver", |
132 | @@ -139,9 +183,11 @@ |
133 | # tests as it's too verbose. |
134 | "--logging-level=INFO", |
135 | "--logging-clear-handlers", |
136 | + # Run only tests tagged "legacy". |
137 | + "-a", "legacy", |
138 | ] |
139 | ${common:inject-test-options} |
140 | -scripts = test.region |
141 | +scripts = test.region.legacy |
142 | extra-paths = |
143 | ${region:extra-paths} |
144 | |
145 | |
146 | === added file 'src/maasserver/__main__.py' |
147 | --- src/maasserver/__main__.py 1970-01-01 00:00:00 +0000 |
148 | +++ src/maasserver/__main__.py 2017-01-05 16:20:57 +0000 |
149 | @@ -0,0 +1,9 @@ |
150 | +# Copyright 2016 Canonical Ltd. This software is licensed under the |
151 | +# GNU Affero General Public License version 3 (see the file LICENSE). |
152 | + |
153 | +"""Execute MAAS's Django subsystem.""" |
154 | + |
155 | +from maasserver import execute_from_command_line |
156 | + |
157 | + |
158 | +raise SystemExit(execute_from_command_line()) |
159 | |
160 | === modified file 'src/maasserver/api/tests/test_discoveries.py' |
161 | --- src/maasserver/api/tests/test_discoveries.py 2016-09-29 16:14:53 +0000 |
162 | +++ src/maasserver/api/tests/test_discoveries.py 2017-01-05 16:20:57 +0000 |
163 | @@ -21,7 +21,6 @@ |
164 | user_friendly_scan_results, |
165 | ) |
166 | from maasserver.clusterrpc.utils import RPCResults |
167 | -from maasserver.dbviews import register_view |
168 | from maasserver.models import Subnet |
169 | from maasserver.testing.api import APITestCase |
170 | from maasserver.testing.factory import factory |
171 | @@ -80,7 +79,6 @@ |
172 | |
173 | def setUp(self): |
174 | super().setUp() |
175 | - register_view("maasserver_discovery") |
176 | # Patch to ensure an actual scan is not attempted. |
177 | scan_all_rack_networks_mock = self.patch( |
178 | discoveries_module.scan_all_rack_networks) |
179 | @@ -182,7 +180,6 @@ |
180 | |
181 | def setUp(self): |
182 | super().setUp() |
183 | - register_view("maasserver_discovery") |
184 | # Patch to ensure an actual scan is not attempted. |
185 | self.scan_all_rack_networks_mock = self.patch( |
186 | discoveries_module.scan_all_rack_networks) |
187 | @@ -316,10 +313,6 @@ |
188 | |
189 | class TestDiscoveryAPI(APITestCase.ForUser): |
190 | |
191 | - def setUp(self): |
192 | - super().setUp() |
193 | - register_view("maasserver_discovery") |
194 | - |
195 | def test_handler_path(self): |
196 | discovery = factory.make_Discovery() |
197 | self.assertEqual( |
198 | |
199 | === modified file 'src/maasserver/api/tests/test_events.py' |
200 | --- src/maasserver/api/tests/test_events.py 2016-07-30 01:17:54 +0000 |
201 | +++ src/maasserver/api/tests/test_events.py 2017-01-05 16:20:57 +0000 |
202 | @@ -157,7 +157,6 @@ |
203 | [event.id for event in reversed(events)], |
204 | extract_event_ids(parsed_result)) |
205 | self.assertEqual(len(events), parsed_result['count']) |
206 | - self.assertNumQueries(1) |
207 | |
208 | def test_GET_query_with_some_matching_ids_returns_matching_nodes(self): |
209 | # If some nodes match the requested ids and some don't, only the |
210 | |
211 | === modified file 'src/maasserver/api/tests/test_interfaces.py' |
212 | --- src/maasserver/api/tests/test_interfaces.py 2016-12-08 16:59:19 +0000 |
213 | +++ src/maasserver/api/tests/test_interfaces.py 2017-01-05 16:20:57 +0000 |
214 | @@ -9,7 +9,6 @@ |
215 | import random |
216 | |
217 | from django.core.urlresolvers import reverse |
218 | -from maasserver.dbviews import register_view |
219 | from maasserver.enum import ( |
220 | INTERFACE_LINK_TYPE, |
221 | INTERFACE_TYPE, |
222 | @@ -1074,7 +1073,6 @@ |
223 | })) |
224 | |
225 | def test_link_subnet_creates_link_on_device(self): |
226 | - register_view("maasserver_discovery") |
227 | parent = factory.make_Node() |
228 | device = factory.make_Device( |
229 | owner=self.user, parent=parent) |
230 | |
231 | === modified file 'src/maasserver/api/tests/test_ipaddresses.py' |
232 | --- src/maasserver/api/tests/test_ipaddresses.py 2016-10-18 16:31:31 +0000 |
233 | +++ src/maasserver/api/tests/test_ipaddresses.py 2017-01-05 16:20:57 +0000 |
234 | @@ -9,7 +9,6 @@ |
235 | |
236 | from django.conf import settings |
237 | from django.core.urlresolvers import reverse |
238 | -from maasserver.dbviews import register_view |
239 | from maasserver.enum import ( |
240 | INTERFACE_LINK_TYPE, |
241 | INTERFACE_TYPE, |
242 | @@ -221,11 +220,6 @@ |
243 | ("with_force", {"force": True}), |
244 | ) |
245 | |
246 | - @transactional |
247 | - def setUp(self): |
248 | - register_view("maasserver_discovery") |
249 | - return super().setUp() |
250 | - |
251 | @property |
252 | def force_should_work(self): |
253 | # The 'force' parameter should only work if (1) the user-under-test |
254 | @@ -372,10 +366,6 @@ |
255 | ("with_ip_address_param", {"ip_param": "ip_address"}), |
256 | ) |
257 | |
258 | - def setUp(self): |
259 | - register_view("maasserver_discovery") |
260 | - return super().setUp() |
261 | - |
262 | def post_reservation_request( |
263 | self, subnet=None, ip_address=None, network=None, mac=None, |
264 | hostname=None): |
265 | |
266 | === modified file 'src/maasserver/api/tests/test_machine.py' |
267 | --- src/maasserver/api/tests/test_machine.py 2016-10-28 08:43:09 +0000 |
268 | +++ src/maasserver/api/tests/test_machine.py 2017-01-05 16:20:57 +0000 |
269 | @@ -15,7 +15,6 @@ |
270 | from django.db import transaction |
271 | from maasserver import forms |
272 | from maasserver.api import machines as machines_module |
273 | -from maasserver.dbviews import register_view |
274 | from maasserver.enum import ( |
275 | FILESYSTEM_FORMAT_TYPE_CHOICES, |
276 | FILESYSTEM_TYPE, |
277 | @@ -49,8 +48,10 @@ |
278 | ) |
279 | from maasserver.testing.architecture import make_usable_architecture |
280 | from maasserver.testing.factory import factory |
281 | +from maasserver.testing.matchers import HasStatusCode |
282 | from maasserver.testing.orm import reload_objects |
283 | from maasserver.testing.osystems import make_usable_osystem |
284 | +from maasserver.testing.testcase import MAASServerTestCase |
285 | from maasserver.testing.testclient import MAASSensibleOAuthClient |
286 | from maasserver.utils.converters import json_load_bytes |
287 | from maasserver.utils.orm import ( |
288 | @@ -81,13 +82,13 @@ |
289 | import yaml |
290 | |
291 | |
292 | -class MachineAnonAPITest(APITestCase.ForAnonymous): |
293 | +class MachineAnonAPITest(MAASServerTestCase): |
294 | |
295 | def test_machine_init_user_cannot_access(self): |
296 | token = NodeKey.objects.get_token_for_node(factory.make_Node()) |
297 | client = MAASSensibleOAuthClient(get_node_init_user(), token) |
298 | response = client.get(reverse('machines_handler')) |
299 | - self.assertEqual(http.client.FORBIDDEN, response.status_code) |
300 | + self.assertThat(response, HasStatusCode(http.client.FORBIDDEN)) |
301 | |
302 | |
303 | class MachinesAPILoggedInTest(APITestCase.ForUserAndAdmin): |
304 | @@ -1349,10 +1350,6 @@ |
305 | class TestMachineAPITransactional(APITransactionTestCase.ForUser): |
306 | """The following TestMachineAPI tests require APITransactionTestCase.""" |
307 | |
308 | - def setUp(self): |
309 | - register_view("maasserver_discovery") |
310 | - return super().setUp() |
311 | - |
312 | def test_POST_start_returns_error_when_static_ips_exhausted(self): |
313 | self.patch(node_module, 'power_driver_check') |
314 | network = IPNetwork("10.0.0.0/30") |
315 | |
316 | === modified file 'src/maasserver/clusterrpc/tests/test_boot_images.py' |
317 | --- src/maasserver/clusterrpc/tests/test_boot_images.py 2016-09-12 21:33:05 +0000 |
318 | +++ src/maasserver/clusterrpc/tests/test_boot_images.py 2017-01-05 16:20:57 +0000 |
319 | @@ -48,7 +48,6 @@ |
320 | MockCallsMatch, |
321 | MockNotCalled, |
322 | ) |
323 | -from maastesting.testcase import MAASTestCase |
324 | from maastesting.twisted import TwistedLoggerFixture |
325 | from provisioningserver.boot.tests import test_tftppath |
326 | from provisioningserver.boot.tftppath import compose_image_path |
327 | @@ -401,7 +400,7 @@ |
328 | param['release'])) |
329 | |
330 | |
331 | -class TestRackControllersImporter(MAASTestCase): |
332 | +class TestRackControllersImporter(MAASServerTestCase): |
333 | """Tests for `RackControllersImporter`.""" |
334 | |
335 | def test__init_with_single_system_id(self): |
336 | |
337 | === modified file 'src/maasserver/dns/tests/test_config.py' |
338 | --- src/maasserver/dns/tests/test_config.py 2016-09-22 02:53:33 +0000 |
339 | +++ src/maasserver/dns/tests/test_config.py 2017-01-05 16:20:57 +0000 |
340 | @@ -75,9 +75,9 @@ |
341 | # A 'sys_dns' signal is also sent, but that is a side-effect of |
342 | # inserting into the DNS publications table, and is tested as part of |
343 | # the system triggers code. |
344 | - self.assertRaises( |
345 | - DNSPublication.DoesNotExist, |
346 | - DNSPublication.objects.get_most_recent) |
347 | + self.assertThat( |
348 | + DNSPublication.objects.get_most_recent(), |
349 | + MatchesStructure.byEquality(source="Initial publication")) |
350 | dns_force_reload() |
351 | self.assertThat( |
352 | DNSPublication.objects.get_most_recent(), |
353 | |
354 | === modified file 'src/maasserver/dns/tests/test_zonegenerator.py' |
355 | --- src/maasserver/dns/tests/test_zonegenerator.py 2016-10-18 16:21:26 +0000 |
356 | +++ src/maasserver/dns/tests/test_zonegenerator.py 2017-01-05 16:20:57 +0000 |
357 | @@ -16,7 +16,6 @@ |
358 | from urllib.parse import urlparse |
359 | |
360 | from maasserver import server_address |
361 | -from maasserver.dbviews import register_view |
362 | from maasserver.dns import zonegenerator |
363 | from maasserver.dns.zonegenerator import ( |
364 | get_dns_search_paths, |
365 | @@ -130,10 +129,10 @@ |
366 | class TestGetDNSSearchPaths(MAASServerTestCase): |
367 | |
368 | def test__returns_all_authoritative_domains(self): |
369 | - domain_names = [ |
370 | + domain_names = get_dns_search_paths() |
371 | + domain_names.update( |
372 | factory.make_Domain(authoritative=True).name |
373 | - for _ in range(3) |
374 | - ] |
375 | + for _ in range(3)) |
376 | for _ in range(3): |
377 | factory.make_Domain(authoritative=False) |
378 | self.assertItemsEqual( |
379 | @@ -507,10 +506,6 @@ |
380 | class TestZoneGeneratorTTL(MAASTransactionServerTestCase): |
381 | """Tests for TTL in :class:ZoneGenerator`.""" |
382 | |
383 | - def setUp(self): |
384 | - register_view("maasserver_discovery") |
385 | - return super().setUp() |
386 | - |
387 | @transactional |
388 | def test_domain_ttl_overrides_global(self): |
389 | global_ttl = random.randint(100, 199) |
390 | |
391 | === modified file 'src/maasserver/management/commands/dbupgrade.py' |
392 | --- src/maasserver/management/commands/dbupgrade.py 2016-12-07 12:46:14 +0000 |
393 | +++ src/maasserver/management/commands/dbupgrade.py 2017-01-05 16:20:57 +0000 |
394 | @@ -288,11 +288,12 @@ |
395 | @classmethod |
396 | def _perform_django_migrations(cls, database): |
397 | """Perform the django migrations.""" |
398 | + env = dict(os.environ, PYTHONPATH=os.pathsep.join(sys.path)) |
399 | cmd = [ |
400 | - sys.argv[0], "dbupgrade", "--database", database, |
401 | - "--django", |
402 | + sys.executable, "-m", "maasserver", "dbupgrade", |
403 | + "--database", database, "--django", |
404 | ] |
405 | - process = subprocess.Popen(cmd) |
406 | + process = subprocess.Popen(cmd, env=env) |
407 | return process.wait() |
408 | |
409 | @classmethod |
410 | |
411 | === modified file 'src/maasserver/models/tests/test_config.py' |
412 | --- src/maasserver/models/tests/test_config.py 2016-09-17 12:03:06 +0000 |
413 | +++ src/maasserver/models/tests/test_config.py 2017-01-05 16:20:57 +0000 |
414 | @@ -9,11 +9,15 @@ |
415 | |
416 | from django.db import IntegrityError |
417 | from fixtures import TestWithFixtures |
418 | -from maasserver.models import Config |
419 | +from maasserver.models import ( |
420 | + Config, |
421 | + signals, |
422 | +) |
423 | import maasserver.models.config |
424 | from maasserver.models.config import get_default_config |
425 | from maasserver.testing.factory import factory |
426 | from maasserver.testing.testcase import MAASServerTestCase |
427 | +from testtools.matchers import Is |
428 | |
429 | |
430 | class ConfigDefaultTest(MAASServerTestCase, TestWithFixtures): |
431 | @@ -162,3 +166,30 @@ |
432 | Config.objects.set_config(name, value) |
433 | |
434 | self.assertEqual([], recorder.calls) |
435 | + |
436 | + |
437 | +class SettingConfigTest(MAASServerTestCase): |
438 | + """Testing of the :class:`Config` model and setting each option.""" |
439 | + |
440 | + scenarios = tuple( |
441 | + (name, {"name": name}) |
442 | + for name in get_default_config() |
443 | + ) |
444 | + |
445 | + def setUp(self): |
446 | + super(SettingConfigTest, self).setUp() |
447 | + # Some of these setting we have to be careful about. |
448 | + if self.name in {"enable_http_proxy", "http_proxy"}: |
449 | + manager = signals.bootsources.signals |
450 | + self.addCleanup(manager.enable) |
451 | + manager.disable() |
452 | + |
453 | + def test_can_be_initialised_to_None_without_crashing(self): |
454 | + Config.objects.set_config(self.name, None) |
455 | + self.assertThat(Config.objects.get_config(self.name), Is(None)) |
456 | + |
457 | + def test_can_be_modified_from_None_without_crashing(self): |
458 | + Config.objects.set_config(self.name, None) |
459 | + something = [factory.make_name("value")] |
460 | + Config.objects.set_config(self.name, something) |
461 | + self.assertEqual(something, Config.objects.get_config(self.name)) |
462 | |
463 | === modified file 'src/maasserver/models/tests/test_discovery.py' |
464 | --- src/maasserver/models/tests/test_discovery.py 2016-12-07 12:46:14 +0000 |
465 | +++ src/maasserver/models/tests/test_discovery.py 2017-01-05 16:20:57 +0000 |
466 | @@ -5,7 +5,6 @@ |
467 | |
468 | __all__ = [] |
469 | |
470 | -from maasserver.dbviews import register_view |
471 | from maasserver.models import ( |
472 | Discovery, |
473 | discovery as discovery_module, |
474 | @@ -29,10 +28,6 @@ |
475 | |
476 | class TestDiscoveryModel(MAASServerTestCase): |
477 | |
478 | - def setUp(self): |
479 | - super().setUp() |
480 | - register_view("maasserver_discovery") |
481 | - |
482 | def test_mac_organization(self): |
483 | discovery = factory.make_Discovery(mac_address="48:51:b7:00:00:00") |
484 | self.assertThat(discovery.mac_organization, IsNonEmptyString) |
485 | |
486 | === modified file 'src/maasserver/models/tests/test_dnspublication.py' |
487 | --- src/maasserver/models/tests/test_dnspublication.py 2016-04-28 20:13:46 +0000 |
488 | +++ src/maasserver/models/tests/test_dnspublication.py 2017-01-05 16:20:57 +0000 |
489 | @@ -86,6 +86,11 @@ |
490 | class TestDNSPublicationManager(MAASServerTestCase): |
491 | """Test `DNSPublicationManager`.""" |
492 | |
493 | + def setUp(self): |
494 | + super(TestDNSPublicationManager, self).setUp() |
495 | + # These tests expect the DNSPublication table to be empty. |
496 | + DNSPublication.objects.all().delete() |
497 | + |
498 | def test_get_most_recent_returns_record_with_highest_id(self): |
499 | DNSPublication(serial=3).save() |
500 | DNSPublication(serial=30).save() |
501 | |
502 | === modified file 'src/maasserver/models/tests/test_interface.py' |
503 | --- src/maasserver/models/tests/test_interface.py 2016-12-20 06:52:13 +0000 |
504 | +++ src/maasserver/models/tests/test_interface.py 2017-01-05 16:20:57 +0000 |
505 | @@ -16,7 +16,6 @@ |
506 | from django.db import transaction |
507 | from django.http import Http404 |
508 | from fixtures import FakeLogger |
509 | -from maasserver.dbviews import register_view |
510 | from maasserver.enum import ( |
511 | INTERFACE_LINK_TYPE, |
512 | INTERFACE_TYPE, |
513 | @@ -2031,10 +2030,6 @@ |
514 | class TestLinkSubnet(MAASTransactionServerTestCase): |
515 | """Tests for `Interface.link_subnet`.""" |
516 | |
517 | - def setUp(self): |
518 | - register_view("maasserver_discovery") |
519 | - return super().setUp() |
520 | - |
521 | def test__AUTO_creates_link_to_AUTO_with_subnet(self): |
522 | interface = factory.make_Interface(INTERFACE_TYPE.PHYSICAL) |
523 | auto_subnet = factory.make_Subnet(vlan=interface.vlan) |
524 | @@ -2328,11 +2323,6 @@ |
525 | class TestUpdateIPAddress(MAASTransactionServerTestCase): |
526 | """Tests for `Interface.update_ip_address`.""" |
527 | |
528 | - @transactional |
529 | - def setUp(self): |
530 | - register_view("maasserver_discovery") |
531 | - return super().setUp() |
532 | - |
533 | def test__switch_dhcp_to_auto(self): |
534 | interface = factory.make_Interface(INTERFACE_TYPE.PHYSICAL) |
535 | subnet = factory.make_Subnet(vlan=interface.vlan) |
536 | @@ -2659,10 +2649,6 @@ |
537 | class TestClaimAutoIPs(MAASTransactionServerTestCase): |
538 | """Tests for `Interface.claim_auto_ips`.""" |
539 | |
540 | - def setUp(self): |
541 | - register_view("maasserver_discovery") |
542 | - return super().setUp() |
543 | - |
544 | def test__claims_all_auto_ip_addresses(self): |
545 | with transaction.atomic(): |
546 | interface = factory.make_Interface(INTERFACE_TYPE.PHYSICAL) |
547 | |
548 | === modified file 'src/maasserver/models/tests/test_managers.py' |
549 | --- src/maasserver/models/tests/test_managers.py 2015-12-01 18:12:59 +0000 |
550 | +++ src/maasserver/models/tests/test_managers.py 2017-01-05 16:20:57 +0000 |
551 | @@ -1,18 +1,18 @@ |
552 | -# Copyright 2012-2015 Canonical Ltd. This software is licensed under the |
553 | +# Copyright 2012-2016 Canonical Ltd. This software is licensed under the |
554 | # GNU Affero General Public License version 3 (see the file LICENSE). |
555 | |
556 | """Test maasserver model managers.""" |
557 | |
558 | __all__ = [] |
559 | |
560 | -from maasserver.testing.testcase import MAASTransactionServerTestCase |
561 | +from maasserver.testing.testcase import MAASLegacyTransactionServerTestCase |
562 | from maasserver.tests.models import ( |
563 | BulkManagerParentTestModel, |
564 | BulkManagerTestModel, |
565 | ) |
566 | |
567 | |
568 | -class BulkManagerTest(MAASTransactionServerTestCase): |
569 | +class BulkManagerTest(MAASLegacyTransactionServerTestCase): |
570 | |
571 | apps = ['maasserver.tests'] |
572 | |
573 | |
574 | === modified file 'src/maasserver/models/tests/test_node.py' |
575 | --- src/maasserver/models/tests/test_node.py 2017-01-04 17:45:30 +0000 |
576 | +++ src/maasserver/models/tests/test_node.py 2017-01-05 16:20:57 +0000 |
577 | @@ -36,7 +36,6 @@ |
578 | power_query, |
579 | ) |
580 | from maasserver.clusterrpc.testing.boot_images import make_rpc_boot_image |
581 | -from maasserver.dbviews import register_view |
582 | from maasserver.enum import ( |
583 | FILESYSTEM_GROUP_TYPE, |
584 | FILESYSTEM_TYPE, |
585 | @@ -4259,10 +4258,6 @@ |
586 | class TestNodeNetworking(MAASTransactionServerTestCase): |
587 | """Tests for methods on the `Node` related to networking.""" |
588 | |
589 | - def setUp(self): |
590 | - register_view("maasserver_discovery") |
591 | - return super().setUp() |
592 | - |
593 | def test__create_acquired_bridges_doesnt_call_on_bridge(self): |
594 | mock_create_acquired_bridge = self.patch( |
595 | Interface, "create_acquired_bridge") |
596 | @@ -4839,10 +4834,6 @@ |
597 | class TestGetDefaultDNSServers(MAASServerTestCase): |
598 | """Tests for `Node.get_default_dns_servers`.""" |
599 | |
600 | - def setUp(self): |
601 | - register_view("maasserver_discovery") |
602 | - return super().setUp() |
603 | - |
604 | def make_Node_with_RackController( |
605 | self, ipv4=True, ipv6=True, ipv4_gateway=True, ipv6_gateway=True, |
606 | ipv4_subnet_dns=None, ipv6_subnet_dns=None): |
607 | @@ -5016,7 +5007,6 @@ |
608 | def setUp(self): |
609 | super(TestNode_Start, self).setUp() |
610 | self.patch_autospec(node_module, 'power_driver_check') |
611 | - register_view("maasserver_discovery") |
612 | |
613 | def make_acquired_node_with_interface( |
614 | self, user, bmc_connected_to=None, power_type="virsh", |
615 | |
616 | === modified file 'src/maasserver/models/tests/test_staticipaddress.py' |
617 | --- src/maasserver/models/tests/test_staticipaddress.py 2016-12-07 12:46:14 +0000 |
618 | +++ src/maasserver/models/tests/test_staticipaddress.py 2017-01-05 16:20:57 +0000 |
619 | @@ -16,7 +16,6 @@ |
620 | from django.core.exceptions import ValidationError |
621 | from django.db import IntegrityError |
622 | from maasserver import locks |
623 | -from maasserver.dbviews import register_view |
624 | from maasserver.enum import ( |
625 | INTERFACE_LINK_TYPE, |
626 | INTERFACE_TYPE, |
627 | @@ -67,10 +66,6 @@ |
628 | |
629 | class TestStaticIPAddressManager(MAASServerTestCase): |
630 | |
631 | - def setUp(self): |
632 | - super(TestStaticIPAddressManager, self).setUp() |
633 | - register_view("maasserver_discovery") |
634 | - |
635 | def test_filter_by_ip_family_ipv4(self): |
636 | network_v4 = factory.make_ipv4_network() |
637 | subnet_v4 = factory.make_Subnet(cidr=str(network_v4.cidr)) |
638 | @@ -328,8 +323,6 @@ |
639 | ) |
640 | |
641 | def test_allocate_new_works_under_extreme_concurrency(self): |
642 | - register_view("maasserver_discovery") |
643 | - |
644 | ipv6 = (self.ip_version == 6) |
645 | subnet = factory.make_managed_Subnet(ipv6=ipv6) |
646 | count = 20 # Allocate this number of IP addresses. |
647 | |
648 | === modified file 'src/maasserver/models/tests/test_subnet.py' |
649 | --- src/maasserver/models/tests/test_subnet.py 2016-12-20 06:52:13 +0000 |
650 | +++ src/maasserver/models/tests/test_subnet.py 2017-01-05 16:20:57 +0000 |
651 | @@ -19,7 +19,6 @@ |
652 | from fixtures import FakeLogger |
653 | from hypothesis import given |
654 | from hypothesis.strategies import integers |
655 | -from maasserver.dbviews import register_view |
656 | from maasserver.enum import ( |
657 | IPADDRESS_TYPE, |
658 | IPRANGE_TYPE, |
659 | @@ -752,7 +751,6 @@ |
660 | self.assertThat(s, Contains(gateway_ip_2)) |
661 | |
662 | def get__get_iprange_usage_includes_neighbours_on_request(self): |
663 | - register_view("maasserver_discovery") |
664 | subnet = factory.make_Subnet( |
665 | cidr="10.0.0.0/30", gateway_ip=None, dns_servers=None) |
666 | rackif = factory.make_Interface(vlan=subnet.vlan) |
667 | @@ -762,7 +760,6 @@ |
668 | MAASIPRange("10.0.0.1", purpose="neighbour"))) |
669 | |
670 | def get__get_iprange_usage_excludes_neighbours_by_default(self): |
671 | - register_view("maasserver_discovery") |
672 | subnet = factory.make_Subnet( |
673 | cidr="10.0.0.0/30", gateway_ip=None, dns_servers=None) |
674 | rackif = factory.make_Interface(vlan=subnet.vlan) |
675 | @@ -853,10 +850,6 @@ |
676 | |
677 | class TestSubnetGetMAASIPSetForNeighbours(MAASServerTestCase): |
678 | |
679 | - def setUp(self): |
680 | - register_view("maasserver_discovery") |
681 | - return super().setUp() |
682 | - |
683 | def test__returns_observed_neighbours(self): |
684 | subnet = factory.make_Subnet( |
685 | cidr="10.0.0.0/30", gateway_ip=None, dns_servers=None) |
686 | @@ -879,10 +872,6 @@ |
687 | |
688 | class TestSubnetGetLeastRecentlySeenUnknownNeighbour(MAASServerTestCase): |
689 | |
690 | - def setUp(self): |
691 | - register_view("maasserver_discovery") |
692 | - return super().setUp() |
693 | - |
694 | def test__returns_least_recently_seen_neighbour(self): |
695 | # Note: 10.0.0.0/30 --> 10.0.0.1 and 10.0.0.0.2 are usable. |
696 | subnet = factory.make_Subnet( |
697 | @@ -931,10 +920,6 @@ |
698 | subnet = reload_object(subnet) |
699 | return subnet |
700 | |
701 | - def setUp(self): |
702 | - register_view("maasserver_discovery") |
703 | - return super().setUp() |
704 | - |
705 | def test__raises_if_no_free_addresses(self): |
706 | # Note: 10.0.0.0/30 --> 10.0.0.1 and 10.0.0.0.2 are usable. |
707 | subnet = self.make_Subnet( |
708 | @@ -1017,9 +1002,6 @@ |
709 | |
710 | |
711 | class TestUnmanagedSubnets(MAASServerTestCase): |
712 | - def setUp(self): |
713 | - register_view("maasserver_discovery") |
714 | - return super().setUp() |
715 | |
716 | def test__allocation_uses_reserved_range(self): |
717 | # Note: 10.0.0.0/29 --> 10.0.0.1 through 10.0.0.0.6 are usable. |
718 | |
719 | === modified file 'src/maasserver/models/tests/test_timestampedmodel.py' |
720 | --- src/maasserver/models/tests/test_timestampedmodel.py 2016-08-25 17:06:55 +0000 |
721 | +++ src/maasserver/models/tests/test_timestampedmodel.py 2017-01-05 16:20:57 +0000 |
722 | @@ -1,4 +1,4 @@ |
723 | -# Copyright 2012-2015 Canonical Ltd. This software is licensed under the |
724 | +# Copyright 2012-2016 Canonical Ltd. This software is licensed under the |
725 | # GNU Affero General Public License version 3 (see the file LICENSE). |
726 | |
727 | """:class:`TimestampedModel` tests.""" |
728 | @@ -14,8 +14,8 @@ |
729 | from django.db import transaction |
730 | from maasserver.models.timestampedmodel import now |
731 | from maasserver.testing.testcase import ( |
732 | + MAASLegacyTransactionServerTestCase, |
733 | MAASServerTestCase, |
734 | - MAASTransactionServerTestCase, |
735 | ) |
736 | from maasserver.tests.models import TimestampedModelTestModel |
737 | |
738 | @@ -25,7 +25,7 @@ |
739 | return datetime.now() - many_seconds_ago |
740 | |
741 | |
742 | -class TimestampedModelTest(MAASTransactionServerTestCase): |
743 | +class TimestampedModelTest(MAASLegacyTransactionServerTestCase): |
744 | """Testing for the class `TimestampedModel`.""" |
745 | |
746 | apps = ['maasserver.tests'] |
747 | |
748 | === modified file 'src/maasserver/regiondservices/tests/test_ntp.py' |
749 | --- src/maasserver/regiondservices/tests/test_ntp.py 2016-10-03 20:14:48 +0000 |
750 | +++ src/maasserver/regiondservices/tests/test_ntp.py 2017-01-05 16:20:57 +0000 |
751 | @@ -8,7 +8,6 @@ |
752 | from os.path import join |
753 | |
754 | from crochet import wait_for |
755 | -from maasserver.dbviews import register_view |
756 | from maasserver.models.config import Config |
757 | from maasserver.regiondservices import ntp |
758 | from maasserver.service_monitor import service_monitor |
759 | @@ -68,7 +67,6 @@ |
760 | |
761 | def setUp(self): |
762 | super(TestRegionNetworkTimeProtocolService, self).setUp() |
763 | - register_view("maasserver_routable_pairs") |
764 | self.useFixture(MAASRootFixture()) |
765 | |
766 | @transactional |
767 | @@ -145,10 +143,6 @@ |
768 | class TestRegionNetworkTimeProtocolService_Database(MAASServerTestCase): |
769 | """Database tests for `RegionNetworkTimeProtocolService`.""" |
770 | |
771 | - def setUp(self): |
772 | - super(TestRegionNetworkTimeProtocolService_Database, self).setUp() |
773 | - register_view("maasserver_routable_pairs") |
774 | - |
775 | def test__getConfiguration_returns_configuration_object(self): |
776 | service = ntp.RegionNetworkTimeProtocolService(reactor) |
777 | |
778 | |
779 | === modified file 'src/maasserver/static/js/angular/factories/events.js' |
780 | --- src/maasserver/static/js/angular/factories/events.js 2016-07-15 02:05:06 +0000 |
781 | +++ src/maasserver/static/js/angular/factories/events.js 2017-01-05 16:20:57 +0000 |
782 | @@ -1,4 +1,4 @@ |
783 | -/* Copyright 2015 Canonical Ltd. This software is licensed under the |
784 | +/* Copyright 2015-2016 Canonical Ltd. This software is licensed under the |
785 | * GNU Affero General Public License version 3 (see the file LICENSE). |
786 | * |
787 | * MAAS Event Manager Factory |
788 | |
789 | === modified file 'src/maasserver/static/js/angular/factories/tests/test_events.js' |
790 | --- src/maasserver/static/js/angular/factories/tests/test_events.js 2016-07-15 02:05:06 +0000 |
791 | +++ src/maasserver/static/js/angular/factories/tests/test_events.js 2017-01-05 16:20:57 +0000 |
792 | @@ -1,4 +1,4 @@ |
793 | -/* Copyright 2015 Canonical Ltd. This software is licensed under the |
794 | +/* Copyright 2015-2016 Canonical Ltd. This software is licensed under the |
795 | * GNU Affero General Public License version 3 (see the file LICENSE). |
796 | * |
797 | * Unit tests for EventsManagerFactory. |
798 | |
799 | === modified file 'src/maasserver/testing/api.py' |
800 | --- src/maasserver/testing/api.py 2016-08-31 13:52:59 +0000 |
801 | +++ src/maasserver/testing/api.py 2017-01-05 16:20:57 +0000 |
802 | @@ -148,7 +148,6 @@ |
803 | self.scenarios = merge_scenarios( |
804 | scenarios_users, scenarios_clients, self.scenarios) |
805 | |
806 | - @transactional |
807 | def setUp(self): |
808 | if not callable(self.userfactory): |
809 | raise AssertionError( |
810 | |
811 | === added file 'src/maasserver/testing/initial.maas_test.sql' |
812 | --- src/maasserver/testing/initial.maas_test.sql 1970-01-01 00:00:00 +0000 |
813 | +++ src/maasserver/testing/initial.maas_test.sql 2017-01-05 16:20:57 +0000 |
814 | @@ -0,0 +1,13837 @@ |
815 | +-- |
816 | +-- PostgreSQL database dump |
817 | +-- |
818 | + |
819 | +-- Dumped from database version 9.5.5 |
820 | +-- Dumped by pg_dump version 9.5.5 |
821 | + |
822 | +SET statement_timeout = 0; |
823 | +SET lock_timeout = 0; |
824 | +SET client_encoding = 'UTF8'; |
825 | +SET standard_conforming_strings = on; |
826 | +SET check_function_bodies = false; |
827 | +SET client_min_messages = warning; |
828 | +SET row_security = off; |
829 | + |
830 | +-- |
831 | +-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: |
832 | +-- |
833 | + |
834 | +CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog; |
835 | + |
836 | + |
837 | +-- |
838 | +-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: |
839 | +-- |
840 | + |
841 | +COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language'; |
842 | + |
843 | + |
844 | +SET search_path = public, pg_catalog; |
845 | + |
846 | +-- |
847 | +-- Name: config_create_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
848 | +-- |
849 | + |
850 | +CREATE FUNCTION config_create_notify() RETURNS trigger |
851 | + LANGUAGE plpgsql |
852 | + AS $$ |
853 | +DECLARE |
854 | +BEGIN |
855 | + PERFORM pg_notify('config_create',CAST(NEW.id AS text)); |
856 | + RETURN NEW; |
857 | +END; |
858 | +$$; |
859 | + |
860 | + |
861 | +ALTER FUNCTION public.config_create_notify() OWNER TO gavin; |
862 | + |
863 | +-- |
864 | +-- Name: config_delete_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
865 | +-- |
866 | + |
867 | +CREATE FUNCTION config_delete_notify() RETURNS trigger |
868 | + LANGUAGE plpgsql |
869 | + AS $$ |
870 | +DECLARE |
871 | +BEGIN |
872 | + PERFORM pg_notify('config_delete',CAST(OLD.id AS text)); |
873 | + RETURN NEW; |
874 | +END; |
875 | +$$; |
876 | + |
877 | + |
878 | +ALTER FUNCTION public.config_delete_notify() OWNER TO gavin; |
879 | + |
880 | +-- |
881 | +-- Name: config_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
882 | +-- |
883 | + |
884 | +CREATE FUNCTION config_update_notify() RETURNS trigger |
885 | + LANGUAGE plpgsql |
886 | + AS $$ |
887 | +DECLARE |
888 | +BEGIN |
889 | + PERFORM pg_notify('config_update',CAST(NEW.id AS text)); |
890 | + RETURN NEW; |
891 | +END; |
892 | +$$; |
893 | + |
894 | + |
895 | +ALTER FUNCTION public.config_update_notify() OWNER TO gavin; |
896 | + |
897 | +-- |
898 | +-- Name: device_create_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
899 | +-- |
900 | + |
901 | +CREATE FUNCTION device_create_notify() RETURNS trigger |
902 | + LANGUAGE plpgsql |
903 | + AS $$ |
904 | +DECLARE |
905 | + pnode RECORD; |
906 | +BEGIN |
907 | + IF NEW.parent_id IS NOT NULL THEN |
908 | + SELECT system_id INTO pnode |
909 | + FROM maasserver_node |
910 | + WHERE id = NEW.parent_id; |
911 | + PERFORM pg_notify('machine_update',CAST(pnode.system_id AS text)); |
912 | + ELSE |
913 | + PERFORM pg_notify('device_create',CAST(NEW.system_id AS text)); |
914 | + END IF; |
915 | + RETURN NEW; |
916 | +END; |
917 | +$$; |
918 | + |
919 | + |
920 | +ALTER FUNCTION public.device_create_notify() OWNER TO gavin; |
921 | + |
922 | +-- |
923 | +-- Name: device_delete_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
924 | +-- |
925 | + |
926 | +CREATE FUNCTION device_delete_notify() RETURNS trigger |
927 | + LANGUAGE plpgsql |
928 | + AS $$ |
929 | +DECLARE |
930 | + pnode RECORD; |
931 | +BEGIN |
932 | + IF OLD.parent_id IS NOT NULL THEN |
933 | + SELECT system_id INTO pnode |
934 | + FROM maasserver_node |
935 | + WHERE id = OLD.parent_id; |
936 | + PERFORM pg_notify('machine_update',CAST(pnode.system_id AS text)); |
937 | + ELSE |
938 | + PERFORM pg_notify('device_delete',CAST(OLD.system_id AS text)); |
939 | + END IF; |
940 | + RETURN NEW; |
941 | +END; |
942 | +$$; |
943 | + |
944 | + |
945 | +ALTER FUNCTION public.device_delete_notify() OWNER TO gavin; |
946 | + |
947 | +-- |
948 | +-- Name: device_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
949 | +-- |
950 | + |
951 | +CREATE FUNCTION device_update_notify() RETURNS trigger |
952 | + LANGUAGE plpgsql |
953 | + AS $$ |
954 | +DECLARE |
955 | + pnode RECORD; |
956 | +BEGIN |
957 | + IF NEW.parent_id IS NOT NULL THEN |
958 | + SELECT system_id INTO pnode |
959 | + FROM maasserver_node |
960 | + WHERE id = NEW.parent_id; |
961 | + PERFORM pg_notify('machine_update',CAST(pnode.system_id AS text)); |
962 | + ELSE |
963 | + PERFORM pg_notify('device_update',CAST(NEW.system_id AS text)); |
964 | + END IF; |
965 | + RETURN NEW; |
966 | +END; |
967 | +$$; |
968 | + |
969 | + |
970 | +ALTER FUNCTION public.device_update_notify() OWNER TO gavin; |
971 | + |
972 | +-- |
973 | +-- Name: dhcpsnippet_create_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
974 | +-- |
975 | + |
976 | +CREATE FUNCTION dhcpsnippet_create_notify() RETURNS trigger |
977 | + LANGUAGE plpgsql |
978 | + AS $$ |
979 | +DECLARE |
980 | +BEGIN |
981 | + PERFORM pg_notify('dhcpsnippet_create',CAST(NEW.id AS text)); |
982 | + RETURN NEW; |
983 | +END; |
984 | +$$; |
985 | + |
986 | + |
987 | +ALTER FUNCTION public.dhcpsnippet_create_notify() OWNER TO gavin; |
988 | + |
989 | +-- |
990 | +-- Name: dhcpsnippet_delete_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
991 | +-- |
992 | + |
993 | +CREATE FUNCTION dhcpsnippet_delete_notify() RETURNS trigger |
994 | + LANGUAGE plpgsql |
995 | + AS $$ |
996 | +DECLARE |
997 | +BEGIN |
998 | + PERFORM pg_notify('dhcpsnippet_delete',CAST(OLD.id AS text)); |
999 | + RETURN NEW; |
1000 | +END; |
1001 | +$$; |
1002 | + |
1003 | + |
1004 | +ALTER FUNCTION public.dhcpsnippet_delete_notify() OWNER TO gavin; |
1005 | + |
1006 | +-- |
1007 | +-- Name: dhcpsnippet_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1008 | +-- |
1009 | + |
1010 | +CREATE FUNCTION dhcpsnippet_update_notify() RETURNS trigger |
1011 | + LANGUAGE plpgsql |
1012 | + AS $$ |
1013 | +DECLARE |
1014 | +BEGIN |
1015 | + PERFORM pg_notify('dhcpsnippet_update',CAST(NEW.id AS text)); |
1016 | + RETURN NEW; |
1017 | +END; |
1018 | +$$; |
1019 | + |
1020 | + |
1021 | +ALTER FUNCTION public.dhcpsnippet_update_notify() OWNER TO gavin; |
1022 | + |
1023 | +-- |
1024 | +-- Name: dnsdata_domain_delete_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1025 | +-- |
1026 | + |
1027 | +CREATE FUNCTION dnsdata_domain_delete_notify() RETURNS trigger |
1028 | + LANGUAGE plpgsql |
1029 | + AS $$ |
1030 | +DECLARE |
1031 | + dom RECORD; |
1032 | +BEGIN |
1033 | + SELECT DISTINCT ON (domain_id) domain_id INTO dom |
1034 | + FROM maasserver_dnsresource AS dnsresource |
1035 | + WHERE dnsresource.id = OLD.dnsresource_id; |
1036 | + PERFORM pg_notify('domain_update',CAST(dom.domain_id AS text)); |
1037 | + RETURN NEW; |
1038 | +END; |
1039 | +$$; |
1040 | + |
1041 | + |
1042 | +ALTER FUNCTION public.dnsdata_domain_delete_notify() OWNER TO gavin; |
1043 | + |
1044 | +-- |
1045 | +-- Name: dnsdata_domain_insert_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1046 | +-- |
1047 | + |
1048 | +CREATE FUNCTION dnsdata_domain_insert_notify() RETURNS trigger |
1049 | + LANGUAGE plpgsql |
1050 | + AS $$ |
1051 | +DECLARE |
1052 | + dom RECORD; |
1053 | +BEGIN |
1054 | + SELECT DISTINCT ON (domain_id) domain_id INTO dom |
1055 | + FROM maasserver_dnsresource AS dnsresource |
1056 | + WHERE dnsresource.id = NEW.dnsresource_id; |
1057 | + PERFORM pg_notify('domain_update',CAST(dom.domain_id AS text)); |
1058 | + RETURN NEW; |
1059 | +END; |
1060 | +$$; |
1061 | + |
1062 | + |
1063 | +ALTER FUNCTION public.dnsdata_domain_insert_notify() OWNER TO gavin; |
1064 | + |
1065 | +-- |
1066 | +-- Name: dnsdata_domain_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1067 | +-- |
1068 | + |
1069 | +CREATE FUNCTION dnsdata_domain_update_notify() RETURNS trigger |
1070 | + LANGUAGE plpgsql |
1071 | + AS $$ |
1072 | +DECLARE |
1073 | + dom RECORD; |
1074 | +BEGIN |
1075 | + SELECT DISTINCT ON (domain_id) domain_id INTO dom |
1076 | + FROM maasserver_dnsresource AS dnsresource |
1077 | + WHERE dnsresource.id = OLD.dnsresource_id OR dnsresource.id = NEW.dnsresource_id; |
1078 | + PERFORM pg_notify('domain_update',CAST(dom.domain_id AS text)); |
1079 | + RETURN NEW; |
1080 | +END; |
1081 | +$$; |
1082 | + |
1083 | + |
1084 | +ALTER FUNCTION public.dnsdata_domain_update_notify() OWNER TO gavin; |
1085 | + |
1086 | +-- |
1087 | +-- Name: dnsresource_domain_delete_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1088 | +-- |
1089 | + |
1090 | +CREATE FUNCTION dnsresource_domain_delete_notify() RETURNS trigger |
1091 | + LANGUAGE plpgsql |
1092 | + AS $$ |
1093 | +DECLARE |
1094 | + domain RECORD; |
1095 | +BEGIN |
1096 | + PERFORM pg_notify('domain_update',CAST(OLD.domain_id AS text)); |
1097 | + RETURN NEW; |
1098 | +END; |
1099 | +$$; |
1100 | + |
1101 | + |
1102 | +ALTER FUNCTION public.dnsresource_domain_delete_notify() OWNER TO gavin; |
1103 | + |
1104 | +-- |
1105 | +-- Name: dnsresource_domain_insert_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1106 | +-- |
1107 | + |
1108 | +CREATE FUNCTION dnsresource_domain_insert_notify() RETURNS trigger |
1109 | + LANGUAGE plpgsql |
1110 | + AS $$ |
1111 | +DECLARE |
1112 | + domain RECORD; |
1113 | +BEGIN |
1114 | + PERFORM pg_notify('domain_update',CAST(NEW.domain_id AS text)); |
1115 | + RETURN NEW; |
1116 | +END; |
1117 | +$$; |
1118 | + |
1119 | + |
1120 | +ALTER FUNCTION public.dnsresource_domain_insert_notify() OWNER TO gavin; |
1121 | + |
1122 | +-- |
1123 | +-- Name: dnsresource_domain_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1124 | +-- |
1125 | + |
1126 | +CREATE FUNCTION dnsresource_domain_update_notify() RETURNS trigger |
1127 | + LANGUAGE plpgsql |
1128 | + AS $$ |
1129 | +DECLARE |
1130 | + domain RECORD; |
1131 | +BEGIN |
1132 | + PERFORM pg_notify('domain_update',CAST(OLD.domain_id AS text)); |
1133 | + IF OLD.domain_id != NEW.domain_id THEN |
1134 | + PERFORM pg_notify('domain_update',CAST(NEW.domain_id AS text)); |
1135 | + END IF; |
1136 | + RETURN NEW; |
1137 | +END; |
1138 | +$$; |
1139 | + |
1140 | + |
1141 | +ALTER FUNCTION public.dnsresource_domain_update_notify() OWNER TO gavin; |
1142 | + |
1143 | +-- |
1144 | +-- Name: domain_create_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1145 | +-- |
1146 | + |
1147 | +CREATE FUNCTION domain_create_notify() RETURNS trigger |
1148 | + LANGUAGE plpgsql |
1149 | + AS $$ |
1150 | +DECLARE |
1151 | +BEGIN |
1152 | + PERFORM pg_notify('domain_create',CAST(NEW.id AS text)); |
1153 | + RETURN NEW; |
1154 | +END; |
1155 | +$$; |
1156 | + |
1157 | + |
1158 | +ALTER FUNCTION public.domain_create_notify() OWNER TO gavin; |
1159 | + |
1160 | +-- |
1161 | +-- Name: domain_delete_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1162 | +-- |
1163 | + |
1164 | +CREATE FUNCTION domain_delete_notify() RETURNS trigger |
1165 | + LANGUAGE plpgsql |
1166 | + AS $$ |
1167 | +DECLARE |
1168 | +BEGIN |
1169 | + PERFORM pg_notify('domain_delete',CAST(OLD.id AS text)); |
1170 | + RETURN NEW; |
1171 | +END; |
1172 | +$$; |
1173 | + |
1174 | + |
1175 | +ALTER FUNCTION public.domain_delete_notify() OWNER TO gavin; |
1176 | + |
1177 | +-- |
1178 | +-- Name: domain_node_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1179 | +-- |
1180 | + |
1181 | +CREATE FUNCTION domain_node_update_notify() RETURNS trigger |
1182 | + LANGUAGE plpgsql |
1183 | + AS $$ |
1184 | +DECLARE |
1185 | + node RECORD; |
1186 | + pnode RECORD; |
1187 | +BEGIN |
1188 | + IF OLD.name != NEW.name THEN |
1189 | + SELECT system_id, node_type, parent_id INTO node |
1190 | + FROM maasserver_node |
1191 | + WHERE maasserver_node.domain_id = NEW.id; |
1192 | + |
1193 | + IF node.system_id IS NOT NULL THEN |
1194 | + IF node.node_type = 0 THEN |
1195 | + PERFORM pg_notify('machine_update',CAST(node.system_id AS text)); |
1196 | + ELSIF node.node_type IN (2, 3, 4) THEN |
1197 | + PERFORM pg_notify( |
1198 | + 'controller_update',CAST(node.system_id AS text)); |
1199 | + ELSIF node.parent_id IS NOT NULL THEN |
1200 | + SELECT system_id INTO pnode |
1201 | + FROM maasserver_node |
1202 | + WHERE id = node.parent_id; |
1203 | + PERFORM pg_notify('machine_update',CAST(pnode.system_id AS text)); |
1204 | + ELSE |
1205 | + PERFORM pg_notify('device_update',CAST(node.system_id AS text)); |
1206 | + END IF; |
1207 | + END IF; |
1208 | + END IF; |
1209 | + RETURN NEW; |
1210 | +END; |
1211 | +$$; |
1212 | + |
1213 | + |
1214 | +ALTER FUNCTION public.domain_node_update_notify() OWNER TO gavin; |
1215 | + |
1216 | +-- |
1217 | +-- Name: domain_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1218 | +-- |
1219 | + |
1220 | +CREATE FUNCTION domain_update_notify() RETURNS trigger |
1221 | + LANGUAGE plpgsql |
1222 | + AS $$ |
1223 | +DECLARE |
1224 | +BEGIN |
1225 | + PERFORM pg_notify('domain_update',CAST(NEW.id AS text)); |
1226 | + RETURN NEW; |
1227 | +END; |
1228 | +$$; |
1229 | + |
1230 | + |
1231 | +ALTER FUNCTION public.domain_update_notify() OWNER TO gavin; |
1232 | + |
1233 | +-- |
1234 | +-- Name: event_create_machine_device_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1235 | +-- |
1236 | + |
1237 | +CREATE FUNCTION event_create_machine_device_notify() RETURNS trigger |
1238 | + LANGUAGE plpgsql |
1239 | + AS $$ |
1240 | +DECLARE |
1241 | + node RECORD; |
1242 | + pnode RECORD; |
1243 | +BEGIN |
1244 | + SELECT system_id, node_type, parent_id INTO node |
1245 | + FROM maasserver_node |
1246 | + WHERE id = NEW.node_id; |
1247 | + |
1248 | + IF node.node_type = 0 THEN |
1249 | + PERFORM pg_notify('machine_update',CAST(node.system_id AS text)); |
1250 | + ELSIF node.node_type IN (2, 3, 4) THEN |
1251 | + PERFORM pg_notify('controller_update',CAST(node.system_id AS text)); |
1252 | + ELSIF node.parent_id IS NOT NULL THEN |
1253 | + SELECT system_id INTO pnode |
1254 | + FROM maasserver_node |
1255 | + WHERE id = node.parent_id; |
1256 | + PERFORM pg_notify('machine_update',CAST(pnode.system_id AS text)); |
1257 | + ELSE |
1258 | + PERFORM pg_notify('device_update',CAST(node.system_id AS text)); |
1259 | + END IF; |
1260 | + RETURN NEW; |
1261 | +END; |
1262 | +$$; |
1263 | + |
1264 | + |
1265 | +ALTER FUNCTION public.event_create_machine_device_notify() OWNER TO gavin; |
1266 | + |
1267 | +-- |
1268 | +-- Name: event_create_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1269 | +-- |
1270 | + |
1271 | +CREATE FUNCTION event_create_notify() RETURNS trigger |
1272 | + LANGUAGE plpgsql |
1273 | + AS $$ |
1274 | +DECLARE |
1275 | +BEGIN |
1276 | + PERFORM pg_notify('event_create',CAST(NEW.id AS text)); |
1277 | + RETURN NEW; |
1278 | +END; |
1279 | +$$; |
1280 | + |
1281 | + |
1282 | +ALTER FUNCTION public.event_create_notify() OWNER TO gavin; |
1283 | + |
1284 | +-- |
1285 | +-- Name: fabric_create_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1286 | +-- |
1287 | + |
1288 | +CREATE FUNCTION fabric_create_notify() RETURNS trigger |
1289 | + LANGUAGE plpgsql |
1290 | + AS $$ |
1291 | +DECLARE |
1292 | +BEGIN |
1293 | + PERFORM pg_notify('fabric_create',CAST(NEW.id AS text)); |
1294 | + RETURN NEW; |
1295 | +END; |
1296 | +$$; |
1297 | + |
1298 | + |
1299 | +ALTER FUNCTION public.fabric_create_notify() OWNER TO gavin; |
1300 | + |
1301 | +-- |
1302 | +-- Name: fabric_delete_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1303 | +-- |
1304 | + |
1305 | +CREATE FUNCTION fabric_delete_notify() RETURNS trigger |
1306 | + LANGUAGE plpgsql |
1307 | + AS $$ |
1308 | +DECLARE |
1309 | +BEGIN |
1310 | + PERFORM pg_notify('fabric_delete',CAST(OLD.id AS text)); |
1311 | + RETURN NEW; |
1312 | +END; |
1313 | +$$; |
1314 | + |
1315 | + |
1316 | +ALTER FUNCTION public.fabric_delete_notify() OWNER TO gavin; |
1317 | + |
1318 | +-- |
1319 | +-- Name: fabric_machine_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1320 | +-- |
1321 | + |
1322 | +CREATE FUNCTION fabric_machine_update_notify() RETURNS trigger |
1323 | + LANGUAGE plpgsql |
1324 | + AS $$ |
1325 | +DECLARE |
1326 | + node RECORD; |
1327 | + pnode RECORD; |
1328 | +BEGIN |
1329 | + FOR node IN ( |
1330 | + SELECT DISTINCT ON (maasserver_node.id) |
1331 | + system_id, node_type, parent_id |
1332 | + FROM |
1333 | + maasserver_node, |
1334 | + maasserver_fabric, |
1335 | + maasserver_interface, |
1336 | + maasserver_vlan |
1337 | + WHERE maasserver_fabric.id = NEW.id |
1338 | + AND maasserver_vlan.fabric_id = maasserver_fabric.id |
1339 | + AND maasserver_node.id = maasserver_interface.node_id |
1340 | + AND maasserver_vlan.id = maasserver_interface.vlan_id) |
1341 | + LOOP |
1342 | + IF node.node_type = 0 THEN |
1343 | + PERFORM pg_notify('machine_update',CAST(node.system_id AS text)); |
1344 | + ELSIF node.node_type IN (2, 3, 4) THEN |
1345 | + PERFORM pg_notify('controller_update',CAST(node.system_id AS text)); |
1346 | + ELSIF node.parent_id IS NOT NULL THEN |
1347 | + SELECT system_id INTO pnode |
1348 | + FROM maasserver_node |
1349 | + WHERE id = node.parent_id; |
1350 | + PERFORM pg_notify('machine_update',CAST(pnode.system_id AS text)); |
1351 | + ELSE |
1352 | + PERFORM pg_notify('device_update',CAST(node.system_id AS text)); |
1353 | + END IF; |
1354 | + END LOOP; |
1355 | + RETURN NEW; |
1356 | +END; |
1357 | +$$; |
1358 | + |
1359 | + |
1360 | +ALTER FUNCTION public.fabric_machine_update_notify() OWNER TO gavin; |
1361 | + |
1362 | +-- |
1363 | +-- Name: fabric_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1364 | +-- |
1365 | + |
1366 | +CREATE FUNCTION fabric_update_notify() RETURNS trigger |
1367 | + LANGUAGE plpgsql |
1368 | + AS $$ |
1369 | +DECLARE |
1370 | +BEGIN |
1371 | + PERFORM pg_notify('fabric_update',CAST(NEW.id AS text)); |
1372 | + RETURN NEW; |
1373 | +END; |
1374 | +$$; |
1375 | + |
1376 | + |
1377 | +ALTER FUNCTION public.fabric_update_notify() OWNER TO gavin; |
1378 | + |
1379 | +-- |
1380 | +-- Name: ipaddress_domain_delete_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1381 | +-- |
1382 | + |
1383 | +CREATE FUNCTION ipaddress_domain_delete_notify() RETURNS trigger |
1384 | + LANGUAGE plpgsql |
1385 | + AS $$ |
1386 | +DECLARE |
1387 | + dom RECORD; |
1388 | +BEGIN |
1389 | + FOR dom IN ( |
1390 | + SELECT DISTINCT ON (domain.id) |
1391 | + domain.id |
1392 | + FROM maasserver_staticipaddress AS staticipaddress |
1393 | + LEFT JOIN ( |
1394 | + maasserver_interface_ip_addresses AS iia |
1395 | + JOIN maasserver_interface AS interface ON |
1396 | + iia.interface_id = interface.id |
1397 | + JOIN maasserver_node AS node ON |
1398 | + node.id = interface.node_id) ON |
1399 | + iia.staticipaddress_id = staticipaddress.id |
1400 | + LEFT JOIN ( |
1401 | + maasserver_dnsresource_ip_addresses AS dia |
1402 | + JOIN maasserver_dnsresource AS dnsresource ON |
1403 | + dia.dnsresource_id = dnsresource.id) ON |
1404 | + dia.staticipaddress_id = staticipaddress.id |
1405 | + JOIN maasserver_domain AS domain ON |
1406 | + domain.id = node.domain_id OR domain.id = dnsresource.domain_id |
1407 | + WHERE staticipaddress.id = OLD.id) |
1408 | + LOOP |
1409 | + PERFORM pg_notify('domain_update',CAST(dom.id AS text)); |
1410 | + END LOOP; |
1411 | + RETURN NEW; |
1412 | +END; |
1413 | +$$; |
1414 | + |
1415 | + |
1416 | +ALTER FUNCTION public.ipaddress_domain_delete_notify() OWNER TO gavin; |
1417 | + |
1418 | +-- |
1419 | +-- Name: ipaddress_domain_insert_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1420 | +-- |
1421 | + |
1422 | +CREATE FUNCTION ipaddress_domain_insert_notify() RETURNS trigger |
1423 | + LANGUAGE plpgsql |
1424 | + AS $$ |
1425 | +DECLARE |
1426 | + dom RECORD; |
1427 | +BEGIN |
1428 | + FOR dom IN ( |
1429 | + SELECT DISTINCT ON (domain.id) |
1430 | + domain.id |
1431 | + FROM maasserver_staticipaddress AS staticipaddress |
1432 | + LEFT JOIN ( |
1433 | + maasserver_interface_ip_addresses AS iia |
1434 | + JOIN maasserver_interface AS interface ON |
1435 | + iia.interface_id = interface.id |
1436 | + JOIN maasserver_node AS node ON |
1437 | + node.id = interface.node_id) ON |
1438 | + iia.staticipaddress_id = staticipaddress.id |
1439 | + LEFT JOIN ( |
1440 | + maasserver_dnsresource_ip_addresses AS dia |
1441 | + JOIN maasserver_dnsresource AS dnsresource ON |
1442 | + dia.dnsresource_id = dnsresource.id) ON |
1443 | + dia.staticipaddress_id = staticipaddress.id |
1444 | + JOIN maasserver_domain AS domain ON |
1445 | + domain.id = node.domain_id OR domain.id = dnsresource.domain_id |
1446 | + WHERE staticipaddress.id = NEW.id) |
1447 | + LOOP |
1448 | + PERFORM pg_notify('domain_update',CAST(dom.id AS text)); |
1449 | + END LOOP; |
1450 | + RETURN NEW; |
1451 | +END; |
1452 | +$$; |
1453 | + |
1454 | + |
1455 | +ALTER FUNCTION public.ipaddress_domain_insert_notify() OWNER TO gavin; |
1456 | + |
1457 | +-- |
1458 | +-- Name: ipaddress_domain_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1459 | +-- |
1460 | + |
1461 | +CREATE FUNCTION ipaddress_domain_update_notify() RETURNS trigger |
1462 | + LANGUAGE plpgsql |
1463 | + AS $$ |
1464 | +DECLARE |
1465 | + dom RECORD; |
1466 | +BEGIN |
1467 | + IF ((OLD.ip IS NULL and NEW.ip IS NOT NULL) OR |
1468 | + (OLD.ip IS NOT NULL and NEW.ip IS NULL) OR |
1469 | + OLD.ip != NEW.ip) THEN |
1470 | + FOR dom IN ( |
1471 | + SELECT DISTINCT ON (domain.id) |
1472 | + domain.id |
1473 | + FROM maasserver_staticipaddress AS staticipaddress |
1474 | + LEFT JOIN ( |
1475 | + maasserver_interface_ip_addresses AS iia |
1476 | + JOIN maasserver_interface AS interface ON |
1477 | + iia.interface_id = interface.id |
1478 | + JOIN maasserver_node AS node ON |
1479 | + node.id = interface.node_id) ON |
1480 | + iia.staticipaddress_id = staticipaddress.id |
1481 | + LEFT JOIN ( |
1482 | + maasserver_dnsresource_ip_addresses AS dia |
1483 | + JOIN maasserver_dnsresource AS dnsresource ON |
1484 | + dia.dnsresource_id = dnsresource.id) ON |
1485 | + dia.staticipaddress_id = staticipaddress.id |
1486 | + JOIN maasserver_domain AS domain ON |
1487 | + domain.id = node.domain_id OR domain.id = dnsresource.domain_id |
1488 | + WHERE staticipaddress.id = OLD.id OR staticipaddress.id = NEW.id) |
1489 | + LOOP |
1490 | + PERFORM pg_notify('domain_update',CAST(dom.id AS text)); |
1491 | + END LOOP; |
1492 | + END IF; |
1493 | + RETURN NEW; |
1494 | +END; |
1495 | +$$; |
1496 | + |
1497 | + |
1498 | +ALTER FUNCTION public.ipaddress_domain_update_notify() OWNER TO gavin; |
1499 | + |
1500 | +-- |
1501 | +-- Name: ipaddress_machine_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1502 | +-- |
1503 | + |
1504 | +CREATE FUNCTION ipaddress_machine_update_notify() RETURNS trigger |
1505 | + LANGUAGE plpgsql |
1506 | + AS $$ |
1507 | +DECLARE |
1508 | + node RECORD; |
1509 | + pnode RECORD; |
1510 | +BEGIN |
1511 | + FOR node IN ( |
1512 | + SELECT DISTINCT ON (maasserver_node.id) |
1513 | + system_id, node_type, parent_id |
1514 | + FROM |
1515 | + maasserver_node, |
1516 | + maasserver_interface, |
1517 | + maasserver_interface_ip_addresses AS ip_link |
1518 | + WHERE ip_link.staticipaddress_id = NEW.id |
1519 | + AND ip_link.interface_id = maasserver_interface.id |
1520 | + AND maasserver_node.id = maasserver_interface.node_id) |
1521 | + LOOP |
1522 | + IF node.node_type = 0 THEN |
1523 | + PERFORM pg_notify('machine_update',CAST(node.system_id AS text)); |
1524 | + ELSIF node.node_type IN (2, 3, 4) THEN |
1525 | + PERFORM pg_notify('controller_update',CAST(node.system_id AS text)); |
1526 | + ELSIF node.parent_id IS NOT NULL THEN |
1527 | + SELECT system_id INTO pnode |
1528 | + FROM maasserver_node |
1529 | + WHERE id = node.parent_id; |
1530 | + PERFORM pg_notify('machine_update',CAST(pnode.system_id AS text)); |
1531 | + ELSE |
1532 | + PERFORM pg_notify('device_update',CAST(node.system_id AS text)); |
1533 | + END IF; |
1534 | + END LOOP; |
1535 | + RETURN NEW; |
1536 | +END; |
1537 | +$$; |
1538 | + |
1539 | + |
1540 | +ALTER FUNCTION public.ipaddress_machine_update_notify() OWNER TO gavin; |
1541 | + |
1542 | +-- |
1543 | +-- Name: ipaddress_subnet_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1544 | +-- |
1545 | + |
1546 | +CREATE FUNCTION ipaddress_subnet_update_notify() RETURNS trigger |
1547 | + LANGUAGE plpgsql |
1548 | + AS $$ |
1549 | +BEGIN |
1550 | + IF OLD.subnet_id != NEW.subnet_id THEN |
1551 | + IF OLD.subnet_id IS NOT NULL THEN |
1552 | + PERFORM pg_notify('subnet_update',CAST(OLD.subnet_id AS text)); |
1553 | + END IF; |
1554 | + END IF; |
1555 | + IF NEW.subnet_id IS NOT NULL THEN |
1556 | + PERFORM pg_notify('subnet_update',CAST(NEW.subnet_id AS text)); |
1557 | + END IF; |
1558 | + RETURN NEW; |
1559 | +END; |
1560 | +$$; |
1561 | + |
1562 | + |
1563 | +ALTER FUNCTION public.ipaddress_subnet_update_notify() OWNER TO gavin; |
1564 | + |
1565 | +-- |
1566 | +-- Name: iprange_create_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1567 | +-- |
1568 | + |
1569 | +CREATE FUNCTION iprange_create_notify() RETURNS trigger |
1570 | + LANGUAGE plpgsql |
1571 | + AS $$ |
1572 | +DECLARE |
1573 | +BEGIN |
1574 | + PERFORM pg_notify('iprange_create',CAST(NEW.id AS text)); |
1575 | + RETURN NEW; |
1576 | +END; |
1577 | +$$; |
1578 | + |
1579 | + |
1580 | +ALTER FUNCTION public.iprange_create_notify() OWNER TO gavin; |
1581 | + |
1582 | +-- |
1583 | +-- Name: iprange_delete_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1584 | +-- |
1585 | + |
1586 | +CREATE FUNCTION iprange_delete_notify() RETURNS trigger |
1587 | + LANGUAGE plpgsql |
1588 | + AS $$ |
1589 | +DECLARE |
1590 | +BEGIN |
1591 | + PERFORM pg_notify('iprange_delete',CAST(OLD.id AS text)); |
1592 | + RETURN NEW; |
1593 | +END; |
1594 | +$$; |
1595 | + |
1596 | + |
1597 | +ALTER FUNCTION public.iprange_delete_notify() OWNER TO gavin; |
1598 | + |
1599 | +-- |
1600 | +-- Name: iprange_subnet_delete_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1601 | +-- |
1602 | + |
1603 | +CREATE FUNCTION iprange_subnet_delete_notify() RETURNS trigger |
1604 | + LANGUAGE plpgsql |
1605 | + AS $$ |
1606 | +BEGIN |
1607 | + IF OLD.subnet_id IS NOT NULL THEN |
1608 | + PERFORM pg_notify('subnet_update',CAST(OLD.subnet_id AS text)); |
1609 | + END IF; |
1610 | + RETURN OLD; |
1611 | +END; |
1612 | +$$; |
1613 | + |
1614 | + |
1615 | +ALTER FUNCTION public.iprange_subnet_delete_notify() OWNER TO gavin; |
1616 | + |
1617 | +-- |
1618 | +-- Name: iprange_subnet_insert_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1619 | +-- |
1620 | + |
1621 | +CREATE FUNCTION iprange_subnet_insert_notify() RETURNS trigger |
1622 | + LANGUAGE plpgsql |
1623 | + AS $$ |
1624 | +BEGIN |
1625 | + IF NEW.subnet_id IS NOT NULL THEN |
1626 | + PERFORM pg_notify('subnet_update',CAST(NEW.subnet_id AS text)); |
1627 | + END IF; |
1628 | + RETURN NEW; |
1629 | +END; |
1630 | +$$; |
1631 | + |
1632 | + |
1633 | +ALTER FUNCTION public.iprange_subnet_insert_notify() OWNER TO gavin; |
1634 | + |
1635 | +-- |
1636 | +-- Name: iprange_subnet_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1637 | +-- |
1638 | + |
1639 | +CREATE FUNCTION iprange_subnet_update_notify() RETURNS trigger |
1640 | + LANGUAGE plpgsql |
1641 | + AS $$ |
1642 | +BEGIN |
1643 | + IF OLD.subnet_id != NEW.subnet_id THEN |
1644 | + IF OLD.subnet_id IS NOT NULL THEN |
1645 | + PERFORM pg_notify('subnet_update',CAST(OLD.subnet_id AS text)); |
1646 | + END IF; |
1647 | + END IF; |
1648 | + IF NEW.subnet_id IS NOT NULL THEN |
1649 | + PERFORM pg_notify('subnet_update',CAST(NEW.subnet_id AS text)); |
1650 | + END IF; |
1651 | + RETURN NEW; |
1652 | +END; |
1653 | +$$; |
1654 | + |
1655 | + |
1656 | +ALTER FUNCTION public.iprange_subnet_update_notify() OWNER TO gavin; |
1657 | + |
1658 | +-- |
1659 | +-- Name: iprange_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1660 | +-- |
1661 | + |
1662 | +CREATE FUNCTION iprange_update_notify() RETURNS trigger |
1663 | + LANGUAGE plpgsql |
1664 | + AS $$ |
1665 | +DECLARE |
1666 | +BEGIN |
1667 | + PERFORM pg_notify('iprange_update',CAST(NEW.id AS text)); |
1668 | + RETURN NEW; |
1669 | +END; |
1670 | +$$; |
1671 | + |
1672 | + |
1673 | +ALTER FUNCTION public.iprange_update_notify() OWNER TO gavin; |
1674 | + |
1675 | +-- |
1676 | +-- Name: machine_create_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1677 | +-- |
1678 | + |
1679 | +CREATE FUNCTION machine_create_notify() RETURNS trigger |
1680 | + LANGUAGE plpgsql |
1681 | + AS $$ |
1682 | +DECLARE |
1683 | +BEGIN |
1684 | + PERFORM pg_notify('machine_create',CAST(NEW.system_id AS text)); |
1685 | + RETURN NEW; |
1686 | +END; |
1687 | +$$; |
1688 | + |
1689 | + |
1690 | +ALTER FUNCTION public.machine_create_notify() OWNER TO gavin; |
1691 | + |
1692 | +-- |
1693 | +-- Name: machine_delete_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1694 | +-- |
1695 | + |
1696 | +CREATE FUNCTION machine_delete_notify() RETURNS trigger |
1697 | + LANGUAGE plpgsql |
1698 | + AS $$ |
1699 | +DECLARE |
1700 | +BEGIN |
1701 | + PERFORM pg_notify('machine_delete',CAST(OLD.system_id AS text)); |
1702 | + RETURN NEW; |
1703 | +END; |
1704 | +$$; |
1705 | + |
1706 | + |
1707 | +ALTER FUNCTION public.machine_delete_notify() OWNER TO gavin; |
1708 | + |
1709 | +-- |
1710 | +-- Name: machine_device_tag_link_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1711 | +-- |
1712 | + |
1713 | +CREATE FUNCTION machine_device_tag_link_notify() RETURNS trigger |
1714 | + LANGUAGE plpgsql |
1715 | + AS $$ |
1716 | +DECLARE |
1717 | + node RECORD; |
1718 | + pnode RECORD; |
1719 | +BEGIN |
1720 | + SELECT system_id, node_type, parent_id INTO node |
1721 | + FROM maasserver_node |
1722 | + WHERE id = NEW.node_id; |
1723 | + |
1724 | + IF node.node_type = 0 THEN |
1725 | + PERFORM pg_notify('machine_update',CAST(node.system_id AS text)); |
1726 | + ELSIF node.node_type IN (2, 3, 4) THEN |
1727 | + PERFORM pg_notify('controller_update',CAST(node.system_id AS text)); |
1728 | + ELSIF node.parent_id IS NOT NULL THEN |
1729 | + SELECT system_id INTO pnode |
1730 | + FROM maasserver_node |
1731 | + WHERE id = node.parent_id; |
1732 | + PERFORM pg_notify('machine_update',CAST(pnode.system_id AS text)); |
1733 | + ELSE |
1734 | + PERFORM pg_notify('device_update',CAST(node.system_id AS text)); |
1735 | + END IF; |
1736 | + RETURN NEW; |
1737 | +END; |
1738 | +$$; |
1739 | + |
1740 | + |
1741 | +ALTER FUNCTION public.machine_device_tag_link_notify() OWNER TO gavin; |
1742 | + |
1743 | +-- |
1744 | +-- Name: machine_device_tag_unlink_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1745 | +-- |
1746 | + |
1747 | +CREATE FUNCTION machine_device_tag_unlink_notify() RETURNS trigger |
1748 | + LANGUAGE plpgsql |
1749 | + AS $$ |
1750 | +DECLARE |
1751 | + node RECORD; |
1752 | + pnode RECORD; |
1753 | +BEGIN |
1754 | + SELECT system_id, node_type, parent_id INTO node |
1755 | + FROM maasserver_node |
1756 | + WHERE id = OLD.node_id; |
1757 | + |
1758 | + IF node.node_type = 0 THEN |
1759 | + PERFORM pg_notify('machine_update',CAST(node.system_id AS text)); |
1760 | + ELSIF node.node_type IN (2, 3, 4) THEN |
1761 | + PERFORM pg_notify('controller_update',CAST(node.system_id AS text)); |
1762 | + ELSIF node.parent_id IS NOT NULL THEN |
1763 | + SELECT system_id INTO pnode |
1764 | + FROM maasserver_node |
1765 | + WHERE id = node.parent_id; |
1766 | + PERFORM pg_notify('machine_update',CAST(pnode.system_id AS text)); |
1767 | + ELSE |
1768 | + PERFORM pg_notify('device_update',CAST(node.system_id AS text)); |
1769 | + END IF; |
1770 | + RETURN NEW; |
1771 | +END; |
1772 | +$$; |
1773 | + |
1774 | + |
1775 | +ALTER FUNCTION public.machine_device_tag_unlink_notify() OWNER TO gavin; |
1776 | + |
1777 | +-- |
1778 | +-- Name: machine_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1779 | +-- |
1780 | + |
1781 | +CREATE FUNCTION machine_update_notify() RETURNS trigger |
1782 | + LANGUAGE plpgsql |
1783 | + AS $$ |
1784 | +DECLARE |
1785 | +BEGIN |
1786 | + PERFORM pg_notify('machine_update',CAST(NEW.system_id AS text)); |
1787 | + RETURN NEW; |
1788 | +END; |
1789 | +$$; |
1790 | + |
1791 | + |
1792 | +ALTER FUNCTION public.machine_update_notify() OWNER TO gavin; |
1793 | + |
1794 | +-- |
1795 | +-- Name: nd_blockdevice_link_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1796 | +-- |
1797 | + |
1798 | +CREATE FUNCTION nd_blockdevice_link_notify() RETURNS trigger |
1799 | + LANGUAGE plpgsql |
1800 | + AS $$ |
1801 | +DECLARE |
1802 | + node RECORD; |
1803 | + pnode RECORD; |
1804 | +BEGIN |
1805 | + SELECT system_id, node_type, parent_id INTO node |
1806 | + FROM maasserver_node |
1807 | + WHERE id = NEW.node_id; |
1808 | + |
1809 | + IF node.node_type = 0 THEN |
1810 | + PERFORM pg_notify('machine_update',CAST(node.system_id AS text)); |
1811 | + ELSIF node.node_type IN (2, 3, 4) THEN |
1812 | + PERFORM pg_notify('controller_update',CAST( |
1813 | + node.system_id AS text)); |
1814 | + ELSIF node.parent_id IS NOT NULL THEN |
1815 | + SELECT system_id INTO pnode |
1816 | + FROM maasserver_node |
1817 | + WHERE id = node.parent_id; |
1818 | + PERFORM pg_notify('machine_update',CAST(pnode.system_id AS text)); |
1819 | + ELSE |
1820 | + PERFORM pg_notify('device_update',CAST(node.system_id AS text)); |
1821 | + END IF; |
1822 | + RETURN NEW; |
1823 | +END; |
1824 | +$$; |
1825 | + |
1826 | + |
1827 | +ALTER FUNCTION public.nd_blockdevice_link_notify() OWNER TO gavin; |
1828 | + |
1829 | +-- |
1830 | +-- Name: nd_blockdevice_unlink_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1831 | +-- |
1832 | + |
1833 | +CREATE FUNCTION nd_blockdevice_unlink_notify() RETURNS trigger |
1834 | + LANGUAGE plpgsql |
1835 | + AS $$ |
1836 | +DECLARE |
1837 | + node RECORD; |
1838 | + pnode RECORD; |
1839 | +BEGIN |
1840 | + SELECT system_id, node_type, parent_id INTO node |
1841 | + FROM maasserver_node |
1842 | + WHERE id = OLD.node_id; |
1843 | + |
1844 | + IF node.node_type = 0 THEN |
1845 | + PERFORM pg_notify('machine_update',CAST(node.system_id AS text)); |
1846 | + ELSIF node.node_type IN (2, 3, 4) THEN |
1847 | + PERFORM pg_notify('controller_update',CAST( |
1848 | + node.system_id AS text)); |
1849 | + ELSIF node.parent_id IS NOT NULL THEN |
1850 | + SELECT system_id INTO pnode |
1851 | + FROM maasserver_node |
1852 | + WHERE id = node.parent_id; |
1853 | + PERFORM pg_notify('machine_update',CAST(pnode.system_id AS text)); |
1854 | + ELSE |
1855 | + PERFORM pg_notify('device_update',CAST(node.system_id AS text)); |
1856 | + END IF; |
1857 | + RETURN NEW; |
1858 | +END; |
1859 | +$$; |
1860 | + |
1861 | + |
1862 | +ALTER FUNCTION public.nd_blockdevice_unlink_notify() OWNER TO gavin; |
1863 | + |
1864 | +-- |
1865 | +-- Name: nd_blockdevice_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1866 | +-- |
1867 | + |
1868 | +CREATE FUNCTION nd_blockdevice_update_notify() RETURNS trigger |
1869 | + LANGUAGE plpgsql |
1870 | + AS $$ |
1871 | +DECLARE |
1872 | + node RECORD; |
1873 | + pnode RECORD; |
1874 | +BEGIN |
1875 | + SELECT system_id, node_type, parent_id INTO node |
1876 | + FROM maasserver_node |
1877 | + WHERE id = NEW.node_id; |
1878 | + |
1879 | + IF node.node_type = 0 THEN |
1880 | + PERFORM pg_notify('machine_update',CAST(node.system_id AS text)); |
1881 | + ELSIF node.node_type IN (2, 3, 4) THEN |
1882 | + PERFORM pg_notify('controller_update',CAST( |
1883 | + node.system_id AS text)); |
1884 | + ELSIF node.parent_id IS NOT NULL THEN |
1885 | + SELECT system_id INTO pnode |
1886 | + FROM maasserver_node |
1887 | + WHERE id = node.parent_id; |
1888 | + PERFORM pg_notify('machine_update',CAST(pnode.system_id AS text)); |
1889 | + ELSE |
1890 | + PERFORM pg_notify('device_update',CAST(node.system_id AS text)); |
1891 | + END IF; |
1892 | + RETURN NEW; |
1893 | +END; |
1894 | +$$; |
1895 | + |
1896 | + |
1897 | +ALTER FUNCTION public.nd_blockdevice_update_notify() OWNER TO gavin; |
1898 | + |
1899 | +-- |
1900 | +-- Name: nd_cacheset_link_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1901 | +-- |
1902 | + |
1903 | +CREATE FUNCTION nd_cacheset_link_notify() RETURNS trigger |
1904 | + LANGUAGE plpgsql |
1905 | + AS $$ |
1906 | +DECLARE |
1907 | + node RECORD; |
1908 | +BEGIN |
1909 | + SELECT system_id, node_type INTO node |
1910 | + FROM maasserver_node, |
1911 | + maasserver_blockdevice, |
1912 | + maasserver_partition, |
1913 | + maasserver_partitiontable, |
1914 | + maasserver_filesystem |
1915 | + WHERE maasserver_node.id = maasserver_blockdevice.node_id |
1916 | + AND maasserver_blockdevice.id = maasserver_partitiontable.block_device_id |
1917 | + AND maasserver_partitiontable.id = |
1918 | + maasserver_partition.partition_table_id |
1919 | + AND maasserver_partition.id = maasserver_filesystem.partition_id |
1920 | + AND maasserver_filesystem.cache_set_id = NEW.id; |
1921 | + |
1922 | + IF node.node_type = 0 THEN |
1923 | + PERFORM pg_notify('machine_update',CAST(node.system_id AS text)); |
1924 | + END IF; |
1925 | + RETURN NEW; |
1926 | +END; |
1927 | +$$; |
1928 | + |
1929 | + |
1930 | +ALTER FUNCTION public.nd_cacheset_link_notify() OWNER TO gavin; |
1931 | + |
1932 | +-- |
1933 | +-- Name: nd_cacheset_unlink_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1934 | +-- |
1935 | + |
1936 | +CREATE FUNCTION nd_cacheset_unlink_notify() RETURNS trigger |
1937 | + LANGUAGE plpgsql |
1938 | + AS $$ |
1939 | +DECLARE |
1940 | + node RECORD; |
1941 | +BEGIN |
1942 | + SELECT system_id, node_type INTO node |
1943 | + FROM maasserver_node, |
1944 | + maasserver_blockdevice, |
1945 | + maasserver_partition, |
1946 | + maasserver_partitiontable, |
1947 | + maasserver_filesystem |
1948 | + WHERE maasserver_node.id = maasserver_blockdevice.node_id |
1949 | + AND maasserver_blockdevice.id = maasserver_partitiontable.block_device_id |
1950 | + AND maasserver_partitiontable.id = |
1951 | + maasserver_partition.partition_table_id |
1952 | + AND maasserver_partition.id = maasserver_filesystem.partition_id |
1953 | + AND maasserver_filesystem.cache_set_id = OLD.id; |
1954 | + |
1955 | + IF node.node_type = 0 THEN |
1956 | + PERFORM pg_notify('machine_update',CAST(node.system_id AS text)); |
1957 | + END IF; |
1958 | + RETURN NEW; |
1959 | +END; |
1960 | +$$; |
1961 | + |
1962 | + |
1963 | +ALTER FUNCTION public.nd_cacheset_unlink_notify() OWNER TO gavin; |
1964 | + |
1965 | +-- |
1966 | +-- Name: nd_cacheset_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
1967 | +-- |
1968 | + |
1969 | +CREATE FUNCTION nd_cacheset_update_notify() RETURNS trigger |
1970 | + LANGUAGE plpgsql |
1971 | + AS $$ |
1972 | +DECLARE |
1973 | + node RECORD; |
1974 | +BEGIN |
1975 | + SELECT system_id, node_type INTO node |
1976 | + FROM maasserver_node, |
1977 | + maasserver_blockdevice, |
1978 | + maasserver_partition, |
1979 | + maasserver_partitiontable, |
1980 | + maasserver_filesystem |
1981 | + WHERE maasserver_node.id = maasserver_blockdevice.node_id |
1982 | + AND maasserver_blockdevice.id = maasserver_partitiontable.block_device_id |
1983 | + AND maasserver_partitiontable.id = |
1984 | + maasserver_partition.partition_table_id |
1985 | + AND maasserver_partition.id = maasserver_filesystem.partition_id |
1986 | + AND maasserver_filesystem.cache_set_id = NEW.id; |
1987 | + |
1988 | + IF node.node_type = 0 THEN |
1989 | + PERFORM pg_notify('machine_update',CAST(node.system_id AS text)); |
1990 | + END IF; |
1991 | + RETURN NEW; |
1992 | +END; |
1993 | +$$; |
1994 | + |
1995 | + |
1996 | +ALTER FUNCTION public.nd_cacheset_update_notify() OWNER TO gavin; |
1997 | + |
1998 | +-- |
1999 | +-- Name: nd_filesystem_link_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2000 | +-- |
2001 | + |
2002 | +CREATE FUNCTION nd_filesystem_link_notify() RETURNS trigger |
2003 | + LANGUAGE plpgsql |
2004 | + AS $$ |
2005 | +DECLARE |
2006 | + node RECORD; |
2007 | +BEGIN |
2008 | + IF NEW.block_device_id IS NOT NULL |
2009 | + THEN |
2010 | + SELECT system_id, node_type INTO node |
2011 | + FROM maasserver_node, |
2012 | + maasserver_blockdevice |
2013 | + WHERE maasserver_node.id = maasserver_blockdevice.node_id |
2014 | + AND maasserver_blockdevice.id = NEW.block_device_id; |
2015 | + ELSIF NEW.partition_id IS NOT NULL |
2016 | + THEN |
2017 | + SELECT system_id, node_type INTO node |
2018 | + FROM maasserver_node, |
2019 | + maasserver_blockdevice, |
2020 | + maasserver_partition, |
2021 | + maasserver_partitiontable |
2022 | + WHERE maasserver_node.id = maasserver_blockdevice.node_id |
2023 | + AND maasserver_blockdevice.id = |
2024 | + maasserver_partitiontable.block_device_id |
2025 | + AND maasserver_partitiontable.id = |
2026 | + maasserver_partition.partition_table_id |
2027 | + AND maasserver_partition.id = NEW.partition_id; |
2028 | + ELSIF NEW.node_id IS NOT NULL |
2029 | + THEN |
2030 | + SELECT system_id, node_type INTO node |
2031 | + FROM maasserver_node |
2032 | + WHERE maasserver_node.id = NEW.node_id; |
2033 | + END IF; |
2034 | + |
2035 | + IF node.node_type = 0 THEN |
2036 | + PERFORM pg_notify('machine_update', CAST(node.system_id AS text)); |
2037 | + END IF; |
2038 | + |
2039 | + RETURN NEW; |
2040 | +END; |
2041 | +$$; |
2042 | + |
2043 | + |
2044 | +ALTER FUNCTION public.nd_filesystem_link_notify() OWNER TO gavin; |
2045 | + |
2046 | +-- |
2047 | +-- Name: nd_filesystem_unlink_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2048 | +-- |
2049 | + |
2050 | +CREATE FUNCTION nd_filesystem_unlink_notify() RETURNS trigger |
2051 | + LANGUAGE plpgsql |
2052 | + AS $$ |
2053 | +DECLARE |
2054 | + node RECORD; |
2055 | +BEGIN |
2056 | + IF OLD.block_device_id IS NOT NULL |
2057 | + THEN |
2058 | + SELECT system_id, node_type INTO node |
2059 | + FROM maasserver_node, |
2060 | + maasserver_blockdevice |
2061 | + WHERE maasserver_node.id = maasserver_blockdevice.node_id |
2062 | + AND maasserver_blockdevice.id = OLD.block_device_id; |
2063 | + ELSIF OLD.partition_id IS NOT NULL |
2064 | + THEN |
2065 | + SELECT system_id, node_type INTO node |
2066 | + FROM maasserver_node, |
2067 | + maasserver_blockdevice, |
2068 | + maasserver_partition, |
2069 | + maasserver_partitiontable |
2070 | + WHERE maasserver_node.id = maasserver_blockdevice.node_id |
2071 | + AND maasserver_blockdevice.id = |
2072 | + maasserver_partitiontable.block_device_id |
2073 | + AND maasserver_partitiontable.id = |
2074 | + maasserver_partition.partition_table_id |
2075 | + AND maasserver_partition.id = OLD.partition_id; |
2076 | + ELSIF OLD.node_id IS NOT NULL |
2077 | + THEN |
2078 | + SELECT system_id, node_type INTO node |
2079 | + FROM maasserver_node |
2080 | + WHERE maasserver_node.id = OLD.node_id; |
2081 | + END IF; |
2082 | + |
2083 | + IF node.node_type = 0 THEN |
2084 | + PERFORM pg_notify('machine_update', CAST(node.system_id AS text)); |
2085 | + END IF; |
2086 | + |
2087 | + RETURN NEW; |
2088 | +END; |
2089 | +$$; |
2090 | + |
2091 | + |
2092 | +ALTER FUNCTION public.nd_filesystem_unlink_notify() OWNER TO gavin; |
2093 | + |
2094 | +-- |
2095 | +-- Name: nd_filesystem_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2096 | +-- |
2097 | + |
2098 | +CREATE FUNCTION nd_filesystem_update_notify() RETURNS trigger |
2099 | + LANGUAGE plpgsql |
2100 | + AS $$ |
2101 | +DECLARE |
2102 | + node RECORD; |
2103 | +BEGIN |
2104 | + IF NEW.block_device_id IS NOT NULL |
2105 | + THEN |
2106 | + SELECT system_id, node_type INTO node |
2107 | + FROM maasserver_node, |
2108 | + maasserver_blockdevice |
2109 | + WHERE maasserver_node.id = maasserver_blockdevice.node_id |
2110 | + AND maasserver_blockdevice.id = NEW.block_device_id; |
2111 | + ELSIF NEW.partition_id IS NOT NULL |
2112 | + THEN |
2113 | + SELECT system_id, node_type INTO node |
2114 | + FROM maasserver_node, |
2115 | + maasserver_blockdevice, |
2116 | + maasserver_partition, |
2117 | + maasserver_partitiontable |
2118 | + WHERE maasserver_node.id = maasserver_blockdevice.node_id |
2119 | + AND maasserver_blockdevice.id = |
2120 | + maasserver_partitiontable.block_device_id |
2121 | + AND maasserver_partitiontable.id = |
2122 | + maasserver_partition.partition_table_id |
2123 | + AND maasserver_partition.id = NEW.partition_id; |
2124 | + ELSIF NEW.node_id IS NOT NULL |
2125 | + THEN |
2126 | + SELECT system_id, node_type INTO node |
2127 | + FROM maasserver_node |
2128 | + WHERE maasserver_node.id = NEW.node_id; |
2129 | + END IF; |
2130 | + |
2131 | + IF node.node_type = 0 THEN |
2132 | + PERFORM pg_notify('machine_update', CAST(node.system_id AS text)); |
2133 | + END IF; |
2134 | + |
2135 | + RETURN NEW; |
2136 | +END; |
2137 | +$$; |
2138 | + |
2139 | + |
2140 | +ALTER FUNCTION public.nd_filesystem_update_notify() OWNER TO gavin; |
2141 | + |
2142 | +-- |
2143 | +-- Name: nd_filesystemgroup_link_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2144 | +-- |
2145 | + |
2146 | +CREATE FUNCTION nd_filesystemgroup_link_notify() RETURNS trigger |
2147 | + LANGUAGE plpgsql |
2148 | + AS $$ |
2149 | +DECLARE |
2150 | + node RECORD; |
2151 | +BEGIN |
2152 | + SELECT system_id, node_type INTO node |
2153 | + FROM maasserver_node, |
2154 | + maasserver_blockdevice, |
2155 | + maasserver_partition, |
2156 | + maasserver_partitiontable, |
2157 | + maasserver_filesystem |
2158 | + WHERE maasserver_node.id = maasserver_blockdevice.node_id |
2159 | + AND maasserver_blockdevice.id = maasserver_partitiontable.block_device_id |
2160 | + AND maasserver_partitiontable.id = |
2161 | + maasserver_partition.partition_table_id |
2162 | + AND maasserver_partition.id = maasserver_filesystem.partition_id |
2163 | + AND (maasserver_filesystem.filesystem_group_id = NEW.id |
2164 | + OR maasserver_filesystem.cache_set_id = NEW.cache_set_id); |
2165 | + |
2166 | + IF node.node_type = 0 THEN |
2167 | + PERFORM pg_notify('machine_update',CAST(node.system_id AS text)); |
2168 | + END IF; |
2169 | + RETURN NEW; |
2170 | +END; |
2171 | +$$; |
2172 | + |
2173 | + |
2174 | +ALTER FUNCTION public.nd_filesystemgroup_link_notify() OWNER TO gavin; |
2175 | + |
2176 | +-- |
2177 | +-- Name: nd_filesystemgroup_unlink_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2178 | +-- |
2179 | + |
2180 | +CREATE FUNCTION nd_filesystemgroup_unlink_notify() RETURNS trigger |
2181 | + LANGUAGE plpgsql |
2182 | + AS $$ |
2183 | +DECLARE |
2184 | + node RECORD; |
2185 | +BEGIN |
2186 | + SELECT system_id, node_type INTO node |
2187 | + FROM maasserver_node, |
2188 | + maasserver_blockdevice, |
2189 | + maasserver_partition, |
2190 | + maasserver_partitiontable, |
2191 | + maasserver_filesystem |
2192 | + WHERE maasserver_node.id = maasserver_blockdevice.node_id |
2193 | + AND maasserver_blockdevice.id = maasserver_partitiontable.block_device_id |
2194 | + AND maasserver_partitiontable.id = |
2195 | + maasserver_partition.partition_table_id |
2196 | + AND maasserver_partition.id = maasserver_filesystem.partition_id |
2197 | + AND (maasserver_filesystem.filesystem_group_id = OLD.id |
2198 | + OR maasserver_filesystem.cache_set_id = OLD.cache_set_id); |
2199 | + |
2200 | + IF node.node_type = 0 THEN |
2201 | + PERFORM pg_notify('machine_update',CAST(node.system_id AS text)); |
2202 | + END IF; |
2203 | + RETURN NEW; |
2204 | +END; |
2205 | +$$; |
2206 | + |
2207 | + |
2208 | +ALTER FUNCTION public.nd_filesystemgroup_unlink_notify() OWNER TO gavin; |
2209 | + |
2210 | +-- |
2211 | +-- Name: nd_filesystemgroup_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2212 | +-- |
2213 | + |
2214 | +CREATE FUNCTION nd_filesystemgroup_update_notify() RETURNS trigger |
2215 | + LANGUAGE plpgsql |
2216 | + AS $$ |
2217 | +DECLARE |
2218 | + node RECORD; |
2219 | +BEGIN |
2220 | + SELECT system_id, node_type INTO node |
2221 | + FROM maasserver_node, |
2222 | + maasserver_blockdevice, |
2223 | + maasserver_partition, |
2224 | + maasserver_partitiontable, |
2225 | + maasserver_filesystem |
2226 | + WHERE maasserver_node.id = maasserver_blockdevice.node_id |
2227 | + AND maasserver_blockdevice.id = maasserver_partitiontable.block_device_id |
2228 | + AND maasserver_partitiontable.id = |
2229 | + maasserver_partition.partition_table_id |
2230 | + AND maasserver_partition.id = maasserver_filesystem.partition_id |
2231 | + AND (maasserver_filesystem.filesystem_group_id = NEW.id |
2232 | + OR maasserver_filesystem.cache_set_id = NEW.cache_set_id); |
2233 | + |
2234 | + IF node.node_type = 0 THEN |
2235 | + PERFORM pg_notify('machine_update',CAST(node.system_id AS text)); |
2236 | + END IF; |
2237 | + RETURN NEW; |
2238 | +END; |
2239 | +$$; |
2240 | + |
2241 | + |
2242 | +ALTER FUNCTION public.nd_filesystemgroup_update_notify() OWNER TO gavin; |
2243 | + |
2244 | +-- |
2245 | +-- Name: nd_interface_link_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2246 | +-- |
2247 | + |
2248 | +CREATE FUNCTION nd_interface_link_notify() RETURNS trigger |
2249 | + LANGUAGE plpgsql |
2250 | + AS $$ |
2251 | +DECLARE |
2252 | + node RECORD; |
2253 | + pnode RECORD; |
2254 | +BEGIN |
2255 | + SELECT system_id, node_type, parent_id INTO node |
2256 | + FROM maasserver_node |
2257 | + WHERE id = NEW.node_id; |
2258 | + |
2259 | + IF node.node_type = 0 THEN |
2260 | + PERFORM pg_notify('machine_update',CAST(node.system_id AS text)); |
2261 | + ELSIF node.node_type IN (2, 3, 4) THEN |
2262 | + PERFORM pg_notify('controller_update',CAST( |
2263 | + node.system_id AS text)); |
2264 | + ELSIF node.parent_id IS NOT NULL THEN |
2265 | + SELECT system_id INTO pnode |
2266 | + FROM maasserver_node |
2267 | + WHERE id = node.parent_id; |
2268 | + PERFORM pg_notify('machine_update',CAST(pnode.system_id AS text)); |
2269 | + ELSE |
2270 | + PERFORM pg_notify('device_update',CAST(node.system_id AS text)); |
2271 | + END IF; |
2272 | + RETURN NEW; |
2273 | +END; |
2274 | +$$; |
2275 | + |
2276 | + |
2277 | +ALTER FUNCTION public.nd_interface_link_notify() OWNER TO gavin; |
2278 | + |
2279 | +-- |
2280 | +-- Name: nd_interface_unlink_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2281 | +-- |
2282 | + |
2283 | +CREATE FUNCTION nd_interface_unlink_notify() RETURNS trigger |
2284 | + LANGUAGE plpgsql |
2285 | + AS $$ |
2286 | +DECLARE |
2287 | + node RECORD; |
2288 | + pnode RECORD; |
2289 | +BEGIN |
2290 | + SELECT system_id, node_type, parent_id INTO node |
2291 | + FROM maasserver_node |
2292 | + WHERE id = OLD.node_id; |
2293 | + |
2294 | + IF node.node_type = 0 THEN |
2295 | + PERFORM pg_notify('machine_update',CAST(node.system_id AS text)); |
2296 | + ELSIF node.node_type IN (2, 3, 4) THEN |
2297 | + PERFORM pg_notify('controller_update',CAST( |
2298 | + node.system_id AS text)); |
2299 | + ELSIF node.parent_id IS NOT NULL THEN |
2300 | + SELECT system_id INTO pnode |
2301 | + FROM maasserver_node |
2302 | + WHERE id = node.parent_id; |
2303 | + PERFORM pg_notify('machine_update',CAST(pnode.system_id AS text)); |
2304 | + ELSE |
2305 | + PERFORM pg_notify('device_update',CAST(node.system_id AS text)); |
2306 | + END IF; |
2307 | + RETURN NEW; |
2308 | +END; |
2309 | +$$; |
2310 | + |
2311 | + |
2312 | +ALTER FUNCTION public.nd_interface_unlink_notify() OWNER TO gavin; |
2313 | + |
2314 | +-- |
2315 | +-- Name: nd_interface_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2316 | +-- |
2317 | + |
2318 | +CREATE FUNCTION nd_interface_update_notify() RETURNS trigger |
2319 | + LANGUAGE plpgsql |
2320 | + AS $$ |
2321 | +DECLARE |
2322 | + node RECORD; |
2323 | + pnode RECORD; |
2324 | +BEGIN |
2325 | + IF OLD.node_id != NEW.node_id THEN |
2326 | + SELECT system_id, node_type, parent_id INTO node |
2327 | + FROM maasserver_node |
2328 | + WHERE id = OLD.node_id; |
2329 | + |
2330 | + IF node.node_type = 0 THEN |
2331 | + PERFORM pg_notify('machine_update',CAST(node.system_id AS text)); |
2332 | + ELSIF node.node_type IN (2, 3, 4) THEN |
2333 | + PERFORM pg_notify('controller_update',CAST(node.system_id AS text)); |
2334 | + ELSIF node.parent_id IS NOT NULL THEN |
2335 | + SELECT system_id INTO pnode |
2336 | + FROM maasserver_node |
2337 | + WHERE id = node.parent_id; |
2338 | + PERFORM pg_notify('machine_update',CAST(pnode.system_id AS text)); |
2339 | + ELSE |
2340 | + PERFORM pg_notify('device_update',CAST(node.system_id AS text)); |
2341 | + END IF; |
2342 | + END IF; |
2343 | + |
2344 | + SELECT system_id, node_type, parent_id INTO node |
2345 | + FROM maasserver_node |
2346 | + WHERE id = NEW.node_id; |
2347 | + |
2348 | + IF node.node_type = 0 THEN |
2349 | + PERFORM pg_notify('machine_update',CAST(node.system_id AS text)); |
2350 | + ELSIF node.node_type IN (2, 3, 4) THEN |
2351 | + PERFORM pg_notify('controller_update',CAST(node.system_id AS text)); |
2352 | + ELSIF node.parent_id IS NOT NULL THEN |
2353 | + SELECT system_id INTO pnode |
2354 | + FROM maasserver_node |
2355 | + WHERE id = node.parent_id; |
2356 | + PERFORM pg_notify('machine_update',CAST(pnode.system_id AS text)); |
2357 | + ELSE |
2358 | + PERFORM pg_notify('device_update',CAST(node.system_id AS text)); |
2359 | + END IF; |
2360 | + RETURN NEW; |
2361 | +END; |
2362 | +$$; |
2363 | + |
2364 | + |
2365 | +ALTER FUNCTION public.nd_interface_update_notify() OWNER TO gavin; |
2366 | + |
2367 | +-- |
2368 | +-- Name: nd_noderesult_link_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2369 | +-- |
2370 | + |
2371 | +CREATE FUNCTION nd_noderesult_link_notify() RETURNS trigger |
2372 | + LANGUAGE plpgsql |
2373 | + AS $$ |
2374 | +DECLARE |
2375 | + node RECORD; |
2376 | + pnode RECORD; |
2377 | +BEGIN |
2378 | + SELECT system_id, node_type, parent_id INTO node |
2379 | + FROM maasserver_node |
2380 | + WHERE id = NEW.node_id; |
2381 | + |
2382 | + IF node.node_type = 0 THEN |
2383 | + PERFORM pg_notify('machine_update',CAST(node.system_id AS text)); |
2384 | + ELSIF node.node_type IN (2, 3, 4) THEN |
2385 | + PERFORM pg_notify('controller_update',CAST( |
2386 | + node.system_id AS text)); |
2387 | + ELSIF node.parent_id IS NOT NULL THEN |
2388 | + SELECT system_id INTO pnode |
2389 | + FROM maasserver_node |
2390 | + WHERE id = node.parent_id; |
2391 | + PERFORM pg_notify('machine_update',CAST(pnode.system_id AS text)); |
2392 | + ELSE |
2393 | + PERFORM pg_notify('device_update',CAST(node.system_id AS text)); |
2394 | + END IF; |
2395 | + RETURN NEW; |
2396 | +END; |
2397 | +$$; |
2398 | + |
2399 | + |
2400 | +ALTER FUNCTION public.nd_noderesult_link_notify() OWNER TO gavin; |
2401 | + |
2402 | +-- |
2403 | +-- Name: nd_noderesult_unlink_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2404 | +-- |
2405 | + |
2406 | +CREATE FUNCTION nd_noderesult_unlink_notify() RETURNS trigger |
2407 | + LANGUAGE plpgsql |
2408 | + AS $$ |
2409 | +DECLARE |
2410 | + node RECORD; |
2411 | + pnode RECORD; |
2412 | +BEGIN |
2413 | + SELECT system_id, node_type, parent_id INTO node |
2414 | + FROM maasserver_node |
2415 | + WHERE id = OLD.node_id; |
2416 | + |
2417 | + IF node.node_type = 0 THEN |
2418 | + PERFORM pg_notify('machine_update',CAST(node.system_id AS text)); |
2419 | + ELSIF node.node_type IN (2, 3, 4) THEN |
2420 | + PERFORM pg_notify('controller_update',CAST( |
2421 | + node.system_id AS text)); |
2422 | + ELSIF node.parent_id IS NOT NULL THEN |
2423 | + SELECT system_id INTO pnode |
2424 | + FROM maasserver_node |
2425 | + WHERE id = node.parent_id; |
2426 | + PERFORM pg_notify('machine_update',CAST(pnode.system_id AS text)); |
2427 | + ELSE |
2428 | + PERFORM pg_notify('device_update',CAST(node.system_id AS text)); |
2429 | + END IF; |
2430 | + RETURN NEW; |
2431 | +END; |
2432 | +$$; |
2433 | + |
2434 | + |
2435 | +ALTER FUNCTION public.nd_noderesult_unlink_notify() OWNER TO gavin; |
2436 | + |
2437 | +-- |
2438 | +-- Name: nd_partition_link_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2439 | +-- |
2440 | + |
2441 | +CREATE FUNCTION nd_partition_link_notify() RETURNS trigger |
2442 | + LANGUAGE plpgsql |
2443 | + AS $$ |
2444 | +DECLARE |
2445 | + node RECORD; |
2446 | +BEGIN |
2447 | + SELECT system_id, node_type INTO node |
2448 | + FROM maasserver_node, |
2449 | + maasserver_blockdevice, |
2450 | + maasserver_partitiontable |
2451 | + WHERE maasserver_node.id = maasserver_blockdevice.node_id |
2452 | + AND maasserver_blockdevice.id = maasserver_partitiontable.block_device_id |
2453 | + AND maasserver_partitiontable.id = NEW.partition_table_id; |
2454 | + |
2455 | + IF node.node_type = 0 THEN |
2456 | + PERFORM pg_notify('machine_update',CAST(node.system_id AS text)); |
2457 | + END IF; |
2458 | + RETURN NEW; |
2459 | +END; |
2460 | +$$; |
2461 | + |
2462 | + |
2463 | +ALTER FUNCTION public.nd_partition_link_notify() OWNER TO gavin; |
2464 | + |
2465 | +-- |
2466 | +-- Name: nd_partition_unlink_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2467 | +-- |
2468 | + |
2469 | +CREATE FUNCTION nd_partition_unlink_notify() RETURNS trigger |
2470 | + LANGUAGE plpgsql |
2471 | + AS $$ |
2472 | +DECLARE |
2473 | + node RECORD; |
2474 | +BEGIN |
2475 | + SELECT system_id, node_type INTO node |
2476 | + FROM maasserver_node, |
2477 | + maasserver_blockdevice, |
2478 | + maasserver_partitiontable |
2479 | + WHERE maasserver_node.id = maasserver_blockdevice.node_id |
2480 | + AND maasserver_blockdevice.id = maasserver_partitiontable.block_device_id |
2481 | + AND maasserver_partitiontable.id = OLD.partition_table_id; |
2482 | + |
2483 | + IF node.node_type = 0 THEN |
2484 | + PERFORM pg_notify('machine_update',CAST(node.system_id AS text)); |
2485 | + END IF; |
2486 | + RETURN NEW; |
2487 | +END; |
2488 | +$$; |
2489 | + |
2490 | + |
2491 | +ALTER FUNCTION public.nd_partition_unlink_notify() OWNER TO gavin; |
2492 | + |
2493 | +-- |
2494 | +-- Name: nd_partition_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2495 | +-- |
2496 | + |
2497 | +CREATE FUNCTION nd_partition_update_notify() RETURNS trigger |
2498 | + LANGUAGE plpgsql |
2499 | + AS $$ |
2500 | +DECLARE |
2501 | + node RECORD; |
2502 | +BEGIN |
2503 | + SELECT system_id, node_type INTO node |
2504 | + FROM maasserver_node, |
2505 | + maasserver_blockdevice, |
2506 | + maasserver_partitiontable |
2507 | + WHERE maasserver_node.id = maasserver_blockdevice.node_id |
2508 | + AND maasserver_blockdevice.id = maasserver_partitiontable.block_device_id |
2509 | + AND maasserver_partitiontable.id = NEW.partition_table_id; |
2510 | + |
2511 | + IF node.node_type = 0 THEN |
2512 | + PERFORM pg_notify('machine_update',CAST(node.system_id AS text)); |
2513 | + END IF; |
2514 | + RETURN NEW; |
2515 | +END; |
2516 | +$$; |
2517 | + |
2518 | + |
2519 | +ALTER FUNCTION public.nd_partition_update_notify() OWNER TO gavin; |
2520 | + |
2521 | +-- |
2522 | +-- Name: nd_partitiontable_link_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2523 | +-- |
2524 | + |
2525 | +CREATE FUNCTION nd_partitiontable_link_notify() RETURNS trigger |
2526 | + LANGUAGE plpgsql |
2527 | + AS $$ |
2528 | +DECLARE |
2529 | + node RECORD; |
2530 | +BEGIN |
2531 | + SELECT system_id, node_type INTO node |
2532 | + FROM maasserver_node, maasserver_blockdevice |
2533 | + WHERE maasserver_node.id = maasserver_blockdevice.node_id |
2534 | + AND maasserver_blockdevice.id = NEW.block_device_id; |
2535 | + |
2536 | + IF node.node_type = 0 THEN |
2537 | + PERFORM pg_notify('machine_update',CAST(node.system_id AS text)); |
2538 | + END IF; |
2539 | + RETURN NEW; |
2540 | +END; |
2541 | +$$; |
2542 | + |
2543 | + |
2544 | +ALTER FUNCTION public.nd_partitiontable_link_notify() OWNER TO gavin; |
2545 | + |
2546 | +-- |
2547 | +-- Name: nd_partitiontable_unlink_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2548 | +-- |
2549 | + |
2550 | +CREATE FUNCTION nd_partitiontable_unlink_notify() RETURNS trigger |
2551 | + LANGUAGE plpgsql |
2552 | + AS $$ |
2553 | +DECLARE |
2554 | + node RECORD; |
2555 | +BEGIN |
2556 | + SELECT system_id, node_type INTO node |
2557 | + FROM maasserver_node, maasserver_blockdevice |
2558 | + WHERE maasserver_node.id = maasserver_blockdevice.node_id |
2559 | + AND maasserver_blockdevice.id = OLD.block_device_id; |
2560 | + |
2561 | + IF node.node_type = 0 THEN |
2562 | + PERFORM pg_notify('machine_update',CAST(node.system_id AS text)); |
2563 | + END IF; |
2564 | + RETURN NEW; |
2565 | +END; |
2566 | +$$; |
2567 | + |
2568 | + |
2569 | +ALTER FUNCTION public.nd_partitiontable_unlink_notify() OWNER TO gavin; |
2570 | + |
2571 | +-- |
2572 | +-- Name: nd_partitiontable_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2573 | +-- |
2574 | + |
2575 | +CREATE FUNCTION nd_partitiontable_update_notify() RETURNS trigger |
2576 | + LANGUAGE plpgsql |
2577 | + AS $$ |
2578 | +DECLARE |
2579 | + node RECORD; |
2580 | +BEGIN |
2581 | + SELECT system_id, node_type INTO node |
2582 | + FROM maasserver_node, maasserver_blockdevice |
2583 | + WHERE maasserver_node.id = maasserver_blockdevice.node_id |
2584 | + AND maasserver_blockdevice.id = NEW.block_device_id; |
2585 | + |
2586 | + IF node.node_type = 0 THEN |
2587 | + PERFORM pg_notify('machine_update',CAST(node.system_id AS text)); |
2588 | + END IF; |
2589 | + RETURN NEW; |
2590 | +END; |
2591 | +$$; |
2592 | + |
2593 | + |
2594 | +ALTER FUNCTION public.nd_partitiontable_update_notify() OWNER TO gavin; |
2595 | + |
2596 | +-- |
2597 | +-- Name: nd_physblockdevice_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2598 | +-- |
2599 | + |
2600 | +CREATE FUNCTION nd_physblockdevice_update_notify() RETURNS trigger |
2601 | + LANGUAGE plpgsql |
2602 | + AS $$ |
2603 | +DECLARE |
2604 | + node RECORD; |
2605 | +BEGIN |
2606 | + SELECT system_id, node_type INTO node |
2607 | + FROM maasserver_node, maasserver_blockdevice |
2608 | + WHERE maasserver_node.id = maasserver_blockdevice.node_id |
2609 | + AND maasserver_blockdevice.id = NEW.blockdevice_ptr_id; |
2610 | + |
2611 | + IF node.node_type = 0 THEN |
2612 | + PERFORM pg_notify('machine_update',CAST(node.system_id AS text)); |
2613 | + END IF; |
2614 | + RETURN NEW; |
2615 | +END; |
2616 | +$$; |
2617 | + |
2618 | + |
2619 | +ALTER FUNCTION public.nd_physblockdevice_update_notify() OWNER TO gavin; |
2620 | + |
2621 | +-- |
2622 | +-- Name: nd_sipaddress_dns_link_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2623 | +-- |
2624 | + |
2625 | +CREATE FUNCTION nd_sipaddress_dns_link_notify() RETURNS trigger |
2626 | + LANGUAGE plpgsql |
2627 | + AS $$ |
2628 | +DECLARE |
2629 | + domain RECORD; |
2630 | +BEGIN |
2631 | + SELECT maasserver_domain.id INTO domain |
2632 | + FROM maasserver_node, maasserver_interface, maasserver_domain |
2633 | + WHERE maasserver_node.id = maasserver_interface.node_id |
2634 | + AND maasserver_domain.id = maasserver_node.domain_id |
2635 | + AND maasserver_interface.id = NEW.interface_id; |
2636 | + |
2637 | + IF domain.id IS NOT NULL THEN |
2638 | + PERFORM pg_notify('domain_update',CAST(domain.id AS text)); |
2639 | + END IF; |
2640 | + RETURN NEW; |
2641 | +END; |
2642 | +$$; |
2643 | + |
2644 | + |
2645 | +ALTER FUNCTION public.nd_sipaddress_dns_link_notify() OWNER TO gavin; |
2646 | + |
2647 | +-- |
2648 | +-- Name: nd_sipaddress_dns_unlink_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2649 | +-- |
2650 | + |
2651 | +CREATE FUNCTION nd_sipaddress_dns_unlink_notify() RETURNS trigger |
2652 | + LANGUAGE plpgsql |
2653 | + AS $$ |
2654 | +DECLARE |
2655 | + domain RECORD; |
2656 | +BEGIN |
2657 | + SELECT maasserver_domain.id INTO domain |
2658 | + FROM maasserver_node, maasserver_interface, maasserver_domain |
2659 | + WHERE maasserver_node.id = maasserver_interface.node_id |
2660 | + AND maasserver_domain.id = maasserver_node.domain_id |
2661 | + AND maasserver_interface.id = OLD.interface_id; |
2662 | + |
2663 | + IF domain.id IS NOT NULL THEN |
2664 | + PERFORM pg_notify('domain_update',CAST(domain.id AS text)); |
2665 | + END IF; |
2666 | + RETURN NEW; |
2667 | +END; |
2668 | +$$; |
2669 | + |
2670 | + |
2671 | +ALTER FUNCTION public.nd_sipaddress_dns_unlink_notify() OWNER TO gavin; |
2672 | + |
2673 | +-- |
2674 | +-- Name: nd_sipaddress_link_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2675 | +-- |
2676 | + |
2677 | +CREATE FUNCTION nd_sipaddress_link_notify() RETURNS trigger |
2678 | + LANGUAGE plpgsql |
2679 | + AS $$ |
2680 | +DECLARE |
2681 | + node RECORD; |
2682 | + pnode RECORD; |
2683 | +BEGIN |
2684 | + SELECT system_id, node_type, parent_id INTO node |
2685 | + FROM maasserver_node, maasserver_interface |
2686 | + WHERE maasserver_node.id = maasserver_interface.node_id |
2687 | + AND maasserver_interface.id = NEW.interface_id; |
2688 | + |
2689 | + IF node.node_type = 0 THEN |
2690 | + PERFORM pg_notify('machine_update',CAST(node.system_id AS text)); |
2691 | + ELSIF node.node_type IN (2, 3, 4) THEN |
2692 | + PERFORM pg_notify('controller_update',CAST(node.system_id AS text)); |
2693 | + ELSIF node.parent_id IS NOT NULL THEN |
2694 | + SELECT system_id INTO pnode |
2695 | + FROM maasserver_node |
2696 | + WHERE id = node.parent_id; |
2697 | + PERFORM pg_notify('machine_update',CAST(pnode.system_id AS text)); |
2698 | + ELSE |
2699 | + PERFORM pg_notify('device_update',CAST(node.system_id AS text)); |
2700 | + END IF; |
2701 | + RETURN NEW; |
2702 | +END; |
2703 | +$$; |
2704 | + |
2705 | + |
2706 | +ALTER FUNCTION public.nd_sipaddress_link_notify() OWNER TO gavin; |
2707 | + |
2708 | +-- |
2709 | +-- Name: nd_sipaddress_unlink_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2710 | +-- |
2711 | + |
2712 | +CREATE FUNCTION nd_sipaddress_unlink_notify() RETURNS trigger |
2713 | + LANGUAGE plpgsql |
2714 | + AS $$ |
2715 | +DECLARE |
2716 | + node RECORD; |
2717 | + pnode RECORD; |
2718 | +BEGIN |
2719 | + SELECT system_id, node_type, parent_id INTO node |
2720 | + FROM maasserver_node, maasserver_interface |
2721 | + WHERE maasserver_node.id = maasserver_interface.node_id |
2722 | + AND maasserver_interface.id = OLD.interface_id; |
2723 | + |
2724 | + IF node.node_type = 0 THEN |
2725 | + PERFORM pg_notify('machine_update',CAST(node.system_id AS text)); |
2726 | + ELSIF node.node_type IN (2, 3, 4) THEN |
2727 | + PERFORM pg_notify('controller_update',CAST(node.system_id AS text)); |
2728 | + ELSIF node.parent_id IS NOT NULL THEN |
2729 | + SELECT system_id INTO pnode |
2730 | + FROM maasserver_node |
2731 | + WHERE id = node.parent_id; |
2732 | + PERFORM pg_notify('machine_update',CAST(pnode.system_id AS text)); |
2733 | + ELSE |
2734 | + PERFORM pg_notify('device_update',CAST(node.system_id AS text)); |
2735 | + END IF; |
2736 | + RETURN NEW; |
2737 | +END; |
2738 | +$$; |
2739 | + |
2740 | + |
2741 | +ALTER FUNCTION public.nd_sipaddress_unlink_notify() OWNER TO gavin; |
2742 | + |
2743 | +-- |
2744 | +-- Name: nd_virtblockdevice_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2745 | +-- |
2746 | + |
2747 | +CREATE FUNCTION nd_virtblockdevice_update_notify() RETURNS trigger |
2748 | + LANGUAGE plpgsql |
2749 | + AS $$ |
2750 | +DECLARE |
2751 | + node RECORD; |
2752 | +BEGIN |
2753 | + SELECT system_id, node_type INTO node |
2754 | + FROM maasserver_node, maasserver_blockdevice |
2755 | + WHERE maasserver_node.id = maasserver_blockdevice.node_id |
2756 | + AND maasserver_blockdevice.id = NEW.blockdevice_ptr_id; |
2757 | + |
2758 | + IF node.node_type = 0 THEN |
2759 | + PERFORM pg_notify('machine_update',CAST(node.system_id AS text)); |
2760 | + END IF; |
2761 | + RETURN NEW; |
2762 | +END; |
2763 | +$$; |
2764 | + |
2765 | + |
2766 | +ALTER FUNCTION public.nd_virtblockdevice_update_notify() OWNER TO gavin; |
2767 | + |
2768 | +-- |
2769 | +-- Name: neighbour_create_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2770 | +-- |
2771 | + |
2772 | +CREATE FUNCTION neighbour_create_notify() RETURNS trigger |
2773 | + LANGUAGE plpgsql |
2774 | + AS $$ |
2775 | +DECLARE |
2776 | +BEGIN |
2777 | + PERFORM pg_notify('neighbour_create',CAST(NEW.ip AS text)); |
2778 | + RETURN NEW; |
2779 | +END; |
2780 | +$$; |
2781 | + |
2782 | + |
2783 | +ALTER FUNCTION public.neighbour_create_notify() OWNER TO gavin; |
2784 | + |
2785 | +-- |
2786 | +-- Name: neighbour_delete_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2787 | +-- |
2788 | + |
2789 | +CREATE FUNCTION neighbour_delete_notify() RETURNS trigger |
2790 | + LANGUAGE plpgsql |
2791 | + AS $$ |
2792 | +DECLARE |
2793 | +BEGIN |
2794 | + PERFORM pg_notify('neighbour_delete',CAST(OLD.ip AS text)); |
2795 | + RETURN NEW; |
2796 | +END; |
2797 | +$$; |
2798 | + |
2799 | + |
2800 | +ALTER FUNCTION public.neighbour_delete_notify() OWNER TO gavin; |
2801 | + |
2802 | +-- |
2803 | +-- Name: neighbour_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2804 | +-- |
2805 | + |
2806 | +CREATE FUNCTION neighbour_update_notify() RETURNS trigger |
2807 | + LANGUAGE plpgsql |
2808 | + AS $$ |
2809 | +DECLARE |
2810 | +BEGIN |
2811 | + PERFORM pg_notify('neighbour_update',CAST(NEW.ip AS text)); |
2812 | + RETURN NEW; |
2813 | +END; |
2814 | +$$; |
2815 | + |
2816 | + |
2817 | +ALTER FUNCTION public.neighbour_update_notify() OWNER TO gavin; |
2818 | + |
2819 | +-- |
2820 | +-- Name: node_type_change_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2821 | +-- |
2822 | + |
2823 | +CREATE FUNCTION node_type_change_notify() RETURNS trigger |
2824 | + LANGUAGE plpgsql |
2825 | + AS $$ |
2826 | +BEGIN |
2827 | + IF (OLD.node_type != NEW.node_type AND NOT ( |
2828 | + ( |
2829 | + OLD.node_type = 2 OR |
2830 | + OLD.node_type = 3 OR |
2831 | + OLD.node_type = 4 |
2832 | + ) AND ( |
2833 | + NEW.node_type = 2 OR |
2834 | + NEW.node_type = 3 OR |
2835 | + NEW.node_type = 4 |
2836 | + ))) THEN |
2837 | + CASE OLD.node_type |
2838 | + WHEN 0 THEN |
2839 | + PERFORM pg_notify('machine_delete',CAST( |
2840 | + OLD.system_id AS TEXT)); |
2841 | + WHEN 1 THEN |
2842 | + PERFORM pg_notify('device_delete',CAST( |
2843 | + OLD.system_id AS TEXT)); |
2844 | + WHEN 2 THEN |
2845 | + PERFORM pg_notify('controller_delete',CAST( |
2846 | + OLD.system_id AS TEXT)); |
2847 | + WHEN 3 THEN |
2848 | + PERFORM pg_notify('controller_delete',CAST( |
2849 | + OLD.system_id AS TEXT)); |
2850 | + WHEN 4 THEN |
2851 | + PERFORM pg_notify('controller_delete',CAST( |
2852 | + OLD.system_id AS TEXT)); |
2853 | + END CASE; |
2854 | + CASE NEW.node_type |
2855 | + WHEN 0 THEN |
2856 | + PERFORM pg_notify('machine_create',CAST( |
2857 | + NEW.system_id AS TEXT)); |
2858 | + WHEN 1 THEN |
2859 | + PERFORM pg_notify('device_create',CAST( |
2860 | + NEW.system_id AS TEXT)); |
2861 | + WHEN 2 THEN |
2862 | + PERFORM pg_notify('controller_create',CAST( |
2863 | + NEW.system_id AS TEXT)); |
2864 | + WHEN 3 THEN |
2865 | + PERFORM pg_notify('controller_create',CAST( |
2866 | + NEW.system_id AS TEXT)); |
2867 | + WHEN 4 THEN |
2868 | + PERFORM pg_notify('controller_create',CAST( |
2869 | + NEW.system_id AS TEXT)); |
2870 | + END CASE; |
2871 | + END IF; |
2872 | + RETURN NEW; |
2873 | +END; |
2874 | +$$; |
2875 | + |
2876 | + |
2877 | +ALTER FUNCTION public.node_type_change_notify() OWNER TO gavin; |
2878 | + |
2879 | +-- |
2880 | +-- Name: packagerepository_create_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2881 | +-- |
2882 | + |
2883 | +CREATE FUNCTION packagerepository_create_notify() RETURNS trigger |
2884 | + LANGUAGE plpgsql |
2885 | + AS $$ |
2886 | +DECLARE |
2887 | +BEGIN |
2888 | + PERFORM pg_notify('packagerepository_create',CAST(NEW.id AS text)); |
2889 | + RETURN NEW; |
2890 | +END; |
2891 | +$$; |
2892 | + |
2893 | + |
2894 | +ALTER FUNCTION public.packagerepository_create_notify() OWNER TO gavin; |
2895 | + |
2896 | +-- |
2897 | +-- Name: packagerepository_delete_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2898 | +-- |
2899 | + |
2900 | +CREATE FUNCTION packagerepository_delete_notify() RETURNS trigger |
2901 | + LANGUAGE plpgsql |
2902 | + AS $$ |
2903 | +DECLARE |
2904 | +BEGIN |
2905 | + PERFORM pg_notify('packagerepository_delete',CAST(OLD.id AS text)); |
2906 | + RETURN NEW; |
2907 | +END; |
2908 | +$$; |
2909 | + |
2910 | + |
2911 | +ALTER FUNCTION public.packagerepository_delete_notify() OWNER TO gavin; |
2912 | + |
2913 | +-- |
2914 | +-- Name: packagerepository_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2915 | +-- |
2916 | + |
2917 | +CREATE FUNCTION packagerepository_update_notify() RETURNS trigger |
2918 | + LANGUAGE plpgsql |
2919 | + AS $$ |
2920 | +DECLARE |
2921 | +BEGIN |
2922 | + PERFORM pg_notify('packagerepository_update',CAST(NEW.id AS text)); |
2923 | + RETURN NEW; |
2924 | +END; |
2925 | +$$; |
2926 | + |
2927 | + |
2928 | +ALTER FUNCTION public.packagerepository_update_notify() OWNER TO gavin; |
2929 | + |
2930 | +-- |
2931 | +-- Name: rack_controller_create_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2932 | +-- |
2933 | + |
2934 | +CREATE FUNCTION rack_controller_create_notify() RETURNS trigger |
2935 | + LANGUAGE plpgsql |
2936 | + AS $$ |
2937 | +DECLARE |
2938 | +BEGIN |
2939 | + PERFORM pg_notify('controller_create',CAST(NEW.system_id AS text)); |
2940 | + RETURN NEW; |
2941 | +END; |
2942 | +$$; |
2943 | + |
2944 | + |
2945 | +ALTER FUNCTION public.rack_controller_create_notify() OWNER TO gavin; |
2946 | + |
2947 | +-- |
2948 | +-- Name: rack_controller_delete_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2949 | +-- |
2950 | + |
2951 | +CREATE FUNCTION rack_controller_delete_notify() RETURNS trigger |
2952 | + LANGUAGE plpgsql |
2953 | + AS $$ |
2954 | +DECLARE |
2955 | +BEGIN |
2956 | + PERFORM pg_notify('controller_delete',CAST(OLD.system_id AS text)); |
2957 | + RETURN NEW; |
2958 | +END; |
2959 | +$$; |
2960 | + |
2961 | + |
2962 | +ALTER FUNCTION public.rack_controller_delete_notify() OWNER TO gavin; |
2963 | + |
2964 | +-- |
2965 | +-- Name: rack_controller_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2966 | +-- |
2967 | + |
2968 | +CREATE FUNCTION rack_controller_update_notify() RETURNS trigger |
2969 | + LANGUAGE plpgsql |
2970 | + AS $$ |
2971 | +DECLARE |
2972 | +BEGIN |
2973 | + PERFORM pg_notify('controller_update',CAST(NEW.system_id AS text)); |
2974 | + RETURN NEW; |
2975 | +END; |
2976 | +$$; |
2977 | + |
2978 | + |
2979 | +ALTER FUNCTION public.rack_controller_update_notify() OWNER TO gavin; |
2980 | + |
2981 | +-- |
2982 | +-- Name: region_and_rack_controller_create_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
2983 | +-- |
2984 | + |
2985 | +CREATE FUNCTION region_and_rack_controller_create_notify() RETURNS trigger |
2986 | + LANGUAGE plpgsql |
2987 | + AS $$ |
2988 | +DECLARE |
2989 | +BEGIN |
2990 | + PERFORM pg_notify('controller_create',CAST(NEW.system_id AS text)); |
2991 | + RETURN NEW; |
2992 | +END; |
2993 | +$$; |
2994 | + |
2995 | + |
2996 | +ALTER FUNCTION public.region_and_rack_controller_create_notify() OWNER TO gavin; |
2997 | + |
2998 | +-- |
2999 | +-- Name: region_and_rack_controller_delete_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
3000 | +-- |
3001 | + |
3002 | +CREATE FUNCTION region_and_rack_controller_delete_notify() RETURNS trigger |
3003 | + LANGUAGE plpgsql |
3004 | + AS $$ |
3005 | +DECLARE |
3006 | +BEGIN |
3007 | + PERFORM pg_notify('controller_delete',CAST(OLD.system_id AS text)); |
3008 | + RETURN NEW; |
3009 | +END; |
3010 | +$$; |
3011 | + |
3012 | + |
3013 | +ALTER FUNCTION public.region_and_rack_controller_delete_notify() OWNER TO gavin; |
3014 | + |
3015 | +-- |
3016 | +-- Name: region_and_rack_controller_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
3017 | +-- |
3018 | + |
3019 | +CREATE FUNCTION region_and_rack_controller_update_notify() RETURNS trigger |
3020 | + LANGUAGE plpgsql |
3021 | + AS $$ |
3022 | +DECLARE |
3023 | +BEGIN |
3024 | + PERFORM pg_notify('controller_update',CAST(NEW.system_id AS text)); |
3025 | + RETURN NEW; |
3026 | +END; |
3027 | +$$; |
3028 | + |
3029 | + |
3030 | +ALTER FUNCTION public.region_and_rack_controller_update_notify() OWNER TO gavin; |
3031 | + |
3032 | +-- |
3033 | +-- Name: region_controller_create_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
3034 | +-- |
3035 | + |
3036 | +CREATE FUNCTION region_controller_create_notify() RETURNS trigger |
3037 | + LANGUAGE plpgsql |
3038 | + AS $$ |
3039 | +DECLARE |
3040 | +BEGIN |
3041 | + PERFORM pg_notify('controller_create',CAST(NEW.system_id AS text)); |
3042 | + RETURN NEW; |
3043 | +END; |
3044 | +$$; |
3045 | + |
3046 | + |
3047 | +ALTER FUNCTION public.region_controller_create_notify() OWNER TO gavin; |
3048 | + |
3049 | +-- |
3050 | +-- Name: region_controller_delete_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
3051 | +-- |
3052 | + |
3053 | +CREATE FUNCTION region_controller_delete_notify() RETURNS trigger |
3054 | + LANGUAGE plpgsql |
3055 | + AS $$ |
3056 | +DECLARE |
3057 | +BEGIN |
3058 | + PERFORM pg_notify('controller_delete',CAST(OLD.system_id AS text)); |
3059 | + RETURN NEW; |
3060 | +END; |
3061 | +$$; |
3062 | + |
3063 | + |
3064 | +ALTER FUNCTION public.region_controller_delete_notify() OWNER TO gavin; |
3065 | + |
3066 | +-- |
3067 | +-- Name: region_controller_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
3068 | +-- |
3069 | + |
3070 | +CREATE FUNCTION region_controller_update_notify() RETURNS trigger |
3071 | + LANGUAGE plpgsql |
3072 | + AS $$ |
3073 | +DECLARE |
3074 | +BEGIN |
3075 | + PERFORM pg_notify('controller_update',CAST(NEW.system_id AS text)); |
3076 | + RETURN NEW; |
3077 | +END; |
3078 | +$$; |
3079 | + |
3080 | + |
3081 | +ALTER FUNCTION public.region_controller_update_notify() OWNER TO gavin; |
3082 | + |
3083 | +-- |
3084 | +-- Name: rrset_sipaddress_link_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
3085 | +-- |
3086 | + |
3087 | +CREATE FUNCTION rrset_sipaddress_link_notify() RETURNS trigger |
3088 | + LANGUAGE plpgsql |
3089 | + AS $$ |
3090 | +DECLARE |
3091 | + domain RECORD; |
3092 | +BEGIN |
3093 | + SELECT maasserver_domain.id INTO domain |
3094 | + FROM maasserver_dnsresource, maasserver_domain |
3095 | + WHERE maasserver_domain.id = maasserver_dnsresource.domain_id |
3096 | + AND maasserver_dnsresource.id = NEW.dnsresource_id; |
3097 | + |
3098 | + IF domain.id IS NOT NULL THEN |
3099 | + PERFORM pg_notify('domain_update',CAST(domain.id AS text)); |
3100 | + END IF; |
3101 | + RETURN NEW; |
3102 | +END; |
3103 | +$$; |
3104 | + |
3105 | + |
3106 | +ALTER FUNCTION public.rrset_sipaddress_link_notify() OWNER TO gavin; |
3107 | + |
3108 | +-- |
3109 | +-- Name: rrset_sipaddress_unlink_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
3110 | +-- |
3111 | + |
3112 | +CREATE FUNCTION rrset_sipaddress_unlink_notify() RETURNS trigger |
3113 | + LANGUAGE plpgsql |
3114 | + AS $$ |
3115 | +DECLARE |
3116 | + domain RECORD; |
3117 | +BEGIN |
3118 | + SELECT maasserver_domain.id INTO domain |
3119 | + FROM maasserver_dnsresource, maasserver_domain |
3120 | + WHERE maasserver_domain.id = maasserver_dnsresource.domain_id |
3121 | + AND maasserver_dnsresource.id = OLD.dnsresource_id; |
3122 | + |
3123 | + IF domain.id IS NOT NULL THEN |
3124 | + PERFORM pg_notify('domain_update',CAST(domain.id AS text)); |
3125 | + END IF; |
3126 | + RETURN NEW; |
3127 | +END; |
3128 | +$$; |
3129 | + |
3130 | + |
3131 | +ALTER FUNCTION public.rrset_sipaddress_unlink_notify() OWNER TO gavin; |
3132 | + |
3133 | +-- |
3134 | +-- Name: service_create_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
3135 | +-- |
3136 | + |
3137 | +CREATE FUNCTION service_create_notify() RETURNS trigger |
3138 | + LANGUAGE plpgsql |
3139 | + AS $$ |
3140 | +DECLARE |
3141 | +BEGIN |
3142 | + PERFORM pg_notify('service_create',CAST(NEW.id AS text)); |
3143 | + RETURN NEW; |
3144 | +END; |
3145 | +$$; |
3146 | + |
3147 | + |
3148 | +ALTER FUNCTION public.service_create_notify() OWNER TO gavin; |
3149 | + |
3150 | +-- |
3151 | +-- Name: service_delete_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
3152 | +-- |
3153 | + |
3154 | +CREATE FUNCTION service_delete_notify() RETURNS trigger |
3155 | + LANGUAGE plpgsql |
3156 | + AS $$ |
3157 | +DECLARE |
3158 | +BEGIN |
3159 | + PERFORM pg_notify('service_delete',CAST(OLD.id AS text)); |
3160 | + RETURN NEW; |
3161 | +END; |
3162 | +$$; |
3163 | + |
3164 | + |
3165 | +ALTER FUNCTION public.service_delete_notify() OWNER TO gavin; |
3166 | + |
3167 | +-- |
3168 | +-- Name: service_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
3169 | +-- |
3170 | + |
3171 | +CREATE FUNCTION service_update_notify() RETURNS trigger |
3172 | + LANGUAGE plpgsql |
3173 | + AS $$ |
3174 | +DECLARE |
3175 | +BEGIN |
3176 | + PERFORM pg_notify('service_update',CAST(NEW.id AS text)); |
3177 | + RETURN NEW; |
3178 | +END; |
3179 | +$$; |
3180 | + |
3181 | + |
3182 | +ALTER FUNCTION public.service_update_notify() OWNER TO gavin; |
3183 | + |
3184 | +-- |
3185 | +-- Name: space_create_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
3186 | +-- |
3187 | + |
3188 | +CREATE FUNCTION space_create_notify() RETURNS trigger |
3189 | + LANGUAGE plpgsql |
3190 | + AS $$ |
3191 | +DECLARE |
3192 | +BEGIN |
3193 | + PERFORM pg_notify('space_create',CAST(NEW.id AS text)); |
3194 | + RETURN NEW; |
3195 | +END; |
3196 | +$$; |
3197 | + |
3198 | + |
3199 | +ALTER FUNCTION public.space_create_notify() OWNER TO gavin; |
3200 | + |
3201 | +-- |
3202 | +-- Name: space_delete_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
3203 | +-- |
3204 | + |
3205 | +CREATE FUNCTION space_delete_notify() RETURNS trigger |
3206 | + LANGUAGE plpgsql |
3207 | + AS $$ |
3208 | +DECLARE |
3209 | +BEGIN |
3210 | + PERFORM pg_notify('space_delete',CAST(OLD.id AS text)); |
3211 | + RETURN NEW; |
3212 | +END; |
3213 | +$$; |
3214 | + |
3215 | + |
3216 | +ALTER FUNCTION public.space_delete_notify() OWNER TO gavin; |
3217 | + |
3218 | +-- |
3219 | +-- Name: space_machine_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
3220 | +-- |
3221 | + |
3222 | +CREATE FUNCTION space_machine_update_notify() RETURNS trigger |
3223 | + LANGUAGE plpgsql |
3224 | + AS $$ |
3225 | +DECLARE |
3226 | + node RECORD; |
3227 | + pnode RECORD; |
3228 | +BEGIN |
3229 | + FOR node IN ( |
3230 | + SELECT DISTINCT ON (maasserver_node.id) |
3231 | + system_id, node_type, parent_id |
3232 | + FROM |
3233 | + maasserver_node, |
3234 | + maasserver_space, |
3235 | + maasserver_subnet, |
3236 | + maasserver_vlan, |
3237 | + maasserver_interface, |
3238 | + maasserver_interface_ip_addresses AS ip_link, |
3239 | + maasserver_staticipaddress |
3240 | + WHERE maasserver_space.id = NEW.id |
3241 | + AND maasserver_subnet.vlan_id = maasserver_vlan.id |
3242 | + AND maasserver_vlan.space_id IS NOT DISTINCT FROM maasserver_space.id |
3243 | + AND maasserver_staticipaddress.subnet_id = maasserver_subnet.id |
3244 | + AND ip_link.staticipaddress_id = maasserver_staticipaddress.id |
3245 | + AND ip_link.interface_id = maasserver_interface.id |
3246 | + AND maasserver_node.id = maasserver_interface.node_id) |
3247 | + LOOP |
3248 | + IF node.node_type = 0 THEN |
3249 | + PERFORM pg_notify('machine_update',CAST(node.system_id AS text)); |
3250 | + ELSIF node.node_type IN (2, 3, 4) THEN |
3251 | + PERFORM pg_notify('controller_update',CAST(node.system_id AS text)); |
3252 | + ELSIF node.parent_id IS NOT NULL THEN |
3253 | + SELECT system_id INTO pnode |
3254 | + FROM maasserver_node |
3255 | + WHERE id = node.parent_id; |
3256 | + PERFORM pg_notify('machine_update',CAST(pnode.system_id AS text)); |
3257 | + ELSE |
3258 | + PERFORM pg_notify('device_update',CAST(node.system_id AS text)); |
3259 | + END IF; |
3260 | + END LOOP; |
3261 | + RETURN NEW; |
3262 | +END; |
3263 | +$$; |
3264 | + |
3265 | + |
3266 | +ALTER FUNCTION public.space_machine_update_notify() OWNER TO gavin; |
3267 | + |
3268 | +-- |
3269 | +-- Name: space_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
3270 | +-- |
3271 | + |
3272 | +CREATE FUNCTION space_update_notify() RETURNS trigger |
3273 | + LANGUAGE plpgsql |
3274 | + AS $$ |
3275 | +DECLARE |
3276 | +BEGIN |
3277 | + PERFORM pg_notify('space_update',CAST(NEW.id AS text)); |
3278 | + RETURN NEW; |
3279 | +END; |
3280 | +$$; |
3281 | + |
3282 | + |
3283 | +ALTER FUNCTION public.space_update_notify() OWNER TO gavin; |
3284 | + |
3285 | +-- |
3286 | +-- Name: sshkey_create_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
3287 | +-- |
3288 | + |
3289 | +CREATE FUNCTION sshkey_create_notify() RETURNS trigger |
3290 | + LANGUAGE plpgsql |
3291 | + AS $$ |
3292 | +DECLARE |
3293 | +BEGIN |
3294 | + PERFORM pg_notify('sshkey_create',CAST(NEW.id AS text)); |
3295 | + RETURN NEW; |
3296 | +END; |
3297 | +$$; |
3298 | + |
3299 | + |
3300 | +ALTER FUNCTION public.sshkey_create_notify() OWNER TO gavin; |
3301 | + |
3302 | +-- |
3303 | +-- Name: sshkey_delete_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
3304 | +-- |
3305 | + |
3306 | +CREATE FUNCTION sshkey_delete_notify() RETURNS trigger |
3307 | + LANGUAGE plpgsql |
3308 | + AS $$ |
3309 | +DECLARE |
3310 | +BEGIN |
3311 | + PERFORM pg_notify('sshkey_delete',CAST(OLD.id AS text)); |
3312 | + RETURN NEW; |
3313 | +END; |
3314 | +$$; |
3315 | + |
3316 | + |
3317 | +ALTER FUNCTION public.sshkey_delete_notify() OWNER TO gavin; |
3318 | + |
3319 | +-- |
3320 | +-- Name: sshkey_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
3321 | +-- |
3322 | + |
3323 | +CREATE FUNCTION sshkey_update_notify() RETURNS trigger |
3324 | + LANGUAGE plpgsql |
3325 | + AS $$ |
3326 | +DECLARE |
3327 | +BEGIN |
3328 | + PERFORM pg_notify('sshkey_update',CAST(NEW.id AS text)); |
3329 | + RETURN NEW; |
3330 | +END; |
3331 | +$$; |
3332 | + |
3333 | + |
3334 | +ALTER FUNCTION public.sshkey_update_notify() OWNER TO gavin; |
3335 | + |
3336 | +-- |
3337 | +-- Name: staticroute_create_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
3338 | +-- |
3339 | + |
3340 | +CREATE FUNCTION staticroute_create_notify() RETURNS trigger |
3341 | + LANGUAGE plpgsql |
3342 | + AS $$ |
3343 | +DECLARE |
3344 | +BEGIN |
3345 | + PERFORM pg_notify('staticroute_create',CAST(NEW.id AS text)); |
3346 | + RETURN NEW; |
3347 | +END; |
3348 | +$$; |
3349 | + |
3350 | + |
3351 | +ALTER FUNCTION public.staticroute_create_notify() OWNER TO gavin; |
3352 | + |
3353 | +-- |
3354 | +-- Name: staticroute_delete_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
3355 | +-- |
3356 | + |
3357 | +CREATE FUNCTION staticroute_delete_notify() RETURNS trigger |
3358 | + LANGUAGE plpgsql |
3359 | + AS $$ |
3360 | +DECLARE |
3361 | +BEGIN |
3362 | + PERFORM pg_notify('staticroute_delete',CAST(OLD.id AS text)); |
3363 | + RETURN NEW; |
3364 | +END; |
3365 | +$$; |
3366 | + |
3367 | + |
3368 | +ALTER FUNCTION public.staticroute_delete_notify() OWNER TO gavin; |
3369 | + |
3370 | +-- |
3371 | +-- Name: staticroute_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
3372 | +-- |
3373 | + |
3374 | +CREATE FUNCTION staticroute_update_notify() RETURNS trigger |
3375 | + LANGUAGE plpgsql |
3376 | + AS $$ |
3377 | +DECLARE |
3378 | +BEGIN |
3379 | + PERFORM pg_notify('staticroute_update',CAST(NEW.id AS text)); |
3380 | + RETURN NEW; |
3381 | +END; |
3382 | +$$; |
3383 | + |
3384 | + |
3385 | +ALTER FUNCTION public.staticroute_update_notify() OWNER TO gavin; |
3386 | + |
3387 | +-- |
3388 | +-- Name: subnet_create_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
3389 | +-- |
3390 | + |
3391 | +CREATE FUNCTION subnet_create_notify() RETURNS trigger |
3392 | + LANGUAGE plpgsql |
3393 | + AS $$ |
3394 | +DECLARE |
3395 | +BEGIN |
3396 | + PERFORM pg_notify('subnet_create',CAST(NEW.id AS text)); |
3397 | + RETURN NEW; |
3398 | +END; |
3399 | +$$; |
3400 | + |
3401 | + |
3402 | +ALTER FUNCTION public.subnet_create_notify() OWNER TO gavin; |
3403 | + |
3404 | +-- |
3405 | +-- Name: subnet_delete_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
3406 | +-- |
3407 | + |
3408 | +CREATE FUNCTION subnet_delete_notify() RETURNS trigger |
3409 | + LANGUAGE plpgsql |
3410 | + AS $$ |
3411 | +DECLARE |
3412 | +BEGIN |
3413 | + PERFORM pg_notify('subnet_delete',CAST(OLD.id AS text)); |
3414 | + RETURN NEW; |
3415 | +END; |
3416 | +$$; |
3417 | + |
3418 | + |
3419 | +ALTER FUNCTION public.subnet_delete_notify() OWNER TO gavin; |
3420 | + |
3421 | +-- |
3422 | +-- Name: subnet_machine_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
3423 | +-- |
3424 | + |
3425 | +CREATE FUNCTION subnet_machine_update_notify() RETURNS trigger |
3426 | + LANGUAGE plpgsql |
3427 | + AS $$ |
3428 | +DECLARE |
3429 | + node RECORD; |
3430 | + pnode RECORD; |
3431 | +BEGIN |
3432 | + FOR node IN ( |
3433 | + SELECT DISTINCT ON (maasserver_node.id) |
3434 | + system_id, node_type, parent_id |
3435 | + FROM |
3436 | + maasserver_node, |
3437 | + maasserver_subnet, |
3438 | + maasserver_interface, |
3439 | + maasserver_interface_ip_addresses AS ip_link, |
3440 | + maasserver_staticipaddress |
3441 | + WHERE maasserver_subnet.id = NEW.id |
3442 | + AND maasserver_staticipaddress.subnet_id = maasserver_subnet.id |
3443 | + AND ip_link.staticipaddress_id = maasserver_staticipaddress.id |
3444 | + AND ip_link.interface_id = maasserver_interface.id |
3445 | + AND maasserver_node.id = maasserver_interface.node_id) |
3446 | + LOOP |
3447 | + IF node.node_type = 0 THEN |
3448 | + PERFORM pg_notify('machine_update',CAST(node.system_id AS text)); |
3449 | + ELSIF node.node_type IN (2, 3, 4) THEN |
3450 | + PERFORM pg_notify('controller_update',CAST(node.system_id AS text)); |
3451 | + ELSIF node.parent_id IS NOT NULL THEN |
3452 | + SELECT system_id INTO pnode |
3453 | + FROM maasserver_node |
3454 | + WHERE id = node.parent_id; |
3455 | + PERFORM pg_notify('machine_update',CAST(pnode.system_id AS text)); |
3456 | + ELSE |
3457 | + PERFORM pg_notify('device_update',CAST(node.system_id AS text)); |
3458 | + END IF; |
3459 | + END LOOP; |
3460 | + RETURN NEW; |
3461 | +END; |
3462 | +$$; |
3463 | + |
3464 | + |
3465 | +ALTER FUNCTION public.subnet_machine_update_notify() OWNER TO gavin; |
3466 | + |
3467 | +-- |
3468 | +-- Name: subnet_update_notify(); Type: FUNCTION; Schema: public; Owner: gavin |
3469 | +-- |
3470 | + |
3471 | +CREATE FUNCTION subnet_update_notify() RETURNS trigger |
3472 | + LANGUAGE plpgsql |
3473 | + AS $$ |
3474 | +DECLARE |
3475 | +BEGIN |
3476 | + PERFORM pg_notify('subnet_update',CAST(NEW.id AS text)); |
3477 | + RETURN NEW; |
3478 | +END; |
3479 | +$$; |
3480 | + |
3481 | + |
3482 | +ALTER FUNCTION public.subnet_update_notify() OWNER TO gavin; |
3483 | + |
3484 | +SET default_tablespace = ''; |
3485 | + |
3486 | +SET default_with_oids = false; |
3487 | + |
3488 | +-- |
3489 | +-- Name: maasserver_regioncontrollerprocess; Type: TABLE; Schema: public; Owner: gavin |
3490 | +-- |
3491 | + |
3492 | +CREATE TABLE maasserver_regioncontrollerprocess ( |
3493 | + id integer NOT NULL, |
3494 | + created timestamp with time zone NOT NULL, |
3495 | + updated timestamp with time zone NOT NULL, |
3496 | + pid integer NOT NULL, |
3497 | + region_id integer NOT NULL |
3498 | +); |
3499 | + |
3500 | + |
3501 | +ALTER TABLE maasserver_regioncontrollerprocess OWNER TO gavin; |
3502 | + |
3503 | +-- |
3504 | +-- Name: sys_core_get_managing_count(maasserver_regioncontrollerprocess); Type: FUNCTION; Schema: public; Owner: gavin |
3505 | +-- |
3506 | + |
3507 | +CREATE FUNCTION sys_core_get_managing_count(process maasserver_regioncontrollerprocess) RETURNS integer |
3508 | + LANGUAGE plpgsql |
3509 | + AS $$ |
3510 | +BEGIN |
3511 | + RETURN (SELECT count(*) |
3512 | + FROM maasserver_node |
3513 | + WHERE maasserver_node.managing_process_id = process.id); |
3514 | +END; |
3515 | +$$; |
3516 | + |
3517 | + |
3518 | +ALTER FUNCTION public.sys_core_get_managing_count(process maasserver_regioncontrollerprocess) OWNER TO gavin; |
3519 | + |
3520 | +-- |
3521 | +-- Name: maasserver_node; Type: TABLE; Schema: public; Owner: gavin |
3522 | +-- |
3523 | + |
3524 | +CREATE TABLE maasserver_node ( |
3525 | + id integer NOT NULL, |
3526 | + created timestamp with time zone NOT NULL, |
3527 | + updated timestamp with time zone NOT NULL, |
3528 | + system_id character varying(41) NOT NULL, |
3529 | + hostname character varying(255) NOT NULL, |
3530 | + status integer NOT NULL, |
3531 | + bios_boot_method character varying(31), |
3532 | + osystem character varying(255) NOT NULL, |
3533 | + distro_series character varying(255) NOT NULL, |
3534 | + architecture character varying(31), |
3535 | + min_hwe_kernel character varying(31), |
3536 | + hwe_kernel character varying(31), |
3537 | + agent_name character varying(255), |
3538 | + error_description text NOT NULL, |
3539 | + cpu_count integer NOT NULL, |
3540 | + memory integer NOT NULL, |
3541 | + swap_size bigint, |
3542 | + instance_power_parameters text NOT NULL, |
3543 | + power_state character varying(10) NOT NULL, |
3544 | + power_state_updated timestamp with time zone, |
3545 | + error character varying(255) NOT NULL, |
3546 | + netboot boolean NOT NULL, |
3547 | + license_key character varying(30), |
3548 | + boot_cluster_ip inet, |
3549 | + enable_ssh boolean NOT NULL, |
3550 | + skip_networking boolean NOT NULL, |
3551 | + skip_storage boolean NOT NULL, |
3552 | + boot_interface_id integer, |
3553 | + gateway_link_ipv4_id integer, |
3554 | + gateway_link_ipv6_id integer, |
3555 | + owner_id integer, |
3556 | + parent_id integer, |
3557 | + token_id integer, |
3558 | + zone_id integer NOT NULL, |
3559 | + boot_disk_id integer, |
3560 | + node_type integer NOT NULL, |
3561 | + domain_id integer, |
3562 | + dns_process_id integer, |
3563 | + bmc_id integer, |
3564 | + address_ttl integer, |
3565 | + status_expires timestamp with time zone, |
3566 | + power_state_queried timestamp with time zone, |
3567 | + url character varying(255) NOT NULL, |
3568 | + managing_process_id integer, |
3569 | + last_image_sync timestamp with time zone, |
3570 | + previous_status integer NOT NULL, |
3571 | + default_user character varying(32) NOT NULL, |
3572 | + cpu_speed integer NOT NULL, |
3573 | + dynamic boolean NOT NULL, |
3574 | + CONSTRAINT maasserver_node_address_ttl_check CHECK ((address_ttl >= 0)) |
3575 | +); |
3576 | + |
3577 | + |
3578 | +ALTER TABLE maasserver_node OWNER TO gavin; |
3579 | + |
3580 | +-- |
3581 | +-- Name: sys_core_get_num_conn(maasserver_node); Type: FUNCTION; Schema: public; Owner: gavin |
3582 | +-- |
3583 | + |
3584 | +CREATE FUNCTION sys_core_get_num_conn(rack maasserver_node) RETURNS integer |
3585 | + LANGUAGE plpgsql |
3586 | + AS $$ |
3587 | +BEGIN |
3588 | + RETURN ( |
3589 | + SELECT count(*) |
3590 | + FROM |
3591 | + maasserver_regionrackrpcconnection AS connection |
3592 | + WHERE connection.rack_controller_id = rack.id); |
3593 | +END; |
3594 | +$$; |
3595 | + |
3596 | + |
3597 | +ALTER FUNCTION public.sys_core_get_num_conn(rack maasserver_node) OWNER TO gavin; |
3598 | + |
3599 | +-- |
3600 | +-- Name: sys_core_get_num_processes(); Type: FUNCTION; Schema: public; Owner: gavin |
3601 | +-- |
3602 | + |
3603 | +CREATE FUNCTION sys_core_get_num_processes() RETURNS integer |
3604 | + LANGUAGE plpgsql |
3605 | + AS $$ |
3606 | +BEGIN |
3607 | + RETURN ( |
3608 | + SELECT count(*) FROM maasserver_regioncontrollerprocess); |
3609 | +END; |
3610 | +$$; |
3611 | + |
3612 | + |
3613 | +ALTER FUNCTION public.sys_core_get_num_processes() OWNER TO gavin; |
3614 | + |
3615 | +-- |
3616 | +-- Name: sys_core_pick_new_region(maasserver_node); Type: FUNCTION; Schema: public; Owner: gavin |
3617 | +-- |
3618 | + |
3619 | +CREATE FUNCTION sys_core_pick_new_region(rack maasserver_node) RETURNS maasserver_regioncontrollerprocess |
3620 | + LANGUAGE plpgsql |
3621 | + AS $$ |
3622 | +DECLARE |
3623 | + selected_managing integer; |
3624 | + number_managing integer; |
3625 | + selected_process maasserver_regioncontrollerprocess; |
3626 | + process maasserver_regioncontrollerprocess; |
3627 | +BEGIN |
3628 | + -- Get best region controller that can manage this rack controller. |
3629 | + -- This is identified by picking a region controller process that |
3630 | + -- at least has a connection to the rack controller and managing the |
3631 | + -- least number of rack controllers. |
3632 | + FOR process IN ( |
3633 | + SELECT DISTINCT ON (maasserver_regioncontrollerprocess.id) |
3634 | + maasserver_regioncontrollerprocess.* |
3635 | + FROM |
3636 | + maasserver_regioncontrollerprocess, |
3637 | + maasserver_regioncontrollerprocessendpoint, |
3638 | + maasserver_regionrackrpcconnection |
3639 | + WHERE maasserver_regionrackrpcconnection.rack_controller_id = rack.id |
3640 | + AND maasserver_regionrackrpcconnection.endpoint_id = |
3641 | + maasserver_regioncontrollerprocessendpoint.id |
3642 | + AND maasserver_regioncontrollerprocessendpoint.process_id = |
3643 | + maasserver_regioncontrollerprocess.id) |
3644 | + LOOP |
3645 | + IF selected_process IS NULL THEN |
3646 | + -- First time through the loop so set the default. |
3647 | + selected_process = process; |
3648 | + selected_managing = sys_core_get_managing_count(process); |
3649 | + ELSE |
3650 | + -- See if the current process is managing less then the currently |
3651 | + -- selected process. |
3652 | + number_managing = sys_core_get_managing_count(process); |
3653 | + IF number_managing = 0 THEN |
3654 | + -- This process is managing zero so its the best, so we exit the |
3655 | + -- loop now to return the selected. |
3656 | + selected_process = process; |
3657 | + EXIT; |
3658 | + ELSIF number_managing < selected_managing THEN |
3659 | + -- Managing less than the currently selected; select this process |
3660 | + -- instead. |
3661 | + selected_process = process; |
3662 | + selected_managing = number_managing; |
3663 | + END IF; |
3664 | + END IF; |
3665 | + END LOOP; |
3666 | + RETURN selected_process; |
3667 | +END; |
3668 | +$$; |
3669 | + |
3670 | + |
3671 | +ALTER FUNCTION public.sys_core_pick_new_region(rack maasserver_node) OWNER TO gavin; |
3672 | + |
3673 | +-- |
3674 | +-- Name: sys_core_rpc_delete(); Type: FUNCTION; Schema: public; Owner: gavin |
3675 | +-- |
3676 | + |
3677 | +CREATE FUNCTION sys_core_rpc_delete() RETURNS trigger |
3678 | + LANGUAGE plpgsql |
3679 | + AS $$ |
3680 | +DECLARE |
3681 | + rack_controller maasserver_node; |
3682 | + region_process maasserver_regioncontrollerprocess; |
3683 | +BEGIN |
3684 | + -- Connection from region <-> rack, has been removed. If that region |
3685 | + -- process was managing that rack controller then a new one needs to |
3686 | + -- be selected. |
3687 | + SELECT maasserver_node.* INTO rack_controller |
3688 | + FROM maasserver_node |
3689 | + WHERE maasserver_node.id = OLD.rack_controller_id; |
3690 | + |
3691 | + -- Get the region process from the endpoint. |
3692 | + SELECT |
3693 | + process.* INTO region_process |
3694 | + FROM |
3695 | + maasserver_regioncontrollerprocess AS process, |
3696 | + maasserver_regioncontrollerprocessendpoint AS endpoint |
3697 | + WHERE process.id = endpoint.process_id |
3698 | + AND endpoint.id = OLD.endpoint_id; |
3699 | + |
3700 | + -- Only perform an action if processes equal. |
3701 | + IF rack_controller.managing_process_id = region_process.id THEN |
3702 | + -- Region process was managing this rack controller. Tell it to stop |
3703 | + -- watching the rack controller. |
3704 | + PERFORM pg_notify( |
3705 | + CONCAT('sys_core_', region_process.id), |
3706 | + CONCAT('unwatch_', CAST(rack_controller.id AS text))); |
3707 | + |
3708 | + -- Pick a new region process for this rack controller. |
3709 | + region_process = sys_core_pick_new_region(rack_controller); |
3710 | + |
3711 | + -- Update the rack controller and inform the new process. |
3712 | + UPDATE maasserver_node |
3713 | + SET managing_process_id = region_process.id |
3714 | + WHERE maasserver_node.id = rack_controller.id; |
3715 | + IF region_process.id IS NOT NULL THEN |
3716 | + PERFORM pg_notify( |
3717 | + CONCAT('sys_core_', region_process.id), |
3718 | + CONCAT('watch_', CAST(rack_controller.id AS text))); |
3719 | + END IF; |
3720 | + END IF; |
3721 | + RETURN NEW; |
3722 | +END; |
3723 | +$$; |
3724 | + |
3725 | + |
3726 | +ALTER FUNCTION public.sys_core_rpc_delete() OWNER TO gavin; |
3727 | + |
3728 | +-- |
3729 | +-- Name: sys_core_rpc_insert(); Type: FUNCTION; Schema: public; Owner: gavin |
3730 | +-- |
3731 | + |
3732 | +CREATE FUNCTION sys_core_rpc_insert() RETURNS trigger |
3733 | + LANGUAGE plpgsql |
3734 | + AS $$ |
3735 | +DECLARE |
3736 | + rack_controller maasserver_node; |
3737 | + region_process maasserver_regioncontrollerprocess; |
3738 | +BEGIN |
3739 | + -- New connection from region <-> rack, check that the rack controller |
3740 | + -- has a managing region controller. |
3741 | + SELECT maasserver_node.* INTO rack_controller |
3742 | + FROM maasserver_node |
3743 | + WHERE maasserver_node.id = NEW.rack_controller_id; |
3744 | + |
3745 | + IF rack_controller.managing_process_id IS NULL THEN |
3746 | + -- No managing region process for this rack controller. |
3747 | + PERFORM sys_core_set_new_region(rack_controller); |
3748 | + ELSE |
3749 | + -- Currently managed check that the managing process is not dead. |
3750 | + SELECT maasserver_regioncontrollerprocess.* INTO region_process |
3751 | + FROM maasserver_regioncontrollerprocess |
3752 | + WHERE maasserver_regioncontrollerprocess.id = |
3753 | + rack_controller.managing_process_id; |
3754 | + IF EXTRACT(EPOCH FROM region_process.updated) - |
3755 | + EXTRACT(EPOCH FROM now()) > 90 THEN |
3756 | + -- Region controller process is dead. A new region process needs to |
3757 | + -- be selected for this rack controller. |
3758 | + UPDATE maasserver_node SET managing_process_id = NULL |
3759 | + WHERE maasserver_node.id = NEW.rack_controller_id; |
3760 | + NEW.rack_controller_id = NULL; |
3761 | + PERFORM sys_core_set_new_region(rack_controller); |
3762 | + ELSE |
3763 | + -- Currently being managed but lets see if we can re-balance the |
3764 | + -- managing processes better. We only do the re-balance once the |
3765 | + -- rack controller is connected to more than half of the running |
3766 | + -- processes. |
3767 | + IF sys_core_get_num_conn(rack_controller) / |
3768 | + sys_core_get_num_processes() > 0.5 THEN |
3769 | + -- Pick a new region process for this rack controller. Only update |
3770 | + -- and perform the notification if the selection is different. |
3771 | + region_process = sys_core_pick_new_region(rack_controller); |
3772 | + IF region_process.id != rack_controller.managing_process_id THEN |
3773 | + -- Alter the old process that its no longer responsable for |
3774 | + -- this rack controller. |
3775 | + PERFORM pg_notify( |
3776 | + CONCAT('sys_core_', rack_controller.managing_process_id), |
3777 | + CONCAT('unwatch_', CAST(rack_controller.id AS text))); |
3778 | + -- Update the rack controller and alert the region controller. |
3779 | + UPDATE maasserver_node |
3780 | + SET managing_process_id = region_process.id |
3781 | + WHERE maasserver_node.id = rack_controller.id; |
3782 | + PERFORM pg_notify( |
3783 | + CONCAT('sys_core_', region_process.id), |
3784 | + CONCAT('watch_', CAST(rack_controller.id AS text))); |
3785 | + END IF; |
3786 | + END IF; |
3787 | + END IF; |
3788 | + END IF; |
3789 | + RETURN NEW; |
3790 | +END; |
3791 | +$$; |
3792 | + |
3793 | + |
3794 | +ALTER FUNCTION public.sys_core_rpc_insert() OWNER TO gavin; |
3795 | + |
3796 | +-- |
3797 | +-- Name: sys_core_set_new_region(maasserver_node); Type: FUNCTION; Schema: public; Owner: gavin |
3798 | +-- |
3799 | + |
3800 | +CREATE FUNCTION sys_core_set_new_region(rack maasserver_node) RETURNS void |
3801 | + LANGUAGE plpgsql |
3802 | + AS $$ |
3803 | +DECLARE |
3804 | + region_process maasserver_regioncontrollerprocess; |
3805 | +BEGIN |
3806 | + -- Pick the new region process to manage this rack controller. |
3807 | + region_process = sys_core_pick_new_region(rack); |
3808 | + |
3809 | + -- Update the rack controller and alert the region controller. |
3810 | + UPDATE maasserver_node SET managing_process_id = region_process.id |
3811 | + WHERE maasserver_node.id = rack.id; |
3812 | + PERFORM pg_notify( |
3813 | + CONCAT('sys_core_', region_process.id), |
3814 | + CONCAT('watch_', CAST(rack.id AS text))); |
3815 | + RETURN; |
3816 | +END; |
3817 | +$$; |
3818 | + |
3819 | + |
3820 | +ALTER FUNCTION public.sys_core_set_new_region(rack maasserver_node) OWNER TO gavin; |
3821 | + |
3822 | +-- |
3823 | +-- Name: maasserver_vlan; Type: TABLE; Schema: public; Owner: gavin |
3824 | +-- |
3825 | + |
3826 | +CREATE TABLE maasserver_vlan ( |
3827 | + id integer NOT NULL, |
3828 | + created timestamp with time zone NOT NULL, |
3829 | + updated timestamp with time zone NOT NULL, |
3830 | + name character varying(256), |
3831 | + vid integer NOT NULL, |
3832 | + mtu integer NOT NULL, |
3833 | + fabric_id integer NOT NULL, |
3834 | + dhcp_on boolean NOT NULL, |
3835 | + primary_rack_id integer, |
3836 | + secondary_rack_id integer, |
3837 | + external_dhcp inet, |
3838 | + description text NOT NULL, |
3839 | + relay_vlan_id integer, |
3840 | + space_id integer |
3841 | +); |
3842 | + |
3843 | + |
3844 | +ALTER TABLE maasserver_vlan OWNER TO gavin; |
3845 | + |
3846 | +-- |
3847 | +-- Name: sys_dhcp_alert(maasserver_vlan); Type: FUNCTION; Schema: public; Owner: gavin |
3848 | +-- |
3849 | + |
3850 | +CREATE FUNCTION sys_dhcp_alert(vlan maasserver_vlan) RETURNS void |
3851 | + LANGUAGE plpgsql |
3852 | + AS $$ |
3853 | +BEGIN |
3854 | + PERFORM pg_notify(CONCAT('sys_dhcp_', vlan.primary_rack_id), ''); |
3855 | + IF vlan.secondary_rack_id IS NOT NULL THEN |
3856 | + PERFORM pg_notify(CONCAT('sys_dhcp_', vlan.secondary_rack_id), ''); |
3857 | + END IF; |
3858 | + RETURN; |
3859 | +END; |
3860 | +$$; |
3861 | + |
3862 | + |
3863 | +ALTER FUNCTION public.sys_dhcp_alert(vlan maasserver_vlan) OWNER TO gavin; |
3864 | + |
3865 | +-- |
3866 | +-- Name: sys_dhcp_config_ntp_servers_delete(); Type: FUNCTION; Schema: public; Owner: gavin |
3867 | +-- |
3868 | + |
3869 | +CREATE FUNCTION sys_dhcp_config_ntp_servers_delete() RETURNS trigger |
3870 | + LANGUAGE plpgsql |
3871 | + AS $$ |
3872 | +BEGIN |
3873 | + IF OLD.name IN ('ntp_servers', 'ntp_external_only') THEN |
3874 | + PERFORM sys_dhcp_update_all_vlans(); |
3875 | + END IF; |
3876 | + RETURN NEW; |
3877 | +END; |
3878 | +$$; |
3879 | + |
3880 | + |
3881 | +ALTER FUNCTION public.sys_dhcp_config_ntp_servers_delete() OWNER TO gavin; |
3882 | + |
3883 | +-- |
3884 | +-- Name: sys_dhcp_config_ntp_servers_insert(); Type: FUNCTION; Schema: public; Owner: gavin |
3885 | +-- |
3886 | + |
3887 | +CREATE FUNCTION sys_dhcp_config_ntp_servers_insert() RETURNS trigger |
3888 | + LANGUAGE plpgsql |
3889 | + AS $$ |
3890 | +BEGIN |
3891 | + IF NEW.name = 'ntp_servers' THEN |
3892 | + PERFORM sys_dhcp_update_all_vlans(); |
3893 | + ELSIF NEW.name = 'ntp_external_only' THEN |
3894 | + PERFORM sys_dhcp_update_all_vlans(); |
3895 | + END IF; |
3896 | + RETURN NEW; |
3897 | +END; |
3898 | +$$; |
3899 | + |
3900 | + |
3901 | +ALTER FUNCTION public.sys_dhcp_config_ntp_servers_insert() OWNER TO gavin; |
3902 | + |
3903 | +-- |
3904 | +-- Name: sys_dhcp_config_ntp_servers_update(); Type: FUNCTION; Schema: public; Owner: gavin |
3905 | +-- |
3906 | + |
3907 | +CREATE FUNCTION sys_dhcp_config_ntp_servers_update() RETURNS trigger |
3908 | + LANGUAGE plpgsql |
3909 | + AS $$ |
3910 | +BEGIN |
3911 | + IF OLD.name IN ('ntp_servers', 'ntp_external_only') |
3912 | + OR NEW.name IN ('ntp_servers', 'ntp_external_only') THEN |
3913 | + IF OLD.value != NEW.value THEN |
3914 | + PERFORM sys_dhcp_update_all_vlans(); |
3915 | + END IF; |
3916 | + END IF; |
3917 | + RETURN NEW; |
3918 | +END; |
3919 | +$$; |
3920 | + |
3921 | + |
3922 | +ALTER FUNCTION public.sys_dhcp_config_ntp_servers_update() OWNER TO gavin; |
3923 | + |
3924 | +-- |
3925 | +-- Name: sys_dhcp_interface_update(); Type: FUNCTION; Schema: public; Owner: gavin |
3926 | +-- |
3927 | + |
3928 | +CREATE FUNCTION sys_dhcp_interface_update() RETURNS trigger |
3929 | + LANGUAGE plpgsql |
3930 | + AS $$ |
3931 | +DECLARE |
3932 | + vlan maasserver_vlan; |
3933 | +BEGIN |
3934 | + -- Update VLAN if DHCP is enabled and the interface name or MAC |
3935 | + -- address has changed. |
3936 | + IF OLD.name != NEW.name OR OLD.mac_address != NEW.mac_address THEN |
3937 | + FOR vlan IN ( |
3938 | + SELECT DISTINCT ON (maasserver_vlan.id) |
3939 | + maasserver_vlan.* |
3940 | + FROM |
3941 | + maasserver_vlan, |
3942 | + maasserver_subnet, |
3943 | + maasserver_staticipaddress, |
3944 | + maasserver_interface_ip_addresses AS ip_link |
3945 | + WHERE maasserver_staticipaddress.subnet_id = maasserver_subnet.id |
3946 | + AND ip_link.staticipaddress_id = maasserver_staticipaddress.id |
3947 | + AND ip_link.interface_id = NEW.id |
3948 | + AND maasserver_staticipaddress.alloc_type != 6 |
3949 | + AND maasserver_staticipaddress.ip IS NOT NULL |
3950 | + AND host(maasserver_staticipaddress.ip) != '' |
3951 | + AND maasserver_vlan.id = maasserver_subnet.vlan_id |
3952 | + AND maasserver_vlan.dhcp_on) |
3953 | + LOOP |
3954 | + PERFORM sys_dhcp_alert(vlan); |
3955 | + END LOOP; |
3956 | + END IF; |
3957 | + RETURN NEW; |
3958 | +END; |
3959 | +$$; |
3960 | + |
3961 | + |
3962 | +ALTER FUNCTION public.sys_dhcp_interface_update() OWNER TO gavin; |
3963 | + |
3964 | +-- |
3965 | +-- Name: sys_dhcp_iprange_delete(); Type: FUNCTION; Schema: public; Owner: gavin |
3966 | +-- |
3967 | + |
3968 | +CREATE FUNCTION sys_dhcp_iprange_delete() RETURNS trigger |
3969 | + LANGUAGE plpgsql |
3970 | + AS $$ |
3971 | +DECLARE |
3972 | + vlan maasserver_vlan; |
3973 | +BEGIN |
3974 | + -- Update VLAN if DHCP is enabled and was dynamic range. |
3975 | + IF OLD.type = 'dynamic' THEN |
3976 | + SELECT maasserver_vlan.* INTO vlan |
3977 | + FROM maasserver_vlan, maasserver_subnet |
3978 | + WHERE maasserver_subnet.id = OLD.subnet_id AND |
3979 | + maasserver_subnet.vlan_id = maasserver_vlan.id; |
3980 | + IF vlan.dhcp_on THEN |
3981 | + PERFORM sys_dhcp_alert(vlan); |
3982 | + END IF; |
3983 | + END IF; |
3984 | + RETURN NEW; |
3985 | +END; |
3986 | +$$; |
3987 | + |
3988 | + |
3989 | +ALTER FUNCTION public.sys_dhcp_iprange_delete() OWNER TO gavin; |
3990 | + |
3991 | +-- |
3992 | +-- Name: sys_dhcp_iprange_insert(); Type: FUNCTION; Schema: public; Owner: gavin |
3993 | +-- |
3994 | + |
3995 | +CREATE FUNCTION sys_dhcp_iprange_insert() RETURNS trigger |
3996 | + LANGUAGE plpgsql |
3997 | + AS $$ |
3998 | +DECLARE |
3999 | + vlan maasserver_vlan; |
4000 | +BEGIN |
4001 | + -- Update VLAN if DHCP is enabled and a dynamic range. |
4002 | + IF NEW.type = 'dynamic' THEN |
4003 | + SELECT maasserver_vlan.* INTO vlan |
4004 | + FROM maasserver_vlan, maasserver_subnet |
4005 | + WHERE maasserver_subnet.id = NEW.subnet_id AND |
4006 | + maasserver_subnet.vlan_id = maasserver_vlan.id; |
4007 | + IF vlan.dhcp_on THEN |
4008 | + PERFORM sys_dhcp_alert(vlan); |
4009 | + END IF; |
4010 | + END IF; |
4011 | + RETURN NEW; |
4012 | +END; |
4013 | +$$; |
4014 | + |
4015 | + |
4016 | +ALTER FUNCTION public.sys_dhcp_iprange_insert() OWNER TO gavin; |
4017 | + |
4018 | +-- |
4019 | +-- Name: sys_dhcp_iprange_update(); Type: FUNCTION; Schema: public; Owner: gavin |
4020 | +-- |
4021 | + |
4022 | +CREATE FUNCTION sys_dhcp_iprange_update() RETURNS trigger |
4023 | + LANGUAGE plpgsql |
4024 | + AS $$ |
4025 | +DECLARE |
4026 | + vlan maasserver_vlan; |
4027 | +BEGIN |
4028 | + -- Update VLAN if DHCP is enabled and was or is now a dynamic range. |
4029 | + IF OLD.type = 'dynamic' OR NEW.type = 'dynamic' THEN |
4030 | + SELECT maasserver_vlan.* INTO vlan |
4031 | + FROM maasserver_vlan, maasserver_subnet |
4032 | + WHERE maasserver_subnet.id = NEW.subnet_id AND |
4033 | + maasserver_subnet.vlan_id = maasserver_vlan.id; |
4034 | + IF vlan.dhcp_on THEN |
4035 | + PERFORM sys_dhcp_alert(vlan); |
4036 | + END IF; |
4037 | + END IF; |
4038 | + RETURN NEW; |
4039 | +END; |
4040 | +$$; |
4041 | + |
4042 | + |
4043 | +ALTER FUNCTION public.sys_dhcp_iprange_update() OWNER TO gavin; |
4044 | + |
4045 | +-- |
4046 | +-- Name: sys_dhcp_node_update(); Type: FUNCTION; Schema: public; Owner: gavin |
4047 | +-- |
4048 | + |
4049 | +CREATE FUNCTION sys_dhcp_node_update() RETURNS trigger |
4050 | + LANGUAGE plpgsql |
4051 | + AS $$ |
4052 | +DECLARE |
4053 | + vlan maasserver_vlan; |
4054 | +BEGIN |
4055 | + -- Update VLAN if on every interface on the node that is managed when |
4056 | + -- the node hostname is changed. |
4057 | + IF OLD.hostname != NEW.hostname THEN |
4058 | + FOR vlan IN ( |
4059 | + SELECT DISTINCT ON (maasserver_vlan.id) |
4060 | + maasserver_vlan.* |
4061 | + FROM |
4062 | + maasserver_vlan, |
4063 | + maasserver_staticipaddress, |
4064 | + maasserver_subnet, |
4065 | + maasserver_interface, |
4066 | + maasserver_interface_ip_addresses AS ip_link |
4067 | + WHERE maasserver_staticipaddress.subnet_id = maasserver_subnet.id |
4068 | + AND ip_link.staticipaddress_id = maasserver_staticipaddress.id |
4069 | + AND ip_link.interface_id = maasserver_interface.id |
4070 | + AND maasserver_interface.node_id = NEW.id |
4071 | + AND maasserver_staticipaddress.alloc_type != 6 |
4072 | + AND maasserver_staticipaddress.ip IS NOT NULL |
4073 | + AND host(maasserver_staticipaddress.ip) != '' |
4074 | + AND maasserver_vlan.id = maasserver_subnet.vlan_id |
4075 | + AND maasserver_vlan.dhcp_on) |
4076 | + LOOP |
4077 | + PERFORM sys_dhcp_alert(vlan); |
4078 | + END LOOP; |
4079 | + END IF; |
4080 | + RETURN NEW; |
4081 | +END; |
4082 | +$$; |
4083 | + |
4084 | + |
4085 | +ALTER FUNCTION public.sys_dhcp_node_update() OWNER TO gavin; |
4086 | + |
4087 | +-- |
4088 | +-- Name: sys_dhcp_snippet_delete(); Type: FUNCTION; Schema: public; Owner: gavin |
4089 | +-- |
4090 | + |
4091 | +CREATE FUNCTION sys_dhcp_snippet_delete() RETURNS trigger |
4092 | + LANGUAGE plpgsql |
4093 | + AS $$ |
4094 | +BEGIN |
4095 | + IF OLD.enabled THEN |
4096 | + PERFORM sys_dhcp_snippet_update_value(OLD); |
4097 | + END IF; |
4098 | + RETURN NEW; |
4099 | +END; |
4100 | +$$; |
4101 | + |
4102 | + |
4103 | +ALTER FUNCTION public.sys_dhcp_snippet_delete() OWNER TO gavin; |
4104 | + |
4105 | +-- |
4106 | +-- Name: sys_dhcp_snippet_insert(); Type: FUNCTION; Schema: public; Owner: gavin |
4107 | +-- |
4108 | + |
4109 | +CREATE FUNCTION sys_dhcp_snippet_insert() RETURNS trigger |
4110 | + LANGUAGE plpgsql |
4111 | + AS $$ |
4112 | +BEGIN |
4113 | + IF NEW.enabled THEN |
4114 | + PERFORM sys_dhcp_snippet_update_value(NEW); |
4115 | + END IF; |
4116 | + RETURN NEW; |
4117 | +END; |
4118 | +$$; |
4119 | + |
4120 | + |
4121 | +ALTER FUNCTION public.sys_dhcp_snippet_insert() OWNER TO gavin; |
4122 | + |
4123 | +-- |
4124 | +-- Name: sys_dhcp_snippet_update(); Type: FUNCTION; Schema: public; Owner: gavin |
4125 | +-- |
4126 | + |
4127 | +CREATE FUNCTION sys_dhcp_snippet_update() RETURNS trigger |
4128 | + LANGUAGE plpgsql |
4129 | + AS $$ |
4130 | +BEGIN |
4131 | + IF OLD.enabled = NEW.enabled AND NEW.enabled IS FALSE THEN |
4132 | + -- If the DHCP snippet is disabled don't fire any alerts |
4133 | + RETURN NEW; |
4134 | + ELSIF ((OLD.value_id != NEW.value_id) OR |
4135 | + (OLD.enabled != NEW.enabled) OR |
4136 | + (OLD.description != NEW.description)) THEN |
4137 | + PERFORM sys_dhcp_snippet_update_value(NEW); |
4138 | + ELSIF ((OLD.subnet_id IS NULL AND NEW.subnet_id IS NOT NULL) OR |
4139 | + (OLD.subnet_id IS NOT NULL AND NEW.subnet_id IS NULL) OR |
4140 | + (OLD.subnet_id != NEW.subnet_id)) THEN |
4141 | + IF NEW.subnet_id IS NOT NULL THEN |
4142 | + PERFORM sys_dhcp_snippet_update_subnet(NEW.subnet_id); |
4143 | + END IF; |
4144 | + IF OLD.subnet_id IS NOT NULL THEN |
4145 | + PERFORM sys_dhcp_snippet_update_subnet(OLD.subnet_id); |
4146 | + END IF; |
4147 | + ELSIF ((OLD.node_id IS NULL AND NEW.node_id IS NOT NULL) OR |
4148 | + (OLD.node_id IS NOT NULL AND NEW.node_id IS NULL) OR |
4149 | + (OLD.node_id != NEW.node_id)) THEN |
4150 | + IF NEW.node_id IS NOT NULL THEN |
4151 | + PERFORM sys_dhcp_snippet_update_node(NEW.node_id); |
4152 | + END IF; |
4153 | + IF OLD.node_id IS NOT NULL THEN |
4154 | + PERFORM sys_dhcp_snippet_update_node(OLD.node_id); |
4155 | + END IF; |
4156 | + END IF; |
4157 | + RETURN NEW; |
4158 | +END; |
4159 | +$$; |
4160 | + |
4161 | + |
4162 | +ALTER FUNCTION public.sys_dhcp_snippet_update() OWNER TO gavin; |
4163 | + |
4164 | +-- |
4165 | +-- Name: sys_dhcp_snippet_update_node(integer); Type: FUNCTION; Schema: public; Owner: gavin |
4166 | +-- |
4167 | + |
4168 | +CREATE FUNCTION sys_dhcp_snippet_update_node(_node_id integer) RETURNS void |
4169 | + LANGUAGE plpgsql |
4170 | + AS $$ |
4171 | +DECLARE |
4172 | + rack INTEGER; |
4173 | +BEGIN |
4174 | + FOR rack IN ( |
4175 | + WITH racks AS ( |
4176 | + SELECT primary_rack_id, secondary_rack_id |
4177 | + FROM maasserver_vlan, maasserver_interface |
4178 | + WHERE maasserver_interface.node_id = _node_id |
4179 | + AND maasserver_interface.vlan_id = maasserver_vlan.id |
4180 | + AND maasserver_vlan.dhcp_on = true |
4181 | + ) |
4182 | + SELECT primary_rack_id FROM racks |
4183 | + WHERE primary_rack_id IS NOT NULL |
4184 | + UNION |
4185 | + SELECT secondary_rack_id FROM racks |
4186 | + WHERE secondary_rack_id IS NOT NULL) |
4187 | + LOOP |
4188 | + PERFORM pg_notify(CONCAT('sys_dhcp_', rack), ''); |
4189 | + END LOOP; |
4190 | + RETURN; |
4191 | +END; |
4192 | +$$; |
4193 | + |
4194 | + |
4195 | +ALTER FUNCTION public.sys_dhcp_snippet_update_node(_node_id integer) OWNER TO gavin; |
4196 | + |
4197 | +-- |
4198 | +-- Name: sys_dhcp_snippet_update_subnet(integer); Type: FUNCTION; Schema: public; Owner: gavin |
4199 | +-- |
4200 | + |
4201 | +CREATE FUNCTION sys_dhcp_snippet_update_subnet(_subnet_id integer) RETURNS void |
4202 | + LANGUAGE plpgsql |
4203 | + AS $$ |
4204 | +DECLARE |
4205 | + vlan maasserver_vlan; |
4206 | +BEGIN |
4207 | + FOR vlan IN ( |
4208 | + SELECT |
4209 | + maasserver_vlan.* |
4210 | + FROM |
4211 | + maasserver_vlan, |
4212 | + maasserver_subnet |
4213 | + WHERE maasserver_subnet.id = _subnet_id |
4214 | + AND maasserver_vlan.id = maasserver_subnet.vlan_id |
4215 | + AND maasserver_vlan.dhcp_on = true) |
4216 | + LOOP |
4217 | + PERFORM sys_dhcp_alert(vlan); |
4218 | + END LOOP; |
4219 | + RETURN; |
4220 | +END; |
4221 | +$$; |
4222 | + |
4223 | + |
4224 | +ALTER FUNCTION public.sys_dhcp_snippet_update_subnet(_subnet_id integer) OWNER TO gavin; |
4225 | + |
4226 | +-- |
4227 | +-- Name: maasserver_dhcpsnippet; Type: TABLE; Schema: public; Owner: gavin |
4228 | +-- |
4229 | + |
4230 | +CREATE TABLE maasserver_dhcpsnippet ( |
4231 | + id integer NOT NULL, |
4232 | + created timestamp with time zone NOT NULL, |
4233 | + updated timestamp with time zone NOT NULL, |
4234 | + name character varying(255) NOT NULL, |
4235 | + description text NOT NULL, |
4236 | + enabled boolean NOT NULL, |
4237 | + node_id integer, |
4238 | + subnet_id integer, |
4239 | + value_id integer NOT NULL |
4240 | +); |
4241 | + |
4242 | + |
4243 | +ALTER TABLE maasserver_dhcpsnippet OWNER TO gavin; |
4244 | + |
4245 | +-- |
4246 | +-- Name: sys_dhcp_snippet_update_value(maasserver_dhcpsnippet); Type: FUNCTION; Schema: public; Owner: gavin |
4247 | +-- |
4248 | + |
4249 | +CREATE FUNCTION sys_dhcp_snippet_update_value(_dhcp_snippet maasserver_dhcpsnippet) RETURNS void |
4250 | + LANGUAGE plpgsql |
4251 | + AS $$ |
4252 | +BEGIN |
4253 | + IF _dhcp_snippet.subnet_id IS NOT NULL THEN |
4254 | + PERFORM sys_dhcp_snippet_update_subnet(_dhcp_snippet.subnet_id); |
4255 | + ELSIF _dhcp_snippet.node_id is NOT NULL THEN |
4256 | + PERFORM sys_dhcp_snippet_update_node(_dhcp_snippet.node_id); |
4257 | + ELSE |
4258 | + -- This is a global snippet, everyone has to update. This should only |
4259 | + -- be triggered when neither subnet_id or node_id are set. We verify |
4260 | + -- that only subnet_id xor node_id are set in DHCPSnippet.clean() |
4261 | + PERFORM sys_dhcp_update_all_vlans(); |
4262 | + END IF; |
4263 | + RETURN; |
4264 | +END; |
4265 | +$$; |
4266 | + |
4267 | + |
4268 | +ALTER FUNCTION public.sys_dhcp_snippet_update_value(_dhcp_snippet maasserver_dhcpsnippet) OWNER TO gavin; |
4269 | + |
4270 | +-- |
4271 | +-- Name: sys_dhcp_staticipaddress_delete(); Type: FUNCTION; Schema: public; Owner: gavin |
4272 | +-- |
4273 | + |
4274 | +CREATE FUNCTION sys_dhcp_staticipaddress_delete() RETURNS trigger |
4275 | + LANGUAGE plpgsql |
4276 | + AS $$ |
4277 | +DECLARE |
4278 | + vlan maasserver_vlan; |
4279 | +BEGIN |
4280 | + -- Update VLAN if DHCP is enabled and has an IP address. |
4281 | + IF host(OLD.ip) != '' THEN |
4282 | + SELECT maasserver_vlan.* INTO vlan |
4283 | + FROM maasserver_vlan, maasserver_subnet |
4284 | + WHERE maasserver_subnet.id = OLD.subnet_id AND |
4285 | + maasserver_subnet.vlan_id = maasserver_vlan.id; |
4286 | + IF vlan.dhcp_on THEN |
4287 | + PERFORM sys_dhcp_alert(vlan); |
4288 | + END IF; |
4289 | + END IF; |
4290 | + RETURN NEW; |
4291 | +END; |
4292 | +$$; |
4293 | + |
4294 | + |
4295 | +ALTER FUNCTION public.sys_dhcp_staticipaddress_delete() OWNER TO gavin; |
4296 | + |
4297 | +-- |
4298 | +-- Name: sys_dhcp_staticipaddress_insert(); Type: FUNCTION; Schema: public; Owner: gavin |
4299 | +-- |
4300 | + |
4301 | +CREATE FUNCTION sys_dhcp_staticipaddress_insert() RETURNS trigger |
4302 | + LANGUAGE plpgsql |
4303 | + AS $$ |
4304 | +DECLARE |
4305 | + vlan maasserver_vlan; |
4306 | +BEGIN |
4307 | + -- Update VLAN if DHCP is enabled, IP is set and not DISCOVERED. |
4308 | + IF NEW.alloc_type != 6 AND NEW.ip IS NOT NULL AND host(NEW.ip) != '' THEN |
4309 | + SELECT maasserver_vlan.* INTO vlan |
4310 | + FROM maasserver_vlan, maasserver_subnet |
4311 | + WHERE maasserver_subnet.id = NEW.subnet_id AND |
4312 | + maasserver_subnet.vlan_id = maasserver_vlan.id; |
4313 | + IF vlan.dhcp_on THEN |
4314 | + PERFORM sys_dhcp_alert(vlan); |
4315 | + END IF; |
4316 | + END IF; |
4317 | + RETURN NEW; |
4318 | +END; |
4319 | +$$; |
4320 | + |
4321 | + |
4322 | +ALTER FUNCTION public.sys_dhcp_staticipaddress_insert() OWNER TO gavin; |
4323 | + |
4324 | +-- |
4325 | +-- Name: sys_dhcp_staticipaddress_update(); Type: FUNCTION; Schema: public; Owner: gavin |
4326 | +-- |
4327 | + |
4328 | +CREATE FUNCTION sys_dhcp_staticipaddress_update() RETURNS trigger |
4329 | + LANGUAGE plpgsql |
4330 | + AS $$ |
4331 | +DECLARE |
4332 | + old_vlan maasserver_vlan; |
4333 | + new_vlan maasserver_vlan; |
4334 | +BEGIN |
4335 | + -- Ignore DISCOVERED IP addresses. |
4336 | + IF NEW.alloc_type != 6 THEN |
4337 | + IF OLD.subnet_id != NEW.subnet_id THEN |
4338 | + -- Subnet has changed; update each VLAN if different. |
4339 | + SELECT maasserver_vlan.* INTO old_vlan |
4340 | + FROM maasserver_vlan, maasserver_subnet |
4341 | + WHERE maasserver_subnet.id = OLD.subnet_id AND |
4342 | + maasserver_subnet.vlan_id = maasserver_vlan.id; |
4343 | + SELECT maasserver_vlan.* INTO new_vlan |
4344 | + FROM maasserver_vlan, maasserver_subnet |
4345 | + WHERE maasserver_subnet.id = NEW.subnet_id AND |
4346 | + maasserver_subnet.vlan_id = maasserver_vlan.id; |
4347 | + IF old_vlan.id != new_vlan.id THEN |
4348 | + -- Different VLAN's; update each if DHCP enabled. |
4349 | + IF old_vlan.dhcp_on THEN |
4350 | + PERFORM sys_dhcp_alert(old_vlan); |
4351 | + END IF; |
4352 | + IF new_vlan.dhcp_on THEN |
4353 | + PERFORM sys_dhcp_alert(new_vlan); |
4354 | + END IF; |
4355 | + ELSE |
4356 | + -- Same VLAN so only need to update once. |
4357 | + IF new_vlan.dhcp_on THEN |
4358 | + PERFORM sys_dhcp_alert(new_vlan); |
4359 | + END IF; |
4360 | + END IF; |
4361 | + ELSIF (OLD.ip IS NULL AND NEW.ip IS NOT NULL) OR |
4362 | + (OLD.ip IS NOT NULL and NEW.ip IS NULL) OR |
4363 | + (host(OLD.ip) != host(NEW.ip)) THEN |
4364 | + -- Assigned IP address has changed. |
4365 | + SELECT maasserver_vlan.* INTO new_vlan |
4366 | + FROM maasserver_vlan, maasserver_subnet |
4367 | + WHERE maasserver_subnet.id = NEW.subnet_id AND |
4368 | + maasserver_subnet.vlan_id = maasserver_vlan.id; |
4369 | + IF new_vlan.dhcp_on THEN |
4370 | + PERFORM sys_dhcp_alert(new_vlan); |
4371 | + END IF; |
4372 | + END IF; |
4373 | + END IF; |
4374 | + RETURN NEW; |
4375 | +END; |
4376 | +$$; |
4377 | + |
4378 | + |
4379 | +ALTER FUNCTION public.sys_dhcp_staticipaddress_update() OWNER TO gavin; |
4380 | + |
4381 | +-- |
4382 | +-- Name: sys_dhcp_subnet_delete(); Type: FUNCTION; Schema: public; Owner: gavin |
4383 | +-- |
4384 | + |
4385 | +CREATE FUNCTION sys_dhcp_subnet_delete() RETURNS trigger |
4386 | + LANGUAGE plpgsql |
4387 | + AS $$ |
4388 | +DECLARE |
4389 | + vlan maasserver_vlan; |
4390 | +BEGIN |
4391 | + -- Update VLAN if DHCP is enabled. |
4392 | + SELECT * INTO vlan |
4393 | + FROM maasserver_vlan WHERE id = OLD.vlan_id; |
4394 | + IF vlan.dhcp_on THEN |
4395 | + PERFORM sys_dhcp_alert(vlan); |
4396 | + END IF; |
4397 | + RETURN NEW; |
4398 | +END; |
4399 | +$$; |
4400 | + |
4401 | + |
4402 | +ALTER FUNCTION public.sys_dhcp_subnet_delete() OWNER TO gavin; |
4403 | + |
4404 | +-- |
4405 | +-- Name: sys_dhcp_subnet_update(); Type: FUNCTION; Schema: public; Owner: gavin |
4406 | +-- |
4407 | + |
4408 | +CREATE FUNCTION sys_dhcp_subnet_update() RETURNS trigger |
4409 | + LANGUAGE plpgsql |
4410 | + AS $$ |
4411 | +DECLARE |
4412 | + vlan maasserver_vlan; |
4413 | +BEGIN |
4414 | + -- Subnet was moved to a new VLAN. |
4415 | + IF OLD.vlan_id != NEW.vlan_id THEN |
4416 | + -- Update old VLAN if DHCP is enabled. |
4417 | + SELECT * INTO vlan |
4418 | + FROM maasserver_vlan WHERE id = OLD.vlan_id; |
4419 | + IF vlan.dhcp_on THEN |
4420 | + PERFORM sys_dhcp_alert(vlan); |
4421 | + END IF; |
4422 | + -- Update the new VLAN if DHCP is enabled. |
4423 | + SELECT * INTO vlan |
4424 | + FROM maasserver_vlan WHERE id = NEW.vlan_id; |
4425 | + IF vlan.dhcp_on THEN |
4426 | + PERFORM sys_dhcp_alert(vlan); |
4427 | + END IF; |
4428 | + -- Related fields of subnet where changed. |
4429 | + ELSIF OLD.cidr != NEW.cidr OR |
4430 | + (OLD.gateway_ip IS NULL AND NEW.gateway_ip IS NOT NULL) OR |
4431 | + (OLD.gateway_ip IS NOT NULL AND NEW.gateway_ip IS NULL) OR |
4432 | + host(OLD.gateway_ip) != host(NEW.gateway_ip) OR |
4433 | + OLD.dns_servers != NEW.dns_servers THEN |
4434 | + -- Network has changed update alert DHCP if enabled. |
4435 | + SELECT * INTO vlan |
4436 | + FROM maasserver_vlan WHERE id = NEW.vlan_id; |
4437 | + IF vlan.dhcp_on THEN |
4438 | + PERFORM sys_dhcp_alert(vlan); |
4439 | + END IF; |
4440 | + END IF; |
4441 | + RETURN NEW; |
4442 | +END; |
4443 | +$$; |
4444 | + |
4445 | + |
4446 | +ALTER FUNCTION public.sys_dhcp_subnet_update() OWNER TO gavin; |
4447 | + |
4448 | +-- |
4449 | +-- Name: sys_dhcp_update_all_vlans(); Type: FUNCTION; Schema: public; Owner: gavin |
4450 | +-- |
4451 | + |
4452 | +CREATE FUNCTION sys_dhcp_update_all_vlans() RETURNS void |
4453 | + LANGUAGE plpgsql |
4454 | + AS $$ |
4455 | +DECLARE |
4456 | + rack INTEGER; |
4457 | +BEGIN |
4458 | + FOR rack IN ( |
4459 | + WITH racks AS ( |
4460 | + SELECT primary_rack_id, secondary_rack_id FROM maasserver_vlan |
4461 | + WHERE maasserver_vlan.dhcp_on = true |
4462 | + ) |
4463 | + SELECT primary_rack_id FROM racks |
4464 | + WHERE primary_rack_id IS NOT NULL |
4465 | + UNION |
4466 | + SELECT secondary_rack_id FROM racks |
4467 | + WHERE secondary_rack_id IS NOT NULL) |
4468 | + LOOP |
4469 | + PERFORM pg_notify(CONCAT('sys_dhcp_', rack), ''); |
4470 | + END LOOP; |
4471 | + RETURN; |
4472 | +END; |
4473 | +$$; |
4474 | + |
4475 | + |
4476 | +ALTER FUNCTION public.sys_dhcp_update_all_vlans() OWNER TO gavin; |
4477 | + |
4478 | +-- |
4479 | +-- Name: sys_dhcp_vlan_update(); Type: FUNCTION; Schema: public; Owner: gavin |
4480 | +-- |
4481 | + |
4482 | +CREATE FUNCTION sys_dhcp_vlan_update() RETURNS trigger |
4483 | + LANGUAGE plpgsql |
4484 | + AS $$ |
4485 | +DECLARE |
4486 | + relay_vlan maasserver_vlan; |
4487 | +BEGIN |
4488 | + -- DHCP was turned off. |
4489 | + IF OLD.dhcp_on AND NOT NEW.dhcp_on THEN |
4490 | + PERFORM pg_notify(CONCAT('sys_dhcp_', OLD.primary_rack_id), ''); |
4491 | + IF OLD.secondary_rack_id IS NOT NULL THEN |
4492 | + PERFORM pg_notify(CONCAT('sys_dhcp_', OLD.secondary_rack_id), ''); |
4493 | + END IF; |
4494 | + -- DHCP was turned on. |
4495 | + ELSIF NOT OLD.dhcp_on AND NEW.dhcp_on THEN |
4496 | + PERFORM pg_notify(CONCAT('sys_dhcp_', NEW.primary_rack_id), ''); |
4497 | + IF NEW.secondary_rack_id IS NOT NULL THEN |
4498 | + PERFORM pg_notify(CONCAT('sys_dhcp_', NEW.secondary_rack_id), ''); |
4499 | + END IF; |
4500 | + -- DHCP state was not changed but the rack controllers might have been. |
4501 | + ELSIF NEW.dhcp_on AND ( |
4502 | + OLD.primary_rack_id != NEW.primary_rack_id OR ( |
4503 | + OLD.secondary_rack_id IS NULL AND |
4504 | + NEW.secondary_rack_id IS NOT NULL) OR ( |
4505 | + OLD.secondary_rack_id IS NOT NULL AND |
4506 | + NEW.secondary_rack_id IS NULL) OR |
4507 | + OLD.secondary_rack_id != NEW.secondary_rack_id) THEN |
4508 | + -- Send the message to the old primary if no longer the primary. |
4509 | + IF OLD.primary_rack_id != NEW.primary_rack_id THEN |
4510 | + PERFORM pg_notify(CONCAT('sys_dhcp_', OLD.primary_rack_id), ''); |
4511 | + END IF; |
4512 | + -- Always send the message to the primary as it has to be set. |
4513 | + PERFORM pg_notify(CONCAT('sys_dhcp_', NEW.primary_rack_id), ''); |
4514 | + -- Send message to both old and new secondary rack controller if set. |
4515 | + IF OLD.secondary_rack_id IS NOT NULL THEN |
4516 | + PERFORM pg_notify(CONCAT('sys_dhcp_', OLD.secondary_rack_id), ''); |
4517 | + END IF; |
4518 | + IF NEW.secondary_rack_id IS NOT NULL THEN |
4519 | + PERFORM pg_notify(CONCAT('sys_dhcp_', NEW.secondary_rack_id), ''); |
4520 | + END IF; |
4521 | + END IF; |
4522 | + |
4523 | + -- Relay VLAN was set when it was previously unset. |
4524 | + IF OLD.relay_vlan_id IS NULL AND NEW.relay_vlan_id IS NOT NULL THEN |
4525 | + SELECT maasserver_vlan.* INTO relay_vlan |
4526 | + FROM maasserver_vlan |
4527 | + WHERE maasserver_vlan.id = NEW.relay_vlan_id; |
4528 | + IF relay_vlan.primary_rack_id IS NOT NULL THEN |
4529 | + PERFORM pg_notify( |
4530 | + CONCAT('sys_dhcp_', relay_vlan.primary_rack_id), ''); |
4531 | + IF relay_vlan.secondary_rack_id IS NOT NULL THEN |
4532 | + PERFORM pg_notify( |
4533 | + CONCAT('sys_dhcp_', relay_vlan.secondary_rack_id), ''); |
4534 | + END IF; |
4535 | + END IF; |
4536 | + -- Relay VLAN was unset when it was previously set. |
4537 | + ELSIF OLD.relay_vlan_id IS NOT NULL AND NEW.relay_vlan_id IS NULL THEN |
4538 | + SELECT maasserver_vlan.* INTO relay_vlan |
4539 | + FROM maasserver_vlan |
4540 | + WHERE maasserver_vlan.id = OLD.relay_vlan_id; |
4541 | + IF relay_vlan.primary_rack_id IS NOT NULL THEN |
4542 | + PERFORM pg_notify( |
4543 | + CONCAT('sys_dhcp_', relay_vlan.primary_rack_id), ''); |
4544 | + IF relay_vlan.secondary_rack_id IS NOT NULL THEN |
4545 | + PERFORM pg_notify( |
4546 | + CONCAT('sys_dhcp_', relay_vlan.secondary_rack_id), ''); |
4547 | + END IF; |
4548 | + END IF; |
4549 | + -- Relay VLAN has changed on the VLAN. |
4550 | + ELSIF OLD.relay_vlan_id != NEW.relay_vlan_id THEN |
4551 | + -- Alert old VLAN if required. |
4552 | + SELECT maasserver_vlan.* INTO relay_vlan |
4553 | + FROM maasserver_vlan |
4554 | + WHERE maasserver_vlan.id = OLD.relay_vlan_id; |
4555 | + IF relay_vlan.primary_rack_id IS NOT NULL THEN |
4556 | + PERFORM pg_notify( |
4557 | + CONCAT('sys_dhcp_', relay_vlan.primary_rack_id), ''); |
4558 | + IF relay_vlan.secondary_rack_id IS NOT NULL THEN |
4559 | + PERFORM pg_notify( |
4560 | + CONCAT('sys_dhcp_', relay_vlan.secondary_rack_id), ''); |
4561 | + END IF; |
4562 | + END IF; |
4563 | + -- Alert new VLAN if required. |
4564 | + SELECT maasserver_vlan.* INTO relay_vlan |
4565 | + FROM maasserver_vlan |
4566 | + WHERE maasserver_vlan.id = NEW.relay_vlan_id; |
4567 | + IF relay_vlan.primary_rack_id IS NOT NULL THEN |
4568 | + PERFORM pg_notify( |
4569 | + CONCAT('sys_dhcp_', relay_vlan.primary_rack_id), ''); |
4570 | + IF relay_vlan.secondary_rack_id IS NOT NULL THEN |
4571 | + PERFORM pg_notify( |
4572 | + CONCAT('sys_dhcp_', relay_vlan.secondary_rack_id), ''); |
4573 | + END IF; |
4574 | + END IF; |
4575 | + END IF; |
4576 | + RETURN NEW; |
4577 | +END; |
4578 | +$$; |
4579 | + |
4580 | + |
4581 | +ALTER FUNCTION public.sys_dhcp_vlan_update() OWNER TO gavin; |
4582 | + |
4583 | +-- |
4584 | +-- Name: sys_dns_config_insert(); Type: FUNCTION; Schema: public; Owner: gavin |
4585 | +-- |
4586 | + |
4587 | +CREATE FUNCTION sys_dns_config_insert() RETURNS trigger |
4588 | + LANGUAGE plpgsql |
4589 | + AS $$ |
4590 | +BEGIN |
4591 | + -- Only care about the |
4592 | + IF (NEW.name = 'upstream_dns' OR |
4593 | + NEW.name = 'dnssec_validation' OR |
4594 | + NEW.name = 'default_dns_ttl' OR |
4595 | + NEW.name = 'windows_kms_host') |
4596 | + THEN |
4597 | + INSERT INTO maasserver_dnspublication |
4598 | + (serial, created, source) |
4599 | + VALUES |
4600 | + (nextval('maasserver_zone_serial_seq'), now(), substring( |
4601 | + ('Configuration ' || NEW.name || ' set to ' || |
4602 | + COALESCE(NEW.value, 'NULL')) |
4603 | + FOR 255)); |
4604 | + END IF; |
4605 | + RETURN NEW; |
4606 | +END; |
4607 | +$$; |
4608 | + |
4609 | + |
4610 | +ALTER FUNCTION public.sys_dns_config_insert() OWNER TO gavin; |
4611 | + |
4612 | +-- |
4613 | +-- Name: sys_dns_config_update(); Type: FUNCTION; Schema: public; Owner: gavin |
4614 | +-- |
4615 | + |
4616 | +CREATE FUNCTION sys_dns_config_update() RETURNS trigger |
4617 | + LANGUAGE plpgsql |
4618 | + AS $$ |
4619 | +BEGIN |
4620 | + -- Only care about the upstream_dns, default_dns_ttl, and |
4621 | + -- windows_kms_host. |
4622 | + IF (OLD.value != NEW.value AND ( |
4623 | + NEW.name = 'upstream_dns' OR |
4624 | + NEW.name = 'dnssec_validation' OR |
4625 | + NEW.name = 'default_dns_ttl' OR |
4626 | + NEW.name = 'windows_kms_host')) |
4627 | + THEN |
4628 | + INSERT INTO maasserver_dnspublication |
4629 | + (serial, created, source) |
4630 | + VALUES |
4631 | + (nextval('maasserver_zone_serial_seq'), now(), substring( |
4632 | + ('Configuration ' || NEW.name || ' changed from ' || |
4633 | + OLD.value || ' to ' || NEW.value) |
4634 | + FOR 255)); |
4635 | + END IF; |
4636 | + RETURN NEW; |
4637 | +END; |
4638 | +$$; |
4639 | + |
4640 | + |
4641 | +ALTER FUNCTION public.sys_dns_config_update() OWNER TO gavin; |
4642 | + |
4643 | +-- |
4644 | +-- Name: sys_dns_dnsdata_delete(); Type: FUNCTION; Schema: public; Owner: gavin |
4645 | +-- |
4646 | + |
4647 | +CREATE FUNCTION sys_dns_dnsdata_delete() RETURNS trigger |
4648 | + LANGUAGE plpgsql |
4649 | + AS $$ |
4650 | +BEGIN |
4651 | + INSERT INTO maasserver_dnspublication |
4652 | + (serial, created, source) |
4653 | + VALUES |
4654 | + (nextval('maasserver_zone_serial_seq'), now(), |
4655 | + substring('Call to sys_dns_dnsdata_delete' FOR 255)); |
4656 | + RETURN OLD; |
4657 | +END; |
4658 | +$$; |
4659 | + |
4660 | + |
4661 | +ALTER FUNCTION public.sys_dns_dnsdata_delete() OWNER TO gavin; |
4662 | + |
4663 | +-- |
4664 | +-- Name: sys_dns_dnsdata_insert(); Type: FUNCTION; Schema: public; Owner: gavin |
4665 | +-- |
4666 | + |
4667 | +CREATE FUNCTION sys_dns_dnsdata_insert() RETURNS trigger |
4668 | + LANGUAGE plpgsql |
4669 | + AS $$ |
4670 | +BEGIN |
4671 | + INSERT INTO maasserver_dnspublication |
4672 | + (serial, created, source) |
4673 | + VALUES |
4674 | + (nextval('maasserver_zone_serial_seq'), now(), |
4675 | + substring('Call to sys_dns_dnsdata_insert' FOR 255)); |
4676 | + RETURN NEW; |
4677 | +END; |
4678 | +$$; |
4679 | + |
4680 | + |
4681 | +ALTER FUNCTION public.sys_dns_dnsdata_insert() OWNER TO gavin; |
4682 | + |
4683 | +-- |
4684 | +-- Name: sys_dns_dnsdata_update(); Type: FUNCTION; Schema: public; Owner: gavin |
4685 | +-- |
4686 | + |
4687 | +CREATE FUNCTION sys_dns_dnsdata_update() RETURNS trigger |
4688 | + LANGUAGE plpgsql |
4689 | + AS $$ |
4690 | +BEGIN |
4691 | + INSERT INTO maasserver_dnspublication |
4692 | + (serial, created, source) |
4693 | + VALUES |
4694 | + (nextval('maasserver_zone_serial_seq'), now(), |
4695 | + substring('Call to sys_dns_dnsdata_update' FOR 255)); |
4696 | + RETURN NEW; |
4697 | +END; |
4698 | +$$; |
4699 | + |
4700 | + |
4701 | +ALTER FUNCTION public.sys_dns_dnsdata_update() OWNER TO gavin; |
4702 | + |
4703 | +-- |
4704 | +-- Name: sys_dns_dnsresource_delete(); Type: FUNCTION; Schema: public; Owner: gavin |
4705 | +-- |
4706 | + |
4707 | +CREATE FUNCTION sys_dns_dnsresource_delete() RETURNS trigger |
4708 | + LANGUAGE plpgsql |
4709 | + AS $$ |
4710 | +BEGIN |
4711 | + INSERT INTO maasserver_dnspublication |
4712 | + (serial, created, source) |
4713 | + VALUES |
4714 | + (nextval('maasserver_zone_serial_seq'), now(), |
4715 | + substring('Call to sys_dns_dnsresource_delete' FOR 255)); |
4716 | + RETURN OLD; |
4717 | +END; |
4718 | +$$; |
4719 | + |
4720 | + |
4721 | +ALTER FUNCTION public.sys_dns_dnsresource_delete() OWNER TO gavin; |
4722 | + |
4723 | +-- |
4724 | +-- Name: sys_dns_dnsresource_insert(); Type: FUNCTION; Schema: public; Owner: gavin |
4725 | +-- |
4726 | + |
4727 | +CREATE FUNCTION sys_dns_dnsresource_insert() RETURNS trigger |
4728 | + LANGUAGE plpgsql |
4729 | + AS $$ |
4730 | +BEGIN |
4731 | + INSERT INTO maasserver_dnspublication |
4732 | + (serial, created, source) |
4733 | + VALUES |
4734 | + (nextval('maasserver_zone_serial_seq'), now(), |
4735 | + substring('Call to sys_dns_dnsresource_insert' FOR 255)); |
4736 | + RETURN NEW; |
4737 | +END; |
4738 | +$$; |
4739 | + |
4740 | + |
4741 | +ALTER FUNCTION public.sys_dns_dnsresource_insert() OWNER TO gavin; |
4742 | + |
4743 | +-- |
4744 | +-- Name: sys_dns_dnsresource_ip_link(); Type: FUNCTION; Schema: public; Owner: gavin |
4745 | +-- |
4746 | + |
4747 | +CREATE FUNCTION sys_dns_dnsresource_ip_link() RETURNS trigger |
4748 | + LANGUAGE plpgsql |
4749 | + AS $$ |
4750 | +BEGIN |
4751 | + INSERT INTO maasserver_dnspublication |
4752 | + (serial, created, source) |
4753 | + VALUES |
4754 | + (nextval('maasserver_zone_serial_seq'), now(), |
4755 | + substring('Call to sys_dns_dnsresource_ip_link' FOR 255)); |
4756 | + RETURN NEW; |
4757 | +END; |
4758 | +$$; |
4759 | + |
4760 | + |
4761 | +ALTER FUNCTION public.sys_dns_dnsresource_ip_link() OWNER TO gavin; |
4762 | + |
4763 | +-- |
4764 | +-- Name: sys_dns_dnsresource_ip_unlink(); Type: FUNCTION; Schema: public; Owner: gavin |
4765 | +-- |
4766 | + |
4767 | +CREATE FUNCTION sys_dns_dnsresource_ip_unlink() RETURNS trigger |
4768 | + LANGUAGE plpgsql |
4769 | + AS $$ |
4770 | +BEGIN |
4771 | + INSERT INTO maasserver_dnspublication |
4772 | + (serial, created, source) |
4773 | + VALUES |
4774 | + (nextval('maasserver_zone_serial_seq'), now(), |
4775 | + substring('Call to sys_dns_dnsresource_ip_unlink' FOR 255)); |
4776 | + RETURN OLD; |
4777 | +END; |
4778 | +$$; |
4779 | + |
4780 | + |
4781 | +ALTER FUNCTION public.sys_dns_dnsresource_ip_unlink() OWNER TO gavin; |
4782 | + |
4783 | +-- |
4784 | +-- Name: sys_dns_dnsresource_update(); Type: FUNCTION; Schema: public; Owner: gavin |
4785 | +-- |
4786 | + |
4787 | +CREATE FUNCTION sys_dns_dnsresource_update() RETURNS trigger |
4788 | + LANGUAGE plpgsql |
4789 | + AS $$ |
4790 | +BEGIN |
4791 | + INSERT INTO maasserver_dnspublication |
4792 | + (serial, created, source) |
4793 | + VALUES |
4794 | + (nextval('maasserver_zone_serial_seq'), now(), |
4795 | + substring('Call to sys_dns_dnsresource_update' FOR 255)); |
4796 | + RETURN NEW; |
4797 | +END; |
4798 | +$$; |
4799 | + |
4800 | + |
4801 | +ALTER FUNCTION public.sys_dns_dnsresource_update() OWNER TO gavin; |
4802 | + |
4803 | +-- |
4804 | +-- Name: sys_dns_domain_delete(); Type: FUNCTION; Schema: public; Owner: gavin |
4805 | +-- |
4806 | + |
4807 | +CREATE FUNCTION sys_dns_domain_delete() RETURNS trigger |
4808 | + LANGUAGE plpgsql |
4809 | + AS $$ |
4810 | +BEGIN |
4811 | + INSERT INTO maasserver_dnspublication |
4812 | + (serial, created, source) |
4813 | + VALUES |
4814 | + (nextval('maasserver_zone_serial_seq'), now(), |
4815 | + substring('Call to sys_dns_domain_delete' FOR 255)); |
4816 | + RETURN OLD; |
4817 | +END; |
4818 | +$$; |
4819 | + |
4820 | + |
4821 | +ALTER FUNCTION public.sys_dns_domain_delete() OWNER TO gavin; |
4822 | + |
4823 | +-- |
4824 | +-- Name: sys_dns_domain_insert(); Type: FUNCTION; Schema: public; Owner: gavin |
4825 | +-- |
4826 | + |
4827 | +CREATE FUNCTION sys_dns_domain_insert() RETURNS trigger |
4828 | + LANGUAGE plpgsql |
4829 | + AS $$ |
4830 | +BEGIN |
4831 | + INSERT INTO maasserver_dnspublication |
4832 | + (serial, created, source) |
4833 | + VALUES |
4834 | + (nextval('maasserver_zone_serial_seq'), now(), |
4835 | + substring('Call to sys_dns_domain_insert' FOR 255)); |
4836 | + RETURN NEW; |
4837 | +END; |
4838 | +$$; |
4839 | + |
4840 | + |
4841 | +ALTER FUNCTION public.sys_dns_domain_insert() OWNER TO gavin; |
4842 | + |
4843 | +-- |
4844 | +-- Name: sys_dns_domain_update(); Type: FUNCTION; Schema: public; Owner: gavin |
4845 | +-- |
4846 | + |
4847 | +CREATE FUNCTION sys_dns_domain_update() RETURNS trigger |
4848 | + LANGUAGE plpgsql |
4849 | + AS $$ |
4850 | +BEGIN |
4851 | + INSERT INTO maasserver_dnspublication |
4852 | + (serial, created, source) |
4853 | + VALUES |
4854 | + (nextval('maasserver_zone_serial_seq'), now(), |
4855 | + substring('Call to sys_dns_domain_update' FOR 255)); |
4856 | + RETURN NEW; |
4857 | +END; |
4858 | +$$; |
4859 | + |
4860 | + |
4861 | +ALTER FUNCTION public.sys_dns_domain_update() OWNER TO gavin; |
4862 | + |
4863 | +-- |
4864 | +-- Name: sys_dns_interface_update(); Type: FUNCTION; Schema: public; Owner: gavin |
4865 | +-- |
4866 | + |
4867 | +CREATE FUNCTION sys_dns_interface_update() RETURNS trigger |
4868 | + LANGUAGE plpgsql |
4869 | + AS $$ |
4870 | +DECLARE |
4871 | + changes text[]; |
4872 | +BEGIN |
4873 | + IF OLD.name != NEW.name THEN |
4874 | + changes := changes || ( |
4875 | + 'renamed from ' || OLD.name || ' to ' || NEW.name); |
4876 | + END IF; |
4877 | + IF OLD.node_id IS NULL AND NEW.node_id IS NOT NULL THEN |
4878 | + changes := changes || 'node set'::text; |
4879 | + ELSIF OLD.node_id IS NOT NULL AND NEW.node_id IS NULL THEN |
4880 | + changes := changes || 'node unset'::text; |
4881 | + ELSIF OLD.node_id != NEW.node_id THEN |
4882 | + changes := changes || 'node changed'::text; |
4883 | + END IF; |
4884 | + IF array_length(changes, 1) != 0 THEN |
4885 | + INSERT INTO maasserver_dnspublication |
4886 | + (serial, created, source) |
4887 | + VALUES |
4888 | + (nextval('maasserver_zone_serial_seq'), now(), |
4889 | + substring( |
4890 | + ('Interface ' || NEW.name || ': ' || |
4891 | + array_to_string(changes, ', ')) |
4892 | + FOR 255)); |
4893 | + END IF; |
4894 | + RETURN NEW; |
4895 | +END; |
4896 | +$$; |
4897 | + |
4898 | + |
4899 | +ALTER FUNCTION public.sys_dns_interface_update() OWNER TO gavin; |
4900 | + |
4901 | +-- |
4902 | +-- Name: sys_dns_nic_ip_link(); Type: FUNCTION; Schema: public; Owner: gavin |
4903 | +-- |
4904 | + |
4905 | +CREATE FUNCTION sys_dns_nic_ip_link() RETURNS trigger |
4906 | + LANGUAGE plpgsql |
4907 | + AS $$ |
4908 | +BEGIN |
4909 | + INSERT INTO maasserver_dnspublication |
4910 | + (serial, created, source) |
4911 | + VALUES |
4912 | + (nextval('maasserver_zone_serial_seq'), now(), |
4913 | + substring('Call to sys_dns_nic_ip_link' FOR 255)); |
4914 | + RETURN NEW; |
4915 | +END; |
4916 | +$$; |
4917 | + |
4918 | + |
4919 | +ALTER FUNCTION public.sys_dns_nic_ip_link() OWNER TO gavin; |
4920 | + |
4921 | +-- |
4922 | +-- Name: sys_dns_nic_ip_unlink(); Type: FUNCTION; Schema: public; Owner: gavin |
4923 | +-- |
4924 | + |
4925 | +CREATE FUNCTION sys_dns_nic_ip_unlink() RETURNS trigger |
4926 | + LANGUAGE plpgsql |
4927 | + AS $$ |
4928 | +BEGIN |
4929 | + INSERT INTO maasserver_dnspublication |
4930 | + (serial, created, source) |
4931 | + VALUES |
4932 | + (nextval('maasserver_zone_serial_seq'), now(), |
4933 | + substring('Call to sys_dns_nic_ip_unlink' FOR 255)); |
4934 | + RETURN OLD; |
4935 | +END; |
4936 | +$$; |
4937 | + |
4938 | + |
4939 | +ALTER FUNCTION public.sys_dns_nic_ip_unlink() OWNER TO gavin; |
4940 | + |
4941 | +-- |
4942 | +-- Name: sys_dns_node_delete(); Type: FUNCTION; Schema: public; Owner: gavin |
4943 | +-- |
4944 | + |
4945 | +CREATE FUNCTION sys_dns_node_delete() RETURNS trigger |
4946 | + LANGUAGE plpgsql |
4947 | + AS $$ |
4948 | +BEGIN |
4949 | + INSERT INTO maasserver_dnspublication |
4950 | + (serial, created, source) |
4951 | + VALUES |
4952 | + (nextval('maasserver_zone_serial_seq'), now(), |
4953 | + substring('Call to sys_dns_node_delete' FOR 255)); |
4954 | + RETURN OLD; |
4955 | +END; |
4956 | +$$; |
4957 | + |
4958 | + |
4959 | +ALTER FUNCTION public.sys_dns_node_delete() OWNER TO gavin; |
4960 | + |
4961 | +-- |
4962 | +-- Name: sys_dns_node_update(); Type: FUNCTION; Schema: public; Owner: gavin |
4963 | +-- |
4964 | + |
4965 | +CREATE FUNCTION sys_dns_node_update() RETURNS trigger |
4966 | + LANGUAGE plpgsql |
4967 | + AS $$ |
4968 | +DECLARE |
4969 | + changes text[]; |
4970 | +BEGIN |
4971 | + IF OLD.hostname != NEW.hostname THEN |
4972 | + changes := changes || ( |
4973 | + 'hostname changed from ' || OLD.hostname || ' to ' || NEW.hostname); |
4974 | + END IF; |
4975 | + IF OLD.domain_id != NEW.domain_id THEN |
4976 | + changes := changes || 'domain changed'::text; |
4977 | + END IF; |
4978 | + IF array_length(changes, 1) != 0 THEN |
4979 | + INSERT INTO maasserver_dnspublication |
4980 | + (serial, created, source) |
4981 | + VALUES |
4982 | + (nextval('maasserver_zone_serial_seq'), now(), |
4983 | + substring( |
4984 | + ('Node ' || NEW.system_id || ': ' || |
4985 | + array_to_string(changes, ', ')) |
4986 | + FOR 255)); |
4987 | + END IF; |
4988 | + RETURN NEW; |
4989 | +END; |
4990 | +$$; |
4991 | + |
4992 | + |
4993 | +ALTER FUNCTION public.sys_dns_node_update() OWNER TO gavin; |
4994 | + |
4995 | +-- |
4996 | +-- Name: sys_dns_publish(); Type: FUNCTION; Schema: public; Owner: gavin |
4997 | +-- |
4998 | + |
4999 | +CREATE FUNCTION sys_dns_publish() RETURNS trigger |
5000 | + LANGUAGE plpgsql |
Looked through the code and I am still some what confused? What is legacy tests? I assume those must run as well when doing "make test"?
Looking at the code it was hard to see the difference between a legacy test and a none legacy test. Also no documentation on when legacy should be used over a standard test type. Is this something where we need to do work on tests that use legacy to remove this new "test.region- legacy" ?