Merge lp:~allenap/maas/non-django-database-test into lp:~maas-committers/maas/trunk

Proposed by Gavin Panella
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
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/Launchpad/maas/trunk
 Makefile                                                        |   14
 buildout.cfg                                                    |   58
 src/maasserver/__main__.py                                      |    9
 src/maasserver/api/tests/test_discoveries.py                    |    7
 src/maasserver/api/tests/test_events.py                         |    1
 src/maasserver/api/tests/test_interfaces.py                     |    2
 src/maasserver/api/tests/test_ipaddresses.py                    |   10
 src/maasserver/api/tests/test_machine.py                        |   11
 src/maasserver/clusterrpc/tests/test_boot_images.py             |    3
 src/maasserver/dns/tests/test_config.py                         |    6
 src/maasserver/dns/tests/test_zonegenerator.py                  |   11
 src/maasserver/management/commands/dbupgrade.py                 |    7
 src/maasserver/models/signals/tests/test_nodes.py               |    7
 src/maasserver/models/tests/test_config.py                      |   33
 src/maasserver/models/tests/test_discovery.py                   |    5
 src/maasserver/models/tests/test_dnspublication.py              |    7
 src/maasserver/models/tests/test_interface.py                   |   14
 src/maasserver/models/tests/test_managers.py                    |    6
 src/maasserver/models/tests/test_node.py                        |   15
 src/maasserver/models/tests/test_staticipaddress.py             |    7
 src/maasserver/models/tests/test_subnet.py                      |   18
 src/maasserver/models/tests/test_timestampedmodel.py            |    6
 src/maasserver/regiondservices/tests/test_ntp.py                |    6
 src/maasserver/static/js/angular/factories/events.js            |    2
 src/maasserver/static/js/angular/factories/tests/test_events.js |    2
 src/maasserver/testing/api.py                                   |    1
 src/maasserver/testing/initial.maas_test.sql                    |13757 ++++++++++
 src/maasserver/testing/resources.py                             |  261
 src/maasserver/testing/testcase.py                              |  119
 src/maasserver/testing/tests/test_sampledata.py                 |    5
 src/maasserver/tests/test_auth.py                               |    5
 src/maasserver/tests/test_commands_dbupgrade.py                 |    4
 src/maasserver/tests/test_dbviews.py                            |    5
 src/maasserver/tests/test_eventloop.py                          |    3
 src/maasserver/tests/test_fields.py                             |   17
 src/maasserver/tests/test_forms_helpers.py                      |    4
 src/maasserver/tests/test_forms_interface_link.py               |   46
 src/maasserver/tests/test_ntp.py                                |   13
 src/maasserver/tests/test_preseed.py                            |   13
 src/maasserver/tests/test_routablepairs.py                      |    5
 src/maasserver/triggers/system.py                               |    3
 src/maasserver/triggers/tests/test_system_listener.py           |   17
 src/maasserver/utils/tests/test_signals.py                      |    4
 src/maasserver/utils/tests/test_threads.py                      |    5
 src/maasserver/views/tests/test_account.py                      |   11
 src/maasserver/views/tests/test_general.py                      |    4
 src/maasserver/websockets/handlers/tests/test_device.py         |    6
 src/maasserver/websockets/handlers/tests/test_discovery.py      |    5
 src/maastesting/djangotestcase.py                               |   16
 src/maastesting/testcase.py                                     |   29
 src/maastesting/twisted.py                                      |   19
 src/metadataserver/nodeinituser.py                              |   17
 src/metadataserver/tests/test_fields.py                         |    4
 src/metadataserver/tests/test_vendor_data.py                    |    2
 src/metadataserver/user_data/disk_erasing.py                    |    2
 src/metadataserver/user_data/tests/test_disk_erasing.py         |    2
 56 files changed, 14375 insertions(+), 296 deletions(-)

To post a comment you must log in.
Revision history for this message
Blake Rouse (blake-rouse) 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-legacy"?

review: Needs Information
Revision history for this message
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-legacy"?

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 TestMAASModelForm(MAASLegacyTransactionServerTestCase):

      apps = ['maasserver.tests']

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_sends_message_for_config_windows_kms_host_insert
  test_sends_message_for_config_windows_kms_host_update

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.region.legacy so we won't be able to land broken
legacy tests.

Revision history for this message
Blake Rouse (blake-rouse) wrote :

Okay thanks for the information.

review: Approve

Preview Diff

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