Class: Cloud66::Commands::Configure

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud66_agent/commands/configure.rb

Class Method Summary collapse

Class Method Details

.perform(server_uid, cloud) ⇒ Object



8
9
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
# File 'lib/cloud66_agent/commands/configure.rb', line 8

def self.perform(server_uid, cloud)
	begin
		if cloud.nil? || cloud.empty?
			# try figure it out
			$config.is_aws = Utils::VitalSigns.is_aws?

			if $config.is_aws
				$config.is_gc = false
			else
				# try figure it out
				$config.is_gc = Utils::VitalSigns.is_gc?
			end
		else
			# use the passed in value
			$config.is_aws = (cloud == 'aws')

			# use the passed in value
			$config.is_gc = (cloud == 'googlecloud')
		end
		data = {
			:timezone => Time.new.zone,
			:server_uid => server_uid,
			:version => Utils::Version.current,
			:system => Utils::VitalSigns.system_info }

		address_info = Utils::VitalSigns.address_info
		data = data.merge(address_info)
	rescue => exc
		data = { error: exc.message }
	end
	result = Utils::Server.send_configure data
	$config.agent_uid = result['agent_uid']
	$config.disabled = false
	$config.save
	exit 0
rescue => exc
	$logger.error "Command \"configure\" failed: #{exc.message}"
	exit -1
end