Class: HashiCorp::VagrantVMwareDesktop::CheckpointClient
- Inherits:
-
Object
- Object
- HashiCorp::VagrantVMwareDesktop::CheckpointClient
- Includes:
- Singleton
- Defined in:
- lib/vagrant-vmware-desktop/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
-
#check ⇒ self
Start checkpoint checks for both the plugin and utility.
-
#check_plugin ⇒ self
Run check for plugin.
-
#check_utility ⇒ self
Run check for utility.
-
#complete? ⇒ Boolean
All checks complete.
-
#complete_plugin? ⇒ Boolean
Plugin check complete.
-
#complete_utility? ⇒ Boolean
Utility check complete.
-
#initialize ⇒ CheckpointClient
constructor
A new instance of CheckpointClient.
-
#result ⇒ Hash
Result of all checks.
-
#result_plugin ⇒ Object
Get result from plugin check, wait if not complete.
-
#result_utility ⇒ Object
Get result from utility check, wait if not complete.
-
#setup(env) ⇒ self
Setup will attempt to load the checkpoint library and log if it is not found.
Constructor Details
#initialize ⇒ CheckpointClient
Returns a new instance of CheckpointClient.
30 31 32 33 |
# File 'lib/vagrant-vmware-desktop/checkpoint_client.rb', line 30 def initialize @logger = Log4r::Logger.new("hashicorp::provider::vmware::checkpoint_client") @enabled = false end |
Instance Attribute Details
#enabled ⇒ Boolean (readonly)
22 23 24 |
# File 'lib/vagrant-vmware-desktop/checkpoint_client.rb', line 22 def enabled @enabled end |
#env ⇒ Vagrant::Environment (readonly)
28 29 30 |
# File 'lib/vagrant-vmware-desktop/checkpoint_client.rb', line 28 def env @env end |
#files ⇒ Hash (readonly)
25 26 27 |
# File 'lib/vagrant-vmware-desktop/checkpoint_client.rb', line 25 def files @files end |
#logger ⇒ Log4r::Logger (readonly)
19 20 21 |
# File 'lib/vagrant-vmware-desktop/checkpoint_client.rb', line 19 def logger @logger end |
Instance Method Details
#check ⇒ self
Start checkpoint checks for both the plugin and utility
67 68 69 70 71 |
# File 'lib/vagrant-vmware-desktop/checkpoint_client.rb', line 67 def check check_plugin check_utility self end |
#check_plugin ⇒ self
Run check for plugin
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 |
# File 'lib/vagrant-vmware-desktop/checkpoint_client.rb', line 133 def check_plugin if enabled && !@checkpoint_threads.key?(:plugin) logger.debug("starting plugin check") @checkpoint_threads[:plugin] = Thread.new do Thread.current.abort_on_exception = false Thread.current.report_on_exception = false begin Thread.current[:result] = Checkpoint.check( product: "vagrant-vmware-desktop", version: VERSION, signature_file: files[:plugin_signature], cache_file: files[:plugin_cache] ) if Thread.current[:result].is_a?(Hash) Thread.current[:result].merge!("installed_version" => VERSION) else Thread.current[:result] = nil end logger.debug("plugin check complete") rescue => e logger.debug("plugin check failure - #{e}") end end end self end |
#check_utility ⇒ self
Run check for utility
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/vagrant-vmware-desktop/checkpoint_client.rb', line 163 def check_utility if enabled && !@checkpoint_threads.key?(:utility) logger.debug("starting utility check") @checkpoint_threads[:utility] = Thread.new do Thread.current.abort_on_exception = false Thread.current.report_on_exception = false begin tmp_config = Config.new tmp_config.finalize! driver = Driver.create(nil, tmp_config) @logger.debug("getting utility version") utility_version = driver.vmware_utility_version @logger.debug("got utility version: #{utility_version.inspect}") if utility_version begin @logger.debug("running utility checkpoint check") Thread.current[:result] = Checkpoint.check( product: "vagrant-vmware-utility", version: utility_version, signature_file: files[:utility_signature], cache_file: files[:utility_cache] ) if Thread.current[:result].is_a?(Hash) Thread.current[:result].merge!("installed_version" => utility_version) else Thread.current[:result] = nil end logger.debug("utility check complete") rescue => e logger.debug("utility check failure - #{e}") end else logger.debug("skipping utility checkpoint, unable to determine version") end rescue => e logger.debug("utility communication error - #{e}") end end end nil end |
#complete? ⇒ Boolean
All checks complete
74 75 76 |
# File 'lib/vagrant-vmware-desktop/checkpoint_client.rb', line 74 def complete? complete_plugin? && complete_utility? end |
#complete_plugin? ⇒ Boolean
Plugin check complete
79 80 81 82 83 84 85 |
# File 'lib/vagrant-vmware-desktop/checkpoint_client.rb', line 79 def complete_plugin? if @checkpoint_threads.key?(:plugin) !@checkpoint_threads[:plugin].alive? else true end end |
#complete_utility? ⇒ Boolean
Utility check complete
88 89 90 91 92 93 94 |
# File 'lib/vagrant-vmware-desktop/checkpoint_client.rb', line 88 def complete_utility? if @checkpoint_threads.key?(:utility) !@checkpoint_threads[:utility].alive? else true end end |
#result ⇒ Hash
Result of all checks
99 100 101 102 103 104 |
# File 'lib/vagrant-vmware-desktop/checkpoint_client.rb', line 99 def result { desktop: result_plugin, utility: result_utility } end |
#result_plugin ⇒ Object
Get result from plugin check, wait if not complete
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/vagrant-vmware-desktop/checkpoint_client.rb', line 107 def result_plugin if !enabled || !@checkpoint_threads.key?(:plugin) nil elsif !defined?(@result_plugin) @checkpoint_threads[:plugin].join(CHECKPOINT_TIMEOUT) @result_plugin = @checkpoint_threads[:result] else @result_plugin end end |
#result_utility ⇒ Object
Get result from utility check, wait if not complete
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/vagrant-vmware-desktop/checkpoint_client.rb', line 119 def result_utility if !enabled || !@checkpoint_threads.key?(:utility) nil elsif !defined?(@result_utility) @checkpoint_threads[:utility].join(CHECKPOINT_TIMEOUT) @result_utility = @checkpoint_threads[:result] else @result_utility end end |
#setup(env) ⇒ self
Setup will attempt to load the checkpoint library and log if it is not found. Checkpoint should be around as it is a dependency of Vagrant, but if it’s not, it shouldn’t be a show stopper
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/vagrant-vmware-desktop/checkpoint_client.rb', line 42 def setup(env) begin require "checkpoint" @enabled = true rescue LoadError @logger.debug("checkpoint library not found. disabling.") end if ENV["VAGRANT_CHECKPOINT_DISABLE"] @logger.debug("checkpoint disabled via explicit request with environment variable") @enabled = false end @files = { plugin_signature: env.data_dir.join("checkpoint_signature-vmp"), plugin_cache: env.data_dir.join("checkpoint_cache-vmp"), utility_signature: env.data_dir.join("checkpoint_signature-vmu"), utility_cache: env.data_dir.join("checkpoint_cache-vmu") } @checkpoint_threads = {} @env = env self end |