Class: Hula::BoshManifest

Inherits:
Object
  • Object
show all
Defined in:
lib/hula/bosh_manifest.rb,
lib/hula/bosh_manifest/job.rb

Defined Under Namespace

Classes: Job, NoManifestPathGiven

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(manifest_yaml, path: nil) ⇒ BoshManifest

Returns a new instance of BoshManifest.



20
21
22
23
24
# 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

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



18
19
20
# File 'lib/hula/bosh_manifest.rb', line 18

def path
  @path
end

Class Method Details

.from_file(path) ⇒ Object



26
27
28
29
30
# 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

Instance Method Details

#deployment_nameObject



45
46
47
48
49
# 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) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# 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) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# 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

#propertiesObject



85
86
87
# File 'lib/hula/bosh_manifest.rb', line 85

def properties
  manifest_hash.fetch('properties')
end

#property(property_name) ⇒ Object



32
33
34
35
36
37
# 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_poolsObject



81
82
83
# File 'lib/hula/bosh_manifest.rb', line 81

def resource_pools
  manifest_hash.fetch('resource_pools')
end

#set_property(property_name, value) ⇒ Object



39
40
41
42
43
# 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