opsmgr-cgfrost 0.35.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/LEGAL.txt +13 -0
  3. data/README.md +123 -0
  4. data/lib/opsmgr.rb +12 -0
  5. data/lib/opsmgr/api/client.rb +116 -0
  6. data/lib/opsmgr/api/http_client.rb +399 -0
  7. data/lib/opsmgr/api/results.rb +280 -0
  8. data/lib/opsmgr/api/version20/endpoints.rb +121 -0
  9. data/lib/opsmgr/bosh_command_runner.rb +84 -0
  10. data/lib/opsmgr/cmd/bosh_command.rb +189 -0
  11. data/lib/opsmgr/cmd/ops_manager.rb +142 -0
  12. data/lib/opsmgr/environments.rb +106 -0
  13. data/lib/opsmgr/errand_runner.rb +62 -0
  14. data/lib/opsmgr/log.rb +70 -0
  15. data/lib/opsmgr/product_upload_wrapper.rb +71 -0
  16. data/lib/opsmgr/renderer.rb +23 -0
  17. data/lib/opsmgr/renderer/aws.rb +148 -0
  18. data/lib/opsmgr/renderer/noop.rb +21 -0
  19. data/lib/opsmgr/settings/microbosh/installation_settings.rb +84 -0
  20. data/lib/opsmgr/settings/microbosh/job.rb +56 -0
  21. data/lib/opsmgr/settings/microbosh/job_list.rb +27 -0
  22. data/lib/opsmgr/settings/microbosh/network.rb +21 -0
  23. data/lib/opsmgr/settings/microbosh/product.rb +90 -0
  24. data/lib/opsmgr/settings/microbosh/product_list.rb +27 -0
  25. data/lib/opsmgr/settings/microbosh/property.rb +33 -0
  26. data/lib/opsmgr/settings/microbosh/property_list.rb +27 -0
  27. data/lib/opsmgr/tasks.rb +16 -0
  28. data/lib/opsmgr/tasks/bosh.rake +104 -0
  29. data/lib/opsmgr/tasks/destroy.rake +42 -0
  30. data/lib/opsmgr/tasks/info.rake +19 -0
  31. data/lib/opsmgr/tasks/opsmgr.rake +205 -0
  32. data/lib/opsmgr/tasks/product.rake +82 -0
  33. data/lib/opsmgr/ui_helpers/add_first_user_spec.rb +25 -0
  34. data/lib/opsmgr/ui_helpers/config_helper.rb +38 -0
  35. data/lib/opsmgr/ui_helpers/delete_installation_spec.rb +41 -0
  36. data/lib/opsmgr/ui_helpers/delete_product_if_present_spec.rb +37 -0
  37. data/lib/opsmgr/ui_helpers/delete_product_spec.rb +39 -0
  38. data/lib/opsmgr/ui_helpers/export_installation_spec.rb +31 -0
  39. data/lib/opsmgr/ui_helpers/get_latest_install_log_spec.rb +29 -0
  40. data/lib/opsmgr/ui_helpers/import_stemcell_spec.rb +30 -0
  41. data/lib/opsmgr/ui_helpers/microbosh/configure_microbosh_spec.rb +32 -0
  42. data/lib/opsmgr/ui_helpers/post_import_configuration_spec.rb +31 -0
  43. data/lib/opsmgr/ui_helpers/revert_staged_changes_spec.rb +39 -0
  44. data/lib/opsmgr/ui_helpers/settings_helper.rb +132 -0
  45. data/lib/opsmgr/ui_helpers/trigger_install_spec.rb +35 -0
  46. data/lib/opsmgr/ui_helpers/ui_spec_runner.rb +122 -0
  47. data/lib/opsmgr/ui_helpers/uncheck_errands_spec.rb +29 -0
  48. data/lib/opsmgr/ui_helpers/upload_and_add_product_spec.rb +27 -0
  49. data/lib/opsmgr/ui_helpers/upload_and_upgrade_product_spec.rb +36 -0
  50. data/lib/opsmgr/version.rb +11 -0
  51. data/sample_env_files/aws.yml +95 -0
  52. data/sample_env_files/vsphere.yml +87 -0
  53. metadata +392 -0
