/
energysaver.pp
172 lines (162 loc) · 4.96 KB
/
energysaver.pp
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# == Class: managedmac::energysaver
#
# Leverages the Mobileconfig type and provider to configure Energy Saver
# settings for Desktops and Laptops.
#
# If no parameters are set, removal of the Mobileconfig resource is implicit.
#
# === Parameters
#
# [*desktop*]
# The settings to apply for Desktop machines. This is a compound parameter
# containing the raw keys/values for configuring EnergySaver. The structure
# is rather complex. See the examples for complete details.
# Type: Hash
#
# [*portable*]
# The settings to apply for Laptop machines. This is a compound parameter
# containing the raw keys/values for configuring EnergySaver. The structure
# is rather complex. See the examples for complete details.
# Type: Hash
#
# === Variables
#
# [*productname*]
# Built-in Facter fact: the common name for the machine model (ie. iMac12,2)
#
# === Examples
#
# This class was designed to be used with Hiera. As such, the best way to pass
# options is to specify them in your Hiera datadir:
#
# # Example: defaults.yaml
# ---
# managedmac::energysaver::desktop:
# ACPower:
# 'Automatic Restart On Power Loss': true
# 'Disk Sleep Timer-boolean': true
# 'Display Sleep Timer': 15
# 'Sleep On Power Button': false
# 'Wake On LAN': true
# 'System Sleep Timer': 30
# Schedule:
# RepeatingPowerOff:
# eventtype: sleep
# time: 1410
# weekdays: 127
# RepeatingPowerOn:
# eventtype: wakepoweron
# time: 480
# weekdays: 127
# managedmac::energysaver::portable:
# ACPower:
# 'Automatic Restart On Power Loss': true
# 'Disk Sleep Timer-boolean': true
# 'Display Sleep Timer': 15
# 'Wake On LAN': true
# 'System Sleep Timer': 30
# BatteryPower:
# 'Automatic Restart On Power Loss': false
# 'Disk Sleep Timer-boolean': true
# 'Display Sleep Timer': 5
# 'System Sleep Timer': 10
# 'Wake On LAN': true
#
# Then simply, create a manifest and include the class...
#
# # Example: my_manifest.pp
# include managedmac::activedirectory
#
# If you just wish to test the functionality of this class, you could also do
# something along these lines:
#
# # Create an Desktop settings Hash
# $desktop = {
# "ACPower" => {
# "Automatic Restart On Power Loss" => true,
# "Disk Sleep Timer-boolean" => true,
# "Display Sleep Timer" => 15,
# "Sleep On Power Button" => false,
# "Wake On LAN" => true,
# "System Sleep Timer" => 30,
# },
# "Schedule" => {
# "RepeatingPowerOff" => {
# "eventtype" => "sleep",
# "time" => 1410,
# "weekdays" => 127
# },
# "RepeatingPowerOn" => {
# "eventtype" => "wakepoweron",
# "time" => 480,
# "weekdays" => 127
# }
# }
# }
#
# # Create an Portable settings Hash
# $portable = {
# "ACPower" => {
# "Automatic Restart On Power Loss" => true,
# "Disk Sleep Timer-boolean" => true,
# "Display Sleep Timer" => 15,
# "Wake On LAN" => true,
# "System Sleep Timer" => 30,
# },
# "BatteryPower" => {
# "Automatic Restart On Power Loss" => false,
# "Disk Sleep Timer-boolean" => true,
# "Display Sleep Timer" => 5,
# "System Sleep Timer" => 10,
# "Wake On LAN" => true
# }
# }
#
# # Invoke the class with params
# class { 'managedmac::energysaver':
# desktop => $desktop,
# laptop => $portable,
# }
#
# === Authors
#
# Brian Warsing <bcw@sfu.ca>
#
# === Copyright
#
# Copyright 2015 Simon Fraser University, unless otherwise noted.
#
class managedmac::energysaver (
$desktop = {},
$portable = {},
) {
validate_hash ($desktop)
validate_hash ($portable)
$params = {
'com.apple.MCX' => {
'com.apple.EnergySaver.desktop.ACPower' => $desktop['ACPower'],
'com.apple.EnergySaver.desktop.Schedule' => $desktop['Schedule'],
'com.apple.EnergySaver.portable.ACPower' => $portable['ACPower'],
'com.apple.EnergySaver.portable.BatteryPower' =>
$portable['BatteryPower'],
'com.apple.EnergySaver.portable.Schedule' => $portable['Schedule'],
'com.apple.EnergySaver.desktop.ACPower-ProfileNumber' => -1,
'com.apple.EnergySaver.portable.ACPower-ProfileNumber' => -1,
'com.apple.EnergySaver.portable.BatteryPower-ProfileNumber' => -1,
}
}
$content = process_mobileconfig_params($params)
$mobileconfig_ensure = empty($desktop) and empty($portable)
$ensure = $mobileconfig_ensure ? {
true => absent,
false => present,
}
$organization = hiera('managedmac::organization', 'Simon Fraser University')
mobileconfig { 'managedmac.energysaver.alacarte':
ensure => $ensure,
displayname => 'Managed Mac: Energy Saver',
description => 'Energy Saver configuration. Installed by Puppet.',
organization => $organization,
content => $content,
}
}