Module: ChefWorkstationInitialize::SelfBootstrap::NoChef::DefaultMethodsHelpers

Included in:
CommandlineHelpers
Defined in:
lib/selfbootstrap/nochef/defaultmethods.rb

Instance Method Summary collapse

Instance Method Details

#analyse_object(object) ⇒ Object



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/selfbootstrap/nochef/defaultmethods.rb', line 152

def analyse_object(object)
  begin
    debug_worklog("Analyzing object = #{object.class.name}")
  rescue StandardError => exception
    debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
  end
  begin
    debug_worklog("#{object.class.name}.methods = #{object.methods}")
    debug_worklog("Empty = \n\n\n")
  rescue StandardError => exception
    debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
  end
  begin
    debug_worklog("#{object.class.name}.singleton_methods = #{object.singleton_methods}")
    debug_worklog("Empty = \n\n\n")
  rescue StandardError => exception
    debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
  end
  begin
    debug_worklog("#{object.class.name}.public_constant = #{object.public_constant}")
    debug_worklog("Empty = \n\n\n")
  rescue StandardError => exception
    debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
  end
  begin
    debug_worklog("#{object.class.name}.public_class_method = #{object.public_class_method}")
    debug_worklog("Empty = \n\n\n")
  rescue StandardError => exception
    debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
  end
  begin
    debug_worklog("#{object.class.name}.singleton_methods = #{object.singleton_methods}")
    debug_worklog("Empty = \n\n\n")
  rescue StandardError => exception
    debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
  end
  begin
    debug_worklog("#{object.class.name}.public_methods = #{object.public_methods}")
    debug_worklog("Empty = \n\n\n")
  rescue StandardError => exception
    debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
  end
  begin
    debug_worklog("#{object.class.name}.included_modules = #{object.included_modules}")
    debug_worklog("Empty = \n\n\n")
  rescue StandardError => exception
    debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
  end
  begin
    debug_worklog("#{object.class.name}.local_variables = #{object.local_variables}")
    debug_worklog("Empty = \n\n\n")
  rescue StandardError => exception
    debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
  end
  begin
    debug_worklog("#{object.class.name}.instance_variables = #{object.instance_variables}")
    debug_worklog("Empty = \n\n\n")
  rescue StandardError => exception
    debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
  end
  begin
    debug_worklog("#{object.class.name}.global_variables = #{object.global_variables}")
    debug_worklog("Empty = \n\n\n")
  rescue StandardError => exception
    debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
  end
  begin
    debug_worklog("#{object.class.name}.class_variables = #{object.class_variables}")
    debug_worklog("Empty = \n\n\n")
  rescue StandardError => exception
    debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
  end
  begin
    debug_worklog("#{object.class.name}.constants = #{object.constants}")
  rescue StandardError => exception
    debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
  end
  begin
    debug_worklog("#{object.class.name}.params = #{object.resource_name}")
  rescue StandardError => exception
    debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
  end
  begin
    debug_worklog("#{object.class.name}.resource_initializing = #{object.resource_initializing}")
  rescue StandardError => exception
    debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
  end
  begin
    debug_worklog("#{object.class.name}.resources = #{object.resources}")
  rescue StandardError => exception
    debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
  end
  begin
    debug_worklog("#{object.class.name}.params = #{object.params}")
  rescue StandardError => exception
    debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
  end
  begin
    debug_worklog("#{object.class.name}.find_resource(\"git_resource[YP]\") = #{object.find_resource(:git_resource, "YP")}")
  rescue StandardError => exception
    debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
  end
  # begin
  #   analyse_object(object.find_resource(:git_resource, "YP"), logger)
  # rescue StandardError => exception
  #   debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
  # end
  begin
    debug_worklog("Chef::Provider::GitResource.public_class_method(:init_git) = #{Chef::Provider::GitResource.public_class_method(:init_git)}")
  rescue StandardError => exception
    debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
  end
end

#check_install_dir(dir_to_check) ⇒ Object



119
120
121
122
123
124
125
# File 'lib/selfbootstrap/nochef/defaultmethods.rb', line 119

def check_install_dir(dir_to_check)
  if ::File.basename(get_path(dir_to_check)) == project_name
    search_local_project_folder(dir_to_check)
  else
    ::File.join(get_path(dir_to_check), project_name)
  end
end

#debug_worklog(logstr) ⇒ Object



67
68
69
# File 'lib/selfbootstrap/nochef/defaultmethods.rb', line 67

def debug_worklog(logstr)
  worklog("DEBUG:: #{logstr}")
end

#default_chefzero_portrange ⇒ Object



87
88
89
# File 'lib/selfbootstrap/nochef/defaultmethods.rb', line 87

def default_chefzero_portrange
  '48999-49999'
end

#default_hostname ⇒ Object



83
84
85
# File 'lib/selfbootstrap/nochef/defaultmethods.rb', line 83

def default_hostname
  respond_to?('node') ? node['hostname'] : Socket.gethostname
end

#default_install_dir ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/selfbootstrap/nochef/defaultmethods.rb', line 133