@@ -0,0 +1,27 @@
1
+ require 'opsmgr/settings/microbosh/job'
2
+
3
+ module Opsmgr
4
+ module Settings
5
+ module Microbosh
6
+ class JobList
7
+ def initialize(job_hashes)
8
+ @job_hashes = job_hashes
9
+ end
10
+
11
+ def find
12
+ @job_hashes.find do |job_hash|
13
+ yield(Job.new(job_hash))
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ # Copyright (c) 2014-2015 Pivotal Software, Inc.
21
+ # All rights reserved.
22
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
23
+ # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
24
+ # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
27
+ # USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,21 @@
1
+ require 'digest/md5'
2
+
3
+ module Opsmgr
4
+ module Settings
5
+ module Microbosh
6
+ class Network
7
+ def self.guid_for_name(name)
8
+ Digest::MD5.hexdigest(name)[0...20]
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+ # Copyright (c) 2014-2015 Pivotal Software, Inc.
15
+ # All rights reserved.
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
17
+ # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
18
+ # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21
+ # USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,90 @@
1
+ require 'opsmgr/settings/microbosh/job'
2
+
3
+ module Opsmgr
4
+ module Settings
5
+ module Microbosh
6
+ class Product
7
+ attr_reader :product_hash
8
+
9
+ def initialize(product_hash)
10
+ @product_hash = product_hash
11
+ end
12
+
13
+ def guid
14
+ product_hash.fetch('guid')
15
+ end
16
+
17
+ def name
18
+ product_hash.fetch('identifier')
19
+ rescue
20
+ product_hash.fetch('type')
21
+ end
22
+
23
+ def disabled_post_deploy_errand_names(errands = nil)
24
+ product_hash['disabled_post_deploy_errand_names'] = errands
25
+ end
26
+
27
+ def availability_zone_references=(zones_array)
28
+ product_hash['availability_zone_references'] = zones_array
29
+ end
30
+
31
+ def singleton_availability_zone=(value)
32
+ product_hash['singleton_availability_zone_reference'] = value
33
+ end
34
+
35
+ def network_reference=(network_references)
36
+ product_hash['network_reference'] = network_references
37
+ end
38
+
39
+ def set_property(name, value)
40
+ property(name)['value'] = value
41
+ end
42
+
43
+ def for_job(job_name)
44
+ job_result = job(job_name)
45
+ yield job_result if job_result
46
+ end
47
+
48
+ def job(job_name)
49
+ jobs.find { |job| job.name == job_name }
50
+ end
51
+
52
+ def jobs
53
+ product_hash['jobs'].map { |h| Opsmgr::Settings::Microbosh::Job.new(h) }
54
+ end
55
+
56
+ def product_version
57
+ product_hash['product_version']
58
+ end
59
+
60
+ def singleton_availability_zone
61
+ product_hash['singleton_availability_zone_reference']
62
+ end
63
+
64
+ def property(name)
65
+ return nil if properties.empty?
66
+ key = properties.first['identifier'] ? 'identifier' : 'definition'
67
+ properties.find { |property| property[key] == name }
68
+ end
69
+
70
+ private
71
+
72
+ def properties
73
+ product_hash['properties'] ||= []
74
+ end
75
+
76
+ def has_property?(property)
77
+ properties.find_index(property) != -1
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+ # Copyright (c) 2014-2015 Pivotal Software, Inc.
84
+ # All rights reserved.
85
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
86
+ # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
87
+ # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
88
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
89
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
90
+ # USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,27 @@
1
+ require 'opsmgr/settings/microbosh/product'
2
+
3
+ module Opsmgr
4
+ module Settings
5
+ module Microbosh
6
+ class ProductList
7
+ def initialize(product_hashes)
8
+ @product_hashes = product_hashes
9
+ end
10
+
11
+ def find
12
+ @product_hashes.find do |product_hash|
13
+ yield(Product.new(product_hash))
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ # Copyright (c) 2014-2015 Pivotal Software, Inc.
21
+ # All rights reserved.
22
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
23
+ # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
24
+ # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
27
+ # USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,33 @@
1
+ module Opsmgr
2
+ module Settings
3
+ module Microbosh
4
+ class Property
5
+ def initialize(hash)
6
+ @hash = hash
7
+ end
8
+
9
+ def name
10
+ @hash.fetch('identifier')
11
+ rescue
12
+ @hash['definition']
13
+ end
14
+
15
+ def value
16
+ @hash['value']
17
+ end
18
+
19
+ def value=(value)
20
+ @hash['value'] = value
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ # Copyright (c) 2014-2015 Pivotal Software, Inc.
27
+ # All rights reserved.
28
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
29
+ # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
30
+ # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
31
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
32
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
33
+ # USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,27 @@
1
+ require 'opsmgr/settings/microbosh/property'
2
+
3
+ module Opsmgr
4
+ module Settings
5
+ module Microbosh
6
+ class PropertyList
7
+ def initialize(property_hashes)
8
+ @property_hashes = property_hashes
9
+ end
10
+
11
+ def find
12
+ @property_hashes.find do |property_hash|
13
+ yield Property.new(property_hash)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ # Copyright (c) 2014-2015 Pivotal Software, Inc.
21
+ # All rights reserved.
22
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
23
+ # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
24
+ # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
27
+ # USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,16 @@
1
+ current_dir = File.expand_path(File.dirname(__FILE__))
2
+ Dir.glob(File.join(current_dir, 'tasks', '*.rake')).each do |tasks_file|
3
+ load tasks_file
4
+ end
5
+
6
+ require 'opsmgr/log'
7
+
8
+ Opsmgr::Log.stdout_mode!
9
+ # Copyright (c) 2014-2015 Pivotal Software, Inc.
10
+ # All rights reserved.
11
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
12
+ # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
13
+ # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
14
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
15
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
16
+ # USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,104 @@
1
+ namespace :opsmgr do
2
+ namespace :microbosh do
3
+ desc 'Print out a copy-pasteable partial bosh command (eg bosh -t example.com -u user -p password)'
4
+ task :command, [:environment, :om_version] do |_, args|
5
+ require 'opsmgr/cmd/bosh_command'
6
+ puts Opsmgr::Cmd::BoshCommand.new(
7
+ env_name: args.environment,
8
+ om_version: args.om_version
9
+ ).command
10
+ end
11
+
12
+ desc 'Print out a bosh command to set the target to the bosh for the given environment'
13
+ task :target, [:environment, :om_version] do |_, args|
14
+ require 'opsmgr/cmd/bosh_command'
15
+ puts Opsmgr::Cmd::BoshCommand.new(
16
+ env_name: args.environment,
17
+ om_version: args.om_version
18
+ ).target
19
+ end
20
+
21
+ desc 'Print out the ip address of the director'
22
+ task :director_ip, [:environment, :om_version] do |_, args|
23
+ require 'opsmgr/cmd/bosh_command'
24
+ puts Opsmgr::Cmd::BoshCommand.new(
25
+ env_name: args.environment,
26
+ om_version: args.om_version
27
+ ).director_ip
28
+ end
29
+
30
+ desc 'Configure Microbosh [:environment, :om_version]'
31
+ task :configure, [:environment, :om_version] do |_, args|
32
+ require 'opsmgr/ui_helpers/ui_spec_runner'
33
+ require 'opsmgr/environments'
34
+ require 'opsmgr/api/client'
35
+ require 'opsmgr/cmd/ops_manager'
36
+
37
+ environment = Opsmgr::Environments.for(args.environment)
38
+ client = Opsmgr::Api::Client.new(environment, args.om_version)
39
+ Opsmgr::Cmd::OpsManager.new(environment).configure_microbosh_infrastructure(client)
40
+
41
+ UiSpecRunner.new(
42
+ environment: args.environment,
43
+ om_version: args.om_version
44
+ ).configure_microbosh
45
+ end
46
+ end
47
+
48
+ desc 'Download BOSH Stemcell from bosh.io'
49
+ task :download_stemcell, [:iaas, :version] do |_, args|
50
+ case args.iaas
51
+ when 'aws'
52
+ system("wget --content-disposition --progress=dot:giga https://bosh.io/d/stemcells/bosh-aws-xen-hvm-ubuntu-trusty-go_agent?v=#{args.version}")
53
+ when 'vsphere'
54
+ system("wget --content-disposition --progress=dot:giga https://bosh.io/d/stemcells/bosh-vsphere-esxi-ubuntu-trusty-go_agent?v=#{args.version}")
55
+ when 'vcloud'
56
+ system("wget --content-disposition --progress=dot:giga https://bosh.io/d/stemcells/bosh-vcloud-esxi-ubuntu-trusty-go_agent?v=#{args.version}")
57
+ when 'openstack'
58
+ system("wget --content-disposition --progress=dot:giga https://bosh.io/d/stemcells/bosh-openstack-kvm-ubuntu-trusty-go_agent-raw?v=#{args.version}")
59
+ end
60
+ system('ls *bosh*.tgz > stemcell_reference.txt')
61
+ end
62
+
63
+ desc 'run a bosh command'
64
+ task :run_command, [:environment_name, :om_version, :command] do |_, args|
65
+ require 'opsmgr/cmd/bosh_command'
66
+ require 'opsmgr/log'
67
+ require 'opsmgr/bosh_command_runner'
68
+
69
+ logger = Opsmgr.logger_for('Rake')
70
+ bosh_command = Opsmgr::Cmd::BoshCommand.new(
71
+ env_name: args.environment_name,
72
+ om_version: args.om_version
73
+ )
74
+ Opsmgr::BoshCommandRunner.new(
75
+ bosh_command: bosh_command,
76
+ logger: logger
77
+ ).run(args.command)
78
+ end
79
+
80
+ desc 'run a bosh command with a deployment'
81
+ task :run_command_with_deployment, [:environment_name, :om_version, :command, :deployment] do |_, args|
82
+ require 'opsmgr/cmd/bosh_command'
83
+ require 'opsmgr/log'
84
+ require 'opsmgr/bosh_command_runner'
85
+
86
+ logger = Opsmgr.logger_for('Rake')
87
+ bosh_command = Opsmgr::Cmd::BoshCommand.new(
88
+ env_name: args.environment_name,
89
+ om_version: args.om_version
90
+ )
91
+ Opsmgr::BoshCommandRunner.new(
92
+ bosh_command: bosh_command,
93
+ logger: logger
94
+ ).run_with_deployment(args.command, args.deployment)
95
+ end
96
+ end
97
+ # Copyright (c) 2014-2015 Pivotal Software, Inc.
98
+ # All rights reserved.
99
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
100
+ # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
101
+ # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
102
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
103
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
104
+ # USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,42 @@
1
+ namespace :opsmgr do
2
+ desc "Alias for opsmgr:destroy:vms"
3
+ task :destroy, [:environment] => %w(opsmgr:destroy:vms)
4
+
5
+ namespace :destroy do
6
+ desc "- Clear our Resource Pool, deleting stemcells, all installed products' VMs (including Ops Mgr)"
7
+ task :vms, [:environment, :om_version] do |_, args|
8
+ require 'opsmgr/cmd/ops_manager'
9
+ require 'opsmgr/environments'
10
+ require 'opsmgr/api/client'
11
+
12
+ env = Opsmgr::Environments.for(args.environment)
13
+ begin
14
+ installation_settings = Opsmgr::Api::Client.new(env, args.om_version).installation_settings.as_hash
15
+ rescue
16
+ installation_settings = { 'infrastructure' => {} }
17
+ end
18
+ require 'vm_shepherd'
19
+ shep = VmShepherd::Shepherd.new(settings: env.settings_with_merged_folders(installation_settings))
20
+ shep.clean_environment
21
+ shep.destroy
22
+ end
23
+
24
+ desc '- Destroy Existing Ops Manager'
25
+ task :opsmgr, [:environment] do |_, args|
26
+ require 'opsmgr/environments'
27
+ require 'vm_shepherd'
28
+ env = Opsmgr::Environments.for(args.environment)
29
+
30
+ shep = VmShepherd::Shepherd.new(settings: env.settings)
31
+ shep.destroy
32
+ end
33
+ end
34
+ end
35
+ # Copyright (c) 2014-2015 Pivotal Software, Inc.
36
+ # All rights reserved.
37
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
38
+ # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
39
+ # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
40
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
41
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
42
+ # USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ namespace :opsmgr do
2
+ namespace :info do
3
+ desc 'Display the host of the Ops Manager for the given environment'
4
+ task :host, [:environment] do |_, args|
5
+ require 'opsmgr/environments'
6
+ require 'uri'
7
+ uri = URI(Opsmgr::Environments.for(args.environment).settings['ops_manager']['url'])
8
+ puts uri.host
9
+ end
10
+ end
11
+ end
12
+ # Copyright (c) 2014-2015 Pivotal Software, Inc.
13
+ # All rights reserved.
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15
+ # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
16
+ # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
17
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
18
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
19
+ # USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,205 @@
1
+ namespace :opsmgr do
2
+ desc 'Trigger an install on Ops Manager for the specified environment'
3
+ task :trigger_install, [:environment, :om_version, :install_timeout, :poll_interval] do |_, args|
4
+ args.with_defaults(poll_interval: '30')
5
+ require 'opsmgr/ui_helpers/ui_spec_runner'
6
+
7
+ UiSpecRunner.new(
8
+ environment: args.environment,
9
+ om_version: args.om_version
10
+ ).trigger_install(args.install_timeout, args.poll_interval)
11
+ end
12
+
13
+ desc 'Get latest install log from Ops Manager'
14
+ task :get_latest_install_log, [:environment, :om_version] do |_, args|
15
+ require 'opsmgr/ui_helpers/ui_spec_runner'
16
+
17
+ UiSpecRunner.new(
18
+ environment: args.environment,
19
+ om_version: args.om_version
20
+ ).get_latest_install_log
21
+ end
22
+
23
+ desc 'Export installation'
24
+ task :export_installation, [:environment, :om_version, :export_destination] do |_, args|
25
+ require 'opsmgr/ui_helpers/ui_spec_runner'
26
+
27
+ UiSpecRunner.new(
28
+ environment: args.environment,
29
+ om_version: args.om_version
30
+ ).export_installation(args.export_destination)
31
+ end
32
+
33
+ desc 'Import installation'
34
+ task :import_installation, [:environment, :om_version, :import_file] do |_, args|
35
+ require 'opsmgr/environments'
36
+ require 'opsmgr/cmd/ops_manager'
37
+ require 'opsmgr/api/client'
38
+
39
+ environment_object = Opsmgr::Environments.for(args.environment)
40
+ client = Opsmgr::Api::Client.new(environment_object, args.om_version)
41
+ opsmgr_cmd = Opsmgr::Cmd::OpsManager.new(environment_object)
42
+ opsmgr_cmd.import_installation(client, args.import_file)
43
+
44
+ if Gem::Version.new(args.om_version) >= Gem::Version.new('1.7')
45
+ require 'opsmgr/ui_helpers/ui_spec_runner'
46
+
47
+ UiSpecRunner.new(
48
+ environment: args.environment,
49
+ om_version: args.om_version
50
+ ).post_import_configuration
51
+ end
52
+ end
53
+
54
+ desc 'Delete installation'
55
+ task :delete_installation, [:environment, :om_version] do |_, args|
56
+ require 'opsmgr/ui_helpers/ui_spec_runner'
57
+ UiSpecRunner.new(
58
+ environment: args.environment,
59
+ om_version: args.om_version
60
+ ).delete_installation
61
+ end
62
+
63
+ desc 'Add first user'
64
+ task :add_first_user, [:environment, :om_version] do |_, args|
65
+ require 'opsmgr/ui_helpers/ui_spec_runner'
66
+
67
+ UiSpecRunner.new(
68
+ environment: args.environment,
69
+ om_version: args.om_version
70
+ ).add_first_user
71
+ end
72
+
73
+ desc 'Prepare Environment'
74
+ task :prepare, [:environment] do |_, args|
75
+ require 'opsmgr/log'
76
+ require 'opsmgr/environments'
77
+ require 'vm_shepherd'
78
+
79
+ logger = Opsmgr.logger_for('Rake')
80
+ logger.info "Preparing environment for #{args[:environment]}"
81
+
82
+ environment = Opsmgr::Environments.for(args.environment)
83
+
84
+ shep = VmShepherd::Shepherd.new(settings: environment.settings)
85
+ shep.prepare_environment
86
+ end
87
+
88
+ desc 'Install Operations Manager .image'
89
+ task :install, [:environment, :image] do |_, args|
90
+ require 'timeout'
91
+ require 'opsmgr/log'
92
+ require 'opsmgr/environments'
93
+ require 'vm_shepherd'
94
+
95
+ logger = Opsmgr.logger_for('Rake')
96
+ logger.info "installing #{args[:environment]}'s Ops Manager"
97
+
98
+ environment = Opsmgr::Environments.for(args.environment)
99
+ image = args[:image]
100
+
101
+ shep = VmShepherd::Shepherd.new(settings: environment.settings)
102
+ shep.deploy(paths: [image])
103
+ end
104
+
105
+ desc 'Delete a product'
106
+ task :delete_product, [:environment, :om_version, :product_name, :timeout, :poll_interval] do |_, args|
107
+ args.with_defaults(poll_interval: '30')
108
+ require 'opsmgr/ui_helpers/ui_spec_runner'
109
+
110
+ DEFAULT_DELETE_TIMEOUT = 25
111
+
112
+ UiSpecRunner.new(
113
+ environment: args.environment,
114
+ om_version: args.om_version
115
+ ).delete_product(args.product_name, args.timeout || DEFAULT_DELETE_TIMEOUT.to_s, args.poll_interval)
116
+ end
117
+
118
+ desc 'Delete a product if present (will not fail if product is not preset)'
119
+ task :delete_product_if_present, [:environment, :om_version, :product_name, :timeout, :poll_interval] do |_, args|
120
+ args.with_defaults(poll_interval: '10')
121
+ require 'opsmgr/ui_helpers/ui_spec_runner'
122
+
123
+ DEFAULT_DELETE_TIMEOUT = 25
124
+
125
+ UiSpecRunner.new(
126
+ environment: args.environment,
127
+ om_version: args.om_version
128
+ ).delete_product_if_present(args.product_name, args.timeout || DEFAULT_DELETE_TIMEOUT.to_s, args.poll_interval)
129
+ end
130
+
131
+ desc 'Delete unused products'
132
+ task :delete_unused_products, [:environment, :om_version] do |_, args|
133
+ require 'opsmgr/api/client'
134
+ require 'opsmgr/cmd/ops_manager'
135
+ require 'opsmgr/environments'
136
+
137
+ unless args.om_version
138
+ raise "Please provide an Ops Manager version (for example, 1.7)"
139
+ end
140
+ environment = Opsmgr::Environments.for(args.environment)
141
+ client = Opsmgr::Api::Client.new(environment, args.om_version)
142
+ Opsmgr::Cmd::OpsManager.new(environment).delete_unused_products(client)
143
+ end
144
+
145
+ desc 'Saves the private key into the given file'
146
+ task :get_private_key, [:environment, :key_file_path] do |_, args|
147
+ require 'opsmgr/environments'
148
+ environment = Opsmgr::Environments.for(args.environment)
149
+ case environment.settings.iaas_type
150
+ when 'aws'
151
+ private_key = environment.settings.ops_manager.aws.ssh_key
152
+ when 'openstack'
153
+ private_key = environment.settings.ops_manager.openstack.ssh_private_key
154
+ else
155
+ raise 'Unsupported IaaS - this task only works for AWS and Openstack'
156
+ end
157
+ File.open(args.key_file_path, 'w+') do |f|
158
+ f << private_key
159
+ f.chmod(0o600)
160
+ end
161
+ end
162
+
163
+ desc 'run an errand'
164
+ task :run_errand, [:environment_name, :om_version, :product_name, :errand_name, :download_logs] do |_, args|
165
+ require 'opsmgr/cmd/bosh_command'
166
+ require 'opsmgr/log'
167
+ require 'opsmgr/errand_runner'
168
+
169
+ logger = Opsmgr.logger_for('Rake')
170
+ bosh_command = Opsmgr::Cmd::BoshCommand.new(
171
+ env_name: args.environment_name,
172
+ om_version: args.om_version
173
+ )
174
+ Opsmgr::ErrandRunner.new(
175
+ bosh_command: bosh_command,
176
+ environment_name: args.environment_name,
177
+ logger: logger,
178
+ product_name: args.product_name,
179
+ errand_name: args.errand_name,
180
+ download_logs: args.with_defaults(download_logs: false)
181
+ ).run_errand
182
+ end
183
+
184
+ desc 'Revert staged changes'
185
+ task :revert_staged_changes, [:environment, :om_version] do |_, args|
186
+ require 'opsmgr/ui_helpers/ui_spec_runner'
187
+
188
+ unless args.om_version
189
+ raise "Please provide an Ops Manager version (for example, 1.7)"
190
+ end
191
+
192
+ UiSpecRunner.new(
193
+ environment: args.environment,
194
+ om_version: args.om_version
195
+ ).revert_staged_changes
196
+ end
197
+ end
198
+ # Copyright (c) 2014-2015 Pivotal Software, Inc.
199
+ # All rights reserved.
200
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
201
+ # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
202
+ # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
203
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
204
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
205
+ # USE OR OTHER DEALINGS IN THE SOFTWARE.