brpm_content 0.1.16 → 0.1.17

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDc1ZGFlMmVjYmM4ZDY2MzNmODY2YjQ2ZjQzN2RkYTBiZWU3N2I0MA==
4
+ ZTAxMmNkNjk4YmQ3MTE4NDhlODQ2MTAxM2ExMTMxNTA0MzE0ZDg2MA==
5
5
  data.tar.gz: !binary |-
6
- ZDQ5ZmNkOTA4ZDBkOTE3ZWE4NGRkZDlhMzY4MTQyYzk5MjBiNjU4Ng==
6
+ YWYwYjZmODUxYWMyMmMxZDI4NWVlYWU4MDIzZjQ2NzE2ZTk4Y2NjZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MTM3YjAwZmRmYTk0NDNkNDU3MmViNjQyYjRjMWFjOTJhNzg3NGIxZDAwNWM2
10
- N2ZmM2UwMDFjNGQ0OGU1Y2EzOWI4MmFkMDU2Yjc4MGY2NTM5NDhlNzg4NmRm
11
- ZjUxZjUzZjc1MDUzMmYxMTY3NDNkZmYyZTM1ZTIyNjZmNzdmYTU=
9
+ MTczNDIwZjkyY2FlZDdlZTBmZjRmZjEzYzQwMzc0ZDQzNjhmZmY5MTBiZDcy
10
+ YzA2NmM1Yjc2YWYxMDkzZjc3YmEyZjYxMDAwNGRiYWIyYWRkNzc3MGQyNzM4
11
+ YTNjODliOTJjNDNiN2NmMzA5YWUwZDY5MTBlMDNlYzJiZDY0NzY=
12
12
  data.tar.gz: !binary |-
13
- MDIzYjg3OTZjYmJlYjhhYmU5YWU5ODkzZmUzZDcwMGU1ZGVlODA2MDY2M2M5
14
- ZDRkOTg2YmM5YWY1MTM4YzI5MGI4MzE3ZDkxYTY4NWY4MGQ5ZTQxYTA5OWNk
15
- OTFmZTY1N2I1ODY5MzI1NzJhYTg1YTJhOGRmMTljYTQ1MjQ1MjE=
13
+ NjI4YzhiMzUyMzQ0MmYxOTQ3YjZhYTU2MTFhZTRhZGUxYTBkMmZjNGQ3YTg2
14
+ OGE3NTY4YmY4ZjU5ZTRmN2FmMGZjMzc5NWJkYWM1ZTljMGI1NTlmZGEwZWZm
15
+ NDAyZWQwYjU4ZjM0YzQ3MWIwNzVhMTQ1MGQ4MGQ3MjUyNmE1MDg=
@@ -1387,7 +1387,6 @@ class BrpmRestClient
1387
1387
  sync_attribute "first received", now, ticket["extended_attributes_attributes"] unless ticket_already_exists
1388
1388
  sync_attribute "last updated", now, ticket["extended_attributes_attributes"]
1389
1389
 
1390
- # Create/update the ticket
1391
1390
  data = {}
1392
1391
  data["ticket"] = ticket
1393
1392
 
@@ -1402,6 +1401,111 @@ class BrpmRestClient
1402
1401
  end
1403
1402
  end
1404
1403
 
