From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id A0691BBA32 for ; Tue, 26 Mar 2024 10:17:14 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 89AA710EDA for ; Tue, 26 Mar 2024 10:17:14 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Tue, 26 Mar 2024 10:17:13 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 46D5942153 for ; Tue, 26 Mar 2024 10:17:13 +0100 (CET) From: Christian Ebner To: pve-devel@lists.proxmox.com Date: Tue, 26 Mar 2024 10:16:56 +0100 Message-Id: <20240326091659.63483-2-c.ebner@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240326091659.63483-1-c.ebner@proxmox.com> References: <20240326091659.63483-1-c.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.032 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [nodeconfig.pm, nodes.pm] Subject: [pve-devel] [PATCH v2 pve-manager 1/4] node: config: make wakeonlan a property string X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Mar 2024 09:17:14 -0000 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 --- 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