Module: Cucumber::Chef::Utility
- Includes:
- BootstrapHelper, ChefHelper, DirHelper, FileHelper, LXCHelper, LabHelper, LogHelper
- Included in:
- Cucumber::Chef
- Defined in:
- lib/cucumber/chef/utility.rb,
lib/cucumber/chef/utility/dir_helper.rb,
lib/cucumber/chef/utility/lab_helper.rb,
lib/cucumber/chef/utility/log_helper.rb,
lib/cucumber/chef/utility/lxc_helper.rb,
lib/cucumber/chef/utility/chef_helper.rb,
lib/cucumber/chef/utility/file_helper.rb,
lib/cucumber/chef/utility/bootstrap_helper.rb
Defined Under Namespace
Modules: BootstrapHelper, ChefHelper, DirHelper, FileHelper, LXCHelper, LabHelper, LogHelper
Instance Method Summary
collapse
Methods included from LXCHelper
#lxc_hostname_full, #lxc_hostname_short, #lxc_identity, #lxc_ip, #lxc_ssh_port, #lxc_user, #lxc_user_home_dir
Methods included from LogHelper
#log_dependencies, #log_details, #log_key_value, #log_page_break, #logger
Methods included from LabHelper
#lab_hostname_full, #lab_hostname_short, #lab_identity, #lab_ip, #lab_ssh_port, #lab_user, #lab_user_home_dir
Methods included from FileHelper
#config_rb, #labfile, #log_file
Methods included from DirHelper
#artifacts_dir, #home_dir, #provider_dir, #root_dir
Methods included from ChefHelper
#chef_identity, #chef_pre_11, #chef_repo, #chef_user, #in_chef_repo?
#bootstrap_identity, #bootstrap_user, #bootstrap_user_home_dir
Instance Method Details
#boot(name = nil) ⇒ Object
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/cucumber/chef/utility.rb', line 129
def boot(name=nil)
if !in_chef_repo?
message = "It does not look like you are inside a chef-repo! Please relocate to one and execute your command again!"
logger.fatal { message }
raise message
end
name and logger.info { "loading #{name}" }
logger.info { "boot(#{Cucumber::Chef.config_rb})" }
Cucumber::Chef::Config.load
Cucumber::Chef::Labfile.load(Cucumber::Chef.labfile)
end
|
#build_command(name, *args) ⇒ Object
124
125
126
127
|
# File 'lib/cucumber/chef/utility.rb', line 124
def build_command(name, *args)
executable = (Cucumber::Chef.locate(:file, "bin", name) rescue "/usr/bin/env #{name}")
[executable, args].flatten.compact.join(" ")
end
|
#build_home_dir(user) ⇒ Object
112
113
114
|
# File 'lib/cucumber/chef/utility.rb', line 112
def build_home_dir(user)
((user == "root") ? "/root" : "/home/#{user}")
end
|
#ensure_directory(dir) ⇒ Object
108
109
110
|
# File 'lib/cucumber/chef/utility.rb', line 108
def ensure_directory(dir)
FileUtils.mkdir_p(File.dirname(dir))
end
|
#ensure_identity_permissions(identity) ⇒ Object
116
117
118
|
# File 'lib/cucumber/chef/utility.rb', line 116
def ensure_identity_permissions(identity)
(File.exists?(identity) && File.chmod(0400, identity))
end
|
#external_ip ⇒ Object
98
99
100
|
# File 'lib/cucumber/chef/utility.rb', line 98
def external_ip
%x(wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//').chomp.strip
end
|
#generate_do_not_edit_warning(message = nil) ⇒ Object
86
87
88
89
90
91
92
93
94
|
# File 'lib/cucumber/chef/utility.rb', line 86
def generate_do_not_edit_warning(message=nil)
warning = Array.new
warning << "#"
warning << "# WARNING: Automatically generated file; DO NOT EDIT!"
warning << [ "# Cucumber-Chef v#{Cucumber::Chef::VERSION}", message ].compact.join(" ")
warning << "# Generated on #{Time.now.utc.to_s}"
warning << "#"
warning.join("\n")
end
|
#is_rc? ⇒ Boolean
46
47
48
|
# File 'lib/cucumber/chef/utility.rb', line 46
def is_rc?
((Cucumber::Chef::VERSION =~ /rc/) || (Cucumber::Chef::VERSION =~ /pre/))
end
|
#locate(type, *args) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/cucumber/chef/utility.rb', line 52
def locate(type, *args)
pwd = Dir.pwd.split(File::SEPARATOR)
(pwd.length - 1).downto(0) do |i|
candidate = File.join(pwd[0..i], args)
case type
when :file
if (File.exists?(candidate) && !File.directory?(candidate))
return File.expand_path(candidate)
end
when :directory
if (File.exists?(candidate) && File.directory?(candidate))
return File.expand_path(candidate)
end
when :any
if File.exists?(candidate)
return File.expand_path(candidate)
end
end
end
message = "Could not locate #{type} '#{File.join(args)}'."
raise UtilityError, message
end
|
#locate_parent(child) ⇒ Object
78
79
80
81
82
|
# File 'lib/cucumber/chef/utility.rb', line 78
def locate_parent(child)
parent = (locate(:any, child).split(File::SEPARATOR) rescue nil)
raise UtilityError, "Could not locate parent of '#{child}'." unless parent
File.expand_path(File.join(parent[0..(parent.length - 2)]))
end
|
#provider_config ⇒ Object
#tag(name = nil) ⇒ Object
120
121
122
|
# File 'lib/cucumber/chef/utility.rb', line 120
def tag(name=nil)
[ name, "v#{Cucumber::Chef::VERSION}" ].compact.join(" ")
end
|