1404
+ def get_project_servers
1405
+ result = brpm_get "v1/project_servers"
1406
+
1407
+ if result["status"] == "success"
1408
+ result_hash = result["response"]
1409
+ else
1410
+ if result["code"] == 404
1411
+ result_hash = {}
1412
+ else
1413
+ raise "Error getting project servers: #{result["error_message"]}"
1414
+ end
1415
+ end
1416
+
1417
+ result_hash
1418
+ end
1419
+
1420
+ def get_id_for_project_server_type(integration_server_type)
1421
+ case integration_server_type.downcase
1422
+ when "Jira".downcase
1423
+ return 2
1424
+ when "Hudson/Jenkins".downcase, "Jenkins".downcase
1425
+ return 5
1426
+ when "Remedy via AO".downcase, "AO".downcase, "AtriumOrchestrator".downcase
1427
+ return 8
1428
+ when "BMC Application Automation".downcase, "Bladelogic".downcase
1429
+ return 9
1430
+ when "RLM Deployment Engine".downcase, "BRPD".downcase
1431
+ return 10
1432
+ else
1433
+ return nil
1434
+ end
1435
+ end
1436
+
1437
+ def get_scripts_by(filter)
1438
+ filter_string = "?"
1439
+ filter.each do |key, value|
1440
+ filter_string += "filters[#{key}]=#{value}&"
1441
+ end
1442
+ filter_string = filter_string[0..-1]
1443
+
1444
+ result = brpm_get "v1/scripts#{filter_string}"
1445
+
1446
+ if result["status"] == "success"
1447
+ result_hash = result["response"]
1448
+ else
1449
+ if result["code"] == 404
1450
+ result_hash = {}
1451
+ else
1452
+ raise "Error searching for scripts by #{filter_string}: #{result["error_message"]}"
1453
+ end
1454
+ end
1455
+
1456
+ result_hash
1457
+ end
1458
+
1459
+ def create_script_from_hash(script)
1460
+ result = brpm_post "v1/scripts", { :script => script }
1461
+
1462
+ unless result["status"] == "success"
1463
+ raise "Could not create the script: #{result["error_message"]}"
1464
+ end
1465
+
1466
+ result["response"]
1467
+ end
1468
+
1469
+ def update_script_from_hash(script)
1470
+ result = brpm_put "v1/scripts/#{script["id"]}", { :script => script }
1471
+
1472
+ unless result["status"] == "success"
1473
+ raise "Could not update the script: #{result["error_message"]}"
1474
+ end
1475
+
1476
+ result["response"]
1477
+ end
1478
+
1479
+ def create_or_update_script(script)
1480
+ BrpmAuto.log "Checking if the corresponding script already exists ..."
1481
+ existing_script = get_script_by_name script["name"]
1482
+
1483
+ if existing_script.nil?
1484
+ BrpmAuto.log "Script doesn't exist yet."
1485
+ script_already_exists=false
1486
+ else
1487
+ BrpmAuto.log "Script already exists."
1488
+ script_already_exists=true
1489
+
1490
+ script["id"] = existing_script["id"].to_s
1491
+ end
1492
+
1493
+ data = {}
1494
+ data["script"] = script
1495
+
1496
+ if script_already_exists
1497
+ BrpmAuto.log "Updating the script..."
1498
+ script = update_script_from_hash(script)
1499
+ BrpmAuto.log "Script is updated."
1500
+ else
1501
+ BrpmAuto.log "Creating the script..."
1502
+ script = create_script_from_hash(script)
1503
+ BrpmAuto.log "Script is created."
1504
+ end
1505
+
1506
+ script
1507
+ end
1508
+
1405
1509
  def sync_attributes(existing_attributes, updated_attributes)
1406
1510
  existing_attributes ||= []
1407
1511
  updated_attributes ||= []
@@ -1,67 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
2
  require "rubygems"
3
3
  require "bundler"
4
- require "brpm_auto"
5
4
  require "yaml"
6
5
 
7
- def install_gem(module_name, module_version)
8
- if module_version
9
- BrpmAuto.log "Executing command 'gem install #{module_name} -v #{module_version}'..."
10
- specs = Gem.install(module_name, module_version)
11
- else
12
- BrpmAuto.log "Executing command 'gem install #{module_name}'..."
13
- specs = Gem.install(module_name)
14
- end
15
- BrpmAuto.log "Installed gems:"
16
- BrpmAuto.log specs.inspect
17
- specs
18
- end
19
-
20
- def install_bundle_if_necessary(spec)
21
- gemfile = File.join(spec.gem_dir, "Gemfile")
22
- gemfile_lock = File.join(spec.gem_dir, "Gemfile.lock")
23
-
24
- if File.exists?(gemfile) && File.exists?(gemfile_lock)
25
- BrpmAuto.log "Found a Gemfile.lock so executing command 'bundle install --gemfile #{gemfile}'..."
26
- # %x(bundle install --gemfile #{gemfile})
27
- result = BrpmAuto.execute_shell("bundle install --gemfile #{gemfile}")
28
- BrpmAuto.log result["stdout"] if result["stdout"] and ! result["stdout"].empty?
29
- unless result["status"] == 0
30
- raise result["stderr"]
31
- end
32
- end
33
- end
34
-
35
- def update_symlink_to_brpm_content(brpm_content_spec)
36
- if brpm_content_spec.version > Gem::Version.new(BrpmAuto.version)
37
- new_version_path = brpm_content_spec.gem_dir
38
- symlink_path = "#{ENV["GEM_HOME"]}/gems/brpm_content-latest"
39
-
40
- BrpmAuto.log "A newer version of brpm_content was installed so updating symlink #{symlink_path} to #{new_version_path}..."
41
- result = BrpmAuto.execute_shell("ln -sfn #{new_version_path} #{symlink_path}")
42
- BrpmAuto.log result["stdout"] if result["stdout"] and ! result["stdout"].empty?
43
- unless result["status"] == 0
44
- raise result["stderr"]
45
- end
46
- end
47
- end
48
-
49
- def install_auto_script_wrappers(spec, brpm_url, brpm_api_token)
50
- brpm_rest_client = BrpmRestClient.new(brpm_url, brpm_api_token)
51
-
52
- integration_servers = brpm_rest_client.get_integration_servers
53
-
54
- Dir.glob("#{spec.gem_dir}/{automations, resource_automations}/*.rb").each do |auto_script|
55
- #TODO: open txt file
56
- #TODO: add wrapper code
57
- #TODO: set integration server id if necessary
58
-
59
- script = {}
60
- brpm_rest_client.create_or_update_script(script)
61
- end
62
- end
63
-
6
+ require "brpm_auto"
64
7
 
