Class: ForjCoreProcess
- Inherits:
-
Object
- Object
- ForjCoreProcess
- Defined in:
- lib/process/forj_core/process/proxy.rb,
lib/process/forj_core/process/test_box.rb,
lib/process/forj_core/process/ca_root_cert.rb,
lib/process/forj_core/process/forj_process.rb,
lib/process/forj_core/process/forj_process.rb,
lib/process/forj_core/process/forj_process.rb,
lib/process/forj_core/process/forj_process.rb,
lib/process/forj_core/process/forj_process.rb,
lib/process/forj_core/process/forj_process.rb,
lib/process/forj_core/process/forj_process.rb,
lib/process/forj_core/process/forj_process.rb,
lib/process/forj_core/process/forj_process.rb,
lib/process/forj_core/process/forj_process.rb,
lib/process/forj_core/process/forj_process.rb,
lib/process/forj_core/process/forj_process.rb,
lib/process/forj_core/process/forj_process.rb,
lib/process/forj_core/process/forj_process.rb,
lib/process/forj_core/process/forj_process.rb,
lib/process/forj_core/process/forj_process.rb,
lib/process/forj_core/process/forj_process.rb,
lib/process/forj_core/process/forj_process.rb,
lib/process/forj_core/process/forj_process.rb,
lib/process/forj_core/process/lorj_account.rb
Overview
lorj_account process functions
Instance Method Summary collapse
-
#_keypair_files_ask(key_name) ⇒ Object
Function to change the keypair name, as already used.
- #active_server?(o_server, o_address, ssh_key, status) ⇒ Boolean
- #analyze_log_output(output_options, s_status, hParams) ⇒ Object
- #analyze_server_status(s_status, o_log, output_options, _hParams) ⇒ Object
- #assign_ip_boot(o_address, boot_options, s_status, o_server, hParams) ⇒ Object
- #boot_keypairs(server) ⇒ Object
- #build_forge(sObjectType, hParams) ⇒ Object
- #build_lorj_account(sObjectType, hParams) ⇒ Object
- #build_metadata(sObjectType, hParams) ⇒ Object
- #build_userdata(sObjectType, hParams) ⇒ Object
-
#ca_root_detect(hParams, log_output) ⇒ Object
This function detects if the server requires the certificate file to be sent.
-
#ca_root_metadata(hParams, metadata) ⇒ Object
function to add extra meta data to support ca_root_cert.
-
#check_about_imported_key(setup_keys, key_name) ⇒ Object
Function to identify if the keypair name has already been imported.
- #check_setup_keypair ⇒ Object
- #choose_best_kp(predef_keypair, server_keypair, server_name) ⇒ Object
- #clone_maestro_repo(maestro_url, path_maestro, config) ⇒ Object
- #clone_or_use_maestro_repo(sObjectType, hParams) ⇒ Object
- #create_directory(base_dir) ⇒ Object
- #create_keys_automatically(keys, private_key_file) ⇒ Object
- #create_or_use_infra(sObjectType, hParams) ⇒ Object
- #decrypt_key(os_enckey, entr) ⇒ Object
- #delete_forge(_sCloudObj, hParams) ⇒ Object
- #display_boot_critical_error(m_cloud_init_error, m_critical) ⇒ Object
- #display_boot_moving_error(m_cloud_init_error) ⇒ Object
- #display_servers_with_ip(o_forge, blueprint, s_msg) ⇒ Object
- #forge_get_or_create(sObjectType, hParams) ⇒ Object
-
#forj_check_cloud_keypair ⇒ Object
post process after asking keypair name return true go to next step return false go back to ask keypair name again.
-
#forj_check_keypairs_files(input_pathbase) ⇒ Object
Check files existence.
-
#forj_cloud_keypair_coherent?(_keypair_files) ⇒ Boolean
pre process before asking keypair files return true continue to ask keypair files return false skip asking keypair files.
- #forj_dns_settings ⇒ Object
- #forj_dns_settings?(key) ⇒ Boolean
- #forj_dns_supported? ⇒ Boolean
-
#forj_setup_keypairs_files ⇒ Object
keypair_files post setup.
- #get_forge(sCloudObj, sForgeId, _hParams) ⇒ Object
-
#infra_cleanup(infra_dir, maestro_dir) ⇒ Object
check from the list of files under maestro control Do cleanup for files that disappeared.
-
#infra_is_original?(infra_dir, maestro_dir) ⇒ Boolean
Function which compare directories from maestro templates to infra.
- #infra_rebuild(infra_dir) ⇒ Object
- #infra_save_md5(md5_list_file, data) ⇒ Object
- #load_encoded_key ⇒ Object
- #load_existing_forge(o_forge, hParams) ⇒ Object
- #load_h_meta(hParams, hpcloud_priv) ⇒ Object
- #load_hpcloud(hParams, os_key) ⇒ Object
- #load_infra(template, dest_cloud_init, md5_list, is_original = false) ⇒ Object
- #lorj_detect(hParams, log_output, keypair) ⇒ Object
- #lorj_metadata(hParams, h_meta) ⇒ Object
-
#maestro_create_status(sStatus, iCurAct = 4, pending_count = 0) ⇒ Object
Function displaying the server status.
- #old_infra_data_update(oConfig, version, infra_dir) ⇒ Object
- #open_build_env(build_env, tags, y_dns) ⇒ Object
-
#proxy_metadata(hParams, metadata) ⇒ Object
This function configure the proxy metadata.
- #read_blueprint_implemented(o_forge, params) ⇒ Object
- #run_userdata_cmd(cmd, bootstrap, mime) ⇒ Object
- #save_internal_key(keys) ⇒ Object
-
#save_md5(private_key_file, forj_private_key_file, public_key_file, forj_public_key_file) ⇒ Object
Update the forj keypair base files copy from the original base files.
-
#save_sequences(private_key_file, forj_private_key_file, public_key_file, forj_public_key_file, key_name) ⇒ Object
Import the keypair base files setup by user in forj keypair files.
-
#server_connect_info(server, image, address, ssh_key, status) ⇒ Object
function to print out the ssh connection information to the user.
-
#server_get_image(server) ⇒ Object
Function to get the image data from the server.
- #setup_ssh_user(_sCloudObj, hParams) ⇒ Object
- #setup_tenant_name ⇒ Object
- #ssh_connection(sObjectType, hParams) ⇒ Object
- #ssh_keypair(o_server) ⇒ Object
- #ssh_login(options, user, public_ip) ⇒ Object
- #ssh_options(h_keys, private_key_file, o_server) ⇒ Object
- #ssh_server_public_ip(o_server) ⇒ Object
-
#tb_detect(hParams, log_output) ⇒ Object
Function which detects the repository to send out to the box.
-
#tb_metadata(hParams, metadata) ⇒ Object
function to add extra meta data to support test-box.
-
#till_server_active(s_status, hParams, o_address, boot_options) ⇒ Object
Loop until server is active.
- #update_build_env(b_update, tag, y_dns, m_obj) ⇒ Object
- #update_build_env?(b_update, tag, y_dns, m_obj) ⇒ Boolean
-
#update_keypair_config(_ = nil) ⇒ Object
Function to convert unclear data structure keypair_path, splitted.
Instance Method Details
#_keypair_files_ask(key_name) ⇒ Object
Function to change the keypair name, as already used.
1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 |
# File 'lib/process/forj_core/process/forj_process.rb', line 1177 def _keypair_files_ask(key_name) new_key_name = key_name s_msg = 'Please, provide a different keypair base file:' while key_name == new_key_name new_key_name = ask(s_msg) do |q| q.validate = /.+/ end new_key_name = new_key_name.to_s s_msg = 'Incorrect. You have to choose a keypair base file different'\ " than '#{key_name}'. If you want to interrupt, press Ctrl-C."\ "\nSo, please, provide a different keypair"\ ' name:' if key_name == new_key_name end new_key_name end |
#active_server?(o_server, o_address, ssh_key, status) ⇒ Boolean
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 |
# File 'lib/process/forj_core/process/forj_process.rb', line 156 def active_server?(o_server, o_address, ssh_key, status) if o_server[:attrs][:status] == :active return :assign_ip if o_address[:public_ip].nil? image = server_get_image o_server s_msg = 'Your forj Maestro server is up and running and is publically'\ " accessible through IP '#{o_address[:public_ip]}'." PrcLib.info(s_msg) PrcLib.high_level_msg("\n%s\n", s_msg) o_log = process_get(:server_log, 25)[:attrs][:output] if /cloud-init boot finished/ =~ o_log status = :active else PrcLib.info(server_connect_info(o_server, image, o_address, ssh_key, status)) PrcLib.high_level_msg("The forge is still building...\n") status = :cloud_init end else sleep 5 status = :starting end status end |
#analyze_log_output(output_options, s_status, hParams) ⇒ Object
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 |
# File 'lib/process/forj_core/process/forj_process.rb', line 420 def analyze_log_output(, s_status, hParams) o_log = process_get(:server_log, 25) return if o_log.nil? || o_log.empty? log = o_log[:attrs][:output] [:cur_act] = 4 if log == [:old_log] [:old_log] = log if /cloud-init boot finished/ =~ log [:status] = :active [:error] = display_boot_moving_error( [:error] ) elsif /\[CRITICAL\]/ =~ log m_critical = log.scan(/.*\[CRITICAL\].*\n/) [:error] = display_boot_critical_error( [:error], m_critical ) else # validate server status = analyze_server_status(s_status, log, , hParams) end end |
#analyze_server_status(s_status, o_log, output_options, _hParams) ⇒ Object
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 |
# File 'lib/process/forj_core/process/forj_process.rb', line 473 def analyze_server_status(s_status, o_log, , _hParams) if s_status == :cloud_init && /cloud-init-nonet gave up waiting for a network device/ =~ o_log # Valid for ubuntu image 12.04 PrcLib.warning( 'Cloud-init has gave up to configure the network. waiting...' ) [:status] = :nonet elsif s_status == :nonet && /Booting system without full network configuration/ =~ o_log # Valid for ubuntu image 12.04 PrcLib.warning( 'forj has detected an issue to bring up your maestro server.' \ ' Removing it and re-creating a new one. please be patient...' ) [:status] = :restart elsif s_status == :restart process_delete(:server) process_create(:internet_server) [:status] = :starting end end |
#assign_ip_boot(o_address, boot_options, s_status, o_server, hParams) ⇒ Object
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
# File 'lib/process/forj_core/process/forj_process.rb', line 339 def assign_ip_boot(o_address, , s_status, o_server, hParams) if o_address.empty? # To be able to ask for server IP assigned query_cache_cleanup(:public_ip) o_addresses = process_query(:public_ip, :server_id => o_server[:id]) if o_addresses.length == 0 # Assigning Public IP. o_address = process_create(:public_ip) else o_address = o_addresses[0] end end image = hParams.refresh[:image] s_msg = "Public IP for server '#{o_address[:public_ip]}' is assigned." s_msg += server_connect_info(o_server, image, o_address, , s_status) PrcLib.info(s_msg) PrcLib.high_level_msg("\n%s\nThe forge is still building...\n", s_msg) s_status = :cloud_init s_status end |
#boot_keypairs(server) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/process/forj_core/process/forj_process.rb', line 104 def boot_keypairs(server) h_keys = process_create(:keypairs) keypair = process_get(:keypairs, server[:key_name]) h_keys = choose_best_kp(h_keys, keypair, server[:name]) h_keys[:keys] = File.join(h_keys[:keypair_path], h_keys[:private_key_name]) unless h_keys[:coherent] PrcLib.warning("The local keypair '%s' public key and '%s' server's "\ "public key are different.\n"\ "You won't be able to access it until "\ 'you get a copy of the key used to create the server.'\ "\nPublic key found in the cloud:\n%s", h_keys[:name], server[:name], keypair[:public_key]) return h_keys end unless h_keys[:private_key_exist?] PrcLib.warning("The local keypair '%s' private key '%s' is not found. "\ "You won't be able to access '%s' until you get a copy"\ 'of the private key use to create the server.'\ "\nPublic key found in the cloud:\n%s", h_keys[:keys], server[:name], keypair[:public_key]) end h_keys end |
#build_forge(sObjectType, hParams) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/process/forj_core/process/forj_process.rb', line 33 def build_forge(sObjectType, hParams) # TODO: To be replaced by a migration task at install phase. update_keypair_config o_forge = forge_get_or_create(sObjectType, hParams) # Refresh full data on the server found or created. server = controller_get(:server, o_forge[:servers, 'maestro'][:id]) o_forge[:servers, 'maestro'] = server = boot_keypairs(server) # Define the log lines to get and test. config.set(:log_lines, 5) PrcLib.info("Maestro server '%s' id is '%s'.", server[:name], server[:id]) # Waiting for server to come online before assigning a public IP. s_status = :checking maestro_create_status(s_status) o_address = hParams.refresh[:public_ip, :ObjectData] o_address = Lorj::Data.new if o_address.nil? s_status = active_server?(server, o_address, , s_status) till_server_active(s_status, hParams, o_address, ) o_forge = get_forge(sObjectType, config[:instance_name], hParams) read_blueprint_implemented(o_forge, hParams) o_forge end |
#build_lorj_account(sObjectType, hParams) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/process/forj_core/process/lorj_account.rb', line 23 def build_lorj_account(sObjectType, hParams) map = {} Lorj.data. do |section, key, data| section_key = "#{section}##{key}" next if data.nil? || data[:export].nil? if data[:export].boolean? map[section_key] = {} if data[:export] next end map[section_key] = { :keys => data[:export] } end data = {} data[:key], data[:data] = account_export(map, true, true, :exclude => ['forj_core']) data_registered = register(data, sObjectType) data_registered[:key] = Base64.strict_encode64(data[:key].to_yaml) data_registered[:data] = data[:data] enabled = !hParams['maestro#lorj_disabled'].is_a?(TrueClass) data_registered[:enabled] = enabled data_registered end |
#build_metadata(sObjectType, hParams) ⇒ Object
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 |
# File 'lib/process/forj_core/process/forj_process.rb', line 657 def (sObjectType, hParams) entr = load_encoded_key os_enckey = hParams['gardener#os_enckey'] os_key = decrypt_key(os_enckey, entr) hpcloud_priv = load_hpcloud(hParams, os_key) = (hParams, hpcloud_priv) config.set(:meta_data, ) # Used by :server object = .clone ['hpcloud_priv'] = 'XXX - data hidden - XXX' m_print = '' max_key = 0 .keys.each { |k| max_key = [max_key, k.length].max } .keys.sort.each do |k| m_print += format("%-#{max_key}s : %s\n", k, ANSI.bold([k])) end PrcLib.info("Metadata set:\n%s", m_print) = register(, sObjectType) [:meta_data] = end |
#build_userdata(sObjectType, hParams) ⇒ Object
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 |
# File 'lib/process/forj_core/process/forj_process.rb', line 1017 def build_userdata(sObjectType, hParams) # get the paths for maestro and infra repositories # maestro_path = hParams[:maestro_repository].values # infra_path = hParams[:infra_repository].values # concatenate the paths for boothook and cloud_config files # ~ build_dir = File.expand_path(File.join($FORJ_DATA_PATH, '.build')) # ~ boothook = File.join(maestro_path, 'build', 'bin', 'build-tools') # ~ cloud_config = File.join(maestro_path, 'build', 'maestro') mime = File.join( Forj.build_path, format('userdata.mime.%s', rand(36**5).to_s(36)) ) unless hParams[:maestro_repository, :maestro_repo_exist?] PrcLib.fatal(1, "Maestro repository doesn't exist. This is required for "\ "cloud_init user_data build. Check why '%s' "\ "doesn't exist.", hParams[:maestro_repository, :maestro_repo]) end = JSON.generate(hParams[:metadata, :meta_data]) build_tmpl_dir = File.(File.join(LIB_PATH, 'build_tmpl')) PrcLib.state("Preparing user_data - file '%s'", mime) # generate boot_*.sh mime_cmd = "#{build_tmpl_dir}/write-mime-multipart.py" bootstrap = "#{build_tmpl_dir}/bootstrap_build.sh" cmd = format( "%s '%s' '%s' '%s' '%s' '%s' '%s' '%s'", bootstrap, # script # $1 = Forj data base dir PrcLib.data_path, # $2 = Maestro repository dir hParams[:maestro_repository, :maestro_repo], # $3 = Bootstrap directories hParams[:infra_repository, :infra_repo] + ' ' + config.get(:bootstrap_dirs, ''), # $4 = Bootstrap extra directory config[:bootstrap_extra_dir], # $5 = meta_data (string) , # $6: mime script file to execute. mime_cmd, # $7: mime file generated. mime ) run_userdata_cmd(cmd, bootstrap, mime) begin user_data = File.read(mime) rescue => e PrcLib.fatal(1, e.) end if PrcLib.core_level < 5 File.delete(mime) else Lorj.debug(5, "user_data temp file '%s' kept", mime) end config[:user_data] = user_data o_user_data = register(hParams, sObjectType) o_user_data[:user_data] = user_data o_user_data[:user_data_encoded] = Base64.strict_encode64(user_data) o_user_data[:mime] = mime PrcLib.info("user_data prepared. File: '%s'", mime) o_user_data end |
#ca_root_detect(hParams, log_output) ⇒ Object
This function detects if the server requires the certificate file to be sent
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/process/forj_core/process/ca_root_cert.rb', line 21 def ca_root_detect(hParams, log_output) return unless hParams['certs#ca_root_cert'] && !config.exist?(:cert_error) cert_file = hParams['certs#ca_root_cert'] re = /forj-cli: ca-root-cert=(.*)/ res = log_output.split("\n")[-4].match(re) return unless res res_found = cert_file.match(/^(.*)#(.*)$/) if res_found cert_file = File.(res_found[1]) dest_file = "/tmp/#{File.basename(res_found[2])}" else cert_file = File.(cert_file) dest_file = File.basename(cert_file) end unless File.readable?(cert_file) PrcLib.error("Unable to read the Root Certificate file '%s'"\ "You will need install it yourself in /tmp + '"\ ".done' flag file", cert_file) config[:cert_error] = true return end server = hParams[:server, :name] public_ip = hParams[:public_ip, :public_ip] identity = File.join(hParams[:keypairs, :keypair_path], hParams[:keypairs, :private_key_name]) # Get ssh user user = hParams[:image, :ssh_user] PrcLib.info("Copying local file '#{cert_file}' to #{server}:#{dest_file}") = '-o StrictHostKeyChecking=no -o ServerAliveInterval=180' += " -i #{identity}" cmd = "scp #{} #{cert_file} #{user}@#{public_ip}:#{dest_file}" PrcLib.debug("Running command '%s'", cmd) res = `#{cmd}` # For any reason, $CHILD_STATUS is empty, while $? is not. # Ruby bug. tested with: # ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux] # rubocop: disable Style/SpecialGlobalVars unless $?.exitstatus == 0 # rubocop: enable Style/SpecialGlobalVars PrcLib.error("Unable to send the Root Certificate file '%s' "\ "You will need install it yourself in /tmp + '"\ ".done' flag file\n%s", cert_file, res) config[:cert_error] = true return end PrcLib.debug('Flagging the server copy.') `ssh #{} #{user}@#{public_ip} touch #{dest_file}.done` end |
#ca_root_metadata(hParams, metadata) ⇒ Object
function to add extra meta data to support ca_root_cert
-
Args:
-
metadata : Hash. Hash structure to update.
-
-
returns*:
-
nothing
-
88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/process/forj_core/process/ca_root_cert.rb', line 88 def (hParams, ) return unless hParams.exist?('certs#ca_root_cert') res_found = hParams['certs#ca_root_cert'].match(/^(.*)#(.*)$/) if res_found dest_file = "#{res_found[2]}" else dest_file = File.basename(hParams['certs#ca_root_cert']) end ['CA_ROOT_CERT'] = dest_file end |
#check_about_imported_key(setup_keys, key_name) ⇒ Object
Function to identify if the keypair name has already been imported. If so, we can’t change the original files used to import it. The script will ask for another keypair_name.
It will loop until keyname is new or until files originally used is identical.
1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 |
# File 'lib/process/forj_core/process/forj_process.rb', line 1134 def check_about_imported_key(setup_keys, key_name) loop do keys_imported = nil if config.local_exist?(key_name.to_sym, :imported_keys) keys_imported = keypair_detect(key_name, config.local_get(key_name.to_sym, :imported_keys)) end return setup_keys if keys_imported.nil? unless keys_imported[:private_key_exist?] || keys_imported[:public_key_exist?] PrcLib.warning("The local keypair '%s' imported files do not exist "\ 'anymore. Removed from imported_keys.', key_name) local_del(key_name.to_sym, :imported_keys) break end setup_keybase = File.join(setup_keys[:keypair_path], setup_keys[:key_basename]) imported_keybase = File.join(keys_imported[:keypair_path], keys_imported[:key_basename]) break if setup_keybase == imported_keybase PrcLib.warning("You entered a keypair base file '%s' for keypair name "\ "'%s'. Originally, this keypair name was created from "\ "'%s' instead.\n"\ 'To not overwrite it, we recommend you'\ ' to choose a different keypair name.', setup_keybase, key_name, imported_keybase) key_name = _keypair_files_ask(key_name) config.set(:key_name, key_name) setup_keys = keypair_detect(key_name, setup_keys[:keypair_path], setup_keys[:key_basename]) end setup_keys end |
#check_setup_keypair ⇒ Object
1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 |
# File 'lib/process/forj_core/process/forj_process.rb', line 1311 def check_setup_keypair key_name = config[:keypair_name] setup_keypair_path = File.(File.dirname(config[:keypair_files])) setup_keypair_base = File.basename(config[:keypair_files]) setup_keys = keypair_detect(key_name, setup_keypair_path, setup_keypair_base) # Request different keypair_name, if exist and already imported from another # :keypair_files if config[:keypair_path] == Forj.keypairs_path check_about_imported_key(setup_keys, key_name) else setup_keys end end |
#choose_best_kp(predef_keypair, server_keypair, server_name) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/process/forj_core/process/forj_process.rb', line 134 def choose_best_kp(predef_keypair, server_keypair, server_name) if server_keypair[:name] != predef_keypair[:name] if coherent_keypair?(predef_keypair, server_keypair) PrcLib.warning("Server '%s' is using keypair name '%s' instead of the"\ " your account keypair name '%s'.\n"\ 'Your predefined keypair name is compatible with '\ 'that server. (public key identical), so Forj will use'\ " '%s' by default", server_name, server_keypair[:name], server_keypair[:name], server_keypair[:name]) return predef_keypair end PrcLib.warning("Server '%s' is using keypair name '%s' instead of the "\ "your account keypair name '%s'.\n"\ "Forj will try to find and use a local keypair name '%s'"\ ' instead.', server_name, server_keypair[:name], predef_keypair[:name], server_keypair[:name]) return server_keypair end predef_keypair end |
#clone_maestro_repo(maestro_url, path_maestro, config) ⇒ Object
690 691 692 693 694 695 696 697 698 699 700 701 702 |
# File 'lib/process/forj_core/process/forj_process.rb', line 690 def clone_maestro_repo(maestro_url, path_maestro, config) PrcLib.state("Cloning maestro repo from '%s' to '%s'", maestro_url, File.join(path_maestro, 'maestro')) if File.directory?(path_maestro) if File.directory?(File.join(path_maestro, 'maestro')) FileUtils.rm_r File.join(path_maestro, 'maestro') end end git = Git.clone(maestro_url, 'maestro', :path => path_maestro) git.checkout(config[:branch]) if config[:branch] != 'master' PrcLib.info("Maestro repo '%s' cloned on branch '%s'", File.join(path_maestro, 'maestro'), config[:branch]) end |
#clone_or_use_maestro_repo(sObjectType, hParams) ⇒ Object
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 |
# File 'lib/process/forj_core/process/forj_process.rb', line 704 def clone_or_use_maestro_repo(sObjectType, hParams) maestro_url = hParams[:maestro_url] maestro_repo = File.( hParams[:maestro_repo] ) unless hParams[:maestro_repo].nil? path_maestro = File.('~/.forj/') h_result = {} begin if maestro_repo && File.directory?(maestro_repo) PrcLib.info("Using maestro repo '%s'", maestro_repo) h_result[:maestro_repo] = maestro_repo else h_result[:maestro_repo] = File.join(path_maestro, 'maestro') clone_maestro_repo(maestro_url, path_maestro, config) end rescue => e PrcLib.error("Error while cloning the repo from %s\n%s\n%s"\ "\nIf this error persist you could clone the repo manually"\ " in '%s'", maestro_url, e., e.backtrace.join("\n"), h_result[:maestro_repo]) end o_maestro = register(h_result, sObjectType) o_maestro[:maestro_repo] = h_result[:maestro_repo] o_maestro[:maestro_repo_exist?] = File.directory?(h_result[:maestro_repo]) o_maestro end |
#create_directory(base_dir) ⇒ Object
1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 |
# File 'lib/process/forj_core/process/forj_process.rb', line 1094 def create_directory(base_dir) # unless File.directory?(base_dir) return true if FIle.directory?(base_dir) if agree( format("'%s' doesn't exist. Do you want to create it?", base_dir) ) PrcLib.ensure_dir_exists(base_dir) # true else return false end # end end |
#create_keys_automatically(keys, private_key_file) ⇒ Object
1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 |
# File 'lib/process/forj_core/process/forj_process.rb', line 1193 def create_keys_automatically(keys, private_key_file) return if keys[:private_key_exist?] unless File.exist?(private_key_file) # Need to create a key. ask if we need so. PrcLib.("The private key file attached to keypair named '%s' is "\ 'not found. Running ssh-keygen to create it.', keys[:keypair_name]) PrcLib.ensure_dir_exists(File.dirname(private_key_file)) command = format('ssh-keygen -t rsa -f %s', private_key_file) PrcLib.debug(format("Executing '%s'", command)) system(command) end return if File.exist?(private_key_file) PrcLib.fatal(1, 'ssh-keygen did not created your key pairs. Aborting.'\ ' Please review errors in ~/.forj/forj.log') end |
#create_or_use_infra(sObjectType, hParams) ⇒ Object
736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 |
# File 'lib/process/forj_core/process/forj_process.rb', line 736 def create_or_use_infra(sObjectType, hParams) infra = File.(hParams[:infra_repo]) maestro_repo = hParams[:maestro_repository, :maestro_repo] # branch = hParams[:branch] dest_cloud_init = File.join(infra, 'cloud-init') template = File.join(maestro_repo, 'templates', 'infra') cloud_init = File.join(template, 'cloud-init') h_infra = { :infra_repo => dest_cloud_init } PrcLib.ensure_dir_exists(dest_cloud_init) b_rebuild_infra = infra_is_original?(infra, maestro_repo) if b_rebuild_infra PrcLib.state("Building your infra workspace in '%s'", infra) if File.directory?(cloud_init) PrcLib.debug("Copying recursively '%s' to '%s'", cloud_init, infra) FileUtils.copy_entry(cloud_init, dest_cloud_init) end file_ver = File.join(infra, 'forj-cli.ver') File.write(file_ver, INFRA_VERSION) infra_cleanup(infra, maestro_repo) PrcLib.info("The infra workspace '%s' has been built from maestro" \ ' predefined files.', infra) else PrcLib.info("Re-using your infra... in '%s'", infra) end o_infra = register(h_infra, sObjectType) o_infra[:infra_repo] = h_infra[:infra_repo] o_infra end |
#decrypt_key(os_enckey, entr) ⇒ Object
577 578 579 580 581 582 583 584 585 586 587 588 589 |
# File 'lib/process/forj_core/process/forj_process.rb', line 577 def decrypt_key(os_enckey, entr) begin os_key = Encryptor.decrypt( :value => Base64.strict_decode64(os_enckey), :key => entr[:key], :iv => Base64.strict_decode64(entr[:iv]), :salt => entr[:salt] ) rescue raise 'Unable to decript your password. You need to re-execute setup.' end os_key end |
#delete_forge(_sCloudObj, hParams) ⇒ Object
1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 |
# File 'lib/process/forj_core/process/forj_process.rb', line 1498 def delete_forge(_sCloudObj, hParams) PrcLib.state('Destroying server(s) of your forge') forge_serverid = hParams[:forge_server] o_forge = hParams[:forge] o_forge[:servers].each do|_type, server| next if forge_serverid && forge_serverid != server[:id] register(server) PrcLib.state("Destroying server '%s - %s'", server[:name], server[:id]) process_delete(:server) end if forge_serverid.nil? PrcLib.high_level_msg("The forge '%s' has been destroyed. (all servers" \ " linked to the forge)\n", o_forge[:name]) else PrcLib.high_level_msg("Server(s) selected in the forge '%s' has been"\ " removed.\n", o_forge[:name]) end end |
#display_boot_critical_error(m_cloud_init_error, m_critical) ⇒ Object
446 447 448 449 450 451 452 453 454 455 456 457 |
# File 'lib/process/forj_core/process/forj_process.rb', line 446 def display_boot_critical_error(m_cloud_init_error, m_critical) # unless (m_cloud_init_error == m_critical) return if m_cloud_init_error == m_critical s_reported = o_log.clone s_reported['CRITICAL'] = ANSI.bold('CRITICAL') PrcLib.error("cloud-init error detected:\n-----\n%s\n-----\n" \ 'Please connect to the box to decide what you' \ ' need to do.', s_reported) m_cloud_init_error = m_critical m_cloud_init_error # end end |
#display_boot_moving_error(m_cloud_init_error) ⇒ Object
459 460 461 462 463 464 465 466 467 468 |
# File 'lib/process/forj_core/process/forj_process.rb', line 459 def display_boot_moving_error(m_cloud_init_error) if m_cloud_init_error != [] PrcLib.high_level_msg( 'Critical error cleared. Cloud-init seems moving...' ) PrcLib.info('Critical error cleared. Cloud-init seems moving...') m_cloud_init_error = [] end m_cloud_init_error end |
#display_servers_with_ip(o_forge, blueprint, s_msg) ⇒ Object
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 |
# File 'lib/process/forj_core/process/forj_process.rb', line 520 def display_servers_with_ip(o_forge, blueprint, s_msg) i_count = 0 o_forge[:servers].each do |_type, server| next if /^maestro\./ =~ server[:name] register(server) o_ip = process_query(:public_ip, :server_id => server[:id]) if o_ip.length == 0 s_msg += format("\n- %s (No public IP)", server[:name]) else s_msg += format("\n- %s (%s)", server[:name], o_ip[0][:public_ip]) end i_count += 1 end if i_count > 0 s_msg += format("\n%d server(s) identified.\n", i_count) else s_msg = 'No servers found except maestro' PrcLib.warning('Something went wrong, while creating nodes for blueprint'\ " '#{blueprint}'. check maestro logs "\ "(Usually /var/log/cloud-init.log).\n"\ 'Consider Lorj Gardener by setting :default/:lorj: '\ 'false in /opt/config/lorj/config.yaml if puppet'\ ' returned some strange ruby error.') end s_msg end |
#forge_get_or_create(sObjectType, hParams) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/process/forj_core/process/forj_process.rb', line 68 def forge_get_or_create(sObjectType, hParams) o_forge = process_get(sObjectType, config[:instance_name]) if o_forge.empty? || o_forge[:servers].length == 0 PrcLib.high_level_msg("\nBuilding your forge...\n") process_create(:internet_server) o_forge[:servers, 'maestro'] = hParams.refresh[:server] else o_forge = load_existing_forge(o_forge, hParams) end o_forge end |
#forj_check_cloud_keypair ⇒ Object
post process after asking keypair name return true go to next step return false go back to ask keypair name again
1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 |
# File 'lib/process/forj_core/process/forj_process.rb', line 1419 def forj_check_cloud_keypair key_name = config[:keypair_name] return true if key_name.nil? config[:key_cloud_coherence] = false cloud_key = process_get(:keypairs, key_name) register(cloud_key) if !cloud_key.empty? if cloud_key[:coherent] config[:key_cloud_coherence] = true return true end else return true end keypair_display(cloud_key) return true unless cloud_key[:public_key_exist?] PrcLib.("You need to create a new keypair instead of '%s'"\ 'or quit the setup to get the original key and retry.', key_name) s_ask = 'Do you want to create new keypair?' PrcLib.fatal(1, 'Quitting setup per your request.') unless agree(s_ask) false end |
#forj_check_keypairs_files(input_pathbase) ⇒ Object
Check files existence
1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 |
# File 'lib/process/forj_core/process/forj_process.rb', line 1109 def forj_check_keypairs_files(input_pathbase) key_name = config.get(:keypair_name) keypair_path = File.(File.dirname(input_pathbase)) keypair_base = File.(File.basename(input_pathbase)) keys_entered = keypair_detect(key_name, keypair_path, keypair_base) if !keys_entered[:private_key_exist?] && !keys_entered[:public_key_exist?] if agree('The key you entered was not found. Do you want to create' \ ' this one?') base_dir = keys_entered[:keypair_path] return create_directory(base_dir) else return false end end true end |
#forj_cloud_keypair_coherent?(_keypair_files) ⇒ Boolean
pre process before asking keypair files return true continue to ask keypair files return false skip asking keypair files
1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 |
# File 'lib/process/forj_core/process/forj_process.rb', line 1449 def forj_cloud_keypair_coherent?(_keypair_files) return true unless config.exist?(:key_cloud_coherence) keypair = data_objects(:keypairs) return true unless keypair.nil? || keypair[:private_key_exist?] if config[:key_cloud_coherence] PrcLib.('Your local ssh keypair is detected ' \ 'and valid to access the box.') return false end match = ANSI.bold(format('matching %s keypair name previously set', ANSI.red(config[:keypair_name]))) desc = 'the base keypair file name (with absolute path) ' + match Lorj.data.set(:sections, :credentials, :keypair_files, { :desc => desc }, 'setup') true end |
#forj_dns_settings ⇒ Object
1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 |
# File 'lib/process/forj_core/process/forj_process.rb', line 1356 def forj_dns_settings config[:dns_settings] = false return true unless forj_dns_supported? s_ask = 'Optionally, you can ask Maestro to use/manage a domain name on' \ " your cloud. It requires your DNS cloud service to be enabled.\nDo" \ ' you want to configure it?' config[:dns_settings] = agree(s_ask) true end |
#forj_dns_settings?(key) ⇒ Boolean
1368 1369 1370 1371 1372 1373 1374 1375 1376 |
# File 'lib/process/forj_core/process/forj_process.rb', line 1368 def forj_dns_settings?(key) # Return true to ask the question. false otherwise unless config[:dns_settings] section, key = Lorj.data.first_section(key) config.del(key, :name => 'account', :section => section) return false # Do not ask end true end |
#forj_dns_supported? ⇒ Boolean
1378 1379 1380 1381 1382 1383 1384 1385 1386 |
# File 'lib/process/forj_core/process/forj_process.rb', line 1378 def forj_dns_supported? unless config[:provider] == 'hpcloud' PrcLib.("maestro running under '%s' provider currently do "\ "support DNS setting.\n", config.get(:provider)) config[:dns_settings] = false return false # Do not ask end true end |
#forj_setup_keypairs_files ⇒ Object
keypair_files post setup
This function will get the keypair_files setup by user and it will:
-
In case keypair already exist, check if imported files is identical.
-
Create SSH keys if missing (ssh-keygen - create_keys_automatically)
-
exit if :keypair_change is not set to the internal forj dir.
-
For new keys, copy new files and keep the original files import place.
-
For existing keys, update them from their original places (imported from)
-
done
1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 |
# File 'lib/process/forj_core/process/forj_process.rb', line 1279 def forj_setup_keypairs_files keys = check_setup_keypair private_key_file = File.join(keys[:keypair_path], keys[:private_key_name]) public_key_file = File.join(keys[:keypair_path], keys[:public_key_name]) # Creation sequences create_keys_automatically(keys, private_key_file) if Forj.keypairs_path != config[:keypair_path] # Do not save in a config keypair_path not managed by forj. save_internal_key(keys) return true end forj_private_key_file = File.join(Forj.keypairs_path, keys[:keypair_name]) forj_public_key_file = File.join(Forj.keypairs_path, keys[:keypair_name] + '.pub') # Saving sequences if !File.exist?(forj_private_key_file) || !File.exist?(forj_public_key_file) save_sequences(private_key_file, forj_private_key_file, public_key_file, forj_public_key_file, keys[:keypair_name]) else save_md5(private_key_file, forj_private_key_file, public_key_file, forj_public_key_file) end save_internal_key(keys) true # forj_setup_keypairs_files successful end |
#get_forge(sCloudObj, sForgeId, _hParams) ⇒ Object
1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 |
# File 'lib/process/forj_core/process/forj_process.rb', line 1473 def get_forge(sCloudObj, sForgeId, _hParams) s_query = {} servers = {} s_query[:name] = Regexp.new("\\.#{sForgeId}$") o_servers = process_query(:server, s_query, :search_for => "for instance #{sForgeId}") o_servers.each do |o_server| type = o_server[:name].clone type['.' + sForgeId] = '' servers[type] = o_server end PrcLib.info('%s server(s) were found under instance name %s ', servers.count, sForgeId) o_forge = register({}, sCloudObj) o_forge[:servers] = servers o_forge[:name] = sForgeId o_forge end |
#infra_cleanup(infra_dir, maestro_dir) ⇒ Object
check from the list of files under maestro control Do cleanup for files that disappeared.
Then it update the hidden maestro controlled file.
777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 |
# File 'lib/process/forj_core/process/forj_process.rb', line 777 def infra_cleanup(infra_dir, maestro_dir) md5_list_file = File.join(infra_dir, '.maestro_original.yaml') md5_list = {} md5_list = YAML.load_file(md5_list_file) if File.exist?(md5_list_file) cur_md5_list = {} template_dir = File.join(maestro_dir, 'templates', 'infra') cloud_init_dir = File.join(infra_dir, 'cloud-init') load_infra(template_dir, cloud_init_dir, cur_md5_list) md5_list.each do |path, _md5| if cur_md5_list.key?(path) md5_list[path] = cur_md5_list[path] else begin File.delete(File.join(template_dir, path)) rescue PrcLib.debug("'%s' infra file has already been removed.", path) else PrcLib.debug("'%s' infra file has been removed.", path) end md5_list.delete(path) end end infra_save_md5(md5_list_file, md5_list) end |
#infra_is_original?(infra_dir, maestro_dir) ⇒ Boolean
Function which compare directories from maestro templates to infra.
-
return:
-
true if the infra repository file contains some files managed by maestro which has not been updated manually.
-
false otherwise.
-
853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 |
# File 'lib/process/forj_core/process/forj_process.rb', line 853 def infra_is_original?(infra_dir, maestro_dir) dest_cloud_init = File.join(infra_dir, 'cloud-init') template = File.join(maestro_dir, 'templates', 'infra') return false unless File.exist?(template) s_md5_list = File.join(infra_dir, '.maestro_original.yaml') b_result = true md5_list = {} if File.exist?(s_md5_list) begin md5_list = YAML.load_file(s_md5_list) rescue PrcLib.error("Unable to load valid Original files list '%s'. " \ "Your infra workspace won't be migrated, until fixed.", s_md5_list) b_result = false end unless md5_list md5_list = {} b_result = false end end b_result = load_infra(template, dest_cloud_init, md5_list, b_result) if b_result PrcLib.debug( 'No original files found has been updated. Infra workspace' \ ' can be updated/created if needed.' ) else PrcLib.warning( 'At least, one file has been updated. Infra workspace' \ " won't be updated by forj cli." ) end b_result end |
#infra_rebuild(infra_dir) ⇒ Object
889 890 891 892 893 894 895 896 897 898 899 900 901 902 |
# File 'lib/process/forj_core/process/forj_process.rb', line 889 def infra_rebuild(infra_dir) return false unless File.exist?(infra_dir) file_ver = File.join(infra_dir, 'forj-cli.ver') forj_infra_version = nil forj_infra_version = File.read(file_ver) if File.exist?(file_ver) if forj_infra_version.nil? || forj_infra_version == '' # Prior version 37 return(old_infra_data_update(oConfig, '0.0.36', infra_dir)) elsif Gem::Version.new(forj_infra_version) < Gem::Version.new(INFRA_VERSION) return(old_infra_data_update(oConfig, forj_infra_version, infra_dir)) end end |
#infra_save_md5(md5_list_file, data) ⇒ Object
837 838 839 840 841 842 |
# File 'lib/process/forj_core/process/forj_process.rb', line 837 def infra_save_md5(md5_list_file, data) File.open(md5_list_file, 'w') { |out| YAML.dump(data, out) } rescue => e PrcLib.error("File '%s': %s\n%s", md5_list_file, e., e.backtrace.join("\n")) end |
#load_encoded_key ⇒ Object
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 |
# File 'lib/process/forj_core/process/forj_process.rb', line 553 def load_encoded_key key_file = File.join(PrcLib.pdata_path, '.key') if !File.exist?(key_file) # Need to create a random key. entr = { :key => rand(36**10).to_s(36), :salt => Time.now.to_i.to_s, :iv => Base64.strict_encode64( OpenSSL::Cipher::Cipher.new('aes-256-cbc').random_iv ) } PrcLib.debug("Writing '%s' key file", key_file) File.open(key_file, 'w') do |out| out.write(Base64.encode64(entr.to_yaml)) end else PrcLib.debug("Loading '%s' key file", key_file) encoded_key = IO.read(key_file) entr = YAML.load(Base64.decode64(encoded_key)) end entr end |
#load_existing_forge(o_forge, hParams) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/process/forj_core/process/forj_process.rb', line 80 def load_existing_forge(o_forge, hParams) PrcLib.high_level_msg("\nChecking your forge...\n") o_server = o_forge[:servers, 'maestro'] if o_server query = { :server_id => o_server[:id] } register(o_server) o_ip = process_query(:public_ip, query, :network_name => hParams['maestro#network_name']) register(o_ip[0]) if o_ip.length > 0 else PrcLib.high_level_msg("\nYour forge exist, without maestro." \ " Building Maestro...\n") process_create(:internet_server) o_forge[:servers, 'maestro'] = hParams.refresh[:server] PrcLib.high_level_msg("\nBuilding your forge...\n") end o_forge end |
#load_h_meta(hParams, hpcloud_priv) ⇒ Object
607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 |
# File 'lib/process/forj_core/process/forj_process.rb', line 607 def (hParams, hpcloud_priv) = { 'flavor_name' => hParams['maestro#bp_flavor'], 'cdksite' => hParams[:server_name], 'cdkdomain' => hParams['dns#domain_name'], 'eroip' => '127.0.0.1', 'erosite' => hParams[:server_name], 'erodomain' => hParams['dns#domain_name'], 'gitbranch' => hParams['maestro#branch'], 'security_groups' => hParams['maestro#security_group'], 'tenant_name' => hParams['maestro#tenant_name'], 'network_name' => hParams['maestro#network_name'], 'hpcloud_os_region' => hParams['services#compute'], 'PUPPET_DEBUG' => 'True', 'image_name' => hParams['maestro#image_name'], 'key_name' => hParams['credentials#keypair_name'], # The following is used by gardener # Remove pad 'hpcloud_priv' => Base64.strict_encode64(hpcloud_priv).gsub('=', ''), 'compute_os_auth_url' => hParams['gardener#os_auth_uri'] } if hParams['dns#dns_service'] ['dns_zone'] = hParams[:'dns#dns_service'] ['dns_tenantid'] = hParams['dns#dns_tenant_id'] ['dns_auth_url'] = hParams['credentials#auth_uri'] end # If requested by user, ask Maestro to instantiate a blueprint. ['blueprint'] = hParams[:blueprint] if hParams[:blueprint] # Add init additionnal git clone steps. ['repos'] = hParams[:repos] if hParams[:repos] # Add init bootstrap additionnal steps ['bootstrap'] = hParams[:bootstrap] if hParams[:bootstrap] if hParams[:extra_metadata] hParams[:extra_metadata].split(/,/).each do |kv| k, v = kv.split(/=/) [k] = v end end (hParams, ) (hParams, ) (hParams, ) (hParams, ) end |
#load_hpcloud(hParams, os_key) ⇒ Object
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 |
# File 'lib/process/forj_core/process/forj_process.rb', line 591 def load_hpcloud(hParams, os_key) hpcloud_priv = nil IO.popen('gzip -c', 'r+') do|pipe| data = <<-END HPCLOUD_OS_USER='#{hParams['gardener#os_user']}' HPCLOUD_OS_KEY='#{os_key}' DNS_KEY='#{hParams[:'credentials#account_id']}' DNS_SECRET='#{hParams['credentials#account_key']}' END pipe.puts(data) pipe.close_write hpcloud_priv = pipe.read end hpcloud_priv end |
#load_infra(template, dest_cloud_init, md5_list, is_original = false) ⇒ Object
807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 |
# File 'lib/process/forj_core/process/forj_process.rb', line 807 def load_infra(template, dest_cloud_init, md5_list, is_original = false) # We are taking care on bootstrap files only. cloud_init_path = File.join(template, 'cloud-init') return is_original unless File.directory?(cloud_init_path) Find.find(cloud_init_path) do |path| next if File.directory?(path) file_original = true # By default we consider it to be original s_maestro_rel_path = path.clone s_maestro_rel_path[cloud_init_path + '/'] = '' s_infra_path = File.join(dest_cloud_init, s_maestro_rel_path) if File.exist?(s_infra_path) md5_file = Digest::MD5.file(s_infra_path).hexdigest if md5_list.key?(s_maestro_rel_path) && md5_list.rh_get(s_maestro_rel_path, :md5) != md5_file file_original = false PrcLib.info("'%s' infra file has changed from original template" \ ' in maestro.', s_infra_path) else PrcLib.debug("'%s' infra file has not been updated.", s_infra_path) end end md5_file = Digest::MD5.file(path).hexdigest md5_list[s_maestro_rel_path] = { :md5 => md5_file, :original => file_original } is_original &= false end is_original end |
#lorj_detect(hParams, log_output, keypair) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/process/forj_core/process/lorj_account.rb', line 53 def lorj_detect(hParams, log_output, keypair) return unless hParams.exist?(:lorj_account, :data) # the server must wait with 4 last lines in server log: # [...] - forj-cli: lorj_tmp_file=[...] lorj_tmp_key=[...] flag_file=[...] # [...] - build.sh: [...] # [...] - forj-cli: Waiting for [...] # [...] - On your workstation, [...] re = /forj-cli: lorj_tmp_file=(.*) lorj_tmp_key=(.*) flag_file=(.*)/ res = log_output.split("\n")[-4].match(re) return unless res PrcLib.info('lorj: your box is waiting for your cloud data. '\ 'One moment.') # TODO : Add tb_ensure_ssh_config task to set this server in ~/.ssh/config. # unless tb_ensure_ssh_config(hParams) # PrcLib.info('test-box: Unable to configure ssh config with this server.'\ # ' You needs to do it yourself manually. Remote box boot '\ # "process is waiting for #{test_box_dir}") # return # end PrcLib.warning('lorj: ssh config is currently not managed. You may '\ "need to configure it yourself, otherwise forj won't "\ 'connect and transfert the data to the box.') pubip = hParams[:public_ip, :public_ip] user = hParams[:image, :ssh_user] identity = File.join(keypair[:keypair_path], keypair[:private_key_name]) if keypair[:coherent] = '-o StrictHostKeyChecking=no -o ServerAliveInterval=180' += " -i #{identity}" += " #{user}@#{pubip}" ssh_cmd = "echo \"#{hParams[:lorj_account, :data]}\" > #{res[1]}" ssh_cmd += "; echo \"#{hParams[:lorj_account, :key]}\" > #{res[2]}" ssh_cmd += "; touch \"#{res[3]}\"" # TODO: Implement testing branch warning. See build.sh lines 618 -> 632 cmd = "ssh #{} '#{ssh_cmd}'" PrcLib.info "Running following shell instructions:\n#{cmd}" return if system(cmd) end msg <<-EOF Unable to copy Lorj data to the server '#{pubip}'. You need to do it yourself manually, now. To do it, execute following instructions: 1. Connect to server #{pubip} as #{user}. You need to find the proper way to connect to '#{pubip}' as the cloud keypair found is not coherent with some local SSH keys in #{PrcLib.data_path}/keypairs Ex: ssh #{} 2. Create 2 files with the following data: $ echo '#{hParams[:lorj_account, :data]}' > '#{res[1]}' $ echo '#{hParams[:lorj_account, :key]}' > '#{res[2]}' 3. touch the flag file $ touch '#{res[3]}' 4. Disconnect. $ exit As soon as those instructions are done, Maestro should go on. EOF PrcLib.error msg loop do break if ask("When you are done, type 'DONE'") == 'DONE' end end |
#lorj_metadata(hParams, h_meta) ⇒ Object
49 50 51 |
# File 'lib/process/forj_core/process/lorj_account.rb', line 49 def (hParams, ) ['lorj_enabled'] = hParams[:lorj_account, :enabled].to_s end |
#maestro_create_status(sStatus, iCurAct = 4, pending_count = 0) ⇒ Object
Function displaying the server status
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 |
# File 'lib/process/forj_core/process/forj_process.rb', line 191 def maestro_create_status(sStatus, iCurAct = 4, pending_count = 0) s_activity = '/-\\|?' if iCurAct < 4 s_cur_act = 'ACTIVE' else s_cur_act = format('%s - %d s', ANSI.bold('PENDING'), (pending_count + 1) * 5) end case sStatus when :checking PrcLib.state('Checking server status') when :starting PrcLib.state('STARTING') when :assign_ip PrcLib.state('%s - %s - Assigning Public IP', s_activity[iCurAct], s_cur_act) when :cloud_init PrcLib.state('%s - %s - Currently running cloud-init. Be patient.', s_activity[iCurAct], s_cur_act) when :nonet PrcLib.state('%s - %s - Currently running cloud-init. Be patient.', s_activity[iCurAct], s_cur_act) when :restart PrcLib.state('RESTARTING - Currently restarting maestro box. Be patient.') when :active PrcLib.info('Server is active') end end |
#old_infra_data_update(oConfig, version, infra_dir) ⇒ Object
951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 |
# File 'lib/process/forj_core/process/forj_process.rb', line 951 def old_infra_data_update(oConfig, version, infra_dir) PrcLib.info('Migrating your local infra repo (%s) to the latest version.', version) # Be default migration is successful. No need to rebuild it. b_rebuild = false case version when '0.0.36' # Moving from 0.0.36 or less to 0.0.37 or higher. # SET_COMPUTE="{SET_COMPUTE!}" => Setting for Compute. # ignored. Coming from HPC # SET_TENANT_NAME="{SET_TENANT_NAME!}" => Setting for Compute. # ignored. Need to query HPC from current Tenant ID # SET_DNS_TENANTID="{SET_DNS_TENANTID!}" => Setting for DNS. # meta = dns_tenantid # ==> :forj_accounts, s_account_name, :dns, :tenant_id # SET_DNS_ZONE="{SET_DNS_ZONE!}" => Setting for DNS. meta = dns_zone # ==> :forj_accounts, s_account_name, :dns, :service # SET_DOMAIN="{SET_DOMAIN!}" => Setting for Maestro (required) # and DNS if enabled. # ==> :forj_accounts, s_account_name, :dns, :domain_name y_dns = {} y_dns = oConfig[:dns] if oConfig.exist?(:dns) Dir.foreach(infra_dir) do |file| next unless /^maestro\.box\..*\.env$/ =~ file build_env = File.join(infra_dir, file) PrcLib.debug("Reading data from '%s'", build_env) = { 'SET_DNS_TENANTID' => :tenant_id, 'SET_DNS_ZONE' => :service, 'SET_DOMAIN' => :domain_name } open_build_env(build_env, , y_dns) end file_ver = File.join(infra_dir, 'forj-cli.ver') File.write(file_ver, INFRA_VERSION) oConfig[:dns] = y_dns oConfig.ac_save return b_rebuild end end |
#open_build_env(build_env, tags, y_dns) ⇒ Object
928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 |
# File 'lib/process/forj_core/process/forj_process.rb', line 928 def open_build_env(build_env, , y_dns) b_update = nil File.open(build_env) do |f| line = f.readline next if line.match(/^(SET_[A-Z_]+)=["'](.*)["'].*$/).nil? # f.each_line do |line| m_obj = line.match(/^(SET_[A-Z_]+)=["'](.*)["'].*$/) # if m_obj PrcLib.debug("Reviewing detected '%s' tag", m_obj[1]) tag = ([m_obj[1]] ? [m_obj[1]] : nil) b_update = update_build_env(b_update, tag, y_dns, m_obj) # end # end end rescue => e PrcLib.fatal(1, "Failed to open the build environment file '%s'", build_env, e) end |
#proxy_metadata(hParams, metadata) ⇒ Object
This function configure the proxy metadata
20 21 22 23 24 |
# File 'lib/process/forj_core/process/proxy.rb', line 20 def (hParams, ) return unless hParams.exist?('network#webproxy') ['webproxy'] = hParams['network#webproxy'] end |
#read_blueprint_implemented(o_forge, params) ⇒ Object
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 |
# File 'lib/process/forj_core/process/forj_process.rb', line 497 def read_blueprint_implemented(o_forge, params) o_address = params[:public_ip, :ObjectData] blueprint = params[:blueprint] instance_name = params[:instance_name] s_msg = "Your Forge '#{instance_name}' is ready and accessible from" \ " IP #{o_address[:public_ip]}." # TODO: read the blueprint/layout to identify which services # are implemented and can be accessible. if blueprint s_msg += "\nMaestro has implemented the following server(s) for your"\ " blueprint '#{blueprint}':" s_msg = display_servers_with_ip(o_forge, blueprint, s_msg) else s_msg += "\nMaestro has NOT implemented any servers, because you did" \ ' not provided a blueprint. Connect to Maestro, and ask Maestro to' \ ' implement any kind of blueprint you need. (Feature currently' \ ' under development)' end PrcLib.info(s_msg) PrcLib.high_level_msg("\n%s\nEnjoy!\n", s_msg) end |
#run_userdata_cmd(cmd, bootstrap, mime) ⇒ Object
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 |
# File 'lib/process/forj_core/process/forj_process.rb', line 999 def run_userdata_cmd(cmd, bootstrap, mime) # TODO: Replace shell script call to ruby functions if PrcLib.core_level >= 1 cmd += " >> #{PrcLib.log_file}" else cmd += " | tee -a #{PrcLib.log_file}" end fail ForjError.new, "#{bootstrap} script file is" \ ' not found.' unless File.exist?(bootstrap) PrcLib.debug("Running '%s'", cmd) Kernel.system(cmd) fail ForjError.new, format( "mime file '%s' not found.", mime ) unless File.exist?(mime) end |
#save_internal_key(keys) ⇒ Object
1260 1261 1262 1263 1264 1265 1266 1267 |
# File 'lib/process/forj_core/process/forj_process.rb', line 1260 def save_internal_key(keys) # Saving internal copy of private key file for forj use. config.set(:keypair_base, keys[:keypair_name], :name => 'account') PrcLib.info("Configured forj keypair '%s' with '%s'", keys[:keypair_name], File.join(keys[:keypair_path], keys[:key_basename]) ) end |
#save_md5(private_key_file, forj_private_key_file, public_key_file, forj_public_key_file) ⇒ Object
Update the forj keypair base files copy from the original base files.
This function is can be executed only if we copy files to internal forj keypair storage. Otherwise this update is ignored.
1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 |
# File 'lib/process/forj_core/process/forj_process.rb', line 1233 def save_md5(private_key_file, forj_private_key_file, public_key_file, forj_public_key_file ) # Checking source/dest files content if Digest::MD5.file(private_key_file).hexdigest != Digest::MD5.file(forj_private_key_file).hexdigest PrcLib.info( 'Updating private key keypair piece to FORJ keypairs list.' ) FileUtils.copy(private_key_file, forj_private_key_file) else PrcLib.info('Private key keypair up to date.') end if Digest::MD5.file(public_key_file).hexdigest != Digest::MD5.file(forj_public_key_file).hexdigest PrcLib.info( 'Updating public key keypair piece to FORJ keypairs list.' ) FileUtils.copy(public_key_file, forj_public_key_file) else PrcLib.info('Public key keypair up to date.') end end |
#save_sequences(private_key_file, forj_private_key_file, public_key_file, forj_public_key_file, key_name) ⇒ Object
Import the keypair base files setup by user in forj keypair files.
This function is can be executed only if we copy files to internal forj keypair storage. Otherwise this update is ignored.
1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 |
# File 'lib/process/forj_core/process/forj_process.rb', line 1217 def save_sequences(private_key_file, forj_private_key_file, public_key_file, forj_public_key_file, key_name ) PrcLib.info('Importing key pair to FORJ keypairs list.') FileUtils.copy(private_key_file, forj_private_key_file) FileUtils.copy(public_key_file, forj_public_key_file) # Attaching this keypair to the account config.set(:keypair_name, key_name, :name => 'account') config.local_set(key_name.to_sym, private_key_file, :imported_keys) end |
#server_connect_info(server, image, address, ssh_key, status) ⇒ Object
function to print out the ssh connection information to the user
-
args:
-
server : Server object with :name
-
image : Image object with :ssh_user
-
address: Server address with :public_ip
-
ssh_key: Server ssh keys with :keys
-
status : Boot status. If boot status is :active the msg will simply display how to connect to. otherwise, it display, how to show instant log.
-
-
returns:
-
msg : A composite message to display
-
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 |
# File 'lib/process/forj_core/process/forj_process.rb', line 375 def server_connect_info(server, image, address, ssh_key, status) server_name = server.nil? ? 'undefined' : server[:name] image_user = image.nil? ? 'undefined' : image[:ssh_user] public_ip = address.nil? ? 'undefined' : address[:public_ip] if ssh_key[:coherent] private_key = ssh_key[:keys] else private_key ANSI.red(ANSI.bold('<no valid private key found>')) more = "\n\n" + ANSI.bold('Unfortunatelly') + ', Forj was not able to find a '\ 'valid keypair to connect to your server.' \ "\nYou need to fix this issue to gain access to your server." end if status == :active "Maestro is accessible through http://#{public_ip}. This will provide"\ " you access to your complete forge implemented by your blueprint.\n\n"\ 'If you want to access your server through ssh, you have several '\ "options:\n- using `forj ssh`\n- using ssh cli with:\n"\ " ssh #{image_user}@#{public_ip} -o StrictHostKeyChecking=no -i "\ "#{private_key}\n\n"\ " You can also create a new host in your ssh config with:\n"\ " echo 'host c_#{server_name}\n"\ " hostname #{public_ip}\n"\ " identity_file #{private_key}\n"\ " User #{image_user}\n"\ " # If you need to set a proxy to access this server\n"\ " # ProxyCommand corkscrew web-proxy 8080 %%h %%p' >> "\ "~/.ssh/config\n"\ "\n So, you will be able to connect to your server with:\n"\ " ssh c_#{server_name}#{more}\n" else "Your forge is still building...\n"\ "Now, as soon as the server respond to the ssh port,\n"\ "you will be able to get a tail of the build with:\n"\ "while [ 1 = 1 ]\n"\ "do\n"\ " ssh #{image_user}@#{public_ip} -o StrictHostKeyChecking=no -i "\ "#{private_key} tail -f /var/log/cloud-init.log\n"\ " sleep 5\n"\ "done#{more}" end end |
#server_get_image(server) ⇒ Object
Function to get the image data from the server
322 323 324 325 326 327 328 329 330 331 |
# File 'lib/process/forj_core/process/forj_process.rb', line 322 def server_get_image(server) image = data_objects(:image, :ObjectData) return image unless image.nil? image = process_get(:image, server[:image_id]) return Lorj::Data.new if image.nil? register(image) end |
#setup_ssh_user(_sCloudObj, hParams) ⇒ Object
1618 1619 1620 1621 1622 1623 1624 1625 |
# File 'lib/process/forj_core/process/forj_process.rb', line 1618 def setup_ssh_user(_sCloudObj, hParams) images = process_query(:image, :name => hParams[:image_name]) result = { :list => config[:users] } if images.length >= 1 && !images[0, :ssh_user].nil? result[:default_value] = images[0, :ssh_user] end result end |
#setup_tenant_name ⇒ Object
1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 |
# File 'lib/process/forj_core/process/forj_process.rb', line 1391 def setup_tenant_name # TODO: To re-introduce with a Controller call instead. o_ssl_error = SSLErrorMgt.new # Retry object PrcLib.debug('Getting tenants from hpcloud cli libraries') begin tenants = Connection.instance.tenants(@sAccountName) rescue => e retry unless o_ssl_error.ErrorDetected(e., e.backtrace, e) PrcLib.fatal(1, 'Network: Unable to connect.') end tenant_id = @oConfig.ExtraGet(:hpc_accounts, @sAccountName, :credentials).rh_get(:tenant_id) tenant_name = nil tenants.each do |elem| tenant_name = elem['name'] if elem['id'] == tenant_id end if tenant_name PrcLib.debug("Tenant ID '%s': '%s' found.", tenant_id, tenant_name) @hAccountData.rh_set(tenant_name, :maestro, :tenant_name) else PrcLib.error("Unable to find the tenant Name for '%s' ID.", tenant_id) end @oConfig.set('tenants', tenants) end |
#ssh_connection(sObjectType, hParams) ⇒ Object
1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 |
# File 'lib/process/forj_core/process/forj_process.rb', line 1523 def ssh_connection(sObjectType, hParams) # Get server information PrcLib.state('Getting server information') o_server = hParams[:server, :ObjectData] register(o_server) public_ip = ssh_server_public_ip(o_server) = ssh_keypair(o_server) # Get ssh user image = process_get(:image, o_server[:image_id]) user = hParams[:ssh_user] user = image[:ssh_user] if user.nil? PrcLib.debug("Using account '%s'.", user) begin PrcLib.state("creating ssh connection with '%s' box", o_server[:name]) ssh_login(, user, public_ip) rescue => e PrcLib.fatal 1, <<-END #{e.} You were not able to connect to this box. Please note that there is no garantuee that your local private key file '#{[:keys]}' is the one that was used while building this box. You have to check with the user who created that box. END end register({ :success => true }, sObjectType) end |
#ssh_keypair(o_server) ⇒ Object
1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 |
# File 'lib/process/forj_core/process/forj_process.rb', line 1554 def ssh_keypair(o_server) if config[:identity].nil? || !config[:identity].is_a?(String) h_keys = keypair_detect( o_server[:key_name], File.join(Forj.keypairs_path, o_server[:key_name]) ) else h_keys = keypair_detect( o_server[:key_name], File.(config[:identity]) ) end private_key_file = File.join( h_keys[:keypair_path], h_keys[:private_key_name] ) public_key_file = File.join(h_keys[:keypair_path], h_keys[:public_key_name]) PrcLib.info("Found openssh private key file '%s'.", private_key_file) if h_keys[:private_key_exist?] if h_keys[:public_key_exist?] PrcLib.info("Found openssh public key file '%s'.", public_key_file) else PrcLib.warning("Openssh public key file '%s' not found. Unable to verify"\ ' keys coherence with remote server.', public_key_file) end = (h_keys, private_key_file, o_server) end |
#ssh_login(options, user, public_ip) ⇒ Object
1627 1628 1629 1630 1631 1632 1633 1634 |
# File 'lib/process/forj_core/process/forj_process.rb', line 1627 def ssh_login(, user, public_ip) s_opts = '-o StrictHostKeyChecking=no -o ServerAliveInterval=180' s_opts += format(' -i %s', [:keys]) if [:keys] command = format('ssh %s %s@%s', s_opts, user, public_ip) PrcLib.debug("Running '%s'", command) system(command) end |
#ssh_options(h_keys, private_key_file, o_server) ⇒ Object
1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 |
# File 'lib/process/forj_core/process/forj_process.rb', line 1586 def (h_keys, private_key_file, o_server) if h_keys[:private_key_exist?] = { :keys => private_key_file } PrcLib.debug("Using private key '%s'.", private_key_file) else PrcLib.fatal 1, <<-END The server '#{o_server[:name]}' has been configured with a keypair '#{o_server[:key_name]}' which is not found locally. You won't be able to connect to that server without '#{o_server[:key_name]}' private key. To connect to this box, you need to provide the appropriate private key file with option -i END end end |
#ssh_server_public_ip(o_server) ⇒ Object
1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 |
# File 'lib/process/forj_core/process/forj_process.rb', line 1603 def ssh_server_public_ip(o_server) # Get Public IP of the server. Needs the server to be loaded. o_address = process_query(:public_ip, :server_id => o_server[:id]) if o_address.length == 0 PrcLib.fatal(1, 'ip address for %s server was not found', o_server[:name]) else public_ip = o_address[0][:public_ip] end public_ip end |
#tb_detect(hParams, log_output) ⇒ Object
Function which detects the repository to send out to the box
-
Args:
-
params
: ObjParams. Take care of following data-
:test_box : Hash. Key is the repo, and value a full path to the local repo.
-
:test_box_path : full path to the test-box.sh script
-
:public_ip: Used for ssh connections
-
:keypairs: Used for ssh connections
-
-
log_output
: log string to parse.
-
-
returns :
-
nothing.
-
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/process/forj_core/process/test_box.rb', line 34 def tb_detect(hParams, log_output) return unless hParams[:test_box_path] tb_repos = hParams[:test_box] script = hParams[:test_box_path] # the server must wait with 4 last lines in server log: # [...] - forj-cli: tb-repo=maestro tb-dir=/opt/co[...] tb-root-repo=ma[...] # [...] - build.sh: test-box-repo=maestro # [...] - Test-box: Waiting for ~ubuntu/git/maestro.[...] # [...] - On your workstation, you can start test-b [...] re = /forj-cli: tb-repo=(.*) tb-dir=(.*) tb-root-repo=(.*)/ res = log_output.split("\n")[-4].match(re) if res repo_dir = "--repo-dir #{res[2]} --root-repo #{res[3]}" else res = log_output.split("\n")[-3].match(/build.sh: test-box-repo=(.*)/) repo_dir = '' end return unless res && res[1] && tb_repos[res[1]] repo = res[1] test_box_dir = tb_repos[repo] PrcLib.info('test-box: your box is waiting for a test-box repository. '\ 'One moment.') # TODO : Add tb_ensure_ssh_config task to set this server in ~/.ssh/config. # unless tb_ensure_ssh_config(hParams) # PrcLib.info('test-box: Unable to configure ssh config with this server.'\ # ' You needs to do it yourself manually. Remote box boot '\ # "process is waiting for #{test_box_dir}") # return # end PrcLib.warning('test-box: ssh config is currently not managed. You may '\ 'need to configure it yourself, otherwise test-box may fail') pubip = hParams[:public_ip, :public_ip] user = hParams[:image, :ssh_user] # TODO: Implement testing branch warning. See build.sh lines 618 -> 632 cmd = <<-CMD cd #{test_box_dir} if [ "$(git branch | grep 'testing-larsonsh-#{user}@#{pubip}')" != "" ] then #{script} --remove-from #{user}@#{pubip} --repo #{repo} #{repo_dir} fi #{script} --push-to #{user}@#{pubip} --repo #{repo} #{repo_dir} CMD PrcLib.info "Running following shell instructions:\n#{cmd}" return if system(cmd) PrcLib.error('Unable to run test-box.sh successfully. You need to run it'\ ' yourself manually, now.') loop do break if ask("When you are done, type 'DONE'") == 'DONE' end end |
#tb_metadata(hParams, metadata) ⇒ Object
function to add extra meta data to support test-box
-
Args:
-
metadata : Hash. Hash structure to update.
-
-
returns*:
-
nothing
-
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/process/forj_core/process/test_box.rb', line 109 def (hParams, ) # META['test-box']="test-box=$REPO_TO_ADD;testing-$(id -un)" # else # META['test-box']="${META['test-box']}|$REPO_TO_ADD;testing-$(id -un)" return unless hParams.exist?(:test_box_path) = `echo "testing-$(id -un)"`.split[0] res = [] hParams[:test_box].each_key { |k| res << format('%s;%s', k, ) } ['test-box'] = res.join('|') end |
#till_server_active(s_status, hParams, o_address, boot_options) ⇒ Object
Loop until server is active
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 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/process/forj_core/process/forj_process.rb', line 227 def till_server_active(s_status, hParams, o_address, ) m_cloud_init_error = [] i_cur_act = 0 o_old_log = '' pending_count = 0 server_error = 0 o_server = hParams.refresh[:server, :ObjectData] server_name = o_server[:attrs, :name] image = server_get_image o_server while s_status != :active if i_cur_act == 4 pending_count += 1 else pending_count = 0 end maestro_create_status(s_status, i_cur_act, pending_count) i_cur_act += 1 i_cur_act = i_cur_act % 4 if s_status == :restart process_delete(:server) PrcLib.("Bad server '%s' removed. Creating a new one...", server_name) sleep(5) process_create(:internet_server) s_status = :starting o_server = hParams.refresh[:server, :ObjectData] next end unless o_server.refresh sleep(5) next end if o_server[:status] == :error if server_error == 1 PrcLib.fatal(1, 'Server tried to be rebuilt but failed again.') end server_error = 1 PrcLib.warning("The creation of server '%s' has currently failed. "\ 'Trying to rebuild it, once before give up.', server_name) s_status = :restart next end if s_status == :starting s_status = :assign_ip if o_server[:status] == :active elsif s_status == :assign_ip s_status = assign_ip_boot(o_address, , s_status, o_server, hParams) else # analyze the log output = { :status => s_status, :error => m_cloud_init_error, :old_log => o_old_log, :cur_act => i_cur_act } = analyze_log_output(, s_status, hParams) s_status = [:status] m_cloud_init_error = [:error] o_old_log = [:old_log] i_cur_act = [:cur_act] tb_detect(hParams, o_old_log) ca_root_detect(hParams, o_old_log) lorj_detect(hParams, o_old_log, ) if pending_count == 60 highlight = ANSI.yellow('-' * 40) PrcLib.warning("No more server activity detected.\n"\ "#{highlight}\n"\ "%s\n"\ "#{highlight}\n"\ "The server '%s' is not providing any output log for"\ " more than 5 minutes.\nPlease review the current "\ 'output shown below to determine if this is a normal '\ "situation.\nYou can connect to the server if you "\ "want to.\nTo connect, use:\n"\ 'ssh %s@%s -o StrictHostKeyChecking=no -i %s', o_old_log, server_name, image[:ssh_user], o_address[:public_ip], [:keys]) end end sleep(5) if s_status != :active end PrcLib.info('The Forge build is over!') msg = server_connect_info(o_server, image, o_address, , s_status) PrcLib.info(msg) PrcLib.high_level_msg("\nThe forge is ready...\n#{msg}\n") end |
#update_build_env(b_update, tag, y_dns, m_obj) ⇒ Object
904 905 906 907 908 909 910 |
# File 'lib/process/forj_core/process/forj_process.rb', line 904 def update_build_env(b_update, tag, y_dns, m_obj) if !b_update.nil? && b_update PrcLib.debug("Saved: '%s' = '%s'", m_obj[1], m_obj[2]) y_dns.rh_set(m_obj[2], tag) end b_update end |
#update_build_env?(b_update, tag, y_dns, m_obj) ⇒ Boolean
912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 |
# File 'lib/process/forj_core/process/forj_process.rb', line 912 def update_build_env?(b_update, tag, y_dns, m_obj) if tag && m_obj[2] if b_update.nil? && y_dns.rh_get(tag) && y_dns.rh_get(tag) != m_obj[2] PrcLib.('Your account setup is different than'\ ' build env.') PrcLib.('We suggest you to update your account'\ ' setup with data from your build env.') b_update = agree('Do you want to update your setup with'\ ' those build environment data?') end b_update = update_build_env(b_update, tag, y_dns, m_obj) end b_update end |
#update_keypair_config(_ = nil) ⇒ Object
Function to convert unclear data structure keypair_path, splitted. Update config with keypair_base and keypair_path - forj 1.0.8
-
split it in path and base.
-
Fix existing config about path&base (update_keypair_config)
-
save it in account file respectively as :keypair_path and :keypair_base
Used in keypair_name pre-step at setup time. return true to not skip the data.
1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 |
# File 'lib/process/forj_core/process/forj_process.rb', line 1340 def update_keypair_config(_ = nil) %w(local account).each do |config_name| next if config.latest_version?(config_name) keypair_path = config.get(:keypair_path, nil, :name => config_name) unless keypair_path.nil? = { :name => config_name } .merge!(:section => :default) if config_name == 'local' config.set(:keypair_base, File.basename(keypair_path), ) config.set(:keypair_path, File.dirname(keypair_path), ) end config.version_set(config_name, Forj.file_version) end true end |