feat(node): return bare IP addresses for attributes declaring allow_prefix [INFP-551]
Counterpart to opsmill/infrahub#10081, the first PR in the Infrahub-side stack for INFP-551.
Why
Infrahub is gaining a parameters.allow_prefix declaration on IPHost attributes. When it is false, the
attribute holds a bare IP address — 10.0.0.1 rather than the 10.0.0.1/32 the server previously
invented — and a real subnet prefix is refused.
Without this change the SDK re-attaches the mask the server just removed: every IPHost response is parsed
with ipaddress.ip_interface, so a bare 10.0.0.1 becomes IPv4Interface('10.0.0.1/32') and the mask
reappears at the SDK boundary. That directly contradicts the feature's contract, which is why this ships
alongside the server change rather than after it.
What changed
- Value coercion (
node/attribute.py): forIPHost, selectipaddress.ip_addresswhenallow_prefix
isFalseandipaddress.ip_interfaceotherwise. The flag is read tolerantly as
(self._schema.parameters or {}).get("allow_prefix", True), becauseAttributeSchemaAPI.parametersis
dict[str, Any] | None— an SDK talking to an older server that does not send the key behaves exactly as
it does today. - Removed the dead
"IPAddress"kind key. No such attribute kind exists server-side: the generated
AttributeKindenum has noIPADDRESSmember, and two tests exercising it were already skipped citing
that. Theip_addresscallable it referenced becomes the declared-IPHostbranch. - Protocol generation (
protocols_generator/generator.py): emitIPAddress/IPAddressOptionalfor a
declared attribute,IPHost/IPHostOptionalotherwise, composing with the existing
optional and default_value is Nonesuffix rule. All four protocol names were already registered and
imported, so no change was needed toconstants.py,protocols_base.py, ortemplate.j2. - Regenerated
schema/generated/{read,write}.py, which gainIPHostAttributeParameters{Read,Write}and
IPHostAttribute{Read,Write}, withAttributeKind.IPHOSTmoving out of the generic variant. - Documented the version floor in the compatibility matrix.
Why the generated models matter to the server
More than a type nicety: SchemaLoadAPI on the server inherits these write models. Without
IPHostAttributeWrite, an IPHost attribute matches GenericAttributeWrite, whose parameters is
field-less with extra="ignore" — so allow_prefix is silently dropped from every schema-load payload
and the server-side feature is inert. The Infrahub PR cannot pass CI until this branch is available.
How to review
node/attribute.py and protocols_generator/generator.py are the whole change; everything else is
generated output or tests.
Coverage follows a three-way pattern rather than two: declared, undeclared, and schema payload
with no allow_prefix key at all — the last being the old-server tolerance case, which is the one most
likely to regress silently.
test_node_IPHost_deserialization_honours_allow_prefix— 7 cases × 2 client typestest_filter_render_iphost_attribute— 8 cases- Two previously-skipped
IPAddresstests repurposed onto declaredIPHostrather than deleted
Merge order
This should merge before opsmill/infrahub#10081. That PR pins this branch's commit provisionally so
both can be reviewed in parallel; once this merges, the Infrahub submodule pointer is re-pinned to the
merged commit and confirmed an ancestor of infrahub-develop.
Summary by cubic
Return bare IP addresses for IPHost attributes that set parameters.allow_prefix: false, and mark them as IPAddress in generated protocols. Addresses INFP-551 by delivering bare IPs without a new attribute kind, while keeping old-server behavior.
-
New Features
- Coerce
IPHostwithipaddress.ip_addresswhenallow_prefixis false; otherwise useipaddress.ip_interface. - Generate
IPAddress/IPAddressOptionaltypes for flaggedIPHost; otherwise keepIPHost/IPHostOptional. - Add
IPHostAttribute{Read,Write}withparameters.allow_prefix(regenerated after description tweak) and update compatibility docs with min versions (SDK ≥ 1.23.0, Infrahub ≥ 1.11).
- Coerce
-
Migration
- Behavior change: flagged attributes return
IPv4Address/IPv6Address(no mask) instead of interfaces. - Compatibility: older servers are safe; when
allow_prefixis absent, values remain interfaces. The server must be ≥ 1.11 to publish the flag.
- Behavior change: flagged attributes return