class Opsmgr::Environments

Public Class Methods

config_file(dir, name) click to toggle source
# File lib/opsmgr/environments.rb, line 41
def self.config_file(dir, name)
  ENV.fetch('ENV_CONFIG_FILE', File.join(dir, name))
end
config_filename(name) click to toggle source
# File lib/opsmgr/environments.rb, line 37
def self.config_filename(name)
  ENV.key?('ENV_DIRECTORY') ? "#{name}.yml" : 'metadata'
end
directory() click to toggle source
# File lib/opsmgr/environments.rb, line 33
def self.directory
  ENV.fetch('ENV_DIRECTORY', File.join(Dir.pwd, '../environment/'))
end
for(name = '') click to toggle source
# File lib/opsmgr/environments.rb, line 12
def self.for(name = '')
  env_config = config_file(directory, config_filename(name))
  unless File.exist?(env_config)
    raise "No environments config found in #{env_config}. Specify path using ENV_DIRECTORY or ENV_CONFIG_FILE."
  end

  new(env_config, name)
end
list() click to toggle source
# File lib/opsmgr/environments.rb, line 21
def self.list
  Dir.glob(config_file(directory, '*')).map do |path|
    fname = File.basename(path, '.*')
    if fname == 'metadata'
      string_keyed_hash = YAML.load(File.read(path))
      string_keyed_hash['name'].to_sym
    else
      fname.to_sym
    end
  end
end
new(config_path, env_name = '') click to toggle source
# File lib/opsmgr/environments.rb, line 45
def initialize(config_path, env_name = '')
  @config_path = config_path
  @env_name = env_name
end

Public Instance Methods

settings() click to toggle source
# File lib/opsmgr/environments.rb, line 61
def settings
  string_keyed_hash = YAML.load(Renderer.for(File.read(@config_path)).rendered_settings)
  unless @env_name == '' || string_keyed_hash['name'] == @env_name
    raise "Specified name #{@env_name} does not match name in #{@config_path}"
  end

  fix_subnets(string_keyed_hash)
end
settings_with_merged_folders(installation_settings) click to toggle source
# File lib/opsmgr/environments.rb, line 50
def settings_with_merged_folders(installation_settings)
  return settings unless installation_settings['infrastructure']['file_system']
  file_system = installation_settings['infrastructure']['file_system']

  settings_to_modify = settings
  settings_to_modify.dig('vm_shepherd', 'vm_configs', 0, 'cleanup', 'datacenter_folders_to_clean') << file_system['microbosh_vm_folder']
  settings_to_modify.dig('vm_shepherd', 'vm_configs', 0, 'cleanup', 'datacenter_folders_to_clean') << file_system['microbosh_template_folder']
  settings_to_modify.dig('vm_shepherd', 'vm_configs', 0, 'cleanup', 'datastore_folders_to_clean') << file_system['microbosh_disk_path']
  settings_to_modify
end

Private Instance Methods

fix_subnets(settings) click to toggle source
# File lib/opsmgr/environments.rb, line 72
def fix_subnets(settings)
  settings['ops_manager']['networks'].each do |n|
    next if n['subnets']
    availability_zones = settings['ops_manager']['availability_zones'] || []
    n['subnets'] = [
      {
        'identifier' => n['identifier'],
        'cidr' => n['subnet'],
        'dns' => n['dns'],
        'gateway' => n['gateway'],
        'reserved_ips' => n['reserved_ips'],
        'availability_zones' => availability_zones.map { |z| z['name'] }
      }
    ]
  end

  if settings['vm_shepherd']['env_config']
    outputs = settings['vm_shepherd']['env_config']['outputs']
    unless outputs['subnets']
      outputs['subnets'] = [outputs['public_subnet_id'], outputs['private_subnet_id']]
    end
  end

  settings
end