Module: ChefVPCToolkit::Util

Defined in:
lib/chef-vpc-toolkit/util.rb

Constant Summary collapse

@@configs =
nil

Class Method Summary collapse

Class Method Details

.hostnameObject



10
11
12
# File 'lib/chef-vpc-toolkit/util.rb', line 10

def self.hostname
	Socket.gethostname
end

.load_configsObject



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
# File 'lib/chef-vpc-toolkit/util.rb', line 14

def self.load_configs

	return @@configs if not @@configs.nil?

	config_file=ENV['CHEF_VPC_TOOLKIT_CONF']
	if config_file.nil? then

		config_file=ENV['HOME']+File::SEPARATOR+".chef_vpc_toolkit.conf"
		if not File.exists?(config_file) then
			config_file="/etc/chef_vpc_toolkit.conf"
		end

	end

	if File.exists?(config_file) then
		configs=YAML.load_file(config_file)
		raise_if_nil_or_empty(configs, "cloud_servers_vpc_url")
		raise_if_nil_or_empty(configs, "cloud_servers_vpc_username")
		raise_if_nil_or_empty(configs, "cloud_servers_vpc_password")
		@@configs=configs
	else
		raise "Failed to load chef VPC toolkit config file. Please configure /etc/chef_vpc_toolkit.conf or create a .chef_vpc_toolkit.conf config file in your HOME directory."
	end

	@@configs

end

.load_public_keyObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/chef-vpc-toolkit/util.rb', line 42

def self.load_public_key

	ssh_dir=ENV['HOME']+File::SEPARATOR+".ssh"+File::SEPARATOR
	if File.exists?(ssh_dir+"id_rsa.pub")
		pubkey=IO.read(ssh_dir+"id_rsa.pub")
	elsif File.exists?(ssh_dir+"id_dsa.pub")
		pubkey=IO.read(ssh_dir+"id_dsa.pub")
	else
		raise "Failed to load SSH key. Please create a SSH public key pair in your HOME directory."
	end

	pubkey.chomp

end

.raise_if_nil_or_empty(options, key) ⇒ Object



57
58
59
60
61
# File 'lib/chef-vpc-toolkit/util.rb', line 57

def self.raise_if_nil_or_empty(options, key)
	if not options or options[key].nil? or options[key].empty? then
		raise "Please specify a valid #{key.to_s} parameter."
	end
end