class Hula::BoshManifest
Attributes
manifest_hash[R]
path[R]
Public Class Methods
from_file(path)
click to toggle source
# File lib/hula/bosh_manifest.rb, line 26 def self.from_file(path) new(File.read(path), path: path) rescue Errno::ENOENT raise "Could not open the manifest file: '#{path}'" end
new(manifest_yaml, path: nil)
click to toggle source
# File lib/hula/bosh_manifest.rb, line 20 def initialize(manifest_yaml, path: nil) @manifest_hash = YAML.load(manifest_yaml) @path = path fail 'Invalid manifest' unless manifest_hash.is_a?(Hash) end
Public Instance Methods
deployment_name()
click to toggle source
# File lib/hula/bosh_manifest.rb, line 45 def deployment_name manifest_hash.fetch('name') rescue KeyError raise "Could not find deployment name in #{manifest_hash.inspect}" end
job(job_name)
click to toggle source
# File lib/hula/bosh_manifest.rb, line 66 def job(job_name) if manifest_hash.has_key?('instance_groups') key = "instance_groups" else key = "jobs" end jobs = manifest_hash.fetch(key) job = jobs.detect { |j| j.fetch('name') == job_name } fail "Could not find job name '#{job_name}' in job list: #{jobs.inspect}" if job.nil? Job.new(job) end
jobs_by_regexp(job_name_regexp)
click to toggle source
# File lib/hula/bosh_manifest.rb, line 51 def jobs_by_regexp(job_name_regexp) if manifest_hash.has_key?('instance_groups') key = "instance_groups" else key = "jobs" end jobs_property = manifest_hash.fetch(key) jobs = jobs_property.select { |job| !job.fetch('name').match(job_name_regexp).nil? } fail "Could not find job name '#{job_name_regexp}' in job list: #{jobs_property.inspect}" if jobs.empty? jobs.map { |job| Job.new(job) } end
properties()
click to toggle source
# File lib/hula/bosh_manifest.rb, line 85 def properties manifest_hash.fetch('properties') end
property(property_name)
click to toggle source
# File lib/hula/bosh_manifest.rb, line 32 def property(property_name) components = property_components(property_name) traverse_properties(components) rescue KeyError raise "Could not find property '#{property_name}' in #{properties.inspect}" end
resource_pools()
click to toggle source
# File lib/hula/bosh_manifest.rb, line 81 def resource_pools manifest_hash.fetch('resource_pools') end
set_property(property_name, value)
click to toggle source
# File lib/hula/bosh_manifest.rb, line 39 def set_property(property_name, value) components = property_components(property_name) traverse_properties_and_set(properties, components, value) save end
Private Instance Methods
property_components(property_name)
click to toggle source
# File lib/hula/bosh_manifest.rb, line 100 def property_components(property_name) property_name.split('.') end
save()
click to toggle source
# File lib/hula/bosh_manifest.rb, line 93 def save unless path fail NoManifestPathGiven, 'Cannot save manifest without providing a path' end File.write(path, manifest_hash.to_yaml) end
traverse_properties(components)
click to toggle source
# File lib/hula/bosh_manifest.rb, line 104 def traverse_properties(components) components.inject(properties) do |current_node, component| current_node.fetch(component) end end
traverse_properties_and_set(properties, components, value)
click to toggle source
# File lib/hula/bosh_manifest.rb, line 110 def traverse_properties_and_set(properties, components, value) component = components.shift if components.any? unless properties.key?(component) fail "Could not find property '#{component}' in #{properties.inspect}" end traverse_properties_and_set(properties[component], components, value) else properties[component] = value end end