Class: ACE::PluginCache

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/plugin_cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(environments_cache_dir) ⇒ PluginCache

Returns a new instance of PluginCache.



12
13
14
15
# File 'lib/ace/plugin_cache.rb', line 12

def initialize(environments_cache_dir)
  @cache_dir = environments_cache_dir
  @cache_dir_mutex = Concurrent::ReadWriteLock.new
end

Instance Attribute Details

#cache_dirObject (readonly)

Returns the value of attribute cache_dir.



11
12
13
# File 'lib/ace/plugin_cache.rb', line 11

def cache_dir
  @cache_dir
end

#cache_dir_mutexObject (readonly)

Returns the value of attribute cache_dir_mutex.



11
12
13
# File 'lib/ace/plugin_cache.rb', line 11

def cache_dir_mutex
  @cache_dir_mutex
end

Instance Method Details

#environment_dir(environment) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/ace/plugin_cache.rb', line 55

def environment_dir(environment)
  environment_dir = File.join(cache_dir, environment)
  cache_dir_mutex.with_write_lock do
    FileUtils.mkdir_p(environment_dir)
    FileUtils.touch(environment_dir)
  end
  environment_dir
end

#libdir(plugin_dest) ⇒ Object

the Puppet will point to a tmp location where the contents from the pluginsync dest is copied too.



46
47
48
49
50
51
52
53
# File 'lib/ace/plugin_cache.rb', line 46

def libdir(plugin_dest)
  tmpdir = Dir.mktmpdir(['plugins', plugin_dest])
  cache_dir_mutex.with_write_lock do
    FileUtils.cp_r(File.join(plugin_dest, '.'), tmpdir)
    FileUtils.touch(tmpdir)
  end
  tmpdir
end

#setupObject



17
18
19
20
# File 'lib/ace/plugin_cache.rb', line 17

def setup
  FileUtils.mkdir_p(cache_dir)
  self
end

#sync_core(environment) ⇒ Object

Puppet is referenced too



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/ace/plugin_cache.rb', line 66

def sync_core(environment)
  env = Puppet::Node::Environment.remote(environment)
  environments_dir = environment_dir(environment)
  Puppet[:vardir] = File.join(environments_dir)
  Puppet[:confdir] = File.join(environments_dir, 'conf')
  Puppet[:rundir] = File.join(environments_dir, 'run')
  Puppet[:logdir] = File.join(environments_dir, 'log')
  Puppet[:codedir] = File.join(environments_dir, 'code')
  Puppet[:plugindest] = File.join(environments_dir, 'plugins')
  Puppet::Configurer::PluginHandler.new.download_plugins(env)
  libdir(File.join(environments_dir, 'plugins'))
end

#with_synced_libdir(environment, certname, &block) ⇒ Object



22
23
24
25
26
27
# File 'lib/ace/plugin_cache.rb', line 22

def with_synced_libdir(environment, certname, &block)
  ForkUtil.isolate do
    ACE::PuppetUtil.isolated_puppet_settings(certname, environment)
    with_synced_libdir_core(environment, &block)
  end
end

#with_synced_libdir_core(environment) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ace/plugin_cache.rb', line 29

def with_synced_libdir_core(environment)
  pool = Puppet::Network::HTTP::Pool.new(Puppet[:http_keepalive_timeout])
  Puppet.push_context({
                        http_pool: pool
                      }, "Isolated HTTP Pool")
  libdir = sync_core(environment)
  Puppet.settings[:libdir] = libdir
  $LOAD_PATH << libdir
  yield
ensure
  FileUtils.remove_dir(libdir)
  pool.close
end