Class: Batali::Source::ChefServer
- Inherits:
-
Batali::Source
- Object
- Grimoire::Utility
- Utility
- Batali::Source
- Batali::Source::ChefServer
- Includes:
- Utility::Chef, Bogo::Memoization
- Defined in:
- lib/batali/source/chef_server.rb
Overview
Chef Server based source
Instance Attribute Summary collapse
-
#cache ⇒ String
Local cache path.
-
#dependencies ⇒ Array<Hash>
readonly
Dependency strings.
-
#identifier ⇒ string
readonly
Unique identifier.
Instance Method Summary collapse
- #api_service ⇒ Chef::Rest
-
#asset ⇒ String
Directory.
-
#cache_directory ⇒ String
Path to cache.
-
#initialize(args = {}) ⇒ self
constructor
Extract extra info before allowing super to load data.
- #unit_dependencies ⇒ Array<Array<name, constraints>>
- #unit_version ⇒ String
Methods included from Utility::Chef
Methods inherited from Batali::Source
#==, build, #clean_asset, #diff
Constructor Details
#initialize(args = {}) ⇒ self
Extract extra info before allowing super to load data
25 26 27 28 29 |
# File 'lib/batali/source/chef_server.rb', line 25 def initialize(args={}) @deps = args.delete(:dependencies) || {} super init_chef! end |
Instance Attribute Details
#cache ⇒ String
Returns local cache path.
15 16 17 |
# File 'lib/batali/source/chef_server.rb', line 15 def cache @cache end |
#dependencies ⇒ Array<Hash> (readonly)
Returns dependency strings.
13 14 15 |
# File 'lib/batali/source/chef_server.rb', line 13 def dependencies @dependencies end |
#identifier ⇒ string (readonly)
Returns unique identifier.
17 18 19 |
# File 'lib/batali/source/chef_server.rb', line 17 def identifier @identifier end |
Instance Method Details
#api_service ⇒ Chef::Rest
32 33 34 35 36 |
# File 'lib/batali/source/chef_server.rb', line 32 def api_service memoize(:api_service) do Chef::Rest.new(endpoint) end end |
#asset ⇒ String
Returns directory.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/batali/source/chef_server.rb', line 59 def asset path = File.join(cache_directory, name, version) begin FileUtils.mkdir_p(path) cookbook = rest.get_rest("cookbooks/#{name}/#{version}") manifest = cookbook.manifest Chef::CookbookVersion::COOKBOOK_SEGMENTS.each do |segement| if(manifest.has_key?(segment)) manifest[segement].each do |s_file| new_path = File.join(path, s_file['path'].gsub('/', File::SEPARATOR)) FileUtils.mkdir_p(File.dirname(new_path)) api_service.sign_on_redirect = false t_file = api_service.get_rest(s_file['url'], true) FilUtils.mv(t_file.path, new_path) end end end rescue => e debug "Failed to fully download cookbook [#{name}<#{version}>] - #{e.class}: #{e}" FileUtils.rm_rf(path) raise end path end |
#cache_directory ⇒ String
Returns path to cache.
49 50 51 52 53 54 55 56 |
# File 'lib/batali/source/chef_server.rb', line 49 def cache_directory memoize(:cache_directory) do unless(@cache) @cache = File.join(Dir.home, '.batali/cache/chef_server', endpoint) end cache end end |
#unit_dependencies ⇒ Array<Array<name, constraints>>
44 45 46 |
# File 'lib/batali/source/chef_server.rb', line 44 def unit_dependencies deps.to_a end |
#unit_version ⇒ String
39 40 41 |
# File 'lib/batali/source/chef_server.rb', line 39 def unit_version version end |