Class: CloudManager::Configuration::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud_manager/configuration/configuration.rb

Overview

The cloud-manager configuration holder.

This class is responsible for loading a configuration file, and instantiate the specific service configuration object for each defined service. The class also defines some functions, that the child configuration objects can use, to get information provided by other services.

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_file, default_region = nil) ⇒ Configuration

Returns a new instance of Configuration.

Every configured service part gets initialized.

Parameters:

  • the file name of the configuration

  • (defaults to: nil)

    the default region to use for the AWS services. If ‘nil’, than the AWS_REGION environment variable will be used.

Raises:

  • on invalid configuration

Since:

  • 0.1.0



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/cloud_manager/configuration/configuration.rb', line 27

def initialize(config_file, default_region = nil)
  @config_file = config_file
  @default_region = default_region
  @services = {}

  @config = YAML::load_file(@config_file)

  if @config.include?('services')
    @config['services'].each do |service_type, service_config|
      case service_type
        when 'ec2'
          service = CloudManager::Configuration::Service::EC2.new(service_config, @default_region, self)
        when 'ansible'
          service = CloudManager::Configuration::Service::Ansible.new(service_config, self)
        when 'test'
          service = CloudManager::Configuration::Service::Test.new(service_config, self)
        else
          raise "Unhandled service type: #{service_type}"
      end

      @services[service_type] = service
    end
  end
end

Instance Attribute Details

#config_fileString (readonly)

Returns the file name of the configuration.

Returns:

  • the file name of the configuration

Since:

  • 0.1.0



17
18
19
# File 'lib/cloud_manager/configuration/configuration.rb', line 17

def config_file
  @config_file
end

Instance Method Details

#dns_names_of(machine_alias) ⇒ Array<String>

Returns the DNS name list for the given machine.

Every service that can provide DNS names will be asked.

Parameters:

Returns:

  • DNS names of the given machine

Since:

  • 0.1.0



95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/cloud_manager/configuration/configuration.rb', line 95

def dns_names_of(machine_alias)
  dns_names = []

  @services.each do |service_type, service|
    case service_type
      when 'ec2'
        dns_names.concat(service.dns_names_of(machine_alias))
      else
        # this service type cannot provide machine dns names
    end
  end

  dns_names
end

#ips_of(machine_alias) ⇒ Array<String>

Returns the IP list for the given machine.

Every service that can provide IPs will be asked.

Parameters:

Returns:

  • IPs of the given machine

Since:

  • 0.1.0



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/cloud_manager/configuration/configuration.rb', line 74

def ips_of(machine_alias)
  ips = []

  @services.each do |service_type, service|
    case service_type
      when 'ec2'
        ips.concat(service.ips_of(machine_alias))
      else
        # this service type cannot provide machine ip
    end
  end

  ips
end

#managevoid

TODO:

might need to implement some service dependency handling

This method returns an undefined value.

Start the management of the defined configuration.

Each defined service gets managed in the order they are given in the configuration.

Since:

  • 0.1.0



59
60
61
62
63
64
65
66
# File 'lib/cloud_manager/configuration/configuration.rb', line 59

def manage
  puts 'Starting management...'

  @services.each do |service_type, service|
    puts "  - managing #{service_type}"
    service.manage
  end
end