brpm_content 0.1.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +38 -0
- data/.travis.yml +14 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +308 -0
- data/Rakefile +24 -0
- data/TO_BE_MIGRATED.txt +8 -0
- data/architecture.png +0 -0
- data/brpm_content.gemspec +31 -0
- data/customers/demo/integrations/brpm/process_event_handler_event.rb +183 -0
- data/customers/demo/integrations/jenkins/spec/api/applications_spec.rb +89 -0
- data/customers/demo/integrations/jenkins/spec/api/plans_spec.rb +69 -0
- data/customers/demo/integrations/jenkins/spec/api/requests_spec.rb +57 -0
- data/customers/demo/integrations/jenkins/spec/spec_helper.rb +33 -0
- data/customers/demo/integrations/jira/process_webhook_event.rb +33 -0
- data/customers/demo/jira_mappings.rb +29 -0
- data/infrastructure/integrations/event_handler.rb +62 -0
- data/infrastructure/integrations/webhook_receiver.rb +49 -0
- data/infrastructure/shell_scripts/backup_database.sh +19 -0
- data/infrastructure/shell_scripts/create_bl_package.sh +34 -0
- data/infrastructure/shell_scripts/create_release_request.sh +34 -0
- data/infrastructure/shell_scripts/ddns.sh +10 -0
- data/infrastructure/shell_scripts/install_brpm.sh +63 -0
- data/infrastructure/shell_scripts/install_content_module.sh +66 -0
- data/infrastructure/shell_scripts/install_content_repo.sh +60 -0
- data/infrastructure/shell_scripts/install_module_from_gem.sh +80 -0
- data/infrastructure/shell_scripts/maintenance.sh +4 -0
- data/infrastructure/shell_scripts/patch_brpm.sh +90 -0
- data/infrastructure/shell_scripts/restore_database.sh +33 -0
- data/infrastructure/shell_scripts/run_event_handler.cmd +16 -0
- data/infrastructure/shell_scripts/run_event_handler.sh +20 -0
- data/infrastructure/shell_scripts/run_webhook_receiver.cmd +14 -0
- data/infrastructure/shell_scripts/run_webhook_receiver.sh +15 -0
- data/infrastructure/shell_scripts/update_content_repo.sh +21 -0
- data/infrastructure/silent_install_options_4.6.txt +93 -0
- data/infrastructure/silent_install_options_upgrade_4.6.txt +92 -0
- data/infrastructure/smtp_settings.rb +42 -0
- data/infrastructure/ssh_script_header_additions.rb +21 -0
- data/modules/ansible/automations/execute_role.rb +3 -0
- data/modules/ansible/automations/execute_role.txt +12 -0
- data/modules/ansible/config.yml +5 -0
- data/modules/ansible/lib/ansible.rb +41 -0
- data/modules/atrium_orchestrator/automations/execute_workflow.rb +12 -0
- data/modules/atrium_orchestrator/automations/execute_workflow.txt +25 -0
- data/modules/atrium_orchestrator/automations/reserve_ip_address.rb +22 -0
- data/modules/atrium_orchestrator/automations/reserve_ip_address.txt +21 -0
- data/modules/atrium_orchestrator/config.yml +7 -0
- data/modules/atrium_orchestrator/lib/ao_soap_client.rb +94 -0
- data/modules/bladelogic/automations/create_package.rb +29 -0
- data/modules/bladelogic/automations/create_package.txt +26 -0
- data/modules/bladelogic/automations/deploy_package.rb +137 -0
- data/modules/bladelogic/automations/deploy_package.txt +53 -0
- data/modules/bladelogic/config.yml +7 -0
- data/modules/bladelogic/lib/bl_rest/bsa_rest_client.rb +65 -0
- data/modules/bladelogic/lib/bl_soap/blpackage.rb +43 -0
- data/modules/bladelogic/lib/bl_soap/bsa_soap_base.rb +118 -0
- data/modules/bladelogic/lib/bl_soap/bsa_soap_client.rb +34 -0
- data/modules/bladelogic/lib/bl_soap/compliance_job.rb +155 -0
- data/modules/bladelogic/lib/bl_soap/deploy_job.rb +48 -0
- data/modules/bladelogic/lib/bl_soap/depot_group.rb +47 -0
- data/modules/bladelogic/lib/bl_soap/job.rb +376 -0
- data/modules/bladelogic/lib/bl_soap/job_group.rb +72 -0
- data/modules/bladelogic/lib/bl_soap/job_management.rb +22 -0
- data/modules/bladelogic/lib/bl_soap/job_result.rb +12 -0
- data/modules/bladelogic/lib/bl_soap/job_run.rb +271 -0
- data/modules/bladelogic/lib/bl_soap/login.rb +47 -0
- data/modules/bladelogic/lib/bl_soap/nsh_script_job.rb +14 -0
- data/modules/bladelogic/lib/bl_soap/patch_catalog.rb +178 -0
- data/modules/bladelogic/lib/bl_soap/patch_remediation_job.rb +137 -0
- data/modules/bladelogic/lib/bl_soap/patching_job.rb +250 -0
- data/modules/bladelogic/lib/bl_soap/server.rb +12 -0
- data/modules/bladelogic/lib/bl_soap/template.rb +13 -0
- data/modules/bladelogic/lib/bl_soap/utility.rb +99 -0
- data/modules/bladelogic/resource_automations/select_job.rb +33 -0
- data/modules/bladelogic/resource_automations/select_job.txt +15 -0
- data/modules/bladelogic/tests/create_package_spec.rb +28 -0
- data/modules/bladelogic/tests/deploy_package_spec.rb +23 -0
- data/modules/bladelogic/tests/spec_helper.rb +82 -0
- data/modules/brpm/automations/create_release_from_excel.rb +34 -0
- data/modules/brpm/automations/create_release_from_excel.txt +5 -0
- data/modules/brpm/automations/create_release_request.rb +100 -0
- data/modules/brpm/automations/create_release_request.txt +5 -0
- data/modules/brpm/automations/create_request.rb +73 -0
- data/modules/brpm/automations/create_request.txt +23 -0
- data/modules/brpm/automations/promote_request.rb +197 -0
- data/modules/brpm/automations/promote_request.txt +24 -0
- data/modules/brpm/automations/select_application_version.rb +22 -0
- data/modules/brpm/automations/select_application_version.txt +17 -0
- data/modules/brpm/automations/select_component_version.rb +12 -0
- data/modules/brpm/automations/select_component_version.txt +5 -0
- data/modules/brpm/automations/select_request_template.rb +6 -0
- data/modules/brpm/automations/select_request_template.txt +13 -0
- data/modules/brpm/automations/wait_for_step_in_other_request.rb +11 -0
- data/modules/brpm/automations/wait_for_step_in_other_request.txt +13 -0
- data/modules/brpm/automations/wait_till_promoted_request_is_completed.rb +9 -0
- data/modules/brpm/automations/wait_till_promoted_request_is_completed.txt +5 -0
- data/modules/brpm/config.yml +6 -0
- data/modules/brpm/lib/brpm_request.rb +207 -0
- data/modules/brpm/lib/brpm_rest.rb +312 -0
- data/modules/brpm/lib/brpm_rest_client.rb +1501 -0
- data/modules/brpm/resource_automations/select_application.rb +16 -0
- data/modules/brpm/resource_automations/select_application.txt +5 -0
- data/modules/brpm/resource_automations/select_environment.rb +14 -0
- data/modules/brpm/resource_automations/select_environment.txt +5 -0
- data/modules/brpm/resource_automations/select_request_template.rb +16 -0
- data/modules/brpm/resource_automations/select_request_template.txt +5 -0
- data/modules/brpm/resource_automations/select_step_in_request.rb +33 -0
- data/modules/brpm/resource_automations/select_step_in_request.txt +5 -0
- data/modules/brpm/sample_applications/e-finance.json +0 -0
- data/modules/brpm/tests/create_release_request_spec.rb +66 -0
- data/modules/brpm/tests/create_request_spec.rb +84 -0
- data/modules/brpm/tests/select_application_version_spec.rb +47 -0
- data/modules/brpm/tests/spec_helper.rb +63 -0
- data/modules/docker_brpm/automations/create_brpm_instance_input_params.rb +10 -0
- data/modules/docker_brpm/automations/create_brpm_instance_input_params.txt +17 -0
- data/modules/docker_brpm/automations/create_brpm_instance_one_shot.rb +60 -0
- data/modules/docker_brpm/automations/create_brpm_instance_one_shot.txt +14 -0
- data/modules/docker_brpm/automations/create_brpm_instance_show_results.rb +23 -0
- data/modules/docker_brpm/automations/create_brpm_instance_show_results.txt +13 -0
- data/modules/docker_brpm/automations/create_database.rb +24 -0
- data/modules/docker_brpm/automations/create_database.txt +3 -0
- data/modules/docker_brpm/automations/create_environment.rb +14 -0
- data/modules/docker_brpm/automations/create_environment.txt +3 -0
- data/modules/docker_brpm/automations/create_image_for_application.rb +23 -0
- data/modules/docker_brpm/automations/create_image_for_application.txt +6 -0
- data/modules/docker_brpm/automations/create_image_for_brpm_application_input_params.rb +7 -0
- data/modules/docker_brpm/automations/create_image_for_brpm_application_input_params.txt +8 -0
- data/modules/docker_brpm/automations/create_image_for_brpm_database_creator_input_params.rb +7 -0
- data/modules/docker_brpm/automations/create_image_for_brpm_database_creator_input_params.txt +8 -0
- data/modules/docker_brpm/automations/create_image_for_database_creator.rb +21 -0
- data/modules/docker_brpm/automations/create_image_for_database_creator.txt +6 -0
- data/modules/docker_brpm/automations/create_installed_component_for_application.rb +11 -0
- data/modules/docker_brpm/automations/create_installed_component_for_application.txt +3 -0
- data/modules/docker_brpm/automations/create_installed_component_for_database.rb +7 -0
- data/modules/docker_brpm/automations/create_installed_component_for_database.txt +3 -0
- data/modules/docker_brpm/automations/create_installed_component_for_database_creator.rb +8 -0
- data/modules/docker_brpm/automations/create_installed_component_for_database_creator.txt +3 -0
- data/modules/docker_brpm/automations/create_installed_component_for_utilities.rb +7 -0
- data/modules/docker_brpm/automations/create_installed_component_for_utilities.txt +3 -0
- data/modules/docker_brpm/automations/create_version_tags_for_component_in_all_envs.rb +13 -0
- data/modules/docker_brpm/automations/create_version_tags_for_component_in_all_envs.txt +6 -0
- data/modules/docker_brpm/automations/delete_brpm_instance.rb +38 -0
- data/modules/docker_brpm/automations/delete_brpm_instance.txt +8 -0
- data/modules/docker_brpm/automations/execute_test_run_in_jenkins.rb +43 -0
- data/modules/docker_brpm/automations/execute_test_run_in_jenkins.txt +13 -0
- data/modules/docker_brpm/automations/execute_test_run_in_jenkins_show_results.rb +5 -0
- data/modules/docker_brpm/automations/execute_test_run_in_jenkins_show_results.txt +9 -0
- data/modules/docker_brpm/automations/launch_create_image_for_brpm_application_request.rb +27 -0
- data/modules/docker_brpm/automations/launch_create_image_for_brpm_application_request.txt +3 -0
- data/modules/docker_brpm/automations/launch_test_run_request.rb +30 -0
- data/modules/docker_brpm/automations/launch_test_run_request.txt +14 -0
- data/modules/docker_brpm/automations/release_brpm_input_params.rb +7 -0
- data/modules/docker_brpm/automations/release_brpm_input_params.txt +8 -0
- data/modules/docker_brpm/automations/run_application_container.rb +27 -0
- data/modules/docker_brpm/automations/run_application_container.txt +3 -0
- data/modules/docker_brpm/automations/run_database_container.rb +14 -0
- data/modules/docker_brpm/automations/run_database_container.txt +3 -0
- data/modules/docker_brpm/automations/stop_application_container.rb +11 -0
- data/modules/docker_brpm/automations/stop_application_container.txt +3 -0
- data/modules/docker_brpm/automations/stop_database_container.rb +11 -0
- data/modules/docker_brpm/automations/stop_database_container.txt +3 -0
- data/modules/docker_brpm/automations/test_rest_api.rb +18 -0
- data/modules/docker_brpm/automations/test_rest_api.txt +3 -0
- data/modules/docker_brpm/automations/upgrade_database.rb +19 -0
- data/modules/docker_brpm/automations/upgrade_database.txt +8 -0
- data/modules/docker_brpm/config.yml +8 -0
- data/modules/docker_brpm/lib/docker.rb +39 -0
- data/modules/docker_brpm/lib/git.rb +16 -0
- data/modules/docker_brpm/sample_applications/dockerizedbrpm.json +0 -0
- data/modules/email/automations/send_notification.rb +48 -0
- data/modules/email/automations/send_notification.txt +27 -0
- data/modules/email/config.yml +6 -0
- data/modules/framework/automations/direct_execute.rb +10 -0
- data/modules/framework/automations/direct_execute.txt +16 -0
- data/modules/framework/automations/install_module.rb +13 -0
- data/modules/framework/automations/install_module.txt +16 -0
- data/modules/framework/bin/brpm_install +106 -0
- data/modules/framework/bin/event_handler +63 -0
- data/modules/framework/bin/webhook_receiver +49 -0
- data/modules/framework/brpm_auto.rb +307 -0
- data/modules/framework/brpm_framework.rb +88 -0
- data/modules/framework/brpm_script_executor.rb +146 -0
- data/modules/framework/config.yml +7 -0
- data/modules/framework/config/customer_include.rb +26 -0
- data/modules/framework/config/server.yml +3 -0
- data/modules/framework/customer_include_default.rb +25 -0
- data/modules/framework/lib/logging/brpm_logger.rb +39 -0
- data/modules/framework/lib/logging/logger_base.rb +36 -0
- data/modules/framework/lib/logging/simple_logger.rb +27 -0
- data/modules/framework/lib/params/all_params.rb +80 -0
- data/modules/framework/lib/params/integration_settings.rb +27 -0
- data/modules/framework/lib/params/params.rb +172 -0
- data/modules/framework/lib/params/params_base.rb +81 -0
- data/modules/framework/lib/params/request_params.rb +38 -0
- data/modules/framework/lib/resource_framework.rb +211 -0
- data/modules/framework/lib/rest_api.rb +155 -0
- data/modules/framework/lib/semaphore.rb +79 -0
- data/modules/framework/lib/utilities.rb +317 -0
- data/modules/framework/lib/version_control/git.rb +192 -0
- data/modules/framework/lib/version_control/svn.rb +221 -0
- data/modules/framework/log.html +39 -0
- data/modules/framework/tests/all_params_spec.rb +116 -0
- data/modules/framework/tests/brpm_auto_spec.rb +84 -0
- data/modules/framework/tests/customer_include/config/customer_include.rb +10 -0
- data/modules/framework/tests/customer_include/config/server.yml +3 -0
- data/modules/framework/tests/customer_include_spec.rb +29 -0
- data/modules/framework/tests/local_jirb.rb +15 -0
- data/modules/framework/tests/params_spec.rb +172 -0
- data/modules/framework/tests/request_params_spec.rb +86 -0
- data/modules/framework/tests/server_yaml_spec.rb +19 -0
- data/modules/framework/tests/spec_helper.rb +42 -0
- data/modules/framework/transport/dispatch_baa.rb +355 -0
- data/modules/framework/transport/dispatch_base.rb +345 -0
- data/modules/framework/transport/dispatch_nsh.rb +248 -0
- data/modules/framework/transport/dispatch_ssh.rb +154 -0
- data/modules/framework/transport/transport_baa.rb +1095 -0
- data/modules/framework/transport/transport_nsh.rb +359 -0
- data/modules/framework/transport/transport_ssh.rb +220 -0
- data/modules/framework/write_to.rb +1 -0
- data/modules/jenkins/automations/create_release.rb +4 -0
- data/modules/jenkins/automations/create_release.txt +23 -0
- data/modules/jenkins/automations/f2_downloadJenkinsArtifact.rb +126 -0
- data/modules/jenkins/config.yml +7 -0
- data/modules/jenkins/lib/jenkins.rb +300 -0
- data/modules/jenkins/resource_automations/f2_rsc_jenkinsJobs.rb +58 -0
- data/modules/jira/automations/add_comment.rb +4 -0
- data/modules/jira/automations/add_comment.txt +23 -0
- data/modules/jira/automations/create_release.rb +4 -0
- data/modules/jira/automations/create_release.txt +23 -0
- data/modules/jira/automations/delete_release.rb +4 -0
- data/modules/jira/automations/delete_release.txt +23 -0
- data/modules/jira/automations/transition_issue.rb +4 -0
- data/modules/jira/automations/transition_issue.txt +23 -0
- data/modules/jira/automations/transition_issues_for_request.rb +29 -0
- data/modules/jira/automations/transition_issues_for_request.txt +20 -0
- data/modules/jira/automations/transition_issues_for_run.rb +26 -0
- data/modules/jira/automations/transition_issues_for_run.txt +20 -0
- data/modules/jira/automations/update_release.rb +4 -0
- data/modules/jira/automations/update_release.txt +26 -0
- data/modules/jira/config.yml +7 -0
- data/modules/jira/lib/jira_rest_client.rb +185 -0
- data/modules/jira/tests/create_read_update_delete_release_spec.rb +39 -0
- data/modules/jira/tests/spec_helper.rb +39 -0
- data/modules/jira/tests/transition_issue_spec.rb +32 -0
- data/modules/patch_process_management/automations/execute_job/script.rb +105 -0
- data/modules/patch_process_management/automations/execute_job/wrapper.txt +39 -0
- data/modules/patch_process_management/automations/patch_analysis/script.rb +107 -0
- data/modules/patch_process_management/automations/patch_analysis/wrapper.txt +33 -0
- data/modules/patch_process_management/automations/patch_readiness/script.rb +89 -0
- data/modules/patch_process_management/automations/patch_readiness/wrapper.txt +33 -0
- data/modules/patch_process_management/automations/patch_remediation/script.rb +217 -0
- data/modules/patch_process_management/automations/patch_remediation/wrapper.txt +40 -0
- data/modules/patch_process_management/config.yml +10 -0
- data/modules/teamcity/automations/trigger_build.rb +4 -0
- data/modules/teamcity/automations/trigger_build.txt +14 -0
- data/modules/teamcity/config.yml +7 -0
- data/modules/teamcity/lib/teamcity_rest_client.rb +17 -0
- data/modules/teamcity/tests/spec_helper.rb +34 -0
- data/modules/teamcity/tests/trigger_build_spec.rb +27 -0
- data/modules/windows/automations/deploy_directory_over_windows_shares/script.rb +87 -0
- data/modules/windows/automations/deploy_directory_over_windows_shares/wrapper.txt +29 -0
- data/modules/windows/automations/deploy_file_over_windows_shares/script.rb +31 -0
- data/modules/windows/automations/deploy_file_over_windows_shares/wrapper.txt +24 -0
- data/modules/windows/config.yml +6 -0
- data/modules/windows/lib/samba.rb +29 -0
- metadata +397 -0
@@ -0,0 +1,359 @@
|
|
1
|
+
# Wrapper class for NSH interactions
|
2
|
+
class TransportNSH
|
3
|
+
|
4
|
+
attr_writer :test_mode
|
5
|
+
|
6
|
+
# Initialize the class
|
7
|
+
#
|
8
|
+
# ==== Attributes
|
9
|
+
#
|
10
|
+
# * +nsh_path+ - path to NSH dir on files system (must contain br directory too)
|
11
|
+
# * +options+ - hash of options to use, send "output_file" to point to the logging file
|
12
|
+
# * +test_mode+ - true/false to simulate commands instead of running them
|
13
|
+
#
|
14
|
+
def initialize(nsh_path, options = {}, compat_options = {})
|
15
|
+
self.extend Utilities
|
16
|
+
if options.has_key?("SS_output_dir")
|
17
|
+
BrpmAuto.log "Load for this class has changed, no longer necessary to send params as 2nd argument"
|
18
|
+
options = compat_options
|
19
|
+
end
|
20
|
+
@nsh_path = nsh_path
|
21
|
+
@test_mode = get_option(options, "test_mode", false)
|
22
|
+
@verbose = get_option(options, "verbose", false)
|
23
|
+
@opts = options
|
24
|
+
@run_key = get_option(options,"timestamp",Time.now.strftime("%Y%m%d%H%M%S"))
|
25
|
+
outf = get_option(options,"output_file", SS_output_file)
|
26
|
+
@output_dir = File.dirname(outf)
|
27
|
+
insure_proxy
|
28
|
+
end
|
29
|
+
|
30
|
+
# Verifies that proxy cred is set
|
31
|
+
#
|
32
|
+
# ==== Returns
|
33
|
+
#
|
34
|
+
# * blcred cred -acquire output
|
35
|
+
def insure_proxy
|
36
|
+
return true if get_option(@opts, "bl_profile") == ""
|
37
|
+
res = get_cred
|
38
|
+
puts res
|
39
|
+
end
|
40
|
+
|
41
|
+
# Displays any errors from a cred status
|
42
|
+
#
|
43
|
+
# ==== Attributes
|
44
|
+
#
|
45
|
+
# * +status+ - output from cred command
|
46
|
+
#
|
47
|
+
# ==== Returns
|
48
|
+
#
|
49
|
+
# * true/false
|
50
|
+
def cred_errors?(status)
|
51
|
+
errors = ["EXPIRED","cache is empty"]
|
52
|
+
errors.each do |err|
|
53
|
+
return true if status.include?(err)
|
54
|
+
end
|
55
|
+
return false
|
56
|
+
end
|
57
|
+
|
58
|
+
# Performs a cred -acquire
|
59
|
+
#
|
60
|
+
# ==== Returns
|
61
|
+
#
|
62
|
+
# * cred result message
|
63
|
+
def get_cred
|
64
|
+
bl_cred_path = safe_cmd("blcred")
|
65
|
+
cred_status = `#{bl_cred_path} cred -list`
|
66
|
+
puts "Current Status:\n#{cred_status}" if @test_mode
|
67
|
+
if (cred_errors?(cred_status))
|
68
|
+
# get cred
|
69
|
+
cmd = "#{bl_cred_path} cred -acquire -profile #{get_option(@opts,"bl_profile")} -username #{get_option(@opts,"bl_username")} -password #{get_option(@opts,"bl_password")}"
|
70
|
+
res = execute_shell(cmd)
|
71
|
+
puts display_result(res) if @test_mode
|
72
|
+
result = "Acquiring new credential"
|
73
|
+
else
|
74
|
+
result = "Current credential is valid"
|
75
|
+
end
|
76
|
+
result
|
77
|
+
end
|
78
|
+
|
79
|
+
# Runs an nsh script
|
80
|
+
#
|
81
|
+
# ==== Attributes
|
82
|
+
#
|
83
|
+
# * +script_path+ - path (local to rpm server) to script file
|
84
|
+
#
|
85
|
+
# ==== Returns
|
86
|
+
#
|
87
|
+
# * results of script
|
88
|
+
def nsh(script_path, raw_result = false)
|
89
|
+
cmd = "#{nsh_cmd("nsh")} #{script_path}"
|
90
|
+
cmd = @test_mode ? "echo \"#{cmd}\"" : cmd
|
91
|
+
result = execute_shell(cmd)
|
92
|
+
return result if raw_result
|
93
|
+
display_result(result)
|
94
|
+
end
|
95
|
+
|
96
|
+
# Runs a simple one-line command in NSH
|
97
|
+
#
|
98
|
+
# ==== Attributes
|
99
|
+
#
|
100
|
+
# * +command+ - command to run
|
101
|
+
#
|
102
|
+
# ==== Returns
|
103
|
+
#
|
104
|
+
# * results of command
|
105
|
+
def nsh_command(command, raw_result = false)
|
106
|
+
path = create_temp_script("echo Running #{command.gsub("\n"," - ")}\n#{command}\n")
|
107
|
+
result = nsh(path, raw_result)
|
108
|
+
File.delete path unless @test_mode
|
109
|
+
result
|
110
|
+
end
|
111
|
+
|
112
|
+
# Copies all files (recursively) from source to destination on target hosts
|
113
|
+
#
|
114
|
+
# ==== Attributes
|
115
|
+
#
|
116
|
+
# * +target_hosts+ - blade hostnames to copy to
|
117
|
+
# * +src_path+ - NSH path to source files (may be an array)
|
118
|
+
# * +target_path+ - path to copy to (same for all target_hosts)
|
119
|
+
#
|
120
|
+
# ==== Returns
|
121
|
+
#
|
122
|
+
# * results of command
|
123
|
+
def ncp(target_hosts, src_path, target_path)
|
124
|
+
#ncp -vr /c/dev/SmartRelease_2/lib -h bradford-96204e -d "/c/dev/BMC Software/file_store"
|
125
|
+
src_path = [src_path] if src_path.is_a?(String)
|
126
|
+
if target_hosts.nil?
|
127
|
+
res = split_nsh_path(src_path[0])
|
128
|
+
target_hosts = [res[0]] unless res[0] == ""
|
129
|
+
src_path[0] = res[1] unless res[0] == ""
|
130
|
+
end
|
131
|
+
paths = src_path.map{|pth| pth.include?(" ") ? "\"#{pth}\"" : pth }
|
132
|
+
path_arg = paths.join(" ")
|
133
|
+
cmd = "#{nsh_cmd("ncp")} -vrA #{path_arg} -h #{target_hosts.join(" ")} -d \"#{target_path}\"" unless target_hosts.nil?
|
134
|
+
#cmd = "#{nsh_cmd("cp")} -vr #{path_arg.gsub("localhost","@")} #{target_path}" if target_hosts.nil?
|
135
|
+
if target_hosts.nil? # Local copy
|
136
|
+
FileUtils.cp_r path_arg.gsub("//localhost",""), target_path, :verbose => true
|
137
|
+
res = "cp #{path_arg.gsub("//localhost","")} #{target_path}"
|
138
|
+
else
|
139
|
+
cmd = @test_mode ? "echo \"#{cmd}\"" : cmd
|
140
|
+
log cmd if @verbose
|
141
|
+
result = execute_shell(cmd)
|
142
|
+
res = display_result(result)
|
143
|
+
end
|
144
|
+
res
|
145
|
+
end
|
146
|
+
|
147
|
+
# Runs a command via nsh on a windows target
|
148
|
+
#
|
149
|
+
# ==== Attributes
|
150
|
+
#
|
151
|
+
# * +target_hosts+ - blade hostnames to copy to
|
152
|
+
# * +target_path+ - path to copy to (same for all target_hosts)
|
153
|
+
# * +command+ - command to run
|
154
|
+
#
|
155
|
+
# ==== Returns
|
156
|
+
#
|
157
|
+
# * results of command per host
|
158
|
+
def nexec_win(target_hosts, target_path, command)
|
159
|
+
# if source_script exists, transport it to the hosts
|
160
|
+
result = "Running: #{command}\n"
|
161
|
+
target_hosts.each do |host|
|
162
|
+
cmd = "#{nsh_cmd("nexec")} #{host} cmd /c \"cd #{target_path}; #{command}\""
|
163
|
+
cmd = @test_mode ? "echo \"#{cmd}\"" : cmd
|
164
|
+
result += "Host: #{host}\n"
|
165
|
+
res = execute_shell(cmd)
|
166
|
+
result += display_result(res)
|
167
|
+
end
|
168
|
+
result
|
169
|
+
end
|
170
|
+
|
171
|
+
# Runs a script on a remote server via NSH
|
172
|
+
#
|
173
|
+
# ==== Attributes
|
174
|
+
#
|
175
|
+
# * +target_hosts+ - blade hostnames to copy to
|
176
|
+
# * +script_path+ - nsh path to the script
|
177
|
+
# * +target_path+ - path from which to execute the script on the remote host
|
178
|
+
# * +options+ - hash of options (raw_result = true)
|
179
|
+
#
|
180
|
+
# ==== Returns
|
181
|
+
#
|
182
|
+
# * results of command per host
|
183
|
+
def script_exec(target_hosts, script_path, target_path, options = {})
|
184
|
+
raw_result = get_option(options,"raw_result", false)
|
185
|
+
script_dir = File.dirname(script_path)
|
186
|
+
err_file = touch_file("#{script_dir}/nsh_errors_#{Time.now.strftime("%Y%m%d%H%M%S%L")}.txt")
|
187
|
+
script_path = "\"#{script_path}\"" if script_path.include?(" ")
|
188
|
+
cmd = "#{nsh_cmd("scriptutil")} -d \"#{nsh_path(target_path)}\" -h #{target_hosts.join(" ")} -s #{script_path}"
|
189
|
+
cmd = cmd + " 2>#{err_file}" unless BrpmAuto.windows?
|
190
|
+
result = execute_shell(cmd)
|
191
|
+
result["stderr"] = "#{result["stderr"]}\n#{File.open(err_file).read}"
|
192
|
+
result = display_result(result) unless raw_result
|
193
|
+
result
|
194
|
+
end
|
195
|
+
|
196
|
+
# Executes a text variable as a script on remote targets
|
197
|
+
#
|
198
|
+
# ==== Attributes
|
199
|
+
#
|
200
|
+
# * +target_hosts+ - array of target hosts
|
201
|
+
# * +script_body+ - body of script
|
202
|
+
# * +target_path+ - path on targets to store/execute script
|
203
|
+
#
|
204
|
+
# ==== Returns
|
205
|
+
#
|
206
|
+
# * output of script
|
207
|
+
#
|
208
|
+
def script_execute_body(target_hosts, script_body, target_path, options = {})
|
209
|
+
ext = get_option(options,"platform", "linux").downcase == "linux" ? ".sh" : ".bat"
|
210
|
+
script_file = "nsh_script_#{Time.now.strftime("%Y%m%d%H%M%S")}#{ext}"
|
211
|
+
full_path = File.join(@params["SS_output_dir"],script_file)
|
212
|
+
fil = File.open(full_path,"w+")
|
213
|
+
fil.write script_body.gsub("\r", "")
|
214
|
+
fil.flush
|
215
|
+
fil.close
|
216
|
+
result = script_exec(target_hosts, full_path, target_path, options)
|
217
|
+
end
|
218
|
+
|
219
|
+
# Runs a simple ls command in NSH
|
220
|
+
#
|
221
|
+
# ==== Attributes
|
222
|
+
#
|
223
|
+
# * +nsh_path+ - path to list files
|
224
|
+
#
|
225
|
+
# ==== Returns
|
226
|
+
#
|
227
|
+
# * array of path contents
|
228
|
+
def ls(nsh_path)
|
229
|
+
res = nsh_command("ls #{nsh_path}")
|
230
|
+
res.split("\n").reject{|l| l.start_with?("Running ")}
|
231
|
+
end
|
232
|
+
|
233
|
+
# Provides a host status for the passed targets
|
234
|
+
#
|
235
|
+
# ==== Attributes
|
236
|
+
#
|
237
|
+
# * +target_hosts+ - array of hosts
|
238
|
+
#
|
239
|
+
# ==== Returns
|
240
|
+
#
|
241
|
+
# * hash of agentinfo on remote hosts
|
242
|
+
def status(target_hosts)
|
243
|
+
result = {}
|
244
|
+
target_hosts.each do |host|
|
245
|
+
res = nsh_command("agentinfo #{host}")
|
246
|
+
result[host] = res
|
247
|
+
end
|
248
|
+
result
|
249
|
+
end
|
250
|
+
|
251
|
+
# Returns the nsh path from a dos path
|
252
|
+
#
|
253
|
+
# ==== Attributes
|
254
|
+
#
|
255
|
+
# * +source_path+ - path in nsh
|
256
|
+
# * +server+ - optional, adds a server in nsh format
|
257
|
+
#
|
258
|
+
# ==== Returns
|
259
|
+
#
|
260
|
+
# * nsh compatible path
|
261
|
+
#
|
262
|
+
def nsh_path(source_path, server = nil)
|
263
|
+
path = ""
|
264
|
+
if source_path.include?(":\\")
|
265
|
+
path_array = source_path.split("\\")
|
266
|
+
path = "/#{path_array[0].gsub(":","/")}"
|
267
|
+
path += path_array[1..-1].join("/")
|
268
|
+
else
|
269
|
+
path = source_path.gsub(":","")
|
270
|
+
path = "/#{path}" unless path.start_with?("/")
|
271
|
+
end
|
272
|
+
path = "//#{server}#{path}" unless server.nil?
|
273
|
+
path.chomp("/")
|
274
|
+
end
|
275
|
+
|
276
|
+
# Builds an NSH compatible path for an uploaded file to BRPM
|
277
|
+
#
|
278
|
+
# ==== Attributes
|
279
|
+
#
|
280
|
+
# * +attachment_local_path+ - path to attachment from params
|
281
|
+
# * +brpm_hostname+ - name of brpm host (as accessible from NSH)
|
282
|
+
# ==== Returns
|
283
|
+
#
|
284
|
+
# nsh path
|
285
|
+
#
|
286
|
+
def get_attachment_nsh_path(attachment_local_path, brpm_hostname)
|
287
|
+
if attachment_local_path[1] == ":"
|
288
|
+
attachment_local_path[1] = attachment_local_path[0]
|
289
|
+
attachment_local_path[0] = '/'
|
290
|
+
end
|
291
|
+
attachment_local_path = attachment_local_path.gsub(/\\/, "/")
|
292
|
+
"//#{brpm_hostname}#{attachment_local_path}"
|
293
|
+
end
|
294
|
+
|
295
|
+
# Zip files using NSH
|
296
|
+
#
|
297
|
+
# ==== Attributes
|
298
|
+
#
|
299
|
+
# * +staging_path+ - path to files
|
300
|
+
# * +package_name+ - name of zip file to create
|
301
|
+
# ==== Returns
|
302
|
+
#
|
303
|
+
# hash of instance_path and md5 - {"instance_path" => "", "md5" => ""}
|
304
|
+
def package_staged_artifacts(staging_path, package_name)
|
305
|
+
instance_path = File.join(staging_path, package_name)
|
306
|
+
staging_artifacts = Dir.entries(staging_path).reject{|k| [".",".."].include?(k) }
|
307
|
+
return {"instance_path" => "ERROR - no files in staging area", "md5" => ""} if staging_artifacts.size < 1
|
308
|
+
FileUtils.cd(staging_path, :verbose => true)
|
309
|
+
cmd = "#{nsh_cmd("zip")} -r #{package_name} *"
|
310
|
+
result = execute_shell(cmd)
|
311
|
+
md5 = Digest::MD5.file(instance_path).hexdigest
|
312
|
+
{"instance_path" => instance_path, "md5" => md5, "manifest" => staging_artifacts }
|
313
|
+
end
|
314
|
+
|
315
|
+
# Copies a single file from source to destination via nsh paths
|
316
|
+
#
|
317
|
+
# ==== Attributes
|
318
|
+
#
|
319
|
+
# * +src_path+ - NSH path to source files
|
320
|
+
# * +target_path+ - NSH path to copy to
|
321
|
+
#
|
322
|
+
# ==== Returns
|
323
|
+
#
|
324
|
+
# * results of command
|
325
|
+
def cp(src_path, target_path)
|
326
|
+
cmd = "#{nsh_cmd("cp")} -f #{src_path} \"#{target_path}\""
|
327
|
+
cmd = @test_mode ? "echo \"#{cmd}\"" : cmd
|
328
|
+
log cmd if @verbose
|
329
|
+
result = execute_shell(cmd)
|
330
|
+
res = display_result(result)
|
331
|
+
res
|
332
|
+
end
|
333
|
+
|
334
|
+
private
|
335
|
+
|
336
|
+
def create_temp_script(body, options = {})
|
337
|
+
script_type = get_option(options,"script_type", "nsh")
|
338
|
+
base_path = get_option(options, "temp_path", platform_temp)
|
339
|
+
tmp_file = "#{script_type}_temp_#{precision_timestamp}.#{script_type}"
|
340
|
+
full_path = "#{base_path}/#{tmp_file}"
|
341
|
+
fil = File.open(full_path,"w+")
|
342
|
+
fil.puts body
|
343
|
+
fil.flush
|
344
|
+
fil.close
|
345
|
+
full_path
|
346
|
+
end
|
347
|
+
|
348
|
+
def nsh_cmd(cmd)
|
349
|
+
res = File.join(@nsh_path, "bin", cmd)
|
350
|
+
res = "\"#{res}\"" if res.include?(" ")
|
351
|
+
res
|
352
|
+
end
|
353
|
+
|
354
|
+
def platform_temp
|
355
|
+
res = "/tmp"
|
356
|
+
res = "C:/Windows/temp" if BrpmAuto.windows?
|
357
|
+
res
|
358
|
+
end
|
359
|
+
end
|
@@ -0,0 +1,220 @@
|
|
1
|
+
|
2
|
+
class TransportSSH
|
3
|
+
# Helper Routines for Capistrano
|
4
|
+
require 'capistrano'
|
5
|
+
require 'capistrano/cli'
|
6
|
+
require 'timeout'
|
7
|
+
|
8
|
+
# Initialize the class
|
9
|
+
#
|
10
|
+
# ==== Attributes
|
11
|
+
#
|
12
|
+
# * +servers+ - array of servers to use
|
13
|
+
# * +params+ - the params hash
|
14
|
+
# * +options+ - hash of options to use, user, password, sudo (yes/no), timeout (minutes)
|
15
|
+
#
|
16
|
+
def initialize(servers, options = {}, compat_options = {})
|
17
|
+
self.extend Utilities
|
18
|
+
if options.has_key?("SS_output_dir")
|
19
|
+
BrpmAuto.log "Load for this class has changed, no longer necessary to send params as 2nd argument"
|
20
|
+
options = compat_options
|
21
|
+
end
|
22
|
+
@user = get_option(options, "user", nil)
|
23
|
+
@password = get_option(options, "password", nil)
|
24
|
+
@servers = servers
|
25
|
+
@sudo = get_option(options, "sudo", nil)
|
26
|
+
@debug = get_option(options, "debug", false)
|
27
|
+
@cap = Capistrano::Configuration.new
|
28
|
+
@cap.logger.level = Capistrano::Logger::TRACE
|
29
|
+
maxtime = get_option(options, "timeout", 60)
|
30
|
+
@maxtime = maxtime.to_i * 60
|
31
|
+
end
|
32
|
+
|
33
|
+
# Resets the security credentials
|
34
|
+
#
|
35
|
+
# ==== Attributes
|
36
|
+
#
|
37
|
+
# * +options+ - hash of options [user,password,sudo, debug, servers]
|
38
|
+
#
|
39
|
+
def set_credential(options = {})
|
40
|
+
@user = get_option(options, "user", @user)
|
41
|
+
@password = get_option(options, "password", @password)
|
42
|
+
@servers = get_option(options, "servers", @servers)
|
43
|
+
@sudo = get_option(options, "sudo", @sudo)
|
44
|
+
@debug = get_option(options, "debug", @debug)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Execute a command on remote targets
|
48
|
+
#
|
49
|
+
# ==== Attributes
|
50
|
+
#
|
51
|
+
# * +command+ - command to execute
|
52
|
+
# * +options+ - hash of options includes servers to override class servers
|
53
|
+
#
|
54
|
+
# ==== Returns
|
55
|
+
#
|
56
|
+
# command_run hash {stdout => <results>, stderr => any errors, pid => process id, status => exit_code}
|
57
|
+
def execute_command(command, options = {})
|
58
|
+
@servers = get_option(options, "servers", @servers)
|
59
|
+
execute_cap "command", {"command" => command}
|
60
|
+
end
|
61
|
+
|
62
|
+
# Copy files to remote targets
|
63
|
+
#
|
64
|
+
# ==== Attributes
|
65
|
+
#
|
66
|
+
# * +source_files+ - array of files to copy
|
67
|
+
# * +target_path+ - path on target hosts to copy to
|
68
|
+
# * +options+ - hash of options includes servers to override class servers
|
69
|
+
#
|
70
|
+
# ==== Returns
|
71
|
+
#
|
72
|
+
# command_run hash {stdout => <results>, stderr => any errors, pid => process id, status => exit_code}
|
73
|
+
def copy_files(source_files, target_path, options = {})
|
74
|
+
@servers = get_option(options, "servers", @servers)
|
75
|
+
source_files = [source_files] if source_files.is_a?(String)
|
76
|
+
execute_cap "upload", {"source_files" => source_files, "target_path" => target_path}
|
77
|
+
end
|
78
|
+
|
79
|
+
# Download files to staging from remote targets
|
80
|
+
#
|
81
|
+
# ==== Attributes
|
82
|
+
#
|
83
|
+
# * +source_files+ - array of file paths to copy
|
84
|
+
# * +staging_path+ - path on local server to copy to
|
85
|
+
# * +options+ - hash of options includes servers to override class servers
|
86
|
+
#
|
87
|
+
# ==== Returns
|
88
|
+
#
|
89
|
+
# command_run hash {stdout => <results>, stderr => any errors, pid => process id, status => exit_code}
|
90
|
+
def download_files(source_files, target_path, options = {})
|
91
|
+
@servers = get_option(options, "servers", @servers)
|
92
|
+
source_files = [source_files] if source_files.is_a?(String)
|
93
|
+
execute_cap "download", {"source_files" => source_files, "target_path" => target_path}
|
94
|
+
end
|
95
|
+
|
96
|
+
# Copies script to remote targets and executes it (bin/bash)
|
97
|
+
#
|
98
|
+
# ==== Attributes
|
99
|
+
#
|
100
|
+
# * +script_path+ - path to script file on local host
|
101
|
+
# * +target_path+ - path on target servers to copy to
|
102
|
+
# * +options+ - hash of options includes servers to override class servers
|
103
|
+
#
|
104
|
+
# ==== Returns
|
105
|
+
#
|
106
|
+
# command_run hash {stdout => <results>, stderr => any errors, pid => process id, status => exit_code}
|
107
|
+
def script_exec(script_path, target_path, options = {})
|
108
|
+
@servers = get_option(options, "servers", @servers)
|
109
|
+
copy_files [script_path], target_path
|
110
|
+
cmd = "/bin/bash #{File.join(target_path, File.basename(script_path))}"
|
111
|
+
result = execute_command(cmd)
|
112
|
+
cmd = "rm -f #{File.join(target_path, File.basename(script_path))}"
|
113
|
+
cleanunp_result = execute_command(cmd) unless @debug
|
114
|
+
result
|
115
|
+
end
|
116
|
+
|
117
|
+
# Resets the servers for ssh execution
|
118
|
+
#
|
119
|
+
# ==== Attributes
|
120
|
+
#
|
121
|
+
# * +servers+ - array of servers
|
122
|
+
#
|
123
|
+
def set_servers(servers)
|
124
|
+
@servers = servers
|
125
|
+
end
|
126
|
+
|
127
|
+
private
|
128
|
+
|
129
|
+
# Executes the capistrano command in a timeout loop integrating stderr and stdout
|
130
|
+
#
|
131
|
+
# ==== Attributes
|
132
|
+
#
|
133
|
+
# * +cap_method+ - can be command, upload, download
|
134
|
+
# * +options+ - hash of options specific to the command type
|
135
|
+
#
|
136
|
+
# ==== Returns
|
137
|
+
#
|
138
|
+
# * command_run hash {stdout => <results>, stderr => any errors, pid => process id, status => exit_code}
|
139
|
+
def execute_cap(cap_method, options = {}, max_time = @max_time)
|
140
|
+
cmd_result = {"stdout" => "","stderr" => "", "pid" => "", "status" => 1}
|
141
|
+
show_errors = true #@params.has_key?("ignore_exit_codes") ? !(@params["ignore_exit_codes"] == 'yes') : false
|
142
|
+
@cap.set :user, @user unless @user.nil?
|
143
|
+
@cap.set :password, @password unless @password.nil?
|
144
|
+
@cap.role :all do
|
145
|
+
@servers
|
146
|
+
end
|
147
|
+
cmd_result["stdout"] = "Capistrano Execution\n"
|
148
|
+
output_dir = File.join("/tmp","#{"brady333"}") #FIXME
|
149
|
+
outfile = "#{output_dir}_stderr.txt"
|
150
|
+
cmd_result["stdout"] += "Script Output:\n"
|
151
|
+
begin
|
152
|
+
orig_stderr = $stderr.clone
|
153
|
+
$stderr.reopen File.open(outfile, 'a' )
|
154
|
+
fil = File.open(outfile, 'a' )
|
155
|
+
timer_status = Timeout.timeout(max_time) {
|
156
|
+
rescue_cap_errors(show_errors) do
|
157
|
+
if cap_method == "command"
|
158
|
+
command = options["command"]
|
159
|
+
cmd_result["stdout"] += "Command: #{command}"
|
160
|
+
use_sudo = @sudo.nil? ? "no" : @sudo
|
161
|
+
@cap.run "#{use_sudo == 'yes' ? sudo : '' } #{command}", :pty => (use_sudo == 'yes') do |ch, str, data|
|
162
|
+
if str == :out
|
163
|
+
fil.puts data
|
164
|
+
fil.flush
|
165
|
+
elsif str == :err
|
166
|
+
cmd_result["stderr"] += data if data.length > 4
|
167
|
+
end
|
168
|
+
end
|
169
|
+
elsif cap_method == "upload"
|
170
|
+
source_files = options["source_files"]
|
171
|
+
target_path = options["target_path"]
|
172
|
+
cmd_result["stdout"] += "Upload: #{source_files.join(",")} |To: #{target_path}"
|
173
|
+
source_files.each do |file_path|
|
174
|
+
ans = split_nsh_path(file_path)
|
175
|
+
f_path = ans[1]
|
176
|
+
cmd_result["stdout"] += "File: #{f_path}\n"
|
177
|
+
@cap.upload f_path, target_path, :via => :scp
|
178
|
+
end
|
179
|
+
elsif cap_method == "download"
|
180
|
+
source_files = options["source_files"]
|
181
|
+
target_path = options["target_path"]
|
182
|
+
cmd_result["stdout"] += "Download: #{source_files.join(",")} |To: #{target_path}"
|
183
|
+
source_files.each do |file_path|
|
184
|
+
ans = split_nsh_path(file_path)
|
185
|
+
f_path = ans[1]
|
186
|
+
cmd_result["stdout"] += "File: #{f_path}\n"
|
187
|
+
target_file = File.join(target_path, File.basename(f_path))
|
188
|
+
@cap.download f_path, target_file, :via => :scp
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
}
|
193
|
+
fil.close
|
194
|
+
fil1 = File.open(outfile)
|
195
|
+
output = fil1.read
|
196
|
+
fil1.close
|
197
|
+
cmd_result["stdout"] = output if output.length > 2
|
198
|
+
cmd_result["status"] = 0
|
199
|
+
rescue Exception => e
|
200
|
+
$stderr.reopen orig_stderr
|
201
|
+
cmd_result["stderr"] += "ERROR\n#{e.message}\n#{e.backtrace}"
|
202
|
+
ensure
|
203
|
+
$stderr.reopen orig_stderr
|
204
|
+
end
|
205
|
+
File.delete(outfile)
|
206
|
+
cmd_result
|
207
|
+
end
|
208
|
+
|
209
|
+
def rescue_cap_errors(show_errors, &block)
|
210
|
+
begin
|
211
|
+
yield
|
212
|
+
rescue RuntimeError => failure
|
213
|
+
if show_errors
|
214
|
+
BrpmAuto.log "SSH-Capistrano_Error: #{failure.message}\n#{failure.backtrace}"
|
215
|
+
BrpmAuto.log "#{EXIT_CODE_FAILURE}"
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
end
|