From cfa83c4bfefe8386b6056639fd7f0fc5d57a94a9 Mon Sep 17 00:00:00 2001 From: David Boucha Date: Sun, 25 Mar 2012 18:35:41 -0600 Subject: [PATCH 1/4] Add WOL list. This wakes up a text file containing one MAC address per line. --- salt/runners/network.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/salt/runners/network.py b/salt/runners/network.py index 6c852a7781..a4ea91b3f6 100644 --- a/salt/runners/network.py +++ b/salt/runners/network.py @@ -4,6 +4,17 @@ Network tools to run from the Master import socket +def wollist(maclist, bcast='255.255.255.255', destport=9): + ''' + Send a "Magic Packet" to wake up a list of Minions. + This list must contain one MAC hardware address per line + + CLI Example:: + + salt-run '/path/to/maclist' + salt-run '/path/to/maclist' 255.255.255.255 7 + salt-run '/path/to/maclist' 255.255.255.255 7 + ''' def wol(mac, bcast='255.255.255.255', destport=9): ''' Send a "Magic Packet" to wake up a Minion From b7fec9b8c56e6623c6330d195eb329043db14fa1 Mon Sep 17 00:00:00 2001 From: David Boucha Date: Mon, 26 Mar 2012 19:25:42 -0600 Subject: [PATCH 2/4] First try at opening the mac file and sending a magic packet to each entry --- salt/runners/network.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/salt/runners/network.py b/salt/runners/network.py index a4ea91b3f6..deb09cac44 100644 --- a/salt/runners/network.py +++ b/salt/runners/network.py @@ -15,6 +15,14 @@ def wollist(maclist, bcast='255.255.255.255', destport=9): salt-run '/path/to/maclist' 255.255.255.255 7 salt-run '/path/to/maclist' 255.255.255.255 7 ''' + try: + macfile = open(maclist, 'r') + for mac in macfile.readline().strip(): + wol(mac, bcast, destport) + print "Waking up %s" % mac + except: + print "Failed to open the MAC file" + def wol(mac, bcast='255.255.255.255', destport=9): ''' Send a "Magic Packet" to wake up a Minion From 92775903421f338fd2bfd2ab3b5d30f55a21d1d2 Mon Sep 17 00:00:00 2001 From: David Boucha Date: Tue, 27 Mar 2012 00:26:36 -0600 Subject: [PATCH 3/4] Fix iterating over the mac file --- salt/runners/network.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/runners/network.py b/salt/runners/network.py index deb09cac44..7860637aa9 100644 --- a/salt/runners/network.py +++ b/salt/runners/network.py @@ -17,7 +17,7 @@ def wollist(maclist, bcast='255.255.255.255', destport=9): ''' try: macfile = open(maclist, 'r') - for mac in macfile.readline().strip(): + for mac in macfile: wol(mac, bcast, destport) print "Waking up %s" % mac except: From 80378619548e85e43ad7a7a0262e0d1040e8b379 Mon Sep 17 00:00:00 2001 From: David Boucha Date: Mon, 2 Apr 2012 23:35:19 -0600 Subject: [PATCH 4/4] Add capability take a text file containing one MAC per line and weak each minion --- salt/runners/network.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/salt/runners/network.py b/salt/runners/network.py index 7860637aa9..7d553a9c42 100644 --- a/salt/runners/network.py +++ b/salt/runners/network.py @@ -16,12 +16,12 @@ def wollist(maclist, bcast='255.255.255.255', destport=9): salt-run '/path/to/maclist' 255.255.255.255 7 ''' try: - macfile = open(maclist, 'r') - for mac in macfile: - wol(mac, bcast, destport) - print "Waking up %s" % mac - except: - print "Failed to open the MAC file" + file = open(maclist, 'r') + for mac in file: + wol(mac.strip(), bcast, destport) + print "Waking up %s" % mac.strip() + except Exception as inst: + print "Failed to open the MAC file. Error: %s" % inst def wol(mac, bcast='255.255.255.255', destport=9): '''