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.



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

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

Class Method Details

.config_file(dir, name) ⇒ Object



40
41
42
# File 'lib/opsmgr/environments.rb', line 40

def self.config_file(dir, name)
  ENV.fetch('ENV_CONFIG_FILE', File.join(dir, name))
end

.config_filename(name) ⇒ Object



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

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

.directoryObject



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

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

.for(name = '') ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/opsmgr/environments.rb', line 11

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



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/opsmgr/environments.rb', line 20

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



60
61
62
63
64
65
66
67
# File 'lib/opsmgr/environments.rb', line 60

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

  RecursiveOpenStruct.new(string_keyed_hash, recurse_over_arrays: true)
end

#settings_with_merged_folders(installation_settings) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/opsmgr/environments.rb', line 49

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.vm_shepherd.vm_configs[0].cleanup.datacenter_folders_to_clean << file_system['microbosh_vm_folder']
  settings_to_modify.vm_shepherd.vm_configs[0].cleanup.datacenter_folders_to_clean << file_system['microbosh_template_folder']
  settings_to_modify.vm_shepherd.vm_configs[0].cleanup.datastore_folders_to_clean  << file_system['microbosh_disk_path']
  settings_to_modify
end