← Back to team overview

sts-sponsors team mailing list archive

Re: [Merge] ~cgrabowski/maas:fix_node_dns_generation into maas:master

 


Diff comments:

> diff --git a/src/maasserver/triggers/system.py b/src/maasserver/triggers/system.py
> index a18fe8a..ed32c70 100644
> --- a/src/maasserver/triggers/system.py
> +++ b/src/maasserver/triggers/system.py
> @@ -2054,6 +2054,123 @@ def render_dns_dynamic_update_subnet_procedure(op):
>      )
>  
>  
> +def render_dns_dynamic_update_interface_static_ip_address(op):
> +    return dedent(
> +        f"""\
> +        CREATE OR REPLACE FUNCTION sys_dns_updates_interface_ip_{op}()
> +        RETURNS trigger as $$
> +        DECLARE
> +          current_hostname text;
> +          domain_id bigint;
> +          domain text;
> +          iface_name text;
> +          ip_addr text;
> +          address_ttl int;
> +        BEGIN
> +          ASSERT TG_WHEN = 'AFTER', 'May only run as an AFTER trigger';
> +          ASSERT TG_LEVEL <> 'STATEMENT', 'Should not be used as a STATEMENT level trigger', TG_NAME;
> +          IF (TG_OP = 'INSERT' AND TG_LEVEL = 'ROW') THEN
> +            SELECT iface.name, node.hostname, node.domain_id INTO iface_name, current_hostname, domain_id FROM maasserver_interface AS iface
> +              JOIN maasserver_node AS node ON iface.node_config_id = node.current_config_id WHERE iface.id=NEW.interface_id;
> +            SELECT name, COALESCE(ttl, 0) INTO domain, address_ttl FROM maasserver_domain WHERE id=domain_id;

+1

> +            SELECT host(ip) INTO ip_addr FROM maasserver_staticipaddress WHERE id=NEW.staticipaddress_id;
> +            PERFORM pg_notify('sys_dns_updates', 'INSERT ' || domain || ' ' || current_hostname || ' A ' || address_ttl || ' ' || ip_addr);
> +            PERFORM pg_notify('sys_dns_updates', 'INSERT ' || domain || ' ' || iface_name || '.' || current_hostname || ' A ' || address_ttl || ' ' || ip_addr);
> +          ELSIF (TG_OP = 'DELETE' AND TG_LEVEL = 'ROW') THEN
> +            IF EXISTS(SELECT id FROM maasserver_interface WHERE id=OLD.interface_id) THEN
> +                SELECT iface.name, node.hostname, node.domain_id INTO iface_name, current_hostname, domain_id FROM maasserver_interface AS iface
> +                  JOIN maasserver_node AS node ON iface.node_config_id = node.current_config_id WHERE iface.id=OLD.interface_id;
> +                SELECT name INTO domain FROM maasserver_domain WHERE id=domain_id;
> +                IF EXISTS(SELECT id FROM maasserver_staticipaddress WHERE id=OLD.staticipaddress_id) THEN
> +                  SELECT host(ip) INTO ip_addr FROM maasserver_staticipaddress WHERE id=OLD.staticipaddress_id;
> +                  PERFORM pg_notify('sys_dns_updates', 'DELETE ' || domain || ' ' || current_hostname || ' A ' || ip_addr);
> +                  PERFORM pg_notify('sys_dns_updates', 'DELETE ' || domain || ' ' || iface_name || '.' || current_hostname || ' A ' || ip_addr);
> +                ELSE
> +                  PERFORM pg_notify('sys_dns_updates', 'DELETE-IFACE-IP ' || domain || ' ' || current_hostname || ' A ' || OLD.interface_id);
> +                  PERFORM pg_notify('sys_dns_updates', 'DELETE-IFACE-IP ' || domain || ' ' || current_hostname || ' AAAA ' || OLD.interface_id);
> +                END IF;
> +            END IF;
> +          END IF;
> +          RETURN NULL;
> +        END;
> +        $$ LANGUAGE plpgsql;
> +        """
> +    )
> +
> +
> +dns_dynamic_update_static_ip_address_update = dedent(
> +    """\
> +    CREATE OR REPLACE FUNCTION sys_dns_updates_ip_update()
> +    RETURNS trigger as $$
> +    DECLARE
> +      current_hostname text;
> +      domain_id bigint;
> +      domain text;
> +      iface_name text;
> +      address_ttl int;
> +      current_interface_id bigint;
> +    BEGIN
> +      IF NEW IS DISTINCT FROM OLD THEN
> +        IF EXISTS(SELECT id FROM maasserver_interface_ip_addresses WHERE staticipaddress_id=NEW.id) THEN
> +          SELECT interface_id INTO current_interface_id FROM maasserver_interface_ip_addresses WHERE staticipaddress_id=NEW.id;
> +          SELECT iface.name, node.hostname, node.domain_id INTO iface_name, current_hostname, domain_id FROM maasserver_interface AS iface
> +            JOIN maasserver_node AS node ON iface.node_config_id = node.current_config_id WHERE iface.id=current_interface_id;
> +          SELECT name, COALESCE(ttl, 0) INTO domain, address_ttl FROM maasserver_domain WHERE id=domain_id;
> +          IF OLD.ip IS NOT NULL THEN
> +            PERFORM pg_notify('sys_dns_updates', 'DELETE ' || domain || ' ' || current_hostname || ' A ' || host(OLD.ip));
> +            PERFORM pg_notify('sys_dns_updates', 'DELETE ' || domain || ' ' || iface_name || '.' || current_hostname || ' A ' || host(OLD.ip));
> +          END IF;
> +          PERFORM pg_notify('sys_dns_updates', 'INSERT ' || domain || ' ' || current_hostname || ' A ' || address_ttl || ' ' || host(NEW.ip));
> +          PERFORM pg_notify('sys_dns_updates', 'INSERT ' || domain || ' ' || iface_name || '.' || current_hostname || ' A ' || address_ttl || ' ' || host(NEW.ip));
> +        END IF;
> +      END IF;
> +      RETURN NULL;
> +    END;
> +    $$ LANGUAGE plpgsql;
> +    """
> +)
> +
> +dns_dynamic_update_node_delete = dedent(
> +    """\
> +    CREATE OR REPLACE FUNCTION sys_dns_updates_maasserver_node_delete()
> +    RETURNS trigger as $$
> +    DECLARE
> +      hostname text;
> +      domain text;
> +      address_ttl int;
> +    BEGIN
> +      SELECT name, COALESCE(ttl, 0) INTO domain, address_ttl FROM maasserver_domain WHERE id=OLD.domain_id;
> +      PERFORM pg_notify('sys_dns_updates', 'DELETE ' || domain || ' ' || OLD.hostname || ' A');
> +      RETURN NULL;
> +    END;
> +    $$ LANGUAGE plpgsql;
> +    """
> +)
> +
> +
> +dns_dynamic_update_interface_delete = dedent(
> +    """\
> +    CREATE OR REPLACE FUNCTION sys_dns_updates_maasserver_interface_delete()
> +    RETURNS trigger as $$
> +    DECLARE
> +      current_hostname text;
> +      current_domain_id bigint;
> +      domain text;
> +      current_node_id bigint;
> +    BEGIN
> +      IF EXISTS(SELECT id FROM maasserver_nodeconfig WHERE id=OLD.node_config_id) THEN
> +        SELECT node_id INTO current_node_id FROM maasserver_nodeconfig WHERE id=OLD.node_config_id;
> +        SELECT hostname, domain_id INTO current_hostname, current_domain_id FROM maasserver_node WHERE id=current_node_id;
> +        SELECT name INTO domain FROM maasserver_domain WHERE id=current_domain_id;
> +        PERFORM pg_notify('sys_dns_updates', 'DELETE ' || domain || ' ' || OLD.name || '.' || current_hostname || ' A');
> +      END IF;
> +      RETURN NULL;
> +    END;
> +    $$ LANGUAGE plpgsql;
> +    """
> +)
> +
> +
>  def render_sys_proxy_procedure(proc_name, on_delete=False):
>      """Render a database procedure with name `proc_name` that notifies that a
>      proxy update is needed.
> diff --git a/src/provisioningserver/dns/zoneconfig.py b/src/provisioningserver/dns/zoneconfig.py
> index 13dca69..36b23bb 100644
> --- a/src/provisioningserver/dns/zoneconfig.py
> +++ b/src/provisioningserver/dns/zoneconfig.py
> @@ -170,6 +170,18 @@ class DomainConfigBase:
>          else:
>              return True
>  
> +    def journal_file_exists(self, zone_info):
> +        try:
> +            os.stat(f"{zone_info.target_path}.jnl")
> +        except FileNotFoundError:
> +            return False
> +        else:
> +            return True
> +
> +    def _remove_journal_file(self, zone_info):
> +        if self.journal_file_exists(zone_info):
> +            os.unlink(f"{zone_info.target_path}.jnl")

+1

> +
>      def dynamic_update(self, zone_info):
>          nsupdate = NSUpdateCommand(
>              zone_info.zone_name,


-- 
https://code.launchpad.net/~cgrabowski/maas/+git/maas/+merge/434522
Your team MAAS Committers is subscribed to branch maas:master.



References