-
Notifications
You must be signed in to change notification settings - Fork 19
/
maas-wol.diff
93 lines (91 loc) · 3.6 KB
/
maas-wol.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
diff -Naur provisioningserver/drivers/power/registry.py provisioningserver-wol/drivers/power/registry.py
--- provisioningserver/drivers/power/registry.py 2017-06-10 18:33:00.969121000 +0800
+++ provisioningserver-wol/drivers/power/registry.py 2017-06-10 19:43:27.634100277 +0800
@@ -26,6 +26,7 @@
from provisioningserver.drivers.power.virsh import VirshPowerDriver
from provisioningserver.drivers.power.vmware import VMwarePowerDriver
from provisioningserver.drivers.power.wedge import WedgePowerDriver
+from provisioningserver.drivers.power.wakeonlan import WakeOnLANPowerDriver
from provisioningserver.utils.registry import Registry
@@ -64,6 +65,7 @@
VirshPowerDriver(),
VMwarePowerDriver(),
WedgePowerDriver(),
+ WakeOnLANPowerDriver(),
]
for driver in power_drivers:
PowerDriverRegistry.register_item(driver.name, driver)
diff -Naur provisioningserver/drivers/power/wakeonlan.py provisioningserver-wol/drivers/power/wakeonlan.py
--- provisioningserver/drivers/power/wakeonlan.py 1970-01-01 08:00:00.000000000 +0800
+++ provisioningserver-wol/drivers/power/wakeonlan.py 2017-06-10 19:43:48.837631026 +0800
@@ -0,0 +1,67 @@
+# Copyright 2016 Canonical Ltd. This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Wake on LAN Power Driver"""
+
+__all__ = []
+
+from provisioningserver.drivers import (
+ make_ip_extractor,
+ make_setting_field,
+ SETTING_SCOPE,
+)
+from provisioningserver.drivers.power import PowerDriver
+from provisioningserver.logger import get_maas_logger
+from provisioningserver.utils import shell
+from twisted.internet.defer import maybeDeferred
+import subprocess
+
+
+maaslog = get_maas_logger("drivers.power.wakeonlan")
+
+REQUIRED_PACKAGES = [["wakeonlan", "wakeonlan"]]
+
+class WakeOnLANPowerDriver(PowerDriver):
+
+ name = 'wakeonlan'
+ description = "Wake on LAN Power Driver"
+ settings = [
+ make_setting_field('power_mac', "MAC address", required=True),
+ make_setting_field('brocast_address', "Brocast address", required=True),
+ make_setting_field('brocast_port', "Brocast port", required=True),
+ ]
+ ip_extractor = None
+ queryable = False
+ can_probe = False
+ chassis = False
+
+ def detect_missing_packages(self):
+ missing_packages = set()
+ for binary, package in REQUIRED_PACKAGES:
+ if not shell.has_command_available(binary):
+ missing_packages.add(package)
+ return list(missing_packages)
+
+ def on(self, system_id, context):
+ """Override `on` as we do not need retry logic."""
+ return maybeDeferred(self.power_on, system_id, context)
+
+ def off(self, system_id, context):
+ """Override `off` as we do not need retry logic."""
+ return maybeDeferred(self.power_off, system_id, context)
+
+ def query(self, system_id, context):
+ """Override `query` as we do not need retry logic."""
+ return maybeDeferred(self.power_query, system_id, context)
+
+ def power_on(self, system_id, context):
+ """Power on machine using wake on lan."""
+ subprocess.call(["wakeonlan", "-i", context.get("brocast_address"), "-p", context.get("brocast_port"), context.get("power_mac")])
+
+ def power_off(self, system_id, context):
+ """Power off machine manually."""
+ maaslog.info(
+ "You need to power off %s manually." % system_id)
+
+ def power_query(self, system_id, context):
+ """Power query machine manually."""
+ maaslog.info(
+ "You need to check power state of %s manually." % system_id)
+ return 'unknown'