~ltrager/maas/remove_di_from_kernel_opts

« back to all changes in this revision

Viewing changes to src/maasserver/triggers/websocket.py

  • Committer: Lee Trager
  • Date: 2016-10-22 06:06:12 UTC
  • mfrom: (5457.1.44 maas)
  • Revision ID: lee.trager@canonical.com-20161022060612-ukar20f6ffs45nas
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
687
687
    $$ LANGUAGE plpgsql;
688
688
    """)
689
689
 
 
690
# Procedure that is called when an IP range is created to update its related
 
691
# subnet.
 
692
IP_RANGE_SUBNET_INSERT_NOTIFY = dedent("""\
 
693
    CREATE OR REPLACE FUNCTION %s() RETURNS trigger AS $$
 
694
    BEGIN
 
695
      IF NEW.subnet_id IS NOT NULL THEN
 
696
        PERFORM pg_notify('subnet_update',CAST(NEW.subnet_id AS text));
 
697
      END IF;
 
698
      RETURN NEW;
 
699
    END;
 
700
    $$ LANGUAGE plpgsql;
 
701
    """)
 
702
 
 
703
# Procedure that is called when an IP range is updated to update its related
 
704
# subnet.
 
705
IP_RANGE_SUBNET_UPDATE_NOTIFY = dedent("""\
 
706
    CREATE OR REPLACE FUNCTION %s() RETURNS trigger AS $$
 
707
    BEGIN
 
708
      IF OLD.subnet_id != NEW.subnet_id THEN
 
709
        IF OLD.subnet_id IS NOT NULL THEN
 
710
          PERFORM pg_notify('subnet_update',CAST(OLD.subnet_id AS text));
 
711
        END IF;
 
712
      END IF;
 
713
      IF NEW.subnet_id IS NOT NULL THEN
 
714
        PERFORM pg_notify('subnet_update',CAST(NEW.subnet_id AS text));
 
715
      END IF;
 
716
      RETURN NEW;
 
717
    END;
 
718
    $$ LANGUAGE plpgsql;
 
719
    """)
 
720
 
 
721
# Procedure that is called when an IP range is deleted to update its related
 
722
# subnet.
 
723
IP_RANGE_SUBNET_DELETE_NOTIFY = dedent("""\
 
724
    CREATE OR REPLACE FUNCTION %s() RETURNS trigger AS $$
 
725
    BEGIN
 
726
      IF OLD.subnet_id IS NOT NULL THEN
 
727
        PERFORM pg_notify('subnet_update',CAST(OLD.subnet_id AS text));
 
728
      END IF;
 
729
      RETURN OLD;
 
730
    END;
 
731
    $$ LANGUAGE plpgsql;
 
732
    """)
 
733
 
690
734
# Procedure that is called when a DNSData entry is changed.
691
735
DNSDATA_DOMAIN_NOTIFY = dedent("""\
692
736
    CREATE OR REPLACE FUNCTION %s() RETURNS trigger AS $$
1134
1178
        "maasserver_staticipaddress",
1135
1179
        "ipaddress_domain_delete_notify", "delete")
1136
1180
 
 
1181
    # IP range subnet notifications
 
1182
    register_procedure(
 
1183
        IP_RANGE_SUBNET_INSERT_NOTIFY % 'iprange_subnet_insert_notify')
 
1184
    register_procedure(
 
1185
        IP_RANGE_SUBNET_UPDATE_NOTIFY % 'iprange_subnet_update_notify')
 
1186
    register_procedure(
 
1187
        IP_RANGE_SUBNET_DELETE_NOTIFY % 'iprange_subnet_delete_notify')
 
1188
    register_trigger(
 
1189
        "maasserver_iprange",
 
1190
        "iprange_subnet_insert_notify", "insert")
 
1191
    register_trigger(
 
1192
        "maasserver_iprange",
 
1193
        "iprange_subnet_update_notify", "update")
 
1194
    register_trigger(
 
1195
        "maasserver_iprange",
 
1196
        "iprange_subnet_delete_notify", "delete")
 
1197
 
1137
1198
    # DNSData table
1138
1199
    register_procedure(
1139
1200
        DNSDATA_DOMAIN_NOTIFY % (