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,154 @@
|
|
1
|
+
# dispatch_srun.rb
|
2
|
+
# Module for action dispatch with nsh protocol
|
3
|
+
libDir = File.expand_path(File.dirname(__FILE__))
|
4
|
+
require "#{libDir}/dispatch_base"
|
5
|
+
|
6
|
+
|
7
|
+
class DispatchSSH < DispatchBase
|
8
|
+
# Initialize the class
|
9
|
+
#
|
10
|
+
# ==== Attributes
|
11
|
+
#
|
12
|
+
# * +nsh_object+ - handle to an NSH object
|
13
|
+
# * +options+ - hash of options to use, send "output_file" to point to the logging file
|
14
|
+
# * +test_mode+ - true/false to simulate commands instead of running them
|
15
|
+
#
|
16
|
+
def initialize(ssh_object, 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
|
+
@ssh = ssh_object
|
23
|
+
@verbose = get_option(options, "verbose", false)
|
24
|
+
@output_dir = BrpmAuto.params("SS_output_dir")
|
25
|
+
end
|
26
|
+
|
27
|
+
# Wrapper to run a shell action
|
28
|
+
# opens passed script path, or executes passed text
|
29
|
+
# processes the script in erb first to allow param substitution
|
30
|
+
# note script may have keyword directives (see additional docs)
|
31
|
+
# ==== Attributes
|
32
|
+
#
|
33
|
+
# * +script_file+ - the path to the script or the text of the script
|
34
|
+
# * +options+ - hash of options, includes: servers to override step servers
|
35
|
+
# ==== Returns
|
36
|
+
#
|
37
|
+
# action output
|
38
|
+
#
|
39
|
+
def execute_script(script_file, options = {})
|
40
|
+
# get the body of the action
|
41
|
+
content = File.open(script_file).read
|
42
|
+
seed_servers = get_option(options, "servers")
|
43
|
+
transfer_properties = get_option(options, "transfer_properties",{})
|
44
|
+
keyword_items = get_keyword_items(content)
|
45
|
+
params_filter = keyword_items.has_key?("RPM_PARAMS_FILTER") ? keyword_items["RPM_PARAMS_FILTER"] : DEFAULT_PARAMS_FILTER
|
46
|
+
transfer_properties.merge!(get_transfer_properties(params_filter, strip_prefix = true))
|
47
|
+
BrpmAuto.log "#----------- Executing Script on Remote Hosts -----------------#"
|
48
|
+
BrpmAuto.log "# Script: #{script_file}"
|
49
|
+
result = "No servers to execute on"
|
50
|
+
# Loop through the platforms
|
51
|
+
OS_PLATFORMS.each do |os, os_details|
|
52
|
+
servers = BrpmAuto.params.get_servers_by_os_platform(os) if seed_servers == ""
|
53
|
+
servers = BrpmAuto.params.get_servers_by_os_platform(os, seed_servers) if seed_servers != ""
|
54
|
+
BrpmAuto.message_box "OS Platform: #{os_details["name"]}"
|
55
|
+
BrpmAuto.log "No servers selected for: #{os_details["name"]}" if servers.size == 0
|
56
|
+
next if servers.size == 0
|
57
|
+
BrpmAuto.log "# #{os_details["name"]} - Targets: #{servers.inspect}"
|
58
|
+
BrpmAuto.log "# Setting Properties:"
|
59
|
+
add_channel_properties(transfer_properties, servers, os)
|
60
|
+
brpd_compatibility(transfer_properties)
|
61
|
+
transfer_properties.each{|k,v| BrpmAuto.log "\t#{k} => #{v}" }
|
62
|
+
shebang = read_shebang(os, content)
|
63
|
+
BrpmAuto.log "Shebang: #{shebang.inspect}"
|
64
|
+
wrapper_path = build_wrapper_script(os, shebang, transfer_properties, {"script_target" => File.basename(script_file)})
|
65
|
+
BrpmAuto.log "# Wrapper: #{wrapper_path}"
|
66
|
+
target_path = transfer_properties["RPM_CHANNEL_ROOT"]
|
67
|
+
BrpmAuto.log "# Copying script to target: "
|
68
|
+
clean_line_breaks(os, script_file, content)
|
69
|
+
@ssh.set_servers(server_dns_names(servers))
|
70
|
+
result = @ssh.copy_files([script_file], target_path)
|
71
|
+
BrpmAuto.log @ssh.display_result(result)
|
72
|
+
BrpmAuto.log "# Executing script on target via wrapper:"
|
73
|
+
result = @ssh.script_exec(wrapper_path, target_path)
|
74
|
+
BrpmAuto.log @ssh.display_result(result)
|
75
|
+
end
|
76
|
+
result
|
77
|
+
end
|
78
|
+
|
79
|
+
# Copies remote files to a local staging repository
|
80
|
+
#
|
81
|
+
# ==== Attributes
|
82
|
+
#
|
83
|
+
# * +file_list+ - array of nsh-style paths (//server/path)
|
84
|
+
# * +options+ - hash of options includes: source_server
|
85
|
+
# ==== Returns
|
86
|
+
#
|
87
|
+
# hash of instance_path and md5 - {"instance_path" => "", "md5" => ""}
|
88
|
+
#
|
89
|
+
def package_artifacts(file_list, options = {})
|
90
|
+
version = get_option(options, "version", "")
|
91
|
+
version = "#{get_param("SS_request_number")}_#{precision_timestamp}" if version == ""
|
92
|
+
staging_path = get_staging_dir(version, true)
|
93
|
+
BrpmAuto.message_box "Copying Files to Staging via SSH"
|
94
|
+
ans = @ssh.split_nsh_path(file_list.first)
|
95
|
+
raise "Command_Failed: staging/build server not found, use nsh-style paths" if ans[0].length < 2
|
96
|
+
@ssh.set_servers(ans[0])
|
97
|
+
BrpmAuto.log "\t StagingPath: #{staging_path}"
|
98
|
+
file_list.each do |file_path|
|
99
|
+
BrpmAuto.log "\t #{file_path}"
|
100
|
+
result = @ssh.download_files(file_path, staging_path)
|
101
|
+
BrpmAuto.log "\tCopy Result: #{@ssh.display_result(result)}"
|
102
|
+
end
|
103
|
+
package_staged_artifacts(staging_path, version)
|
104
|
+
end
|
105
|
+
|
106
|
+
# Deploys a packaged instance based on staging info
|
107
|
+
# staging info is generated by the stage_files routine
|
108
|
+
# ==== Attributes
|
109
|
+
#
|
110
|
+
# * +staging_info+ - hash returned by stage_files
|
111
|
+
# * +options+ - hash of options, includes allow_md5_mismatch(true/false) and target_path to override server channel_root
|
112
|
+
# ==== Returns
|
113
|
+
#
|
114
|
+
# action output
|
115
|
+
#
|
116
|
+
def deploy_package_instance(staging_info, options = {})
|
117
|
+
mismatch_ok = get_option(options, "allow_md5_mismatch", false)
|
118
|
+
target_path = get_option(options, "target_path")
|
119
|
+
instance_path = staging_info["instance_path"]
|
120
|
+
BrpmAuto.message_box "Deploying Files to Targets via SSH"
|
121
|
+
raise "Command_Failed: no artifacts staged in #{File.dirname(instance_path)}" if Dir.entries(File.dirname(instance_path)).size < 3
|
122
|
+
BrpmAuto.log "\t StagingArchive: #{instance_path}"
|
123
|
+
md5 = Digest::MD5.file(instance_path).hexdigest
|
124
|
+
md5_match = md5 == staging_info["md5"]
|
125
|
+
BrpmAuto.log "\t Checksum: expected: #{staging_info["md5"]} - actual: #{md5}#{md5_match ? " MATCHED" : " NO MATCH"}"
|
126
|
+
raise "Command_Failed: bad md5 checksum match" if !md5_match && !allow_md5_mismatch
|
127
|
+
result = "No servers to execute on"
|
128
|
+
# Loop through the platforms
|
129
|
+
OS_PLATFORMS.each do |os, os_details|
|
130
|
+
servers = BrpmAuto.params.get_servers_by_os_platform(os)
|
131
|
+
BrpmAuto.message_box "OS Platform: #{os_details["name"]}"
|
132
|
+
BrpmAuto.log "No servers selected for: #{os_details["name"]}" if servers.size == 0
|
133
|
+
next if servers.size == 0
|
134
|
+
BrpmAuto.log "# #{os_details["name"]} - Targets: #{servers.inspect}"
|
135
|
+
target_path = servers.first[1].has_key?("CHANNEL_ROOT") ? servers.first[1]["CHANNEL_ROOT"] : os_details["tmp_dir"] if target_path == ""
|
136
|
+
BrpmAuto.log "# Deploying package on target:"
|
137
|
+
@ssh.set_servers(server_dns_names(servers))
|
138
|
+
result = @ssh.copy_files(instance_path, target_path)
|
139
|
+
BrpmAuto.log @ssh.display_result(result)
|
140
|
+
BrpmAuto.log "# Unzipping package on target:"
|
141
|
+
wrapper_path = create_command_wrapper("unzip -o", os, instance_path, target_path)
|
142
|
+
result = @ssh.script_exec(wrapper_path, target_path)
|
143
|
+
BrpmAuto.log @ssh.display_result(result)
|
144
|
+
end
|
145
|
+
@ssh.display_result(result)
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
@rpm.BrpmAuto.log "Initializing ssh transport"
|
151
|
+
debug = defined?(@debug) ? @debug : false
|
152
|
+
options = {"debug" => debug}
|
153
|
+
@ssh = TransportSSH.new([], options)
|
154
|
+
@transport = DispatchSSH.new(@ssh, options)
|
@@ -0,0 +1,1095 @@
|
|
1
|
+
# BAA rest automation class
|
2
|
+
# this also wraps the BAAUtilities that ships with BRPM
|
3
|
+
require 'savon'
|
4
|
+
|
5
|
+
class TransportBAA
|
6
|
+
|
7
|
+
# Initializes the instance of the baa class
|
8
|
+
# this will authenticate to the Bladelogic server and
|
9
|
+
# perform an assume_role to the specified role
|
10
|
+
# ==== Attributes
|
11
|
+
#
|
12
|
+
# * +url+ - url of the Bladelogic server
|
13
|
+
# * +params+ - the params hash
|
14
|
+
# * +options+ - hash of options, includes:
|
15
|
+
# +baa_username+ - user for Bladelogic account
|
16
|
+
# +baa_password+ - password for Bladelogic account
|
17
|
+
# +baa_role+ - role for Bladelogic account
|
18
|
+
#
|
19
|
+
def initialize(baa_url, options = {}, compat_options = {})
|
20
|
+
self.extend Utilities
|
21
|
+
if options.has_key?("SS_output_dir")
|
22
|
+
BrpmAuto.log "Load for this class has changed, no longer necessary to send params as 2nd argument"
|
23
|
+
options = compat_options
|
24
|
+
end
|
25
|
+
@url = baa_url
|
26
|
+
@username = get_option(options, "baa_username")
|
27
|
+
@password = get_option(options, "baa_password")
|
28
|
+
@role = get_option(options, "baa_role")
|
29
|
+
if @password != ""
|
30
|
+
@session_time = nil
|
31
|
+
get_session_id
|
32
|
+
assume_role
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Resets session and credentials
|
37
|
+
#
|
38
|
+
# ==== Attributes
|
39
|
+
#
|
40
|
+
# * +baa_username+ - username for baa
|
41
|
+
# * +baa_password+ - password for baa
|
42
|
+
# * +baa_role+ - role to assume (uses default role from class if ommitted)
|
43
|
+
# ==== Returns
|
44
|
+
#
|
45
|
+
# * command output
|
46
|
+
#
|
47
|
+
def set_credential(baa_url, baa_username, baa_password, baa_role)
|
48
|
+
@url = baa_url
|
49
|
+
@username = baa_username
|
50
|
+
@password = baa_password
|
51
|
+
@role = baa_role
|
52
|
+
@session_time = nil
|
53
|
+
get_session_id
|
54
|
+
assume_role
|
55
|
+
end
|
56
|
+
|
57
|
+
# Assumes the role (for SOAP only)
|
58
|
+
#
|
59
|
+
# ==== Attributes
|
60
|
+
#
|
61
|
+
# * +role+ - role to assume (uses default role from class if ommitted)
|
62
|
+
# ==== Returns
|
63
|
+
#
|
64
|
+
# * command output
|
65
|
+
#
|
66
|
+
def assume_role(role = @role)
|
67
|
+
@role = role
|
68
|
+
BaaUtilities.baa_soap_assume_role(@url, role, @session_id)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Gets a new session id via SOAP login
|
72
|
+
#
|
73
|
+
# ==== Returns
|
74
|
+
#
|
75
|
+
# * session_id
|
76
|
+
#
|
77
|
+
def get_session_id
|
78
|
+
@session_id = BaaUtilities.baa_soap_login(@url, @username, @password)
|
79
|
+
raise "Could not login to BAA Cli Tunnel Service" if @session_id.nil?
|
80
|
+
@session_time = Time.now
|
81
|
+
end
|
82
|
+
|
83
|
+
# Returns current session id
|
84
|
+
#
|
85
|
+
# ==== Returns
|
86
|
+
#
|
87
|
+
# * session_id
|
88
|
+
#
|
89
|
+
def session_id
|
90
|
+
@session_id
|
91
|
+
end
|
92
|
+
|
93
|
+
# Executes a BLCLI command
|
94
|
+
# (follow BLCLI docs)
|
95
|
+
# ==== Attributes
|
96
|
+
#
|
97
|
+
# * +namespace+ - namespace of command
|
98
|
+
# * +command+ - command to run
|
99
|
+
# * +args+ - array of arguments to the command
|
100
|
+
# * +options+ - hash of options includes: client_timeout (default is 300 seconds)
|
101
|
+
#
|
102
|
+
# ==== Returns
|
103
|
+
#
|
104
|
+
# * text result from command or "ERROR: SoapError" if failure
|
105
|
+
# * logs to a special stderr file the verbose output in the step output folder
|
106
|
+
#
|
107
|
+
# ==== Examples
|
108
|
+
#
|
109
|
+
# result = @baa.execute_cli_command("Server", "listAllServersInGroup", ["mysmartgroup"])
|
110
|
+
#
|
111
|
+
def execute_cli_command(namespace, command, args, options = {})
|
112
|
+
begin
|
113
|
+
response = nil
|
114
|
+
check_session
|
115
|
+
BrpmAuto.log "CLI: #{namespace}, #{command}, #{args.inspect}"
|
116
|
+
client = Savon.client("#{@url}/services/BSACLITunnelService.wsdl") do |wsdl, http|
|
117
|
+
http.auth.ssl.verify_mode = :none
|
118
|
+
end
|
119
|
+
client.http.read_timeout = get_option(options,"client_timeout",300)
|
120
|
+
redirect_stdout do
|
121
|
+
response = client.request(:execute_command_by_param_list) do |soap|
|
122
|
+
soap.endpoint = "#{@url}/services/CLITunnelService"
|
123
|
+
soap.header = {"ins1:sessionId" => @session_id}
|
124
|
+
soap.body = { :nameSpace => namespace, :commandName => command, :commandArguments => args }
|
125
|
+
end
|
126
|
+
end
|
127
|
+
raw_result = response.body[:execute_command_by_param_list_response][:return]
|
128
|
+
result = cli_result(raw_result)
|
129
|
+
rescue Exception => e
|
130
|
+
result = "ERROR: SoapError: #{e.message}\n#{e.backtrace}"
|
131
|
+
end
|
132
|
+
result
|
133
|
+
end
|
134
|
+
|
135
|
+
# Executes a BLCLI command to return an attachment
|
136
|
+
#
|
137
|
+
# ==== Attributes
|
138
|
+
#
|
139
|
+
# * +namespace+ - namespace of command
|
140
|
+
# * +command+ - command to run
|
141
|
+
# * +args+ - array of arguments to the command
|
142
|
+
#
|
143
|
+
# ==== Returns
|
144
|
+
#
|
145
|
+
# * response_object hash which includes the attachment response["attachment"] base64 encoded
|
146
|
+
#
|
147
|
+
def execute_cli_command_using_attachments(namespace, command, args)
|
148
|
+
payload = nil
|
149
|
+
begin
|
150
|
+
client = Savon.client("#{@url}/services/BSACLITunnelService.wsdl") do |wsdl, http|
|
151
|
+
http.auth.ssl.verify_mode = :none
|
152
|
+
end
|
153
|
+
|
154
|
+
client.http.read_timeout = 300
|
155
|
+
client.config.BrpmAuto.log = false
|
156
|
+
response = client.request(:execute_command_using_attachments) do |soap|
|
157
|
+
soap.endpoint = "#{@url}/services/CLITunnelService"
|
158
|
+
soap.header = {"ins1:sessionId" => @session_id}
|
159
|
+
body_details = { :nameSpace => namespace, :commandName => command, :commandArguments => args }
|
160
|
+
body_details.merge!({:payload => payload}) if payload
|
161
|
+
soap.body = body_details
|
162
|
+
end
|
163
|
+
rescue Exception => e
|
164
|
+
result = "ERROR: SoapError: #{e.message}\n#{e.backtrace}"
|
165
|
+
end
|
166
|
+
result = response.body[:execute_command_using_attachments_response][:return]
|
167
|
+
end
|
168
|
+
|
169
|
+
# Returns the string for url and soap params
|
170
|
+
#
|
171
|
+
# ==== Attributes
|
172
|
+
# * +obj_type+ - type of object [BlPackage,DeployJob,Template]
|
173
|
+
# * +info_type+ - object or folder
|
174
|
+
#
|
175
|
+
# ==== Returns
|
176
|
+
#
|
177
|
+
# * string to use in url
|
178
|
+
#
|
179
|
+
def obj_to_url_item(obj_type, info_type = "folder")
|
180
|
+
case obj_type
|
181
|
+
when "BlPackage"
|
182
|
+
return info_type == "folder" ? "Depot" : "Depot"
|
183
|
+
when "DeployJob", "Jobs"
|
184
|
+
return info_type == "folder" ? "Jobs" : "Job"
|
185
|
+
when "Template"
|
186
|
+
return info_type == "folder" ? "Component Templates" : "Template"
|
187
|
+
else
|
188
|
+
return obj_type
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
# Gets the object in a group_path
|
193
|
+
#
|
194
|
+
# ==== Attributes
|
195
|
+
# * +group_path+ - path to group
|
196
|
+
# * +obj_type+ - base for group [DeployJob/BlPackage/ComponentTemplates]
|
197
|
+
# * +return_contents+ - true to return a list of items in the group, false returns the full object
|
198
|
+
# * +options+ - hash of options includes: verbose
|
199
|
+
#
|
200
|
+
# ==== Returns
|
201
|
+
#
|
202
|
+
# * array of group items or hash of group_object
|
203
|
+
#
|
204
|
+
def get_group_items(group_path, obj_type = "DeployJob", return_contents = true, options = {})
|
205
|
+
group_path = "#{group_path}/" unless group_path.end_with?("/") if return_contents
|
206
|
+
group_path = "/#{group_path}" unless group_path.start_with?("/")
|
207
|
+
url = "#{@url}/group/#{obj_to_url_item(obj_type)}#{group_path}#{bl_auth}"
|
208
|
+
result = Rest.rest_call(URI.escape(url), "get")
|
209
|
+
BrpmAuto.log "RAW RESULT\n#{url}\n#{result.inspect}" if get_option(options,"verbose", false)
|
210
|
+
return "ERROR: #{result["data"]["ErrorResponse"]["Error"]}" if result["data"].has_key?("ErrorResponse")
|
211
|
+
return [] if return_contents && result["data"]["GroupChildrenResponse"]["GroupChildren"]["PropertySetInstances"].nil?
|
212
|
+
return result["data"]["GroupChildrenResponse"]["GroupChildren"]["PropertySetInstances"]["Elements"] if return_contents
|
213
|
+
return result["data"]
|
214
|
+
end
|
215
|
+
|
216
|
+
# Verifies that a path exists
|
217
|
+
#
|
218
|
+
# ==== Attributes
|
219
|
+
# * +group_path+ - path to group
|
220
|
+
# * +obj_type+ - base for group [DeployJob/BlPackage/ComponentTemplates]
|
221
|
+
#
|
222
|
+
# ==== Returns
|
223
|
+
#
|
224
|
+
# * group_id or "ERROR"
|
225
|
+
#
|
226
|
+
def group_path_exists(group_path, obj_type = "Jobs")
|
227
|
+
res = get_group_items(group_path, obj_type, false)
|
228
|
+
return("ERROR") if res.is_a?(String) && res.start_with?("ERROR")
|
229
|
+
group_id = res["GroupResponse"]["Group"]["groupId"]
|
230
|
+
group_id
|
231
|
+
end
|
232
|
+
|
233
|
+
# Ensures that a group_path exists, will create if necessary
|
234
|
+
#
|
235
|
+
# ==== Attributes
|
236
|
+
# * +group_path+ - path to group
|
237
|
+
# * +obj_type+ - base for group [DeployJob/BlPackage/ComponentTemplates]
|
238
|
+
#
|
239
|
+
# ==== Returns
|
240
|
+
#
|
241
|
+
# * hash of group_object or "ERROR"
|
242
|
+
#
|
243
|
+
def ensure_group_path(group_path, obj_type = "Jobs")
|
244
|
+
result = nil; create_result = nil
|
245
|
+
cur_path = group_path.dup
|
246
|
+
path_exists = false
|
247
|
+
parts = group_path.split("/")
|
248
|
+
not_there = []
|
249
|
+
until path_exists
|
250
|
+
cur_path = group_path.gsub(not_there.reverse.join("/"),"").chomp("/")
|
251
|
+
result = group_path_exists(cur_path, obj_type)
|
252
|
+
if result == "ERROR"
|
253
|
+
BrpmAuto.log "#{cur_path} - not present"
|
254
|
+
not_there << cur_path.split("/")[-1]
|
255
|
+
BrpmAuto.log "NotThere: #{not_there.join(",")}"
|
256
|
+
else
|
257
|
+
path_exists = true
|
258
|
+
end
|
259
|
+
end
|
260
|
+
BrpmAuto.log "#{cur_path} - Found"
|
261
|
+
not_there.reverse.each do |item|
|
262
|
+
cur_path += "/#{item}"
|
263
|
+
create_result = create_group(item, result, obj_type)
|
264
|
+
BrpmAuto.log "Creating: #{cur_path} => #{create_result}"
|
265
|
+
result = create_result
|
266
|
+
end
|
267
|
+
create_result.nil? ? result : create_result
|
268
|
+
end
|
269
|
+
|
270
|
+
# Creates a group inside a parent group
|
271
|
+
#
|
272
|
+
# ==== Attributes
|
273
|
+
# * +group_path+ - path to group
|
274
|
+
# * +parent_id+ - group id of parent group
|
275
|
+
# * +obj_type+ - base for group [DeployJob/BlPackage/ComponentTemplates]
|
276
|
+
#
|
277
|
+
# ==== Returns
|
278
|
+
#
|
279
|
+
# * array of group items or hash of group_object
|
280
|
+
#
|
281
|
+
def create_group(group_name, parent_id, obj_type = "Job")
|
282
|
+
# Job, Template, Depot
|
283
|
+
namespace = "#{obj_to_url_item(obj_type, "other")}Group"
|
284
|
+
command = "create#{obj_to_url_item(obj_type, "other")}Group"
|
285
|
+
args = [
|
286
|
+
group_name,
|
287
|
+
parent_id,
|
288
|
+
]
|
289
|
+
result = execute_cli_command(namespace, command, args)
|
290
|
+
end
|
291
|
+
|
292
|
+
# Adds a file part to a ComponentTemplate
|
293
|
+
#
|
294
|
+
# ==== Attributes
|
295
|
+
# * +template_dbkey+ - dbkey for component template
|
296
|
+
# * +asset_path+ - path to file
|
297
|
+
# * +options+ - hash of options includes: (see BLCLI documentation for Template|addFilePart)
|
298
|
+
#
|
299
|
+
# ==== Returns
|
300
|
+
#
|
301
|
+
# * returnResult from CLI command
|
302
|
+
#
|
303
|
+
def add_file_to_template(template_dbkey, asset_path, options = {})
|
304
|
+
namespace = "Template"
|
305
|
+
command = "addFilePart"
|
306
|
+
args = [
|
307
|
+
template_dbkey,
|
308
|
+
asset_path,
|
309
|
+
get_option(options, "b_includeLightChecksum" , false),
|
310
|
+
get_option(options, "b_includeChecksum" , true),
|
311
|
+
get_option(options, "b_includeFileAcls" , false),
|
312
|
+
get_option(options, "b_copyfiles" , true),
|
313
|
+
get_option(options, "b_auditFileSize" , false),
|
314
|
+
get_option(options, "b_auditFileCreatedDate" , false),
|
315
|
+
get_option(options, "b_auditFileModifiedDate" , false),
|
316
|
+
get_option(options, "b_auditFilePermissions" , false),
|
317
|
+
get_option(options, "b_auditFileUidGid" , false)
|
318
|
+
]
|
319
|
+
result = execute_cli_command(namespace, command, args)
|
320
|
+
end
|
321
|
+
|
322
|
+
# Adds a directory to a ComponentTemplate
|
323
|
+
#
|
324
|
+
# ==== Attributes
|
325
|
+
# * +template_dbkey+ - dbkey for component template
|
326
|
+
# * +asset_path+ - path to directory
|
327
|
+
# * +options+ - hash of options includes: (see BLCLI documentation for Template|addDirectoryPart)
|
328
|
+
#
|
329
|
+
# ==== Returns
|
330
|
+
#
|
331
|
+
# * returnResult from CLI command
|
332
|
+
#
|
333
|
+
def add_directory_to_template(template_dbkey, asset_path, options = {})
|
334
|
+
namespace = "Template"
|
335
|
+
command = "addDirectoryPart"
|
336
|
+
args = [
|
337
|
+
template_dbkey,
|
338
|
+
asset_path,
|
339
|
+
get_option(options, "b_includeLightChecksum" , false),
|
340
|
+
get_option(options, "b_includeChecksum" , true),
|
341
|
+
get_option(options, "b_includeFileAcls" , false),
|
342
|
+
get_option(options, "b_recurse" , true),
|
343
|
+
get_option(options, "b_copyfiles" , true),
|
344
|
+
get_option(options, "b_auditFileSize" , false),
|
345
|
+
get_option(options, "b_auditFileCreatedDate" , false),
|
346
|
+
get_option(options, "b_auditFileModifiedDate" , false),
|
347
|
+
get_option(options, "b_auditFilePermissions" , false),
|
348
|
+
get_option(options, "b_auditFileUidGid" , false)
|
349
|
+
]
|
350
|
+
result = execute_cli_command(namespace, command, args)
|
351
|
+
end
|
352
|
+
|
353
|
+
# Adds files and directories to a ComponentTemplate
|
354
|
+
#
|
355
|
+
# ==== Attributes
|
356
|
+
# * +template_dbkey+ - dbkey for component template
|
357
|
+
# * +part_array+ - array of paths to add to the template
|
358
|
+
# * +options+ - hash of options includes:
|
359
|
+
# +path_property+ to abstract baa path ex. path_property => BAA_BASE_PATH=/mnt/deploy/stage
|
360
|
+
# this will substitute ??BAA_BASE_PATH?? for /mnt/deploy/stage in the added template part
|
361
|
+
# ===== (see BLCLI documentation for Template|addDirectoryPart)
|
362
|
+
#
|
363
|
+
# ==== Returns
|
364
|
+
#
|
365
|
+
# * returnResult from CLI command
|
366
|
+
#
|
367
|
+
def add_template_content(template_dbkey, parts_hash, options = {})
|
368
|
+
path_property = get_option(options, "path_property", nil)
|
369
|
+
summary = nil
|
370
|
+
parts_hash.each do |part, part_type|
|
371
|
+
part = split_nsh_path(part)[1]
|
372
|
+
if !path_property.nil? && path_property.include?("=")
|
373
|
+
part = part.gsub(path_property.split("=")[1], "??#{path_property.split("=")[0]}??")
|
374
|
+
BrpmAuto.log "\tAdding part: #{part}"
|
375
|
+
end
|
376
|
+
if part_type == "file"
|
377
|
+
summary = add_file_to_template(template_dbkey, part, options)
|
378
|
+
elsif part =~ /\.\w\w\w/
|
379
|
+
summary = add_file_to_template(template_dbkey, part, options)
|
380
|
+
elsif part.end_with?("/")
|
381
|
+
summary = add_directory_to_template(template_dbkey, part, options)
|
382
|
+
else
|
383
|
+
summary = add_directory_to_template(template_dbkey, part, options)
|
384
|
+
end
|
385
|
+
end
|
386
|
+
summary
|
387
|
+
end
|
388
|
+
|
389
|
+
# Creates an empty ComponentTemplate
|
390
|
+
#
|
391
|
+
# ==== Attributes
|
392
|
+
# * +template_name+ - dbkey for component template
|
393
|
+
# * +group_id+ - group_id of group_path
|
394
|
+
#
|
395
|
+
# ==== Returns
|
396
|
+
#
|
397
|
+
# * returnResult from CLI command (BLCLI Template|createEmptyTemplate)
|
398
|
+
#
|
399
|
+
def create_empty_template(template_name, group_id)
|
400
|
+
namespace = "Template"
|
401
|
+
command = "createEmptyTemplate"
|
402
|
+
args = [
|
403
|
+
template_name,
|
404
|
+
group_id,
|
405
|
+
true
|
406
|
+
]
|
407
|
+
result = execute_cli_command(namespace, command, args)
|
408
|
+
end
|
409
|
+
|
410
|
+
# Creates a Component
|
411
|
+
#
|
412
|
+
# ==== Attributes
|
413
|
+
# * +component_name+ - name of component
|
414
|
+
# * +template_key+ - dbkey of ComponentTemplate
|
415
|
+
# * +server_id+ - id of server to bind template
|
416
|
+
#
|
417
|
+
# ==== Returns
|
418
|
+
#
|
419
|
+
# * returnResult from CLI command (BLCLI Component|createComponent)
|
420
|
+
#
|
421
|
+
def create_component(component_name, template_key, server_id)
|
422
|
+
namespace = "Component"
|
423
|
+
command = "createComponent"
|
424
|
+
args = [
|
425
|
+
component_name,
|
426
|
+
template_key,
|
427
|
+
server_id
|
428
|
+
]
|
429
|
+
result = execute_cli_command(namespace, command, args)
|
430
|
+
end
|
431
|
+
|
432
|
+
# Creates an empty Package in the Depot
|
433
|
+
#
|
434
|
+
# ==== Attributes
|
435
|
+
# * +package_name+ - name of the package
|
436
|
+
# * +group_id+ - group_id of group_path
|
437
|
+
# * +options+ - hash of options, includes: "description"
|
438
|
+
#
|
439
|
+
# ==== Returns
|
440
|
+
#
|
441
|
+
# * returnResult from CLI command (BLCLI BlPackage|createEmptyPackage)
|
442
|
+
#
|
443
|
+
def create_empty_package(package_name, group_id, options = {})
|
444
|
+
namespace = "BlPackage"
|
445
|
+
command = "createEmptyPackage"
|
446
|
+
args = [
|
447
|
+
package_name,
|
448
|
+
group_id,
|
449
|
+
get_option(options, "description" , false)
|
450
|
+
]
|
451
|
+
result = execute_cli_command(namespace, command, args)
|
452
|
+
end
|
453
|
+
|
454
|
+
# Gets the id of a server
|
455
|
+
#
|
456
|
+
# ==== Attributes
|
457
|
+
# * +server_name+ - name of server
|
458
|
+
#
|
459
|
+
# ==== Returns
|
460
|
+
#
|
461
|
+
# * server_id (BLCLI - Server|getServerIdByName)
|
462
|
+
#
|
463
|
+
def get_server_id(server_name)
|
464
|
+
namespace = "Server"
|
465
|
+
command = "getServerIdByName"
|
466
|
+
args = [
|
467
|
+
server_name
|
468
|
+
]
|
469
|
+
result = execute_cli_command(namespace, command, args)
|
470
|
+
end
|
471
|
+
|
472
|
+
# Creates a package from a component
|
473
|
+
#
|
474
|
+
# ==== Attributes
|
475
|
+
# * +package_name+ - name for package
|
476
|
+
# * +depot_group_id+ - group_id of group_path
|
477
|
+
# * +template_id+ - id of ComponentTemplate
|
478
|
+
# * +server_name+ - name of server to bind to template
|
479
|
+
# * +options+ - hash of options (see BLCLI docs)
|
480
|
+
#
|
481
|
+
# ==== Returns
|
482
|
+
#
|
483
|
+
# * returnResult from CLI command (BLCLI BlPackage|createPackageFromComponent)
|
484
|
+
#
|
485
|
+
def create_component_package(package_name, depot_group_id, template_id, server_name, options = {})
|
486
|
+
server_id = get_server_id(server_name)
|
487
|
+
component_id = create_component(package_name, template_id, server_id)
|
488
|
+
result = execute_cli_command("BlPackage", "createPackageFromComponent",
|
489
|
+
[
|
490
|
+
package_name, #packageName
|
491
|
+
depot_group_id, #groupId
|
492
|
+
get_option(options, "bSoftLinked", true), #bSoftLinked
|
493
|
+
get_option(options, "bCollectFileAcl", false), #bCollectFileAcl
|
494
|
+
get_option(options, "bCollectFileAttributes", false), #bCollectFileAttributes
|
495
|
+
get_option(options, "bCopyFileContents", true), #bCopyFileContents
|
496
|
+
get_option(options, "bCollectRegistryAcl", false), #bCollectRegistryAcl
|
497
|
+
component_id, #componentKey
|
498
|
+
])
|
499
|
+
end
|
500
|
+
|
501
|
+
# Creates a Job from a package
|
502
|
+
#
|
503
|
+
# ==== Attributes
|
504
|
+
# * +job_name+ - name for job
|
505
|
+
# * +job_group_id+ - group_id of group_path
|
506
|
+
# * +servers+ - array of servers for job targets
|
507
|
+
# * +options+ - hash of options (see BLCLI docs)
|
508
|
+
#
|
509
|
+
# ==== Returns
|
510
|
+
#
|
511
|
+
# * job_key from CLI command (BLCLI BlPackage|createDeployJob)
|
512
|
+
#
|
513
|
+
def create_package_job(job_name, job_group_id, package_id, servers, options = {})
|
514
|
+
job_key = execute_cli_command("DeployJob", "createDeployJob",
|
515
|
+
[
|
516
|
+
job_name, #packageName
|
517
|
+
job_group_id, #groupId
|
518
|
+
package_id, # db_key
|
519
|
+
servers.first,
|
520
|
+
get_option(options, "isSimulateEnabled" , true), #isSimulateEnabled
|
521
|
+
get_option(options, "isCommitEnabled" , true), #isCommitEnabled
|
522
|
+
get_option(options, "isStagedIndirect" , false) #isStagedIndirect
|
523
|
+
])
|
524
|
+
if servers.size > 1
|
525
|
+
add_target_servers(job_key, servers[1..-1])
|
526
|
+
end
|
527
|
+
job_key
|
528
|
+
end
|
529
|
+
|
530
|
+
# Adds server targets to a Job
|
531
|
+
#
|
532
|
+
# ==== Attributes
|
533
|
+
# * +job_key+ - dbkey for job
|
534
|
+
# * +servers+ - array of servers
|
535
|
+
#
|
536
|
+
# ==== Returns
|
537
|
+
#
|
538
|
+
# * job_key from CLI command (BLCLI Job|addTargetServers)
|
539
|
+
#
|
540
|
+
def add_target_servers(job_key, servers)
|
541
|
+
job_key = execute_cli_command("Job", "addTargetServers",
|
542
|
+
[
|
543
|
+
job_key, # Jobkey
|
544
|
+
servers.join(",") # serverslist
|
545
|
+
])
|
546
|
+
job_key
|
547
|
+
end
|
548
|
+
|
549
|
+
# Sets override package properties on a Job
|
550
|
+
#
|
551
|
+
# ==== Attributes
|
552
|
+
# * +job_name+ - dbkey for component template
|
553
|
+
# * +group_path+ - group_path
|
554
|
+
# * +props+ - hash of name/values for properties to set
|
555
|
+
#
|
556
|
+
# ==== Returns
|
557
|
+
#
|
558
|
+
# * text of all property adds from CLI command (BLCLI DeployJob|setOverriddenParameterValue)
|
559
|
+
#
|
560
|
+
def set_job_properties(job_name, group_path, props)
|
561
|
+
begin
|
562
|
+
result = []
|
563
|
+
return "" if props.size == 0
|
564
|
+
BrpmAuto.log "Setting package properties on job:"
|
565
|
+
props.each_pair do |prop,val|
|
566
|
+
BrpmAuto.log "\t#{prop} => #{val}"
|
567
|
+
result << execute_cli_command("DeployJob", "setOverriddenParameterValue",
|
568
|
+
[
|
569
|
+
group_path, #groupName
|
570
|
+
job_name, #jobName
|
571
|
+
prop, #parameterName
|
572
|
+
val #valueAsString
|
573
|
+
])
|
574
|
+
end
|
575
|
+
rescue Exception => e1
|
576
|
+
raise "Could not set property values: #{e1.message}"
|
577
|
+
end
|
578
|
+
result.join(",")
|
579
|
+
end
|
580
|
+
|
581
|
+
# Sets properties on a ComponentTemplate
|
582
|
+
#
|
583
|
+
# ==== Attributes
|
584
|
+
# * +template_name+ - name for component template
|
585
|
+
# * +group_path+ - group_path
|
586
|
+
# * +props+ - hash of name/values for properties to set
|
587
|
+
# * +options+ - hash of options (see BLCLI docs)
|
588
|
+
#
|
589
|
+
# ==== Returns
|
590
|
+
#
|
591
|
+
# * returnResult from CLI command (BLCLI Template|addLocalParameter)
|
592
|
+
#
|
593
|
+
def set_template_properties(template_name, group_path, props, options = {})
|
594
|
+
begin
|
595
|
+
result = nil
|
596
|
+
BrpmAuto.log "Setting template properties:"
|
597
|
+
props.each_pair do |prop,val|
|
598
|
+
BrpmAuto.log "\t#{prop} => #{val}"
|
599
|
+
result = add_template_property(template_name, group_path, prop, val, options)
|
600
|
+
end
|
601
|
+
rescue Exception => e1
|
602
|
+
raise "Could not set property values: #{e1.message}"
|
603
|
+
end
|
604
|
+
result
|
605
|
+
end
|
606
|
+
|
607
|
+
# Sets a single property on a ComponentTemplate
|
608
|
+
#
|
609
|
+
# ==== Attributes
|
610
|
+
# * +template_name+ - name for component template
|
611
|
+
# * +group_path+ - group_path
|
612
|
+
# * +property_name+ - name of property
|
613
|
+
# * +property_value+ - value of property
|
614
|
+
# * +options+ - hash of options (see BLCLI docs)
|
615
|
+
#
|
616
|
+
# ==== Returns
|
617
|
+
#
|
618
|
+
# * returnResult from CLI command (BLCLI Template|addLocalParameter)
|
619
|
+
#
|
620
|
+
def add_template_property(template_name, group_path, property_name, property_value, options = {})
|
621
|
+
prop_key = execute_cli_command("Template", "addLocalParameter",
|
622
|
+
[
|
623
|
+
template_name, # Component template
|
624
|
+
group_path, # template group
|
625
|
+
property_name, # Name of property
|
626
|
+
get_option(options, "description"), # property_description
|
627
|
+
"Primitive:/String", #property_type
|
628
|
+
get_option(options, "editable" , true), # editable
|
629
|
+
get_option(options, "required", false), # required
|
630
|
+
property_value # value
|
631
|
+
])
|
632
|
+
prop_key
|
633
|
+
end
|
634
|
+
|
635
|
+
# Exports DeployJob results to specified file
|
636
|
+
#
|
637
|
+
# ==== Attributes
|
638
|
+
# * +job_folder+ - group folder of job
|
639
|
+
# * +job_name+ - name of job
|
640
|
+
# * +job_run_id+ - if of the job run
|
641
|
+
# * +output_file+ - file to export to
|
642
|
+
#
|
643
|
+
# ==== Returns
|
644
|
+
#
|
645
|
+
# * returnResult from CLI command (BLCLI Utility|exportDeployRun)
|
646
|
+
#
|
647
|
+
def export_deploy_job_results(job_folder, job_name, job_run_id, output_file = "/tmp/test.csv")
|
648
|
+
result = execute_cli_command_using_attachments("Utility", "exportDeployRun", [job_folder, job_name, job_run_id, output_file])
|
649
|
+
if result && (result.has_key?(:attachment))
|
650
|
+
attachment = result[:attachment]
|
651
|
+
csv_data = Base64.decode64(attachment)
|
652
|
+
fil = File.open(output_file,"w+")
|
653
|
+
fil.write csv_data
|
654
|
+
fil.flush
|
655
|
+
fil.close
|
656
|
+
return "Success"
|
657
|
+
else
|
658
|
+
return "Failed to export results"
|
659
|
+
end
|
660
|
+
nil
|
661
|
+
end
|
662
|
+
|
663
|
+
# Packages passed references in BAA using a component template
|
664
|
+
# * note artifacts all need to reside on the same server
|
665
|
+
#
|
666
|
+
# ==== Attributes
|
667
|
+
#
|
668
|
+
# * +package_name+ - name for package (and template)
|
669
|
+
# * +group_path+ - path in Blade to store package
|
670
|
+
# * +artifacts+ - array of file/nsh paths
|
671
|
+
# * +options+ - hash of options, includes:
|
672
|
+
# properties (hash of name/values to set),
|
673
|
+
# staging_server (default is first artifact server)
|
674
|
+
#
|
675
|
+
# ==== Returns
|
676
|
+
#
|
677
|
+
# * package_id
|
678
|
+
def package_artifacts(package_name, group_path, artifacts, options)
|
679
|
+
result = {"status" => "ERROR", "group_path" => group_path, "package_name" => package_name}
|
680
|
+
artifact_hash = {}
|
681
|
+
artifact_hash = artifacts if artifacts.is_a?(Hash)
|
682
|
+
artifact_type = get_option(options, "artifact_type", "file")
|
683
|
+
artifacts.each{|l| artifact_hash[l] = artifact_type } if artifacts.is_a?(Array)
|
684
|
+
properties = get_option(options, "properties", nil)
|
685
|
+
staging_server = get_option(options, "staging_server", nil)
|
686
|
+
if staging_server.nil?
|
687
|
+
pair = split_nsh_path(artifact_hash.keys.first)
|
688
|
+
raise "Command_Failed: no staging server in options or artifacts" if pair[0].length < 2
|
689
|
+
staging_server = pair[0]
|
690
|
+
end
|
691
|
+
result["staging_server"] = staging_server
|
692
|
+
group_id = ensure_group_path(group_path, "Template")
|
693
|
+
# group_items = get_group_items(group_path, "Template", true, options)
|
694
|
+
templates_in_path = get_group_items(group_path, "Template", true, options)
|
695
|
+
cur_templates = templates_in_path.map{|l| l["name"] }
|
696
|
+
if cur_templates.include?(package_name)
|
697
|
+
BrpmAuto.log "#=> Component Template exists: #{package_name}"
|
698
|
+
template_id = templates_in_path[cur_templates.index(package_name)]["dbKey"]
|
699
|
+
else # Create a new one
|
700
|
+
BrpmAuto.log "#=> Create Component Template: #{package_name}"
|
701
|
+
template_id = create_empty_template(package_name, group_id)
|
702
|
+
BrpmAuto.log "\tApplying properties...to template with id #{template_id}" if properties
|
703
|
+
template_id = set_template_properties(package_name, group_path, properties) if properties
|
704
|
+
end
|
705
|
+
BrpmAuto.log "\tAdd content to template #{template_id}\n"
|
706
|
+
template_id = add_template_content(template_id, artifact_hash)
|
707
|
+
result["template_db_key"] = template_id
|
708
|
+
raise "Command_Failed: #{template_id}" if template_id.start_with?("ERROR")
|
709
|
+
BrpmAuto.log "#=> Create component package: #{staging_server}\n"
|
710
|
+
depot_group_id = ensure_group_path(group_path, "BlPackage")
|
711
|
+
package_id = create_component_package(package_name, depot_group_id, template_id, staging_server)
|
712
|
+
raise "Command_Failed: #{package_id}" if package_id.start_with?("ERROR")
|
713
|
+
result["status"] = "SUCCESS"
|
714
|
+
result["package_id"] = package_id
|
715
|
+
result
|
716
|
+
end
|
717
|
+
|
718
|
+
# Deploys an existing Package in BAA to target servers
|
719
|
+
#
|
720
|
+
# ==== Attributes
|
721
|
+
#
|
722
|
+
# * +job_name+ - name for deploy job
|
723
|
+
# * +package_id+ - id of existing package
|
724
|
+
# * +group_path+ - path in Blade to store job
|
725
|
+
# * +target_servers+ - array of file/nsh paths
|
726
|
+
# * +options+ - hash of options, includes:
|
727
|
+
# execute_now - (true/false to execute the job immediately default - true)
|
728
|
+
# properties (hash of name/values to set),
|
729
|
+
#
|
730
|
+
# ==== Returns
|
731
|
+
#
|
732
|
+
# * hash of job results, includes - job_run_id, job_status
|
733
|
+
def deploy_package(job_name, package_id, group_path, target_servers, options = {})
|
734
|
+
execute_now = get_option(options,"execute_now",true)
|
735
|
+
properties = get_option(options,"properties",{})
|
736
|
+
result = {"status" => "ERROR"}
|
737
|
+
BrpmAuto.log "#=> Building Job from Package:\n\tGroup: #{group_path}\n\tPackage: #{package_id}"
|
738
|
+
BrpmAuto.log "#=> Mapping selected servers: #{target_servers.join(",")}"
|
739
|
+
raise "ERROR: No servers found" if target_servers.empty?
|
740
|
+
targets = baa_soap_map_server_names_to_rest_uri(target_servers)
|
741
|
+
BrpmAuto.log "\tBuilding group path..."
|
742
|
+
job_group_id = ensure_group_path(group_path, "Jobs")
|
743
|
+
BrpmAuto.log "\tCreating package job..."
|
744
|
+
cur_jobs = execute_cli_command("Job","listAllByGroup",[group_path])
|
745
|
+
if cur_jobs.split("\n").include?(job_name)
|
746
|
+
BrpmAuto.log "\tJob Exists: deleting..."
|
747
|
+
ans = execute_cli_command("DeployJob","deleteJobByGroupAndName",[group_path, job_name])
|
748
|
+
end
|
749
|
+
job_db_key = create_package_job(job_name, job_group_id, package_id, target_servers)
|
750
|
+
if job_db_key.start_with?("ERROR")
|
751
|
+
BrpmAuto.log job_db_key
|
752
|
+
raise "Command_Failed: job creation failed"
|
753
|
+
end
|
754
|
+
result["job_db_key"] = job_db_key
|
755
|
+
result["status"] = "JOB_CREATED_SUCCESSFULLY"
|
756
|
+
BrpmAuto.log "\tApplying properties..."
|
757
|
+
prop_results = set_job_properties(job_name, group_path, properties)
|
758
|
+
result["property_results"] = prop_results
|
759
|
+
if execute_now
|
760
|
+
BrpmAuto.log "#=> Executing Job"
|
761
|
+
execute_results = execute_job_with_results(job_db_key, result)
|
762
|
+
result["results"] = execute_results
|
763
|
+
end
|
764
|
+
result
|
765
|
+
end
|
766
|
+
|
767
|
+
# Creates an NSH Script Job in BAA to target servers
|
768
|
+
#
|
769
|
+
# ==== Attributes
|
770
|
+
#
|
771
|
+
# * +job_name+ - name for package (and template)
|
772
|
+
# * +group_path+ - path in Blade for job
|
773
|
+
# * +script_name+ - name of nsh script
|
774
|
+
# * +script_group+ - path in depot to script
|
775
|
+
# * +job_params+ - array of params (in order) for script job
|
776
|
+
# * +targets+ - array of servers or smartgroups
|
777
|
+
# * +options+ - hash of options, includes: execute_now and num_par_proces (max parallel processes), target_type (servers/groups)
|
778
|
+
#
|
779
|
+
# ==== Returns
|
780
|
+
#
|
781
|
+
# * hash of job results, includes - job_run_id, job_status
|
782
|
+
def create_nsh_script_job(job_name, group_path, script_name, script_group, job_params, targets, options = {})
|
783
|
+
result = {"status" => "ERROR"}
|
784
|
+
job_type = "NSHScriptJob"
|
785
|
+
num_par_procs = get_option(options,"num_par_procs", 50)
|
786
|
+
execute_now = get_option(options,"execute_now", false)
|
787
|
+
target_type = get_option(options,"target_type", "servers")
|
788
|
+
args = [
|
789
|
+
group_path, #jobGroup
|
790
|
+
job_name, #jobName
|
791
|
+
"Script job from automation", #description
|
792
|
+
script_group,
|
793
|
+
script_name,
|
794
|
+
num_par_procs # number of parallel processes
|
795
|
+
]
|
796
|
+
ss_job_key = execute_cli_command(job_type,"createNSHScriptJob",args)
|
797
|
+
raise "Command_Failed: cannot create job: #{ss_job_key}" if ss_job_key.include?("ERROR")
|
798
|
+
BrpmAuto.log "Created: #{job_name} in group: #{group_path}"
|
799
|
+
#targets.collect!{|k| k.gsub(/^\//,"/Servers/") unless k.start_with?("/Servers") }
|
800
|
+
#c. Make the call to addTargetGroup (should be a new method)
|
801
|
+
if targets.is_a?(String) || targets.size < 2
|
802
|
+
method_call = target_type == "servers" ? "addTargetServer" : "addTargetGroup"
|
803
|
+
servers = targets.first if targets.is_a?(Array)
|
804
|
+
else
|
805
|
+
method_call = target_type == "servers" ? "addTargetServers" : "addTargetGroups"
|
806
|
+
servers = targets.join(",")
|
807
|
+
end
|
808
|
+
ss_job_key = execute_cli_command("Job", method_call,
|
809
|
+
[
|
810
|
+
ss_job_key, #jobName
|
811
|
+
servers #comma separated list of groups
|
812
|
+
])
|
813
|
+
raise "Command_Failed: cannot add targets: #{ss_job_key}" if ss_job_key.include?("ERROR")
|
814
|
+
if execute_now
|
815
|
+
param_result = set_nsh_script_params(job_name, group_path, job_params, false)
|
816
|
+
raise "Command_Failed: cannot set job parameters: #{param_result}" if param_result.include?("ERROR")
|
817
|
+
execute_result = execute_job_with_results(param_result["job_db_key"], result)
|
818
|
+
raise "Command_Failed: cannot execute job: #{execute_result.inspect}" if execute_result["status"].include?("ERROR")
|
819
|
+
end
|
820
|
+
result["job_db_key"] = ss_job_key
|
821
|
+
result["status"] = "SUCCESS"
|
822
|
+
result
|
823
|
+
end
|
824
|
+
|
825
|
+
# Executes an NSH Script Job in BAA to target servers
|
826
|
+
#
|
827
|
+
# ==== Attributes
|
828
|
+
#
|
829
|
+
# * +job_name+ - name for package (and template)
|
830
|
+
# * +group_path+ - path in Blade for job
|
831
|
+
# * +job_params+ - array of params (in order) for script job
|
832
|
+
# * +targets+ - array of servers or smartgroups
|
833
|
+
# * +target_type+ - server/group type of server target
|
834
|
+
#
|
835
|
+
# ==== Returns
|
836
|
+
#
|
837
|
+
# * hash of job results, includes - job_run_id, job_status
|
838
|
+
def execute_nsh_script_job(job_name, group_path, job_params, targets, target_type = "server")
|
839
|
+
result = {"status" => "ERROR"}
|
840
|
+
job_type = "NSHScriptJob"
|
841
|
+
ss_job_key = execute_cli_command(job_type,"getDBKeyByGroupAndName",[group_path, job_name])
|
842
|
+
ss_job_key = execute_cli_command("Job","clearTargetServers",[ss_job_key]) if target_type == "server"
|
843
|
+
ss_job_key = execute_cli_command("Job","clearTargetGroups",[ss_job_key]) if target_type != "server"
|
844
|
+
raise "Command_Failed: cannot clear targets: #{ss_job_key}" if ss_job_key.include?("ERROR")
|
845
|
+
ss_job_key = execute_cli_command("Job","addTargetServers",[ss_job_key,targets.join(",")]) if target_type == "server" && targets.count > 1
|
846
|
+
ss_job_key = execute_cli_command("Job","addTargetGroups",[ss_job_key,targets.join(",")]) if target_type != "server" && targets.count > 1
|
847
|
+
ss_job_key = execute_cli_command("Job","addTargetServer",[ss_job_key,targets.join]) if target_type == "server" && targets.count == 1
|
848
|
+
ss_job_key = execute_cli_command("Job","addTargetGroup",[ss_job_key,targets.join]) if target_type != "server" && targets.count == 1
|
849
|
+
raise "Command_Failed: cannot add targets: #{ss_job_key}" if ss_job_key.include?("ERROR")
|
850
|
+
BrpmAuto.message_box("Executing NSHScript Job","title")
|
851
|
+
BrpmAuto.log "#{job_name} in group: #{group_path}"
|
852
|
+
param_result = set_nsh_script_params(job_name, group_path, job_params)
|
853
|
+
raise "Command_Failed: cannot set job parameters: #{param_result}" if param_result.include?("ERROR")
|
854
|
+
execute_result = execute_job_with_results(param_result["job_db_key"], result)
|
855
|
+
raise "Command_Failed: cannot add targets: #{execute_result.insepct}" if execute_result["status"].include?("ERROR")
|
856
|
+
result["result"] = execute_result
|
857
|
+
result["status"] = "SUCCESS"
|
858
|
+
result
|
859
|
+
end
|
860
|
+
|
861
|
+
# Executes a Job in BAA and returns detailed results
|
862
|
+
#
|
863
|
+
# ==== Attributes
|
864
|
+
#
|
865
|
+
# * +job_db_key+ - db_key of job
|
866
|
+
# * +results+ - hash of existing results to add to
|
867
|
+
#
|
868
|
+
# ==== Returns
|
869
|
+
#
|
870
|
+
# * hash of job results, includes - job_run_id, job_status
|
871
|
+
def execute_job_with_results(job_db_key, results = {})
|
872
|
+
job_url = baa_soap_db_key_to_rest_uri(job_db_key)
|
873
|
+
raise "Could not fetch REST URI for job: #{job_db_key}" if job_url.nil?
|
874
|
+
job_result = execute_job(job_url)
|
875
|
+
raise "Could run specified job, did not get a valid response from server" if job_result.nil?
|
876
|
+
execution_status = "_SUCCESSFULLY"
|
877
|
+
execution_status = "_WITH_WARNINGS" if (job_result["had_warnings"] == "true")
|
878
|
+
if (job_result["had_errors"] == "true")
|
879
|
+
execution_status = "_WITH_ERRORS"
|
880
|
+
log("Job Execution failed: Please check job logs for errors")
|
881
|
+
end
|
882
|
+
results["status"] = job_result["status"] + execution_status
|
883
|
+
job_run_url = job_result["job_run_url"]
|
884
|
+
results["job_run_url"] = job_run_url
|
885
|
+
job_run_id = get_job_run_id(job_run_url)
|
886
|
+
results["job_run_id"] = job_run_id
|
887
|
+
raise "Could not fetch job_run_id" if job_run_id.nil?
|
888
|
+
job_result_url = get_job_result_url(job_run_url)
|
889
|
+
raise "Could not fetch job_result_url" if job_result_url.nil?
|
890
|
+
job_result = get_per_target_results(job_result_url)
|
891
|
+
results["target_status"] = job_result
|
892
|
+
results
|
893
|
+
end
|
894
|
+
|
895
|
+
# Sets parameters on an NSH Script Job in BAA
|
896
|
+
#
|
897
|
+
# ==== Attributes
|
898
|
+
#
|
899
|
+
# * +job_name+ - name for package (and template)
|
900
|
+
# * +group_path+ - path in Blade for job
|
901
|
+
# * +job_params+ - array of params (in order) for script job
|
902
|
+
#
|
903
|
+
# ==== Returns
|
904
|
+
#
|
905
|
+
# * hash of job results
|
906
|
+
def set_nsh_script_params(job_name, group_path, job_params,clear_params=true)
|
907
|
+
result = {"status" => "ERROR"}
|
908
|
+
job_type = "NSHScriptJob"
|
909
|
+
BrpmAuto.log "Executing NSH Script Job"
|
910
|
+
BrpmAuto.log "Job: #{job_name}, In: #{group_path}"
|
911
|
+
if clear_params
|
912
|
+
BrpmAuto.log "\tRemove parameters"
|
913
|
+
ss_job_key = execute_cli_command(job_type,"clearNSHScriptParameterValuesByGroupAndName",[group_path, job_name])
|
914
|
+
raise "Command_Failed: cannot clear parameter values: #{ss_job_key}" if ss_job_key.include?("ERROR")
|
915
|
+
end
|
916
|
+
job_params.each_with_index do |param, idx|
|
917
|
+
BrpmAuto.log "\tAdding param ##{idx}: #{param}"
|
918
|
+
ss_job_key = execute_cli_command(job_type,"addNSHScriptParameterValueByGroupAndName",[group_path, job_name, idx, param])
|
919
|
+
raise "Command_Failed: cannot clear parameter values: #{ss_job_key}" if ss_job_key.include?("ERROR")
|
920
|
+
end
|
921
|
+
result["job_db_key"] = ss_job_key
|
922
|
+
result["status"] = "SUCCESS"
|
923
|
+
result
|
924
|
+
end
|
925
|
+
|
926
|
+
# Creates a file deploy Job in BAA
|
927
|
+
#
|
928
|
+
# ==== Attributes
|
929
|
+
#
|
930
|
+
# * +job_name+ - name for package (and template)
|
931
|
+
# * +group_path+ - path in Blade for job
|
932
|
+
# * +source_files+ - array of files/directories to move
|
933
|
+
# * +target_path+ - base path on target to deploy to
|
934
|
+
# * +targets+ - array of servers/groups to deploy to
|
935
|
+
# * +options+ - hash of options, includes: preserve_file_paths(true/false), num_par_procs=50, target_type=server, execute_now
|
936
|
+
#
|
937
|
+
# ==== Returns
|
938
|
+
#
|
939
|
+
# * hash of job results
|
940
|
+
def create_file_deploy_job(job_name, group_path, source_files, target_path, targets, options = {})
|
941
|
+
result = {"status" => "ERROR"}
|
942
|
+
num_par_procs = get_option(options,"num_par_procs", 50)
|
943
|
+
execute_now = get_option(options,"execute_now", false)
|
944
|
+
target_type = get_option(options,"target_type", "server")
|
945
|
+
preserve_file_paths = get_option(options,"preserve_file_paths", false)
|
946
|
+
args = [
|
947
|
+
job_name, #job_name
|
948
|
+
group_path, #job_group
|
949
|
+
source_files.join(","), #source_files
|
950
|
+
target_path, #destination
|
951
|
+
preserve_file_paths, #isPreserveSourceFilePaths
|
952
|
+
num_par_procs, #numTargetsInParallel
|
953
|
+
targets.join(","), #targetServerGroups
|
954
|
+
]
|
955
|
+
BrpmAuto.log "Creating file deploy job: #{job_name} in: #{group_path}"
|
956
|
+
job_db_key = execute_cli_command("FileDeployJob", "createJobByServerGroups", args) if target_type != "server"
|
957
|
+
job_db_key = execute_cli_command("FileDeployJob", "createJobByServers", args) if target_type == "server"
|
958
|
+
raise "Command_Failed: deploy job failed - #{job_db_key}" if job_db_key.include?("ERROR")
|
959
|
+
result["job_db_key"] = job_db_key
|
960
|
+
if execute_now
|
961
|
+
BrpmAuto.log "#=> Executing Job"
|
962
|
+
deploy_results_id = execute_cli_command("FileDeployJob", "executeJobAndWait", [job_db_key])
|
963
|
+
raise "Command_Failed: deploy job failed - #{deploy_results_id}" if deploy_results_id.include?("ERROR")
|
964
|
+
result["deploy_results_id"] = deploy_results_id
|
965
|
+
end
|
966
|
+
result["status"] = "SUCCESS"
|
967
|
+
result
|
968
|
+
end
|
969
|
+
|
970
|
+
# Copies an NSHScriptJob in BAA to a new job
|
971
|
+
#
|
972
|
+
# ==== Attributes
|
973
|
+
#
|
974
|
+
# * +source_job+ - name for package (and template)
|
975
|
+
# * +source_goup+ - path in Blade for job
|
976
|
+
# * +target_job+ - array of files/directories to move
|
977
|
+
# * +target_group+ - base path on target to deploy to
|
978
|
+
#
|
979
|
+
# ==== Returns
|
980
|
+
#
|
981
|
+
# * job dbKey
|
982
|
+
def copy_job(source_job, source_group, target_job, target_group)
|
983
|
+
args = [source_group, source_job]
|
984
|
+
ss_job_key = execute_cli_command("NSHScriptJob","getDBKeyByGroupAndName",args)
|
985
|
+
raise "Command_Failed: cannot find job: #{ss_job_key}" if ss_job_key.include?("ERROR")
|
986
|
+
args = [ss_job_key, target_group, target_job]
|
987
|
+
copy_job_key = execute_cli_command("Job","copyJob",args)
|
988
|
+
raise "Command_Failed: cannot create job: #{copy_job_key}" if copy_job_key.include?("ERROR")
|
989
|
+
copy_job_key
|
990
|
+
end
|
991
|
+
|
992
|
+
# Separates the server and path from an NSH path
|
993
|
+
# offers the option of embedding a property (blade-style) in lieu of the base_path
|
994
|
+
#
|
995
|
+
# ==== Attributes
|
996
|
+
#
|
997
|
+
# * +path+ - the nsh path
|
998
|
+
# * +base_path+ - a path fragment to substitute with a property
|
999
|
+
# * +path_property+ - a property name
|
1000
|
+
#
|
1001
|
+
# ==== Returns
|
1002
|
+
#
|
1003
|
+
# * the path portion of the nsh path
|
1004
|
+
# * if a property_name is passed, the return is like this:
|
1005
|
+
# /opt/bmc/RLM/??DEPLOY_VERSION??/appserver
|
1006
|
+
def path_from_nsh_path(path, base_path = nil, path_property = nil)
|
1007
|
+
result = path
|
1008
|
+
result = "/#{result.split("/")[3..-1].join("/")}" if result.start_with?("//")
|
1009
|
+
unless path_property.nil?
|
1010
|
+
result = result.gsub(base_path, "??#{path_property}??")
|
1011
|
+
end
|
1012
|
+
result
|
1013
|
+
end
|
1014
|
+
|
1015
|
+
# Returns the nsh path from a dos path
|
1016
|
+
#
|
1017
|
+
# ==== Attributes
|
1018
|
+
#
|
1019
|
+
# * +source_path+ - path in nsh
|
1020
|
+
# * +server+ - optional, adds a server in nsh format
|
1021
|
+
#
|
1022
|
+
# ==== Returns
|
1023
|
+
#
|
1024
|
+
# * nsh compatible path
|
1025
|
+
#
|
1026
|
+
def nsh_path(source_path, server = nil)
|
1027
|
+
path = ""
|
1028
|
+
if source_path.include?(":\\")
|
1029
|
+
path_array = source_path.split("\\")
|
1030
|
+
path = "/#{path_array[0].gsub(":","/")}"
|
1031
|
+
path += path_array[1..-1].join("/")
|
1032
|
+
else
|
1033
|
+
path = source_path
|
1034
|
+
end
|
1035
|
+
path = "//server#{path}" unless server.nil?
|
1036
|
+
path.chomp("/")
|
1037
|
+
end
|
1038
|
+
|
1039
|
+
private
|
1040
|
+
|
1041
|
+
def bl_auth
|
1042
|
+
"?username=#{@username}&password=#{@password}&role=#{@role}"
|
1043
|
+
end
|
1044
|
+
|
1045
|
+
def method_missing(destination, *args)
|
1046
|
+
if destination.to_s.start_with?("baa_soap")
|
1047
|
+
check_session
|
1048
|
+
args_new = [@url, @session_id] + args
|
1049
|
+
else
|
1050
|
+
args_new = [@url, @username, @password, @role] + args
|
1051
|
+
end
|
1052
|
+
puts "#=> Invoking BaaUtility method: #{destination} - #{args_new.inspect}"
|
1053
|
+
result = BaaUtilities.send(destination, *args_new)
|
1054
|
+
end
|
1055
|
+
|
1056
|
+
def redirect_stdout
|
1057
|
+
begin
|
1058
|
+
orig_stderr = $stderr.clone
|
1059
|
+
orig_stdout = $stdout.clone
|
1060
|
+
$stderr.reopen File.open("#{@output_file.gsub(".txt","")}_stdout.txt", 'a' )
|
1061
|
+
$stdout.reopen File.open("#{@output_file.gsub(".txt","")}_stderr.txt", 'a' )
|
1062
|
+
retval = yield
|
1063
|
+
rescue Exception => e
|
1064
|
+
$stdout.reopen orig_stdout
|
1065
|
+
$stderr.reopen orig_stderr
|
1066
|
+
raise e
|
1067
|
+
ensure
|
1068
|
+
$stdout.reopen orig_stdout
|
1069
|
+
$stderr.reopen orig_stderr
|
1070
|
+
end
|
1071
|
+
retval
|
1072
|
+
end
|
1073
|
+
|
1074
|
+
def check_session
|
1075
|
+
if Time.now - @session_time > 300
|
1076
|
+
get_session_id
|
1077
|
+
assume_role
|
1078
|
+
end
|
1079
|
+
@session_id
|
1080
|
+
end
|
1081
|
+
|
1082
|
+
def cli_result(raw_result)
|
1083
|
+
if raw_result && (raw_result.is_a? Hash)
|
1084
|
+
return "ERROR: Command execution failed: #{raw_result[:error]}, #{raw_result[:comments]}" if raw_result[:success] == false
|
1085
|
+
return raw_result[:return_value]
|
1086
|
+
else
|
1087
|
+
return "ERROR: Command execution did not return a valid response: #{raw_result.inspect}"
|
1088
|
+
end
|
1089
|
+
nil
|
1090
|
+
end
|
1091
|
+
|
1092
|
+
end
|
1093
|
+
|
1094
|
+
|
1095
|
+
|