Class: OctocatalogDiff::API::V1::CatalogDiff
- Inherits:
-
Object
- Object
- OctocatalogDiff::API::V1::CatalogDiff
- Defined in:
- lib/octocatalog-diff/api/v1/catalog-diff.rb
Overview
This class allows octocatalog-diff to be used to compile catalogs (if needed) and then compute the differences between them.
Class Method Summary collapse
-
.catalog_diff(options = nil) ⇒ OpenStruct
Public: Run catalog-diff.
Class Method Details
.catalog_diff(options = nil) ⇒ OpenStruct
Public: Run catalog-diff
Parameters are to be passed in a hash. Other catalog-diff parameters are required
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/octocatalog-diff/api/v1/catalog-diff.rb', line 23 def self.catalog_diff( = nil) # Validate the required options. unless .is_a?(Hash) raise ArgumentError, 'Usage: #catalog_diff(options_hash)' end pass_opts, logger = OctocatalogDiff::API::V1::Common.() # Compile catalogs logger.debug "Compiling catalogs for #{[:node]}" catalogs_obj = OctocatalogDiff::Util::Catalogs.new(pass_opts, logger) catalogs = catalogs_obj.catalogs logger.info "Catalogs compiled for #{[:node]}" # Cache catalogs if master caching is enabled. If a catalog is being read from the cached master # directory, set the compilation directory attribute, so that the "compilation directory dependent" # suppressor will still work. %w(from to).each do |x| next unless ["#{x}_env".to_sym] == .fetch(:master_cache_branch, 'origin/master') next if [:cached_master_dir].nil? catalogs[x.to_sym].compilation_dir = ["#{x}_catalog_compilation_dir".to_sym] || [:cached_master_dir] rc = OctocatalogDiff::CatalogUtil::CachedMasterDirectory.save_catalog_in_cache_dir( [:node], [:cached_master_dir], catalogs[x.to_sym] ) logger.debug "Cached master catalog for #{[:node]}" if rc end # Compute diffs diffs_obj = OctocatalogDiff::Cli::Diffs.new(, logger) diffs = diffs_obj.diffs(catalogs) logger.info "Diffs computed for #{[:node]}" logger.info 'No differences' if diffs.empty? # Return diffs and catalogs in expected format OpenStruct.new( diffs: diffs.map { |x| OctocatalogDiff::API::V1::Diff.factory(x) }, from: OctocatalogDiff::API::V1::Catalog.new(catalogs[:from]), to: OctocatalogDiff::API::V1::Catalog.new(catalogs[:to]) ) end |