8
+ params = {}
9
+ params["log_file"] = "/tmp/brpm_install.log"
10
+ params["also_log_to_console"] = "true"
11
+ params["unit_test"] = "true" if ENV["UNIT_TEST"] == "1"
12
+ BrpmAuto.setup(params)
65
13
 
66
14
  if ARGV.size < 1
67
15
  BrpmAuto.log "Missing arguments."
@@ -69,38 +17,7 @@ if ARGV.size < 1
69
17
  end
70
18
 
71
19
  module_name = ARGV[0]
72
- module_version = ARGV[1]
73
-
74
- params = {}
75
- params["log_file"] = "/tmp/brpm_install.log"
76
- params["also_log_to_console"] = "true"
77
- BrpmAuto.setup(params)
78
-
79
- BrpmAuto.log "Installing module #{module_name} #{module_version.nil? ? "" : module_version}..."
80
-
81
- specs = install_gem(module_name, module_version)
82
- module_spec = specs.last
83
-
84
- install_bundle_if_necessary(module_spec)
85
-
86
- if ENV["BRPM_HOME"] and ! ENV["BRPM_HOME"].empty?
87
- brpm_content_spec = specs.find { |spec| spec.name == "brpm_content" }
88
- update_symlink_to_brpm_content(brpm_content_spec) if brpm_content_spec
89
-
90
- if File.exists?("~/.brpm")
91
- config = YAML.load_file("~/.brpm")
92
-
93
- if config["brpm_url"] and config["brpm_api_token"]
94
- install_auto_script_wrappers(spec, brpm_url, brpm_api_token)
95
- else
96
- BrpmAuto.log "Properties brpm_url and/or brpm_api_token don't exist in file ~/.brpm so not installing the automation script wrappers in BRPM. If you want to install them the next time you should add brpm_url and brpm_api_token properties in yaml format in file ~/.brpm."
97
- end
98
- else
99
- BrpmAuto.log "File ~/.brpm doesn't exist so not installing the automation script wrappers in BRPM. If you want to install them the next time you should create this file and add brpm_url and brpm_api_token properties in yaml format."
100
- end
101
-
102
- if module_name == "brpm_content"
103
- #TODO: cp $CONTENT_REPO_PATH/modules/framework/log.html $BRPM_HOME/automation_results
20
+ module_version = ARGV[1] # optional
104
21
 
105
- end
106
- end
22
+ brpm_installer = BrpmInstaller.new
23
+ brpm_installer.install_module(module_name, module_version)
@@ -113,13 +113,12 @@ class BrpmAuto
113
113
 
114
114
  def require_module_from_gem(module_name, module_version = nil)
115
115
  module_version ||= get_latest_installed_version(module_name)
116
-
117
116
  module_gem_path = get_module_gem_path(module_name, module_version)
118
117
 
119
118
  if File.exists?(module_gem_path)
120
119
  BrpmAuto.log "Found the module in gem path #{module_gem_path}."
121
120
  else
122
- raise "Module #{module_name} version #{module_version} is not installed. Expected it on path #{module_gem_path}."
121
+ raise GemNotFoundException, "Module #{module_name} version #{module_version} is not installed. Expected it on path #{module_gem_path}."
123
122
  end
124
123
 
