Class: Vagrant::Util::CheckpointClient
- Inherits:
-
Object
- Object
- Vagrant::Util::CheckpointClient
- Includes:
- Singleton
- Defined in:
- lib/vagrant/util/checkpoint_client.rb
Constant Summary collapse
- CHECKPOINT_TIMEOUT =
Maximum number of seconds to wait for check to complete
10
Instance Attribute Summary collapse
- #enabled ⇒ Boolean readonly
- #env ⇒ Vagrant::Environment readonly
- #files ⇒ Hash readonly
- #logger ⇒ Log4r::Logger readonly
Instance Method Summary collapse
- #alerts_check ⇒ Object
-
#check ⇒ self
Run check.
-
#complete? ⇒ Boolean
Check has completed.
-
#display ⇒ boolean
Display any alerts or version update information.
-
#initialize ⇒ CheckpointClient
constructor
A new instance of CheckpointClient.
-
#reset! ⇒ Object
Reset the cached values for platform.
-
#result ⇒ Hash?
Result of check.
-
#setup(env) ⇒ self
Setup will attempt to load the checkpoint library and define required paths.
- #version_check ⇒ Object
Constructor Details
#initialize ⇒ CheckpointClient
Returns a new instance of CheckpointClient.
28 29 30 31 |
# File 'lib/vagrant/util/checkpoint_client.rb', line 28 def initialize @logger = Log4r::Logger.new("vagrant::checkpoint_client") @enabled = false end |
Instance Attribute Details
#enabled ⇒ Boolean (readonly)
20 21 22 |
# File 'lib/vagrant/util/checkpoint_client.rb', line 20 def enabled @enabled end |
#env ⇒ Vagrant::Environment (readonly)
26 27 28 |
# File 'lib/vagrant/util/checkpoint_client.rb', line 26 def env @env end |
#files ⇒ Hash (readonly)
23 24 25 |
# File 'lib/vagrant/util/checkpoint_client.rb', line 23 def files @files end |
#logger ⇒ Log4r::Logger (readonly)
17 18 19 |
# File 'lib/vagrant/util/checkpoint_client.rb', line 17 def logger @logger end |
Instance Method Details
#alerts_check ⇒ Object
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 |
# File 'lib/vagrant/util/checkpoint_client.rb', line 128 def alerts_check if result["alerts"] && !result["alerts"].empty? result["alerts"].group_by{|a| a["level"]}.each_pair do |_, alerts| alerts.each do |alert| date = nil begin date = Time.at(alert["date"]) rescue date = Time.now end output = I18n.t("vagrant.alert", message: alert["message"], date: date, url: alert["url"] ) case alert["level"] when "info" alert_ui = Vagrant::UI::Prefixed.new(env.ui, "vagrant") alert_ui.info(output) when "warn" alert_ui = Vagrant::UI::Prefixed.new(env.ui, "vagrant-warning") alert_ui.warn(output) when "critical" alert_ui = Vagrant::UI::Prefixed.new(env.ui, "vagrant-alert") alert_ui.error(output) end end env.ui.info("") end else @logger.debug("no alert notifications to display") end end |
#check ⇒ self
Run check
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 |
# File 'lib/vagrant/util/checkpoint_client.rb', line 80 def check if enabled && @checkpoint_thread.nil? logger.debug("starting plugin check") @checkpoint_thread = Thread.new do Thread.current.abort_on_exception = false if Thread.current.respond_to?(:report_on_exception=) Thread.current.report_on_exception = false end begin Thread.current[:result] = Checkpoint.check( product: "vagrant", version: VERSION, signature_file: files[:signature], cache_file: files[:cache] ) if !Thread.current[:result].is_a?(Hash) Thread.current[:result] = nil end logger.debug("plugin check complete") rescue => e logger.debug("plugin check failure - #{e}") end end end self end |
#complete? ⇒ Boolean
Check has completed
59 60 61 |
# File 'lib/vagrant/util/checkpoint_client.rb', line 59 def complete? !@checkpoint_thread.nil? && !@checkpoint_thread.alive? end |
#display ⇒ boolean
Display any alerts or version update information
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/vagrant/util/checkpoint_client.rb', line 110 def display if !defined?(@displayed) if !complete? @logger.debug("waiting for checkpoint to complete...") end # Don't display if information is cached if result && !result["cached"] version_check alerts_check else @logger.debug("no information received from checkpoint") end @displayed = true else false end end |
#reset! ⇒ Object
Reset the cached values for platform. This is not considered a public API and should only be used for testing.
178 179 180 181 182 183 |
# File 'lib/vagrant/util/checkpoint_client.rb', line 178 def reset! logger = @logger instance_variables.each(&method(:remove_instance_variable)) @logger = logger @enabled = false end |
#result ⇒ Hash?
Result of check
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/vagrant/util/checkpoint_client.rb', line 66 def result if !enabled || @checkpoint_thread.nil? nil elsif !defined?(@result) @checkpoint_thread.join(CHECKPOINT_TIMEOUT) @result = @checkpoint_thread[:result] else @result end end |
#setup(env) ⇒ self
Setup will attempt to load the checkpoint library and define required paths
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/vagrant/util/checkpoint_client.rb', line 38 def setup(env) begin require "checkpoint" @enabled = true rescue LoadError @logger.warn("checkpoint library not found. disabling.") end if ENV["VAGRANT_CHECKPOINT_DISABLE"] @logger.debug("checkpoint disabled via explicit user request") @enabled = false end @files = { signature: env.data_dir.join("checkpoint_signature"), cache: env.data_dir.join("checkpoint_cache") } @checkpoint_thread = nil @env = env self end |
#version_check ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/vagrant/util/checkpoint_client.rb', line 162 def version_check latest_version = Gem::Version.new(result["current_version"]) installed_version = Gem::Version.new(VERSION) ui = Vagrant::UI::Prefixed.new(env.ui, "vagrant") if latest_version > installed_version @logger.info("new version of Vagrant available - #{latest_version}") ui.info(I18n.t("vagrant.version_upgrade_available", latest_version: latest_version, installed_version: installed_version), channel: :error) env.ui.info("", channel: :error) else @logger.debug("vagrant is currently up to date") end end |