]> git.proxmox.com Git - pve-manager.git/commitdiff
node: config: make wakeonlan a property string
authorChristian Ebner <c.ebner@proxmox.com>
Tue, 26 Mar 2024 09:16:56 +0000 (10:16 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 28 Mar 2024 16:27:47 +0000 (17:27 +0100)
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>
PVE/API2/Nodes.pm
PVE/NodeConfig.pm

index cc5ee65e8e9226e1efc9904c1cf41828a69ab872..6e75cd5f33dc41331558b54d642905190aee92e0 100644 (file)
@@ -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({
index 941e6009e8cbd9b681c3f69f341bcf30be8b7ed0..a09c9be103a4a378351df80eafb5431069a07178 100644 (file)
@@ -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