public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Christian Ebner <c.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH v2 pve-manager 1/4] node: config: make wakeonlan a property string
Date: Tue, 26 Mar 2024 10:16:56 +0100	[thread overview]
Message-ID: <20240326091659.63483-2-c.ebner@proxmox.com> (raw)
In-Reply-To: <20240326091659.63483-1-c.ebner@proxmox.com>

Moves the wakeonlan property to be a property string, with current mac
address as default key. This allows to later add further optional
properties such as bind-interface and broadcast-address.

Adds the `get_wakeonlan_config` helper function to parse the string
when read from the node config.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
---
changes since version 1:
- not present in previous version

 PVE/API2/Nodes.pm |  6 ++++--
 PVE/NodeConfig.pm | 39 +++++++++++++++++++++++++++++++++------
 2 files changed, 37 insertions(+), 8 deletions(-)

diff --git a/PVE/API2/Nodes.pm b/PVE/API2/Nodes.pm
index cc5ee65e..6e75cd5f 100644
--- a/PVE/API2/Nodes.pm
+++ b/PVE/API2/Nodes.pm
@@ -25,6 +25,7 @@ use PVE::HA::Env::PVE2;
 use PVE::INotify;
 use PVE::JSONSchema qw(get_standard_option);
 use PVE::LXC;
+use PVE::NodeConfig;
 use PVE::ProcFSTools;
 use PVE::QemuConfig;
 use PVE::QemuServer;
@@ -689,7 +690,8 @@ __PACKAGE__->register_method({
 	PVE::Cluster::check_node_exists($node);
 
 	my $config = PVE::NodeConfig::load_config($node);
-	my $mac_addr = $config->{wakeonlan};
+	my $wol_config = PVE::NodeConfig::get_wakeonlan_config($config);
+	my $mac_addr = $wol_config->{mac};
 	if (!defined($mac_addr)) {
 	    die "No wake on LAN MAC address defined for '$node'!\n";
 	}
@@ -711,7 +713,7 @@ __PACKAGE__->register_method({
 
 	close($sock);
 
-	return $config->{wakeonlan};
+	return $wol_config->{mac};
     }});
 
 __PACKAGE__->register_method({
diff --git a/PVE/NodeConfig.pm b/PVE/NodeConfig.pm
index 941e6009..a09c9be1 100644
--- a/PVE/NodeConfig.pm
+++ b/PVE/NodeConfig.pm
@@ -85,12 +85,6 @@ my $confdesc = {
 	maxLength => 64 * 1024,
 	optional => 1,
     },
-    wakeonlan => {
-	type => 'string',
-	description => 'MAC address for wake on LAN',
-	format => 'mac-addr',
-	optional => 1,
-    },
     'startall-onboot-delay' => {
 	description => 'Initial delay in seconds, before starting all the Virtual Guests with on-boot enabled.',
 	type => 'integer',
@@ -101,6 +95,23 @@ my $confdesc = {
     },
 };
 
+my $wakeonlan_desc = {
+    mac => {
+	type => 'string',
+	description => 'MAC address for wake on LAN',
+	format => 'mac-addr',
+	format_description => 'MAC address',
+	default_key => 1,
+    },
+};
+
+$confdesc->{wakeonlan} = {
+    type => 'string',
+    description => 'Node specific wake on LAN settings.',
+    format => $wakeonlan_desc,
+    optional => 1,
+};
+
 my $acme_domain_desc = {
     domain => {
 	type => 'string',
@@ -193,6 +204,22 @@ sub write_node_config {
     return $raw;
 }
 
+sub get_wakeonlan_config {
+    my ($node_conf) = @_;
+
+    $node_conf //= {};
+
+    my $res = {};
+    if (defined($node_conf->{wakeonlan})) {
+	$res = eval {
+	    PVE::JSONSchema::parse_property_string($wakeonlan_desc, $node_conf->{wakeonlan})
+	};
+	die $@ if $@;
+    }
+
+    return $res;
+}
+
 # we always convert domain values to lower case, since DNS entries are not case
 # sensitive and ACME implementations might convert the ordered identifiers
 # to lower case
-- 
2.39.2





  reply	other threads:[~2024-03-26  9:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-26  9:16 [pve-devel] [PATCH v2 pve-manager pve-docs 0/4] add optional WoL config options Christian Ebner
2024-03-26  9:16 ` Christian Ebner [this message]
2024-03-26  9:16 ` [pve-devel] [PATCH v2 pve-manager 2/4] fix #5255: node: wol: add optional bind interface Christian Ebner
2024-03-26  9:16 ` [pve-devel] [PATCH v2 pve-manager 3/4] fix #5255: node: wol: configurable broadcast address Christian Ebner
2024-03-26  9:16 ` [pve-devel] [PATCH v2 pve-docs 4/4] pvenode/wake-on-lan: mention optional config options Christian Ebner
2024-03-28 17:27 ` [pve-devel] applied-series: [PATCH v2 pve-manager pve-docs 0/4] add optional WoL " Thomas Lamprecht
2024-03-29  7:44   ` Christian Ebner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240326091659.63483-2-c.ebner@proxmox.com \
    --to=c.ebner@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal