sts-sponsors team mailing list archive
-
sts-sponsors team
-
Mailing list archive
-
Message #04081
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..6b19e2b 100644
> --- a/src/maasserver/triggers/system.py
> +++ b/src/maasserver/triggers/system.py
> @@ -2054,6 +2054,134 @@ 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;
> + default_domain_id bigint;
> + domain text;
> + iface_name text;
> + ip_addr text;
> + address_ttl int;
> + current_node_config_id bigint;
> + current_node_id bigint;
> + 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;
> + SELECT domain_id INTO default_domain_id FROM maasserver_globaldefault LIMIT 1;
ah we do, will change.
> + SELECT name, COALESCE(ttl, 0) INTO domain, address_ttl FROM maasserver_domain WHERE id=default_domain_id;
> + IF (TG_OP = 'INSERT' AND TG_LEVEL = 'ROW') THEN
> + SELECT name, node_config_id INTO iface_name, current_node_config_id FROM maasserver_interface WHERE id=NEW.interface_id;
> + SELECT node_id INTO current_node_id FROM maasserver_nodeconfig WHERE id=current_node_config_id;
> + SELECT hostname INTO current_hostname FROM maasserver_node WHERE id=current_node_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 name, node_config_id INTO iface_name, current_node_config_id FROM maasserver_interface WHERE id=OLD.interface_id;
> + SELECT node_id INTO current_node_id FROM maasserver_nodeconfig WHERE id=current_node_config_id;
> + SELECT hostname INTO current_hostname FROM maasserver_node WHERE id=current_node_id;
+1
> + 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;
> + default_domain_id bigint;
> + domain text;
> + iface_name text;
> + address_ttl int;
> + current_node_config_id bigint;
> + current_node_id bigint;
> + 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 domain_id INTO default_domain_id FROM maasserver_globaldefault LIMIT 1;
> + SELECT name, COALESCE(ttl, 0) INTO domain, address_ttl FROM maasserver_domain WHERE id=default_domain_id;
> + SELECT interface_id INTO current_interface_id FROM maasserver_interface_ip_addresses WHERE staticipaddress_id=NEW.id;
> + SELECT node_config_id, name INTO current_node_config_id, iface_name FROM maasserver_interface WHERE id=current_interface_id;
> + SELECT node_id INTO current_node_id FROM maasserver_nodeconfig WHERE id=current_node_config_id;
+1
> + SELECT hostname INTO current_hostname FROM maasserver_node WHERE id=current_node_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;
> + default_domain_id bigint;
> + domain text;
> + address_ttl int;
> + BEGIN
> + SELECT domain_id INTO default_domain_id FROM maasserver_globaldefault LIMIT 1;
> + SELECT name, COALESCE(ttl, 0) INTO domain, address_ttl FROM maasserver_domain WHERE id=default_domain_id;
> + PERFORM pg_notify('sys_dns_updates', 'DELETE ' || domain || ' ' || OLD.hostname || ' A');
So yes, this isn't ideal, but in the DB we don't have an easy way of knowing if the IP is a V4 or a V6, so we handle that when processing the notify instead. The only place where we also use AAAA are in the DELETE-IP and DELETE-IFACE-IP where that checks for all other IPs assigned to that resource / node and each is processed into updates for A or AAAA.
> + 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;
> + default_domain_id bigint;
> + domain text;
> + current_node_id bigint;
> + BEGIN
> + SELECT domain_id INTO default_domain_id FROM maasserver_globaldefault LIMIT 1;
> + SELECT name INTO domain FROM maasserver_domain WHERE id=default_domain_id;
> + 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 INTO current_hostname FROM maasserver_node WHERE id=current_node_id;
> + PERFORM pg_notify('sys_dns_updates', 'DELETE ' || domain || ' ' || OLD.name || '.' || current_hostname || ' A');
Same as above, here we can't easily determine V4 or V6, so it's done when processing the notify
> + 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.
--
https://code.launchpad.net/~cgrabowski/maas/+git/maas/+merge/434522
Your team MAAS Committers is subscribed to branch maas:master.
References