Class: Opsmgr::Environments

Inherits:
Object
  • Object
show all
Defined in:
lib/opsmgr/environments.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_path, env_name = '') ⇒ Environments

Returns a new instance of Environments.



45
46
47
48
# File 'lib/opsmgr/environments.rb', line 45

def initialize(config_path, env_name = '')
  @config_path = config_path
  @env_name = env_name
end

Class Method Details

.config_file(dir, name) ⇒ Object



41
42
43
# 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) ⇒ Object



37
38
39
# File 'lib/opsmgr/environments.rb', line 37

def self.config_filename(name)
  ENV.key?('ENV_DIRECTORY') ? "#{name}.yml" : 'metadata'
end

.directoryObject



33
34
35
# File 'lib/opsmgr/environments.rb', line 33

def self.directory
  ENV.fetch('ENV_DIRECTORY', File.join(Dir.pwd, '../environment/'))
end

.for(name = '') ⇒ Object



12
13
14
15
16
17
18
19
# 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

.listObject



21
22
23
24
25
26
27
28
29
30
31
# 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

Instance Method Details

#settingsObject



61
62
63
64
65
66
67
68
# 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) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# 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