Skip to content

hostnamed: add JSON output to hostnamectl - #19451

Merged
poettering merged 9 commits into
systemd:mainfrom
poettering:hostnamed-json
Apr 29, 2021
Merged

poettering merged 9 commits into
systemd:mainfrom
poettering:hostnamed-json

Conversation

@poettering

Copy link
Copy Markdown
Member

This is inspired by various PRs that are curently pending: we probably need a nice way how we can systematically provide a parsable interface in our tool. Given we have structured data to output I figure this should be JSON.

Now, we could convert to JSON client side, but that's always lossy, and means we'd propagate D-Bus semantics into JSON. Moreover if we add varlink interfaces later on anyway, it makes sense to generate the data in JSON right-away.

So this is more than just a specific implementation of this idea for hostnamed: it's a proposal that all across the board we should add a "Describe" method like here to all objects we maintain, that return a comprehensive JSON description of the object in question. The tools should then retrieve this data and output it, possibly prettified. Users can pick out individual fields with "jq" then.

many of our tools that do not involve a D-Bus service already output JSON natively. This is an attempt to open this up for D-Bus daemons too, i.e. to marry the D-Bus world and the JSON world a bit.

Comment thread src/hostname/hostnamed.c Outdated
SD_BUS_PARAM(uuid),
method_get_product_uuid,
SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD_WITH_NAMES("Describe",

@yuwata yuwata Apr 29, 2021 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why Describe is method, rather than property?

Maybe, it is better to use SD_BUS_METHOD_WITH_ARGS macro.

@poettering poettering Apr 29, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Three reasons:

  1. Properties must be quick to query, shouldn't fail to query. This is implied by clients such as gdbus that query/cache them. However, here we actually ask Polkit for auth if the client is unprivileged, and if the auth works we'll include the product uuid in it, and if not we set null instead. Doing polkit already means: you cannot expose this as property. I mean, that's why GetProductUUID() is a method and not a property, already.

  2. The data is quite comprehensive, and redundant. Exposing large fields as props is a bit icky, since clients query them with GetAllProperties(), under the assumption that's reasonably cheap and not redundant. But pretty much everything we expose here is already available as dbus property, hence it doesn't bring much to the table if it is a property except it's redundant as property.

  3. I think philosophically Describe() is a lot like GetAllProperties(), i.e. it's an API to get a full description of the object. People should choose one, or the other way to get, but it if we'd nest one in the other, by making the JSON description a property, then they couldn't choose. i.e. we want these to be alternative ways to query the data, and not make one a primary concept and the other a secondary concept tied to it.

Does that make sense?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, Thanks. I will also try to implement Describe() in networkd.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to use SD_BUS_METHOD_WITH_ARGS, but it doesn't work, and I don't grok C preprocessor stuff well enough to fix it. see #19468

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... OK. let's convert to SD_BUS_METHOD_WITH_ARGS after #19468 is fixed.

Comment thread src/libsystemd/sd-id128/id128-util.c Resolved
Comment thread src/libsystemd/sd-id128/id128-util.c Resolved
Comment thread src/hostname/hostnamed.c Resolved

@bluca bluca left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me, just a couple minor comments

@bluca

bluca commented Apr 29, 2021

Copy link
Copy Markdown
Member

as per usual, would be good to have integration tests for this - unfortunately there's very little coverage of hostnamed under test/, just something in test/networkd-test.py to check the hostname

@poettering

Copy link
Copy Markdown
Member Author

as per usual, would be good to have integration tests for this

integration tests? what's that? ;-)

@poettering

Copy link
Copy Markdown
Member Author

Force pushed a new version, addressing the raised issues. The dbus interface docs need updating once #19468 is addressed, but I'd consider that a separate issue.

Upgrading green label, since these were such minor changes.

@poettering poettering added good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed and removed good-to-merge/with-minor-suggestions labels Apr 29, 2021
@poettering

Copy link
Copy Markdown
Member Author

CI failures appear unrelated.

@poettering
poettering merged commit 34bcc67 into systemd:main Apr 29, 2021
@keszybz keszybz removed the good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed label Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

4 participants