|
19 | 19 |
|
20 | 20 | mk_resource_methods |
21 | 21 |
|
| 22 | + def self.prefetch(resources) |
| 23 | + # Build a hash of name => install_options from the catalog |
| 24 | + desired_options = resources.transform_values { |res| res[:install_options] } |
| 25 | + |
| 26 | + installed_snaps.each do |snap| |
| 27 | + resource = resources[snap['name']] |
| 28 | + next unless resource |
| 29 | + |
| 30 | + current_hold_time = snap['hold'] |
| 31 | + desired_hold_time = parse_time_from_options(desired_options[snap['name']]) |
| 32 | + |
| 33 | + # Determine the appropriate mark |
| 34 | + mark = if should_change_hold?(desired_hold_time, current_hold_time) |
| 35 | + :none # force re-hold |
| 36 | + else |
| 37 | + :hold |
| 38 | + end |
| 39 | + |
| 40 | + provider = new( |
| 41 | + name: snap['name'], |
| 42 | + ensure: snap['tracking-channel'], |
| 43 | + mark: mark, |
| 44 | + hold_time: current_hold_time, |
| 45 | + provider: 'snap' |
| 46 | + ) |
| 47 | + |
| 48 | + resource.provider = provider |
| 49 | + end |
| 50 | + end |
| 51 | + |
22 | 52 | def self.instances |
23 | 53 | installed_snaps.map do |snap| |
24 | | - mark = snap['hold'].nil? ? 'none' : 'hold' |
25 | | - Puppet.info("refresh-inhibit = #{mark}") |
| 54 | + mark = snap['hold'].nil? ? :none : :hold |
| 55 | + Puppet.info("name = #{snap['name']}, refresh-inhibit = #{mark}") |
26 | 56 | new(name: snap['name'], ensure: snap['tracking-channel'], mark: mark, hold_time: snap['hold'], provider: 'snap') |
27 | 57 | end |
28 | 58 | end |
@@ -65,12 +95,13 @@ def hold |
65 | 95 | Puppet.info('called hold') |
66 | 96 | Puppet.info("@property_hash = #{@property_hash}") |
67 | 97 | Puppet.info("install_options = #{@resource[:install_options]}") |
68 | | - modify_snap('hold') if should_change_hold?(@resource[:install_options]) |
| 98 | + modify_snap('hold') |
| 99 | + # @property_hash[:mark] = 'hold' |
69 | 100 | end |
70 | 101 |
|
71 | 102 | def unhold |
72 | 103 | Puppet.info('called unhold') |
73 | | - modify_snap('unhold') unless @property_hash[:mark].equal?('none') |
| 104 | + modify_snap('unhold') |
74 | 105 | end |
75 | 106 |
|
76 | 107 | def modify_snap(action, options = @resource[:install_options]) |
@@ -139,18 +170,20 @@ def self.parse_time_from_options(options) |
139 | 170 | end |
140 | 171 | end |
141 | 172 |
|
142 | | - def should_change_hold?(options) |
| 173 | + def should_change_hold?(options, current_hold_time) |
143 | 174 | should_hold_time = self.class.parse_time_from_options(options) |
144 | | - current_hold_time = @property_hash[:hold_time] |
| 175 | + # current_hold_time = @property_hash[:hold_time] |
| 176 | + |
| 177 | + # if current hold time is nil we are fresh holding this snap |
| 178 | + return true if current_hold_time.nil? |
145 | 179 |
|
146 | 180 | parsed_hold_time = DateTime.parse(current_hold_time) |
147 | 181 | # If the hold time is more than 100 years, assume "forever" |
148 | 182 | current_hold_time = 'forever' if (parsed_hold_time - DateTime.now).to_i > 365 * 100 |
149 | 183 |
|
150 | 184 | Puppet.info("should = #{should_hold_time}, current = #{current_hold_time}") |
151 | | - |
152 | | - false if current_hold_time == should_hold_time |
153 | | - true |
| 185 | + Puppet.info("equal = #{current_hold_time == should_hold_time}") |
| 186 | + current_hold_time != should_hold_time |
154 | 187 | end |
155 | 188 |
|
156 | 189 | def self.channel_from_options(options) |
|
0 commit comments