Class: MobyDerp::SystemConfig

Inherits:
ConfigFile show all
Defined in:
lib/moby_derp/system_config.rb

Instance Attribute Summary collapse

Attributes inherited from ConfigFile

#logger

Instance Method Summary collapse

Constructor Details

#initialize(config_data_or_filename, moby_info, logger) ⇒ SystemConfig

Returns a new instance of SystemConfig.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
# File 'lib/moby_derp/system_config.rb', line 10

def initialize(config_data_or_filename, moby_info, logger)
	@logger = logger

	case config_data_or_filename
	when String
		super(config_data_or_filename)
	when Hash
		@config = stringify_keys(config_data_or_filename)
	else
		raise ArgumentError, "Unsupported type for config_data_or_filename parameter"
	end

	@host_hostname        = @config["host_hostname"] || Socket.gethostname
	@mount_root           = @config["mount_root"]
	@port_whitelist       = stringify_keys(@config["port_whitelist"] || {})
	@network_name         = @config["network_name"] || "bridge"
	@use_host_resolv_conf = @config["use_host_resolv_conf"] || false

	@cpu_count = moby_info["NCPU"]
	# As far as I can tell, the only 32-bit platform Moby supports is
	# armhf; if that turns out to be incorrect, amend the list below.
	@cpu_bits  = %w{armhf}.include?(moby_info["Architecture"]) ? 32 : 64

	unless @mount_root.is_a?(String)
		raise ConfigurationError,
		      "mount_root must be a string"
	end

	unless @mount_root =~ /\A\//
		raise ConfigurationError,
		      "mount_root must be an absolute path"
	end

	unless @network_name.is_a?(String)
		raise ConfigurationError,
		      "network_name must be a string"
	end

	unless [true, false].include?(@use_host_resolv_conf)
		raise ConfigurationError,
		      "use_host_resolv_conf must be true or false"
	end
end

Instance Attribute Details

#cpu_bitsObject (readonly)

Returns the value of attribute cpu_bits.



7
8
9
# File 'lib/moby_derp/system_config.rb', line 7

def cpu_bits
  @cpu_bits
end

#cpu_countObject (readonly)

Returns the value of attribute cpu_count.



7
8
9
# File 'lib/moby_derp/system_config.rb', line 7

def cpu_count
  @cpu_count
end

#host_hostnameObject (readonly)

Returns the value of attribute host_hostname.



7
8
9
# File 'lib/moby_derp/system_config.rb', line 7

def host_hostname
  @host_hostname
end

#mount_rootObject (readonly)

Returns the value of attribute mount_root.



7
8
9
# File 'lib/moby_derp/system_config.rb', line 7

def mount_root
  @mount_root
end

#network_nameObject (readonly)

Returns the value of attribute network_name.



7
8
9
# File 'lib/moby_derp/system_config.rb', line 7

def network_name
  @network_name
end

#port_whitelistObject (readonly)

Returns the value of attribute port_whitelist.



7
8
9
# File 'lib/moby_derp/system_config.rb', line 7

def port_whitelist
  @port_whitelist
end

#use_host_resolv_confObject (readonly)

Returns the value of attribute use_host_resolv_conf.



7
8
9
# File 'lib/moby_derp/system_config.rb', line 7

def use_host_resolv_conf
  @use_host_resolv_conf
end