[pve-devel] [PATCH v2 #1752 pve-manager 3/3] Impl basic wake on LAN functionality
Christian Ebner
c.ebner at proxmox.com
Tue Jan 15 11:54:01 CET 2019
Implements the basic requirements for waking a sleeping node in a cluster via
wake on LAN.
Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
PVE/API2/Nodes.pm | 21 +++++++++++----------
PVE/NodeConfig.pm | 2 +-
2 files changed, 12 insertions(+), 11 deletions(-)
diff --git a/PVE/API2/Nodes.pm b/PVE/API2/Nodes.pm
index f831bc41..4c20357b 100644
--- a/PVE/API2/Nodes.pm
+++ b/PVE/API2/Nodes.pm
@@ -473,16 +473,16 @@ __PACKAGE__->register_method({
path => 'wol',
method => 'POST',
permissions => {
- check => ['perm', '/nodes/{node}', [ 'Sys.PowerMgmt' ]],
+ check => ['perm', '/nodes/', [ 'Sys.PowerMgmt' ]],
},
protected => 1,
description => "Boot node via 'wake on LAN'.",
parameters => {
additionalProperties => 0,
properties => {
- node => get_standard_option('pve-node'), {
+ node => get_standard_option('pve-node', {
description => 'target node for wake on LAN packet',
- },
+ }),
},
},
returns => { type => "null" },
@@ -490,11 +490,12 @@ __PACKAGE__->register_method({
my ($param) = @_;
my $config = PVE::NodeConfig::load_config($param->{node});
- my $mac_addr = $config->{wol_mac};
- die "No wake on LAN mac address defined for node '$param->{node}'!\n"
- if !defined($mac_addr);
+ my $mac_addr = $config->{wakeonlan};
+ if (!defined($mac_addr)) {
+ die "No wake on LAN MAC address defined for '$param->{node}'!\n";
+ }
- $mac_addr =~ s/://;
+ $mac_addr =~ s/://g;
my $packet = chr(0xff) x 6 . pack('H*', $mac_addr) x 16;
my $proto = getprotobyname('udp');
@@ -502,11 +503,11 @@ __PACKAGE__->register_method({
my $port = getservbyname('discard', 'udp');
my $to = Socket::pack_sockaddr_in($port, $addr);
socket(my $sock, Socket::AF_INET, Socket::SOCK_DGRAM, $proto) or
- die "Unable to open socket for sending wake on LAN magic packet!\n";
+ die "Unable to open socket for sending wake on LAN packet!\n";
setsockopt($sock, Socket::SOL_SOCKET, Socket::SO_BROADCAST, 1) or
- die "Unable to set socket options for sending wake on LAN magic packet!\n";
+ die "Unable to set socket option for sending wake on LAN packet!\n";
send($sock, $packet, 0, $to) or
- die "Unable to send wake on LAN magic packet!\n";
+ die "Unable to send wake on LAN packet!\n";
close($sock);
return undef;
diff --git a/PVE/NodeConfig.pm b/PVE/NodeConfig.pm
index 456886f4..98aefa8d 100644
--- a/PVE/NodeConfig.pm
+++ b/PVE/NodeConfig.pm
@@ -61,7 +61,7 @@ my $confdesc = {
description => 'Node description/comment.',
optional => 1,
},
- wol_mac => {
+ wakeonlan => {
type => 'string',
description => 'MAC address for wake on LAN',
pattern => '^([0-9a-fA-F]{2}:){5}([0-9a-fA-F]{2})$',
--
2.11.0
More information about the pve-devel
mailing list