-
Notifications
You must be signed in to change notification settings - Fork 69
Hostname handling #2142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Hostname handling #2142
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
06b75b5
Fix some bootloader comments
teclator 3955e43
Added specific hostname management support
teclator b2d1575
Allow to set the persistent hostname through cmdline
teclator d8ee5df
Do not expose the hostname dhcp settings by now
teclator d6ea67e
Allow to disable set hostname by DHCP
teclator 5dab1cc
Ensure the directory exists
teclator 2ed4a57
Added hostname install settings
teclator 5914e58
Added changelog
teclator eecced9
Fix copyright year
teclator b967cc5
Some fixes based on code review
teclator 46ba799
Make the hostname settings optional
teclator 65e3ab8
Do not clone but use a reference
teclator File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
live/root/usr/lib/dracut/modules.d/99agama-cmdline/save-agama-conf.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #! /bin/sh | ||
|
|
||
| [ -e /dracut-state.sh ] && . /dracut-state.sh | ||
|
|
||
| . /lib/dracut-lib.sh | ||
|
|
||
| if [ -e /etc/hostname ]; then | ||
| cp /etc/hostname "$NEWROOT/etc/hostname" | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,12 @@ | ||
| ------------------------------------------------------------------- | ||
| Wed Mar 12 17:17:08 UTC 2025 - Knut Anderssen <[email protected]> | ||
|
|
||
| - (gh#agama-project/agama#2142) | ||
| - Allow to set the static hostname using the hostname kernel | ||
| cmdline argument. | ||
| - Allow to disable the set of the hostname via DHCP using the | ||
| SetHostname kernel cmdline argument. | ||
|
|
||
| ------------------------------------------------------------------- | ||
| Tue Mar 11 16:29:40 UTC 2025 - Ladislav Slezák <[email protected]> | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // Copyright (c) [2025] SUSE LLC | ||
| // | ||
| // All Rights Reserved. | ||
| // | ||
| // This program is free software; you can redistribute it and/or modify it | ||
| // under the terms of the GNU General Public License as published by the Free | ||
| // Software Foundation; either version 2 of the License, or (at your option) | ||
| // any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, but WITHOUT | ||
| // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
| // more details. | ||
| // | ||
| // You should have received a copy of the GNU General Public License along | ||
| // with this program; if not, contact SUSE LLC. | ||
| // | ||
| // To contact SUSE LLC about this file by physical or electronic mail, you may | ||
| // find current contact information at www.suse.com. | ||
|
|
||
| //! Implements support for handling the hostname settings | ||
|
|
||
| pub mod client; | ||
| pub mod http_client; | ||
| pub mod model; | ||
| pub mod store; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| // Copyright (c) [2025] SUSE LLC | ||
| // | ||
| // All Rights Reserved. | ||
| // | ||
| // This program is free software; you can redistribute it and/or modify it | ||
| // under the terms of the GNU General Public License as published by the Free | ||
| // Software Foundation; either version 2 of the License, or (at your option) | ||
| // any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, but WITHOUT | ||
| // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
| // more details. | ||
| // | ||
| // You should have received a copy of the GNU General Public License along | ||
| // with this program; if not, contact SUSE LLC. | ||
| // | ||
| // To contact SUSE LLC about this file by physical or electronic mail, you may | ||
| // find current contact information at www.suse.com. | ||
|
|
||
| //! Implements a client to access Hostnamed D-Bus API related to hostname management. | ||
|
|
||
| use crate::{error::ServiceError, hostname::model::HostnameSettings, proxies::Hostname1Proxy}; | ||
|
|
||
| /// Client to connect to org.freedesktop.hostname1 DBUS API on the system bus for Hostname management. | ||
| #[derive(Clone)] | ||
| pub struct HostnameClient<'a> { | ||
| hostname_proxy: Hostname1Proxy<'a>, | ||
| } | ||
|
|
||
| impl<'a> HostnameClient<'a> { | ||
| pub async fn new() -> Result<HostnameClient<'a>, ServiceError> { | ||
| let connection = zbus::Connection::system().await?; | ||
| let hostname_proxy = Hostname1Proxy::new(&connection).await?; | ||
|
|
||
| Ok(Self { hostname_proxy }) | ||
| } | ||
|
|
||
| pub async fn get_config(&self) -> Result<HostnameSettings, ServiceError> { | ||
| let hostname = self.hostname_proxy.hostname().await?; | ||
| let static_hostname = self.hostname_proxy.static_hostname().await?; | ||
|
|
||
| let settings = HostnameSettings { | ||
| hostname: Some(hostname), | ||
| static_hostname: Some(static_hostname), | ||
| ..Default::default() | ||
| }; | ||
|
|
||
| Ok(settings) | ||
| } | ||
|
|
||
| pub async fn set_config(&self, config: &HostnameSettings) -> Result<(), ServiceError> { | ||
| let settings = self.get_config().await?; | ||
|
|
||
| // order is important as otherwise the transient hostname could not be set in case the | ||
| // static one is not empty | ||
| if let Some(config_static_hostname) = &config.static_hostname { | ||
| if settings.static_hostname != config.static_hostname { | ||
| self.hostname_proxy | ||
| .set_static_hostname(config_static_hostname.as_str(), false) | ||
| .await?; | ||
| } | ||
| } | ||
|
|
||
| if let Some(config_hostname) = &config.hostname { | ||
| if settings.hostname != config.hostname { | ||
| self.hostname_proxy | ||
| .set_hostname(config_hostname.as_str(), false) | ||
| .await?; | ||
| } | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // Copyright (c) [2025] SUSE LLC | ||
| // | ||
| // All Rights Reserved. | ||
| // | ||
| // This program is free software; you can redistribute it and/or modify it | ||
| // under the terms of the GNU General Public License as published by the Free | ||
| // Software Foundation; either version 2 of the License, or (at your option) | ||
| // any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, but WITHOUT | ||
| // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
| // more details. | ||
| // | ||
| // You should have received a copy of the GNU General Public License along | ||
| // with this program; if not, contact SUSE LLC. | ||
| // | ||
| // To contact SUSE LLC about this file by physical or electronic mail, you may | ||
| // find current contact information at www.suse.com. | ||
|
|
||
| //! Implements a client to access Agama's HTTP API related to Hostname management. | ||
|
|
||
| use crate::base_http_client::BaseHTTPClient; | ||
| use crate::hostname::model::HostnameSettings; | ||
| use crate::ServiceError; | ||
|
|
||
| pub struct HostnameHTTPClient { | ||
| client: BaseHTTPClient, | ||
| } | ||
|
|
||
| impl HostnameHTTPClient { | ||
| pub fn new(base: BaseHTTPClient) -> Self { | ||
| Self { client: base } | ||
| } | ||
|
|
||
| pub async fn get_config(&self) -> Result<HostnameSettings, ServiceError> { | ||
| self.client.get("/hostname/config").await | ||
| } | ||
|
|
||
| pub async fn set_config(&self, config: &HostnameSettings) -> Result<(), ServiceError> { | ||
| self.client.put_void("/hostname/config", config).await | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // Copyright (c) [2025] SUSE LLC | ||
| // | ||
| // All Rights Reserved. | ||
| // | ||
| // This program is free software; you can redistribute it and/or modify it | ||
| // under the terms of the GNU General Public License as published by the Free | ||
| // Software Foundation; either version 2 of the License, or (at your option) | ||
| // any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, but WITHOUT | ||
| // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
| // more details. | ||
| // | ||
| // You should have received a copy of the GNU General Public License along | ||
| // with this program; if not, contact SUSE LLC. | ||
| // | ||
| // To contact SUSE LLC about this file by physical or electronic mail, you may | ||
| // find current contact information at www.suse.com. | ||
|
|
||
| //! Implements a data model for Hostname configuration. | ||
|
|
||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| /// Represents a Hostname | ||
| #[derive(Clone, Debug, Serialize, Deserialize, Default, utoipa::ToSchema)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct HostnameSettings { | ||
| #[serde(rename = "transient")] | ||
| pub hostname: Option<String>, | ||
| // empty string means removing the static hostname | ||
| #[serde(rename = "static")] | ||
| pub static_hostname: Option<String>, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // Copyright (c) [2025] SUSE LLC | ||
| // | ||
| // All Rights Reserved. | ||
| // | ||
| // This program is free software; you can redistribute it and/or modify it | ||
| // under the terms of the GNU General Public License as published by the Free | ||
| // Software Foundation; either version 2 of the License, or (at your option) | ||
| // any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, but WITHOUT | ||
| // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
| // more details. | ||
| // | ||
| // You should have received a copy of the GNU General Public License along | ||
| // with this program; if not, contact SUSE LLC. | ||
| // | ||
| // To contact SUSE LLC about this file by physical or electronic mail, you may | ||
| // find current contact information at www.suse.com. | ||
|
|
||
| //! Implements the store for the hostname settings. | ||
|
|
||
| use crate::base_http_client::BaseHTTPClient; | ||
| use crate::error::ServiceError; | ||
|
|
||
| use super::http_client::HostnameHTTPClient; | ||
| use super::model::HostnameSettings; | ||
|
|
||
| /// Loads and stores the hostname settings from/to the HTTP service. | ||
| pub struct HostnameStore { | ||
| hostname_client: HostnameHTTPClient, | ||
| } | ||
|
|
||
| impl HostnameStore { | ||
| pub fn new(client: BaseHTTPClient) -> Result<Self, ServiceError> { | ||
| Ok(Self { | ||
| hostname_client: HostnameHTTPClient::new(client), | ||
| }) | ||
| } | ||
|
|
||
| pub async fn load(&self) -> Result<HostnameSettings, ServiceError> { | ||
| self.hostname_client.get_config().await | ||
| } | ||
|
|
||
| pub async fn store(&self, settings: &HostnameSettings) -> Result<(), ServiceError> { | ||
| self.hostname_client.set_config(settings).await | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.