125
124
  gemfile_lock_path = "#{module_gem_path}/Gemfile.lock"
@@ -191,6 +190,10 @@ class BrpmAuto
191
190
  @logger = SimpleLogger.new(log_file, also_log_to_console)
192
191
  end
193
192
 
193
+ def run_from_brpm
194
+ @params.run_from_brpm
195
+ end
196
+
194
197
  def log(message)
195
198
  @logger.log(message)
196
199
  end
@@ -221,8 +224,10 @@ class BrpmAuto
221
224
  module_path = get_module_gem_path(module_name, module_version)
222
225
 
223
226
  module_config_file_path = "#{module_path}/config.yml"
227
+
224
228
  if File.exist?(module_config_file_path)
225
229
  module_config = YAML.load_file(module_config_file_path)
230
+
226
231
  if module_config["dependencies"]
227
232
  BrpmAuto.log "Loading the dependent modules..."
228
233
  module_config["dependencies"].each do |dependency|
@@ -289,7 +294,7 @@ class BrpmAuto
289
294
  all_version_search = get_module_gem_path(module_name, "*")
290
295
  version_paths = Dir.glob(all_version_search)
291
296
 
292
- raise "Could not find any installed version of module #{module_name}. Expected them in #{get_module_gem_path(module_name, "*")}" if version_paths.empty?
297
+ raise GemNoVersionsInstalledError, "Could not find any installed version of module #{module_name}. Expected them in #{get_module_gem_path(module_name, "*")}" if version_paths.empty?
293
298
 
294
299
  versions = version_paths.map { |path| File.basename(path).sub("#{module_name}-", "") }
295
300
 
@@ -305,3 +310,8 @@ class BrpmAuto
305
310
  self.init
306
311
  end
307
312
 
313
+ class GemNoVersionsInstalledError < Gem::GemNotFoundException
314
+ end
315
+
316
+ class GemNotInstalledError < Gem::GemNotFoundException
317
+ end
@@ -81,7 +81,7 @@ class BrpmScriptExecutor
81
81
  start_time = Time.now
82
82
 
83
83
  BrpmAuto.log "Loading the module and its dependencies..."
84
- module_path = BrpmAuto.require_module_from_gem(modul)
84
+ module_path = BrpmAuto.require_module_from_gem(modul, params["module_version"])
85
85
  BrpmAuto.log "Finished loading the module."
86
86
 
87
87
  automation_script_path = "#{module_path}/automations/#{name}.rb"
@@ -115,13 +115,13 @@ class BrpmScriptExecutor
115
115
  start_time = Time.now
116
116
 
117
117
  BrpmAuto.log "Loading the module and its dependencies..."
118
- module_path = BrpmAuto.require_module_from_gem(modul)
118
+ module_path = BrpmAuto.require_module_from_gem(modul) #TODO: from where should we get the module version of the script?
119
119
  BrpmAuto.log "Finished loading the module."
120
120
 
121
121
  automation_script_path = "#{module_path}/resource_automations/#{name}.rb"
122
122
 
123
123
  BrpmAuto.log "Loading the resource automation script #{automation_script_path}..."
124
- result = load automation_script_path
124
+ load automation_script_path
125
125
 
126
126
  BrpmAuto.log "Calling execute_resource_automation_script(params, parent_id, offset, max_records)..."
127
127
  execute_script(params, parent_id, offset, max_records)
@@ -1,4 +1,4 @@
1
- version: 0.1.16
1
+ version: 0.1.17
2
2
 
3
3
  author: Niek Bartholomeus
4
4
  email: niek.bartholomeus@gmail.com
