Class: Mist::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/mist/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Config

Returns a new instance of Config.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/mist/config.rb', line 27

def initialize(path)
  config = YAML.load(File.read(path))

  server_config = config['server'] || nil
  client_config = config['client'] || nil

  if server_config
    @default_distro = server_config['default_distro'] || 'ubuntu'
    @default_release = server_config['default_release'] || 'trusty'
    @username = server_config['username'] || 'mist'
    @ssh_public_key = server_config['ssh_public_key'] || File.join(%w(/ etc mist id_rsa.pub))
    @ssh_private_key = server_config['ssh_private_key'] || File.join(%w(/ etc mist id_rsa))
    @network = server_config['network'] || 'default'
    @subnet = server_config['subnet'] || nil
    @zone = server_config['zone'] || 'us-central1-a'
    @machine_type = server_config['machine_type'] || 'f1-micro'
    @instance_name = server_config['instance_name'] || 'mist'
    @startup_script_path = server_config['startup_scripts'] ||
                           File.join(%w(/ etc mist startup-scripts))
    @use_public_ip = server_config['use_public_ip'] || true
  end

  if client_config
    @servers = client_config['servers']
    @ssh_private_key = client_config['ssh_private_key'] || File.join(%w(/ etc mist id_rsa))
  end
rescue StandardError => ex
  Mist.logger.error "Failed to load configuration file #{path}: #{ex}"
  abort 'could not load configuration file'
end

Instance Attribute Details

#default_distroObject (readonly)

Server config attributes



19
20
21
# File 'lib/mist/config.rb', line 19

def default_distro
  @default_distro
end

#default_releaseObject (readonly)

Server config attributes



19
20
21
# File 'lib/mist/config.rb', line 19

def default_release
  @default_release
end

#instance_nameObject (readonly)

Returns the value of attribute instance_name.



21
22
23
# File 'lib/mist/config.rb', line 21

def instance_name
  @instance_name
end

#machine_typeObject (readonly)

Returns the value of attribute machine_type.



21
22
23
# File 'lib/mist/config.rb', line 21

def machine_type
  @machine_type
end

#networkObject (readonly)

Returns the value of attribute network.



21
22
23
# File 'lib/mist/config.rb', line 21

def network
  @network
end

#serversObject (readonly)

Client config attributes



25
26
27
# File 'lib/mist/config.rb', line 25

def servers
  @servers
end

#ssh_private_keyObject (readonly)

Returns the value of attribute ssh_private_key.



20
21
22
# File 'lib/mist/config.rb', line 20

def ssh_private_key
  @ssh_private_key
end

#ssh_public_keyObject (readonly)

Returns the value of attribute ssh_public_key.



20
21
22
# File 'lib/mist/config.rb', line 20

def ssh_public_key
  @ssh_public_key
end

#startup_script_pathObject (readonly)

Returns the value of attribute startup_script_path.



21
22
23
# File 'lib/mist/config.rb', line 21

def startup_script_path
  @startup_script_path
end

#subnetObject (readonly)

Returns the value of attribute subnet.



21
22
23
# File 'lib/mist/config.rb', line 21

def subnet
  @subnet
end

#use_public_ipObject (readonly)

Returns the value of attribute use_public_ip.



22
23
24
# File 'lib/mist/config.rb', line 22

def use_public_ip
  @use_public_ip
end

#usernameObject (readonly)

Returns the value of attribute username.



20
21
22
# File 'lib/mist/config.rb', line 20

def username
  @username
end

#zoneObject (readonly)

Returns the value of attribute zone.



21
22
23
# File 'lib/mist/config.rb', line 21

def zone
  @zone
end