def default_install_dir
  if @workstation.nil?
    working_dir = ENV['default_install_dir'].nil? ? ::Dir.getwd : ENV['default_install_dir']
    install_path = search_local_project_folder(working_dir)
    if ::Dir.exist?(install_path)
      ::Dir.new(install_path)
    else
      error_worklog("Unable to get the project from '#{install_path}' while in the folder #{working_dir}")
    end
  # elsif respond_to?('node')
  #   check_install_dir ::Dir.new("/usr/local/chef/repo/#{node['infra_chef']['project_name']}")
  elsif workstation_resource[:install_dir].nil?
    debug_worklog('workstation defined but install_dir not define')
    generate_default_install_dir
  else
    check_install_dir workstation_resource[:install_dir]
  end
end

#define_resource_requirements ⇒ Object



31
32
# File 'lib/selfbootstrap/nochef/defaultmethods.rb', line 31

def define_resource_requirements
end

#error_worklog(logstr) ⇒ Object



59
60
61
# File 'lib/selfbootstrap/nochef/defaultmethods.rb', line 59

def error_worklog(logstr)
  worklog("ERROR:: #{logstr}")
end

#generate_default_install_dir ⇒ Object



127
128
129
130
131
# File 'lib/selfbootstrap/nochef/defaultmethods.rb', line 127

def generate_default_install_dir
  generic_install_dir = '/usr/local/chef/repo'
  # generate_directory default_install_dir
  ::Dir.exist?(generic_install_dir) ? ::Dir.new(generic_install_dir) : generic_install_dir
end

#generate_directory(dir_path) ⇒ Object



91
92
93
94
95
96
97
# File 'lib/selfbootstrap/nochef/defaultmethods.rb', line 91

def generate_directory(dir_path)
  corrected_dir_path = get_path(dir_path)
  FileUtils.mkdir_p(corrected_dir_path) unless ::File.exist?(corrected_dir_path)
  FileUtils.chown_R(workstation_resource[:user], workstation_resource[:group], corrected_dir_path)
  FileUtils.chmod_R(0775, corrected_dir_path)
  corrected_dir_path
end

#get_out_of_cache_path(cachepath) ⇒ Object



107
108
109
# File 'lib/selfbootstrap/nochef/defaultmethods.rb', line 107

def get_out_of_cache_path(cachepath)
  get_out_of_folder(cachepath, 'cache')
end

#get_out_of_folder(folderpath, folder_to_get_out) ⇒ Object



99
100
101
102
103
104
105
# File 'lib/selfbootstrap/nochef/defaultmethods.rb', line 99

def get_out_of_folder(folderpath, folder_to_get_out)
  if get_path(folderpath).include?(folder_to_get_out)
    get_out_of_folder(::File.dirname(folderpath))
  else
    folderpath
  end
end

#get_out_of_local_chef_path(projectpath) ⇒ Object



111
112
113
# File 'lib/selfbootstrap/nochef/defaultmethods.rb', line 111

def get_out_of_local_chef_path(projectpath)
  get_out_of_folder(projectpath, '.chef')
end

#get_path(dir_obj) ⇒ Object



75
76
77
# File 'lib/selfbootstrap/nochef/defaultmethods.rb', line 75

def get_path(dir_obj)
  dir_obj.is_a?(::Dir) ? dir_obj.path : dir_obj
end

#is_chef_constant_enabled?(constant) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
41
42
# File 'lib/selfbootstrap/nochef/defaultmethods.rb', line 34

def is_chef_constant_enabled?(constant)
  # if is_chefworkstation_available?
    constant_defined = const_defined?(constant)
    worklog "constant_defined = #{constant_defined.class} for #{constant}"
    constant_defined
  # else
  #   false
  # end
end

#parent_nil?(hashobject, *names) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/selfbootstrap/nochef/defaultmethods.rb', line 79

def parent_nil?(hashobject, *names)
  hashobject.nil? ? true : hashobject.depth_nil?(names)
end

#require_implement_method(method_name, *arguments) ⇒ Object



71
72
73
# File 'lib/selfbootstrap/nochef/defaultmethods.rb', line 71

def require_implement_method(method_name, *arguments)
  warning_worklog("Method '#{method_name}' need to be implement from another module or class with arguments '#{arguments.join(', ')}'")
end

#search_local_project_folder(projectpath) ⇒ Object



115
116
117
# File 'lib/selfbootstrap/nochef/defaultmethods.rb', line 115

def search_local_project_folder(projectpath)
  get_out_of_local_chef_path(get_out_of_cache_path(projectpath))
end

#warning_worklog(logstr) ⇒ Object



63
64
65
# File 'lib/selfbootstrap/nochef/defaultmethods.rb', line 63

def warning_worklog(logstr)
  worklog("WARN:: #{logstr}")
end

#worklog(logstr) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/selfbootstrap/nochef/defaultmethods.rb', line 49

def worklog(logstr)
  # if skip_boostrap?
  #   create_chef_additionnal_dir unless ::File.exist?(workstation_logs_dir)
  #   ::File.open(::File.join(get_path(workstation_logs_dir), 'knife.log'), 'a+') do |file|
  #     file.puts logstr
  #   end
  # els
  puts("#{DateTime.now}(#{worklog_counter}):: #{logstr}\n")
end

#worklog_counter ⇒ Object



44
45
46
47
# File 'lib/selfbootstrap/nochef/defaultmethods.rb', line 44

def worklog_counter
  @worklog_counter ||= 0
  @worklog_counter += 1
end