Class: Opsmgr::Settings::Microbosh::InstallationSettings

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/opsmgr/settings/microbosh/installation_settings.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Loggable

included, #log

Constructor Details

#initialize(installation_hash) ⇒ InstallationSettings

Returns a new instance of InstallationSettings.



15
16
17
# File 'lib/opsmgr/settings/microbosh/installation_settings.rb', line 15

def initialize(installation_hash)
  @installation_hash = installation_hash
end

Class Method Details

.from_api_result(result) ⇒ Object



11
12
13
# File 'lib/opsmgr/settings/microbosh/installation_settings.rb', line 11

def self.from_api_result(result)
  new(result.as_hash)
end

Instance Method Details

#availability_zone_guid(zone_name) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/opsmgr/settings/microbosh/installation_settings.rb', line 41

def availability_zone_guid(zone_name)
  zones = installation_hash.fetch('infrastructure', {}).fetch('availability_zones', [])
  matching_zone = zones.find do |zone|
    zone['name'] == zone_name
  end

  if matching_zone.nil?
    available_zone_names = zones.map { |network| network['name'] }
    log.warn("No availability zone matching name #{zone_name}. Available names: #{available_zone_names.join(', ')}")
    return nil
  end

  matching_zone.fetch('guid')
end

#default_availability_zone_guidObject



36
37
38
39
# File 'lib/opsmgr/settings/microbosh/installation_settings.rb', line 36

def default_availability_zone_guid
  first_zone = installation_hash.fetch('infrastructure', {}).fetch('availability_zones', []).first
  first_zone['guid'] if first_zone
end

#network_guid(network_name) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/opsmgr/settings/microbosh/installation_settings.rb', line 23

def network_guid(network_name)
  networks = installation_hash.fetch('infrastructure', {}).fetch('networks', [])
  matching_network = networks.find { |network| network['name'] == network_name }

  if matching_network.nil?
    available_network_names = networks.map { |network| network['name'] }
    log.warn("No network matching name #{network_name}. Available names: #{available_network_names.join(', ')}")
    return nil
  end

  matching_network.fetch('guid')
end

#product(product_name) ⇒ Object



19
20
21
# File 'lib/opsmgr/settings/microbosh/installation_settings.rb', line 19

def product(product_name)
  products.find { |p| p.name == product_name }
end

#to_yamlObject



56
57
58
# File 'lib/opsmgr/settings/microbosh/installation_settings.rb', line 56

def to_yaml
  YAML.dump(installation_hash)
end