brpm_content_framework 0.1.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/.gitignore +38 -0
- data/.travis.yml +17 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +308 -0
- data/Rakefile +23 -0
- data/TO_BE_MIGRATED.txt +9 -0
- data/architecture.png +0 -0
- data/automations/direct_execute.meta +10 -0
- data/automations/direct_execute.rb +10 -0
- data/automations/install_module.meta +10 -0
- data/automations/install_module.rb +13 -0
- data/bin/brpm_install +30 -0
- data/bin/brpm_uninstall +30 -0
- data/bin/event_handler +63 -0
- data/bin/webhook_receiver +49 -0
- data/brpm_content.gemspec +31 -0
- data/config.yml +8 -0
- data/infrastructure/.bashrc +6 -0
- data/infrastructure/.brpm +2 -0
- data/infrastructure/config/customer_include.rb +26 -0
- data/infrastructure/config/server.yml +3 -0
- data/infrastructure/log.html +39 -0
- data/infrastructure/scripts/backup_database.sh +19 -0
- data/infrastructure/scripts/ddns.sh +10 -0
- data/infrastructure/scripts/install_brpm.sh +63 -0
- data/infrastructure/scripts/maintenance.sh +4 -0
- data/infrastructure/scripts/patch_brpm.sh +90 -0
- data/infrastructure/scripts/restore_database.sh +33 -0
- data/infrastructure/scripts/run_event_handler.cmd +19 -0
- data/infrastructure/scripts/run_event_handler.sh +20 -0
- data/infrastructure/scripts/run_webhook_receiver.cmd +15 -0
- data/infrastructure/scripts/run_webhook_receiver.sh +15 -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/lib/brpm_auto.rb +358 -0
- data/lib/brpm_script_executor.rb +80 -0
- data/lib/logging/brpm_logger.rb +39 -0
- data/lib/logging/logger_base.rb +36 -0
- data/lib/logging/simple_logger.rb +27 -0
- data/lib/module_installer.rb +483 -0
- data/lib/params/all_params.rb +80 -0
- data/lib/params/integration_settings.rb +27 -0
- data/lib/params/params.rb +174 -0
- data/lib/params/params_base.rb +81 -0
- data/lib/params/request_params.rb +38 -0
- data/lib/rest_api.rb +155 -0
- data/lib/semaphore.rb +79 -0
- data/lib/utilities.rb +317 -0
- data/lib/version_control/git.rb +192 -0
- data/lib/version_control/svn.rb +221 -0
- data/lib/write_to.rb +1 -0
- data/tests/all_params_spec.rb +116 -0
- data/tests/brpm_auto_spec.rb +84 -0
- data/tests/customer_include/config/customer_include.rb +10 -0
- data/tests/customer_include/config/server.yml +3 -0
- data/tests/customer_include_spec.rb +29 -0
- data/tests/gemspec_spec.rb +11 -0
- data/tests/module_installer_spec.rb +46 -0
- data/tests/params_spec.rb +172 -0
- data/tests/request_params_spec.rb +86 -0
- data/tests/server_yaml_spec.rb +19 -0
- data/tests/spec_helper.rb +64 -0
- data/to_be_migrated/brpm_framework.rb +88 -0
- data/to_be_migrated/customer_include_default.rb +25 -0
- data/to_be_migrated/local_jirb.rb +15 -0
- data/to_be_migrated/resource_framework.rb +211 -0
- data/transport/dispatch_baa.rb +355 -0
- data/transport/dispatch_base.rb +345 -0
- data/transport/dispatch_nsh.rb +248 -0
- data/transport/dispatch_ssh.rb +154 -0
- data/transport/transport_baa.rb +1095 -0
- data/transport/transport_nsh.rb +359 -0
- data/transport/transport_ssh.rb +220 -0
- metadata +204 -0
@@ -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
|
+
|