class Appforce::Spawn::Template
Public Class Methods
ansible_dest_path(client_api_name)
click to toggle source
# File lib/appforce/spawn/template.rb, line 78 def self.ansible_dest_path(client_api_name) "#{run_path}/#{client_api_name}" end
ansible_source_path()
click to toggle source
# File lib/appforce/spawn/template.rb, line 74 def self.ansible_source_path File.join(gem_path, '../../../ansible') end
copy_template(*args)
click to toggle source
# File lib/appforce/spawn/template.rb, line 21 def self.copy_template(*args) opts = args[1] unless opts[:client_api_name] logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingParameters -- Missing Client API Name" raise Appforce::Spawn::MissingParameters, "Missing Client API Name" end logger.info "[#{self.name}##{__method__.to_s}] Copying files from Template..." FileUtils.cp_r("#{ansible_source_path}/.", "#{ansible_dest_path(opts[:client_api_name])}") end
create_dirs(*args)
click to toggle source
# File lib/appforce/spawn/template.rb, line 6 def self.create_dirs(*args) opts = args[1] unless opts[:client_api_name] logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingParameters -- Missing Client API Name" raise Appforce::Spawn::MissingParameters, "Missing Client API Name" end dir = "#{ansible_dest_path(opts[:client_api_name])}" logger.info "[#{self.name}##{__method__.to_s}] Creating directory: #{dir}" begin FileUtils.mkdir(dir) rescue Errno::EEXIST logger.warn "[#{self.name}##{__method__.to_s}] Directory (#{dir}) already exists." end end
download_files(*args)
click to toggle source
# File lib/appforce/spawn/template.rb, line 31 def self.download_files(*args) opts = args[1] unless opts[:client_api_name] logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingParameters -- Missing Client API Name" raise Appforce::Spawn::MissingParameters, "Missing Client API Name" end logger.info "[#{self.name}##{__method__.to_s}] Pulling Hosts file for Client '#{opts[:client_api_name]}'" write_to_file(Appforce::Spawn::Api::Call.get_hosts(*args), "#{ansible_dest_path(opts[:client_api_name])}/hosts") logger.info "[#{self.name}##{__method__.to_s}] Pulling Active Users file for Client '#{opts[:client_api_name]}'" write_to_file(Appforce::Spawn::Api::Call.get_active_users(*args), "#{ansible_dest_path(opts[:client_api_name])}/active_users.yml") logger.info "[#{self.name}##{__method__.to_s}] Pulling Inactive Users file for Client '#{opts[:client_api_name]}'" write_to_file(Appforce::Spawn::Api::Call.get_inactive_users(*args), "#{ansible_dest_path(opts[:client_api_name])}/inactive_users.yml") logger.info "[#{self.name}##{__method__.to_s}] Pulling Vars file for Client '#{opts[:client_api_name]}'" write_to_file(Appforce::Spawn::Api::Call.get_vars(*args), "#{ansible_dest_path(opts[:client_api_name])}/vars.yml") logger.info "[#{self.name}##{__method__.to_s}] Pulling Main Scout file for Client '#{opts[:client_api_name]}'" write_to_file(Appforce::Spawn::Api::Call.get_main_scout(*args), "#{ansible_dest_path(opts[:client_api_name])}/roles/scout/vars/main.yml") logger.info "[#{self.name}##{__method__.to_s}] Pulling Scout Host Data for Client '#{opts[:client_api_name]}'" write_to_file(Appforce::Spawn::Api::Call.get_private_key(*args), "#{ansible_dest_path(opts[:client_api_name])}/private_key.pem") logger.info "[#{self.name}##{__method__.to_s}] Pulling Private Key Data for Client '#{opts[:client_api_name]}'" File.chmod(0600, "#{ansible_dest_path(opts[:client_api_name])}/private_key.pem") host_data = Appforce::Spawn::Api::Call.get_all_host_data(*args) host_data.each do |host| if host['scout'] == 'true' filename = "#{host[host['method']]}.yml" logger.info "[#{self.name}##{__method__.to_s}] Pulling Scout Host Data for Host '#{host[host['method']]}'" args[1][:host_api_name] = host['id'] write_to_file(Appforce::Spawn::Api::Call.get_host_scout_vars(*args), "#{ansible_dest_path(opts[:client_api_name])}/roles/scout/vars/#{filename}") args[1].delete(:host_api_name) end end end
gem_path()
click to toggle source
# File lib/appforce/spawn/template.rb, line 70 def self.gem_path File.expand_path(File.dirname(__FILE__)) end
run_path()
click to toggle source
# File lib/appforce/spawn/template.rb, line 66 def self.run_path Dir.pwd end
write_to_file(data, path)
click to toggle source
# File lib/appforce/spawn/template.rb, line 82 def self.write_to_file(data, path) begin file = File.open(path, "w") file.write(data) rescue IOError => e logger.fatal "[#{self.name}##{__method__.to_s}] Exception writing to file '#{path}' -- #{e}" raise e ensure file.close unless file == nil end end
Private Class Methods
logger()
click to toggle source
# File lib/appforce/spawn/template.rb, line 96 def self.logger Appforce::Logger.logger end