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.
27 28 29 30 |
# File 'lib/vagrant-vmware-desktop/checkpoint_client.rb', line 27 def initialize @logger = Log4r::Logger.new("hashicorp::provider::vmware::checkpoint_client") @enabled = false end |
Instance Attribute Details
#enabled ⇒ Boolean (readonly)
19 20 21 |
# File 'lib/vagrant-vmware-desktop/checkpoint_client.rb', line 19 def enabled @enabled end |
#env ⇒ Vagrant::Environment (readonly)
25 26 27 |
# File 'lib/vagrant-vmware-desktop/checkpoint_client.rb', line 25 def env @env end |
#files ⇒ Hash (readonly)
22 23 24 |
# File 'lib/vagrant-vmware-desktop/checkpoint_client.rb', line 22 def files @files end |
#logger ⇒ Log4r::Logger (readonly)
16 17 18 |
# File 'lib/vagrant-vmware-desktop/checkpoint_client.rb', line 16 def logger @logger end |
Instance Method Details
#check ⇒ self
Start checkpoint checks for both the plugin and utility
64 65 66 67 68 |
# File 'lib/vagrant-vmware-desktop/checkpoint_client.rb', line 64 def check check_plugin check_utility self end |
#check_plugin ⇒ self
Run check for plugin
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 |
# File 'lib/vagrant-vmware-desktop/checkpoint_client.rb', line 130 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
160 161 162 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 |
# File 'lib/vagrant-vmware-desktop/checkpoint_client.rb', line 160 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
71 72 73 |
# File 'lib/vagrant-vmware-desktop/checkpoint_client.rb', line 71 def complete? complete_plugin? && complete_utility? end |
#complete_plugin? ⇒ Boolean
Plugin check complete
76 77 78 79 80 81 82 |
# File 'lib/vagrant-vmware-desktop/checkpoint_client.rb', line 76 def complete_plugin? if @checkpoint_threads.key?(:plugin) !@checkpoint_threads[:plugin].alive? else true end end |
#complete_utility? ⇒ Boolean
Utility check complete
85 86 87 88 89 90 91 |
# File 'lib/vagrant-vmware-desktop/checkpoint_client.rb', line 85 def complete_utility? if @checkpoint_threads.key?(:utility) !@checkpoint_threads[:utility].alive? else true end end |
#result ⇒ Hash
Result of all checks
96 97 98 99 100 101 |
# File 'lib/vagrant-vmware-desktop/checkpoint_client.rb', line 96 def result { desktop: result_plugin, utility: result_utility } end |
#result_plugin ⇒ Object
Get result from plugin check, wait if not complete
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/vagrant-vmware-desktop/checkpoint_client.rb', line 104 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
116 117 118 119 120 121 122 123 124 125 |
# File 'lib/vagrant-vmware-desktop/checkpoint_client.rb', line 116 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
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/vagrant-vmware-desktop/checkpoint_client.rb', line 39 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 |