@@ -0,0 +1,244 @@
1
+ class BrpmInstaller
2
+ def install_module(module_name, module_version)
3
+ BrpmAuto.log "Installing module #{module_name} #{module_version.nil? ? "" : module_version}..."
4
+
5
+ specs = install_gem(module_name, module_version)
6
+ module_spec = specs.last
7
+
8
+ install_bundle_if_necessary(module_spec)
9
+
10
+ if brpm_installed_locally?
11
+ BrpmAuto.log "A BRPM instance is installed locally"
12
+
13
+ brpm_content_spec = specs.find { |spec| spec.name == "brpm_content" }
14
+ if brpm_content_spec and brpm_content_spec.version > Gem::Version.new(BrpmAuto.version)
15
+ BrpmAuto.log "WARNING - A newer version of brpm_content was installed."
16
+
17
+ BrpmAuto.log "Checking if the symlink to brpm_content-latest should be updated..."
18
+ update_symlink_to_brpm_content_if_necessary(brpm_content_spec)
19
+
20
+ BrpmAuto.log "Copying the log.html file to te automation_results directory..."
21
+ File.cp("#{brpm_content_spec.gem_dir}/modules/framework/log.html", "#{Env["BRPM_HOME"]}/automation_results")
22
+ end
23
+
24
+ BrpmAuto.log "Installing the automation script wrappers in the local BRPM instance..."
25
+ install_auto_script_wrappers(module_spec.gem_dir, module_spec.name)
26
+ end
27
+ end
28
+
29
+ def install_gem(module_name, module_version)
30
+ if BrpmAuto.run_from_brpm or BrpmAuto.params.unit_test
31
+ # we need to override the GEM_HOME env var, otherwise the gems will be installed in BRPM's own gemset
32
+ ENV["GEM_HOME"] = ENV["BRPM_CONTENT_HOME"] || "#{ENV["BRPM_HOME"]}/modules"
33
+ Gem.paths = ENV
34
+ end
35
+
36
+ if module_version
37
+ BrpmAuto.log "Executing command 'gem install #{module_name} -v #{module_version}'..."
38
+ specs = Gem.install(module_name, module_version)
39
+ else
40
+ BrpmAuto.log "Executing command 'gem install #{module_name}'..."
41
+ specs = Gem.install(module_name)
42
+ end
43
+ BrpmAuto.log "Installed gems:"
44
+ specs.each do |spec|
45
+ BrpmAuto.log " - #{spec.name} #{spec.version}"
46
+ end
47
+ specs
48
+ end
49
+
50
+ def install_bundle_if_necessary(spec)
51
+ gemfile = File.join(spec.gem_dir, "Gemfile")
52
+ gemfile_lock = File.join(spec.gem_dir, "Gemfile.lock")
53
+
54
+ if File.exists?(gemfile) && File.exists?(gemfile_lock)
55
+ BrpmAuto.log "Found a Gemfile.lock so executing command 'bundle install --gemfile #{gemfile}'..."
56
+ # %x(bundle install --gemfile #{gemfile})
57
+ result = BrpmAuto.execute_shell("bundle install --gemfile #{gemfile}") #TODO: check if we must set GEM_HOME (when run from BRPM)
58
+ BrpmAuto.log result["stdout"] if result["stdout"] and !result["stdout"].empty?
59
+ unless result["status"] == 0
60
+ raise result["stderr"]
61
+ end
62
+ end
63
+ end
64
+
65
+ def update_symlink_to_brpm_content_if_necessary(brpm_content_spec)
66
+ new_version_path = brpm_content_spec.gem_dir
67
+ symlink_path = "#{ENV["GEM_HOME"]}/gems/brpm_content-latest"
68
+
69
+ BrpmAuto.log "A newer version of brpm_content was installed so updating symlink #{symlink_path} to #{new_version_path}..."
70
+ result = BrpmAuto.execute_shell("ln -sfn #{new_version_path} #{symlink_path}")
71
+ BrpmAuto.log result["stdout"] if result["stdout"] and !result["stdout"].empty?
72
+ unless result["status"] == 0
73
+ raise result["stderr"]
74
+ end
75
+ end
76
+
77
+ def brpm_installed_locally?
78
+ ENV["BRPM_HOME"] and !ENV["BRPM_HOME"].empty?
79
+ end
80
+
81
+ def install_auto_script_wrappers(module_path, module_name)
82
+ brpm_file = File.expand_path("~/.brpm")
83
+ if File.exists?(brpm_file)
84
+ config = YAML.load_file(brpm_file)
85
+ end
86
+
87
+ if config
88
+ unless config["brpm_url"] and config["brpm_api_token"]
89
+ BrpmAuto.log "WARNING - Properties brpm_url and/or brpm_api_token don't exist in file ~/.brpm so not installing the automation script wrappers in BRPM. If you want to install them the next time you should add brpm_url and brpm_api_token properties in yaml format in file ~/.brpm."
90
+ return false
91
+ end
92
+ else
93
+ BrpmAuto.log "WARNING - File ~/.brpm doesn't exist so not installing the automation script wrappers in BRPM. If you want to install them the next time you should create this file and add brpm_url and brpm_api_token properties in yaml format."
94
+ return false
95
+ end
96
+
97
+ begin
98
+ BrpmAuto.require_module_from_gem "brpm_module_brpm"
99
+ rescue Gem::GemNotFoundException
100
+ BrpmAuto.log "WARNING - Module brpm_module_brpm is not installed so not installing the automation script wrappers in BRPM."
101
+ return false
102
+ end
103
+
104
+ brpm_rest_client = BrpmRestClient.new(config["brpm_url"], config["brpm_api_token"])
105
+
106
+ BrpmAuto.log "Retrieving the integration servers..."
107
+ integration_servers = brpm_rest_client.get_project_servers
108
+
109
+ # For resource automations
110
+ resource_automation_dir = "#{module_path}/resource_automations"
111
+ resource_automation_script_paths = Dir.glob("#{resource_automation_dir}/*.rb")
112
+
113
+ if resource_automation_script_paths.size > 0
114
+ BrpmAuto.log "Installing the wrapper scripts for the resource automations..."
115
+
116
+ resource_automation_script_paths.each do |auto_script_path|
117
+ install_auto_script_wrapper(auto_script_path, "ResourceAutomation", module_name, integration_servers, brpm_rest_client)
118
+ end
119
+ end
120
+
121
+ # For automations
122
+ automation_dir = "#{module_path}/automations"
123
+ automation_script_paths = Dir.glob("#{automation_dir}/*.rb")
124
+
125
+ if automation_script_paths.size > 0
126
+ BrpmAuto.log "Installing the wrapper scripts for the automations..."
127
+
128
+ automation_script_paths.each do |auto_script_path|
129
+ install_auto_script_wrapper(auto_script_path, "Automation", module_name, integration_servers, brpm_rest_client)
130
+ end
131
+ end
132
+ end
133
+
134
+ def install_auto_script_wrapper(auto_script_path, automation_type, module_name, integration_servers, brpm_rest_client)
135
+ auto_script_name = File.basename(auto_script_path, ".rb")
136
+ BrpmAuto.log "Installing the wrapper script for resource automation #{auto_script_name}..."
137
+
138
+ auto_script_config_path = "#{File.dirname(auto_script_path)}/#{auto_script_name}.txt"
139
+
140
+ auto_script_config_content = File.exists?(auto_script_config_path) ? File.read(auto_script_config_path) : ""
141
+ match = auto_script_config_content.match(/###\n(.*)\n###/m)
142
+ input_params_content = match ? match[1] : ""
143
+
144
+ input_params_content += <<EOR
145
+
146
+ # framework_version:
147
+ # name: Framework version
148
+ # required: no
149
+ # module_version:
150
+ # name: Module version
151
+ # required: no
152
+ EOR
153
+
154
+ wrapper_script_content = "###\n#{input_params_content}###"
155
+
156
+ auto_script_config = YAML.load(auto_script_config_content) || {}
157
+
158
+ integration_server = nil
159
+ if auto_script_config["integration_server_type"]
160
+ server_type_id = brpm_rest_client.get_id_for_project_server_type(auto_script_config["integration_server_type"])
161
+ if server_type_id
162
+ integration_server = integration_servers.find { |integration_server| integration_server["server_name_id"] == server_type_id } #TODO: support multiple integration servers of same type (user should pick one)
163
+
164
+ if integration_server
165
+ wrapper_script_content += <<EOR
166
+
167
+ #=== #{auto_script_config["integration_server_type"]} Integration Server: #{integration_server["name"]} ===#
168
+ # [integration_id=#{integration_server["id"]}]
169
+ #=== End ===#
170
+
171
+ params["SS_integration_dns"] = SS_integration_dns
172
+ params["SS_integration_username"] = SS_integration_username
173
+ params["SS_integration_password_enc"] = SS_integration_password_enc
174
+ params["SS_integration_details"] = YAML.load(SS_integration_details)
175
+ EOR
176
+ else
177
+ BrpmAuto.log "WARNING - An integration server of type #{auto_script_config["integration_server_type"]} doesn't exist so not setting the integration server in the wrapper script."
178
+ end
179
+ else
180
+ BrpmAuto.log "WARNING - Integration server type '#{auto_script_config["integration_server_type"]}' is not supported so not setting the integration server in the wrapper script."
181
+ end
182
+ end
183
+
184
+ wrapper_script_content += <<EOR
185
+
186
+ params["direct_execute"] = "true"
187
+
188
+ params["framework_version"] = nil if params["framework_version"].empty?
189
+ params["module_version"] = nil if params["module_version"].empty?
190
+
191
+ require "\#{ENV["BRPM_CONTENT_HOME"] || "\#{ENV["BRPM_HOME"]}/modules"}/gems/brpm_content-\#{params["framework_version"] || "latest"}/modules/framework/brpm_script_executor.rb"
192
+ EOR
193
+
194
+ if automation_type == "Automation"
195
+
196
+ wrapper_script_content += <<EOR
197
+
198
+ BrpmScriptExecutor.execute_automation_script_from_gem("#{module_name}", "#{auto_script_name}", params)
199
+ EOR
200
+
201
+ elsif automation_type == "ResourceAutomation"
202
+
203
+ wrapper_script_content += <<EOR
204
+
205
+ def execute(script_params, parent_id, offset, max_records)
206
+ BrpmScriptExecutor.execute_resource_automation_script_from_gem("#{module_name}", "#{auto_script_name}", script_params, parent_id, offset, max_records)
207
+ end
208
+ EOR
209
+ end
210
+
211
+ auto_script_friendly_name = auto_script_config["friendly_name"] || "#{module_name.sub("brpm_module_", "").capitalize} - #{auto_script_name.gsub("_", " ").capitalize}"
212
+ automation_category = auto_script_config["automation_category"] || "#{module_name.sub("brpm_module_", "").capitalize}"
213
+
214
+ script = {}
215
+ script["name"] = auto_script_friendly_name
216
+ script["description"] = auto_script_friendly_name
217
+ script["automation_type"] = automation_type
218
+ script["automation_category"] = automation_category
219
+ script["content"] = wrapper_script_content
220
+ script["integration_id"] = integration_server["id"] if auto_script_config["integration_server_type"] and integration_server
221
+ if automation_type == "ResourceAutomation"
222
+ script["resource_id"] = auto_script_config["resource_id"] if auto_script_config["resource_id"]
223
+ script["render_as"] = auto_script_config["render_as"] if auto_script_config["render_as"]
224
+ end
225
+
226
+ script = brpm_rest_client.create_or_update_script(script)
227
+
228
+ if script["aasm_state"] == "draft"
229
+ BrpmAuto.log "Updating the aasm_state of the script to 'pending'..."
230
+ script_to_update = {}
231
+ script_to_update["id"] = script["id"]
232
+ script_to_update["aasm_state"] = "pending"
233
+ script = brpm_rest_client.update_script_from_hash(script_to_update)
234
+ end
235
+
236
+ if script["aasm_state"] == "pending"
237
+ BrpmAuto.log "Updating the aasm_state of the script to 'released'..."
238
+ script_to_update = {}
239
+ script_to_update["id"] = script["id"]
240
+ script_to_update["aasm_state"] = "released"
241
+ script = brpm_rest_client.update_script_from_hash(script_to_update)
242
+ end
243
+ end
244
+ end
@@ -47,6 +47,7 @@ class Params < ParamsBase
47
47
  attr_reader :brpm_api_token
48
48
 
49
49
  attr_reader :run_from_brpm
50
+ attr_reader :unit_test
50
51
  attr_reader :also_log_to_console
51
52
 
52
53
  attr_reader :private_params
@@ -106,6 +107,7 @@ class Params < ParamsBase
106
107
  @brpm_api_token = params["SS_api_token"] || params["brpm_api_token"]
107
108
 
108
109
  @run_from_brpm = (@run_key != nil)
110
+ @unit_test = (params["unit_test"] == "true" || params["unit_test"] == 'true')
109
111
  @also_log_to_console = (params["also_log_to_console"] == "true" || params["also_log_to_console"] == 'true')
110
112
 
111
113
  @private_params = {}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brpm_content
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.16
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Niek Bartholomeus
8
8
  autorequire:
9
9
  bindir: modules/framework/bin
10
10
  cert_chain: []
11
- date: 2015-07-17 00:00:00.000000000 Z
11
+ date: 2015-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -291,6 +291,7 @@ files:
291
291
  - modules/framework/config/customer_include.rb
292
292
  - modules/framework/config/server.yml
293
293
  - modules/framework/customer_include_default.rb
294
+ - modules/framework/lib/brpm_installer.rb
294
295
  - modules/framework/lib/logging/brpm_logger.rb
295
296
  - modules/framework/lib/logging/logger_base.rb
296
297
  - modules/framework/lib/logging/simple_logger.rb