opsmgr 0.33.5 → 0.34.0

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.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/lib/opsmgr/api/client.rb +6 -3
  3. data/lib/opsmgr/api/http_client.rb +168 -26
  4. data/lib/opsmgr/api/version20/endpoints.rb +18 -2
  5. data/lib/opsmgr/bosh_command_runner.rb +21 -17
  6. data/lib/opsmgr/cmd/bosh_command.rb +54 -78
  7. data/lib/opsmgr/cmd/ops_manager.rb +7 -4
  8. data/lib/opsmgr/environments.rb +34 -5
  9. data/lib/opsmgr/errand_runner.rb +1 -3
  10. data/lib/opsmgr/product_upload_wrapper.rb +8 -8
  11. data/lib/opsmgr/tasks/bosh.rake +1 -7
  12. data/lib/opsmgr/tasks/destroy.rake +2 -2
  13. data/lib/opsmgr/tasks/info.rake +1 -1
  14. data/lib/opsmgr/tasks/opsmgr.rake +11 -8
  15. data/lib/opsmgr/tasks/product.rake +9 -6
  16. data/lib/opsmgr/ui_helpers/add_first_user_spec.rb +2 -2
  17. data/lib/opsmgr/ui_helpers/config_helper.rb +18 -18
  18. data/lib/opsmgr/ui_helpers/delete_installation_spec.rb +2 -2
  19. data/lib/opsmgr/ui_helpers/delete_product_if_present_spec.rb +2 -2
  20. data/lib/opsmgr/ui_helpers/delete_product_spec.rb +2 -2
  21. data/lib/opsmgr/ui_helpers/export_installation_spec.rb +2 -2
  22. data/lib/opsmgr/ui_helpers/get_latest_install_log_spec.rb +2 -2
  23. data/lib/opsmgr/ui_helpers/import_stemcell_spec.rb +2 -2
  24. data/lib/opsmgr/ui_helpers/microbosh/configure_microbosh_spec.rb +2 -2
  25. data/lib/opsmgr/ui_helpers/{import_installation_spec.rb → post_import_configuration_spec.rb} +7 -5
  26. data/lib/opsmgr/ui_helpers/trigger_install_spec.rb +2 -2
  27. data/lib/opsmgr/ui_helpers/ui_spec_runner.rb +2 -4
  28. data/lib/opsmgr/ui_helpers/uncheck_errands_spec.rb +2 -2
  29. data/lib/opsmgr/ui_helpers/upload_and_add_product_spec.rb +2 -2
  30. data/lib/opsmgr/ui_helpers/upload_and_upgrade_product_spec.rb +2 -2
  31. data/lib/opsmgr/version.rb +1 -1
  32. data/sample_env_files/aws.yml +1 -0
  33. metadata +23 -10
  34. data/lib/opsmgr/api/endpoints_factory.rb +0 -39
@@ -1,10 +1,15 @@
1
+ require 'backport_refinements'
2
+ using OpsManagerUiDrivers::BackportRefinements
3
+
1
4
  require 'opsmgr/ui_helpers/ui_spec_runner'
2
5
  require 'opsmgr/environments'
6
+ require 'opsmgr/api/client'
3
7
  require 'ops_manager_ui_drivers'
4
8
  require 'capybara'
5
9
  require 'capybara/dsl'
6
10
  require 'capybara/webkit'
7
11
  require 'net/ssh/gateway'
12
+ require 'net/scp'
8
13
 
9
14
  module Opsmgr
10
15
  module Cmd
@@ -18,27 +23,22 @@ module Opsmgr
18
23
  @env_name = env_name
19
24
  @om_version = om_version
20
25
  @current_ops_manager = setup_or_login
26
+
27
+ configure_client_credentials
21
28
  end
22
29
 
23
30
  def command
24
31
  ip = ENV['DIRECTOR_IP_OVERRIDE'] || director_ip
25
32
 
26
- %W(
27
- bosh
28
- -t #{ip}
29
- -u director
30
- -p #{director_password}
31
- ).join(' ')
32
- end
33
-
34
- def target
35
- ip = ENV['DIRECTOR_IP_OVERRIDE'] || director_ip
33
+ if Gem::Version.new(om_version) >= Gem::Version.new('1.7')
34
+ return "BOSH_CLIENT=#{@bosh_client} BOSH_CLIENT_SECRET=#{@bosh_client_secret} bosh -t #{ip} --ca-cert #{root_cert_file}"
35
+ end
36
36
 
37
37
  %W(
38
38
  bosh
39
+ -t #{ip}
39
40
  -u director
40
41
  -p #{director_password}
41
- target #{ip}
42
42
  ).join(' ')
43
43
  end
44
44
 
@@ -46,9 +46,9 @@ module Opsmgr
46
46
  status_page = current_ops_manager.product_status_for(director_tile_name)
47
47
 
48
48
  partitioned_job_name = 'director-partition-null-az'
49
- availability_zones = env_settings.ops_manager.availability_zones
49
+ availability_zones = env_settings['ops_manager']['availability_zones']
50
50
  if availability_zones
51
- az_name = availability_zones.first.iaas_identifier || 'first-az'
51
+ az_name = availability_zones.first['iaas_identifier'] || 'first-az'
52
52
  partitioned_job_name = "director-partition-#{current_ops_manager.availability_zone_guid_for_name(az_name)}"
53
53
  end
54
54
 
@@ -59,12 +59,49 @@ module Opsmgr
59
59
 
60
60
  private
61
61
 
62
+ def configure_client_credentials
63
+ return unless Gem::Version.new(om_version) >= Gem::Version.new('1.7')
64
+
65
+ installation_settings = Opsmgr::Api::Client.new(Opsmgr::Environments.for(@env_name), @om_version).installation_settings.as_hash
66
+ uaa_credentials = installation_settings['products'].find { |p| p['identifier'] == 'p-bosh' }['uaa_credentials']
67
+
68
+
69
+ @bosh_client = uaa_credentials['identity']
70
+ @bosh_client_secret = uaa_credentials['password']
71
+ end
72
+
73
+ def root_cert_file
74
+ @root_cert_file_name ||= begin
75
+ Net::SCP.download!(
76
+ env_settings['ops_manager']['url'].gsub('https://', '').gsub('/', ''),
77
+ 'ubuntu',
78
+ '/var/tempest/workspaces/default/root_ca_certificate',
79
+ filename,
80
+ ssh: { password: 'tempest', key_data: ops_manager_ssh_key }
81
+ )
82
+ filename
83
+ end
84
+ end
85
+
86
+ def filename
87
+ ENV.fetch('TMPDIR', '/tmp') + '/root_ca_certificate'
88
+ end
89
+
90
+ def ops_manager_ssh_key
91
+ case @env_settings.dig('iaas_type')
92
+ when 'aws'
93
+ @env_settings.dig('ops_manager', 'aws', 'ssh_key')
94
+ when 'openstack'
95
+ @env_settings.dig('ops_manager', 'openstack', 'ssh_private_key')
96
+ end
97
+ end
98
+
62
99
  def setup_or_login
63
100
  driver = ops_manager_driver(om_version)
64
101
 
65
102
  driver.setup_page.setup_or_login(
66
- user: env_settings.ops_manager.username,
67
- password: env_settings.ops_manager.password,
103
+ user: env_settings['ops_manager']['username'],
104
+ password: env_settings['ops_manager']['password'],
68
105
  )
69
106
  driver
70
107
  end
@@ -73,12 +110,12 @@ module Opsmgr
73
110
  Capybara.configure do |c|
74
111
  c.default_driver = :webkit
75
112
  c.run_server = false
76
- c.app_host = env_settings.ops_manager.url
113
+ c.app_host = env_settings['ops_manager']['url']
77
114
  end
78
115
 
79
116
  Capybara::Webkit.configure do |c|
80
117
  c.ignore_ssl_errors = true
81
- c.allow_url(env_settings.ops_manager.url)
118
+ c.allow_url(env_settings['ops_manager']['url'])
82
119
  end
83
120
 
84
121
  page.current_window.resize_to(1024, 1600) # avoid overlapping footer spec failures
@@ -141,67 +178,6 @@ module Opsmgr
141
178
 
142
179
  attr_reader :env_settings, :om_version, :current_ops_manager
143
180
  end
144
-
145
- class IaasGateway
146
- def initialize(bosh_command:, environment_name:, logger:)
147
- @bosh_command = bosh_command
148
- @environment = Opsmgr::Environments.for(environment_name)
149
- @logger = logger
150
- end
151
-
152
- def gateway(&block)
153
- case environment.settings.iaas_type
154
- when 'vsphere'
155
- block.call
156
- when 'aws', 'openstack'
157
- ssh_key_gateway(block)
158
- when 'vcloud'
159
- ssh_password_gateway(block)
160
- end
161
- end
162
-
163
- private
164
-
165
- attr_reader :bosh_command, :environment, :logger
166
-
167
- def ssh_password_gateway(block)
168
- ENV['DIRECTOR_IP_OVERRIDE'] = 'localhost'
169
- uri = URI.parse(environment.settings.ops_manager.url)
170
- director_ip = bosh_command.director_ip
171
- logger.info("Setting up SSH gateway to OpsManager at #{uri.host}")
172
- Net::SSH::Gateway.new(
173
- uri.host,
174
- 'ubuntu',
175
- password: 'tempest'
176
- ).open(director_ip, 25_555, 25_555) do |_|
177
- logger.info("Opened tunnel to Director at #{director_ip}")
178
- block.call
179
- end
180
- end
181
-
182
- def ssh_key_gateway(block)
183
- ENV['DIRECTOR_IP_OVERRIDE'] = 'localhost'
184
- uri = URI.parse(environment.settings.ops_manager.url)
185
- director_ip = bosh_command.director_ip
186
- Net::SSH::Gateway.new(
187
- uri.host,
188
- 'ubuntu',
189
- key_data: [ssh_key]
190
- ).open(director_ip, 25_555, 25_555) do |_|
191
- logger.info("Opened tunnel to Director at #{director_ip}")
192
- block.call
193
- end
194
- end
195
-
196
- def ssh_key
197
- case environment.settings.iaas_type
198
- when 'aws'
199
- environment.settings.ops_manager.aws.ssh_key
200
- when 'openstack'
201
- environment.settings.ops_manager.openstack.ssh_private_key
202
- end
203
- end
204
- end
205
181
  end
206
182
  end
207
183
  # Copyright (c) 2014-2015 Pivotal Software, Inc.
@@ -1,3 +1,6 @@
1
+ require 'backport_refinements'
2
+ using OpsManagerUiDrivers::BackportRefinements
3
+
1
4
  require 'opsmgr/log'
2
5
 
3
6
  module Opsmgr
@@ -18,9 +21,9 @@ module Opsmgr
18
21
  return if result['infrastructure']['type'] != 'vsphere'
19
22
 
20
23
  result['infrastructure']['file_system'] = {
21
- 'microbosh_vm_folder' => environment.settings.name,
22
- 'microbosh_template_folder' => environment.settings.name,
23
- 'microbosh_disk_path' => environment.settings.name,
24
+ 'microbosh_vm_folder' => environment.settings.dig('name'),
25
+ 'microbosh_template_folder' => environment.settings.dig('name'),
26
+ 'microbosh_disk_path' => environment.settings.dig('name'),
24
27
  }
25
28
 
26
29
  file = Tempfile.new('om_install_settings')
@@ -85,7 +88,7 @@ module Opsmgr
85
88
  end
86
89
 
87
90
  def import_installation(client, path)
88
- result = client.import_installation(path, environment.settings.ops_manager.password)
91
+ result = client.import_installation(path, environment.settings.dig('ops_manager', 'password'))
89
92
  if result.success?
90
93
  log.info 'Successfully imported installation'
91
94
  else
@@ -1,4 +1,5 @@
1
- require 'recursive-open-struct'
1
+ require 'backport_refinements'
2
+ using OpsManagerUiDrivers::BackportRefinements
2
3
 
3
4
  require 'active_support'
4
5
  require 'active_support/core_ext'
@@ -51,9 +52,9 @@ module Opsmgr
51
52
  file_system = installation_settings['infrastructure']['file_system']
52
53
 
53
54
  settings_to_modify = settings
54
- settings_to_modify.vm_shepherd.vm_configs[0].cleanup.datacenter_folders_to_clean << file_system['microbosh_vm_folder']
55
- settings_to_modify.vm_shepherd.vm_configs[0].cleanup.datacenter_folders_to_clean << file_system['microbosh_template_folder']
56
- settings_to_modify.vm_shepherd.vm_configs[0].cleanup.datastore_folders_to_clean << file_system['microbosh_disk_path']
55
+ settings_to_modify.dig('vm_shepherd', 'vm_configs', 0, 'cleanup', 'datacenter_folders_to_clean') << file_system['microbosh_vm_folder']
56
+ settings_to_modify.dig('vm_shepherd', 'vm_configs', 0, 'cleanup', 'datacenter_folders_to_clean') << file_system['microbosh_template_folder']
57
+ settings_to_modify.dig('vm_shepherd', 'vm_configs', 0, 'cleanup', 'datastore_folders_to_clean') << file_system['microbosh_disk_path']
57
58
  settings_to_modify
58
59
  end
59
60
 
@@ -63,7 +64,35 @@ module Opsmgr
63
64
  raise "Specified name #{@env_name} does not match name in #{@config_path}"
64
65
  end
65
66
 
66
- RecursiveOpenStruct.new(string_keyed_hash, recurse_over_arrays: true)
67
+ fix_subnets(string_keyed_hash)
68
+ end
69
+
70
+ private
71
+
72
+ def fix_subnets(settings)
73
+ settings['ops_manager']['networks'].each do |n|
74
+ next if n['subnets']
75
+ availability_zones = settings['ops_manager']['availability_zones'] || []
76
+ n['subnets'] = [
77
+ {
78
+ 'identifier' => n['identifier'],
79
+ 'cidr' => n['subnet'],
80
+ 'dns' => n['dns'],
81
+ 'gateway' => n['gateway'],
82
+ 'reserved_ips' => n['reserved_ips'],
83
+ 'availability_zones' => availability_zones.map { |z| z['name'] }
84
+ }
85
+ ]
86
+ end
87
+
88
+ if settings['vm_shepherd']['env_config']
89
+ outputs = settings['vm_shepherd']['env_config']['outputs']
90
+ unless outputs['subnets']
91
+ outputs['subnets'] = [outputs['public_subnet_id'], outputs['private_subnet_id']]
92
+ end
93
+ end
94
+
95
+ settings
67
96
  end
68
97
  end
69
98
  end
@@ -3,8 +3,7 @@ require 'open3'
3
3
 
4
4
  module Opsmgr
5
5
  class ErrandRunner
6
- def initialize(iaas_gateway:, bosh_command:, environment_name:, logger:, product_name:, errand_name:, download_logs:)
7
- @iaas_gateway = iaas_gateway
6
+ def initialize(bosh_command:, environment_name:, logger:, product_name:, errand_name:, download_logs:)
8
7
  @bosh_command = bosh_command
9
8
  @environment_name = environment_name
10
9
  @logger = logger
@@ -13,7 +12,6 @@ module Opsmgr
13
12
  @download_logs = download_logs ? "--download-logs" : ""
14
13
 
15
14
  @bosh_command_runner = Opsmgr::BoshCommandRunner.new(
16
- iaas_gateway: @iaas_gateway,
17
15
  bosh_command: @bosh_command,
18
16
  logger: @logger
19
17
  )
@@ -4,25 +4,25 @@ require 'opsmgr/cmd/ops_manager'
4
4
  require 'opsmgr/api/client'
5
5
 
6
6
  class ProductUploadWrapper
7
- def self.wrap_add(environment:, product_path:, product_name:)
8
- wrap_operation(environment, product_path, product_name, 'add')
7
+ def self.wrap_add(environment:, product_path:, product_name:, om_version:)
8
+ wrap_operation(environment, product_path, product_name, 'add', om_version)
9
9
  end
10
10
 
11
- def self.wrap_upgrade(environment:, product_path:, product_name:)
12
- wrap_operation(environment, product_path, product_name, 'upgrade')
11
+ def self.wrap_upgrade(environment:, product_path:, product_name:, om_version:)
12
+ wrap_operation(environment, product_path, product_name, 'upgrade', om_version)
13
13
  end
14
14
 
15
- def self.wrap_upload(environment:, product_path:, product_name:)
16
- wrap_operation(environment, product_path, product_name, 'upload')
15
+ def self.wrap_upload(environment:, product_path:, product_name:, om_version:)
16
+ wrap_operation(environment, product_path, product_name, 'upload', om_version)
17
17
  end
18
18
 
19
- def self.wrap_operation(environment, product_path, product_name, operation)
19
+ def self.wrap_operation(environment, product_path, product_name, operation, om_version)
20
20
  unless %w(add upgrade upload).include?(operation)
21
21
  fail "Operation '#{operation}' is not available"
22
22
  end
23
23
 
24
24
  environment_object = Opsmgr::Environments.for(environment)
25
- client = Opsmgr::Api::Client.new(environment_object)
25
+ client = Opsmgr::Api::Client.new(environment_object, om_version)
26
26
  opsmgr_cmd = Opsmgr::Cmd::OpsManager.new(environment_object)
27
27
  opsmgr_cmd.upload_product(client, product_path)
28
28
 
@@ -35,7 +35,7 @@ namespace :opsmgr do
35
35
  require 'opsmgr/cmd/ops_manager'
36
36
 
37
37
  environment = Opsmgr::Environments.for(args.environment)
38
- client = Opsmgr::Api::Client.new(environment)
38
+ client = Opsmgr::Api::Client.new(environment, args.om_version)
39
39
  Opsmgr::Cmd::OpsManager.new(environment).configure_microbosh_infrastructure(client)
40
40
 
41
41
  UiSpecRunner.new(
@@ -71,13 +71,7 @@ namespace :opsmgr do
71
71
  env_name: args.environment_name,
72
72
  om_version: args.om_version
73
73
  )
74
- iaas_gateway = Opsmgr::Cmd::IaasGateway.new(
75
- bosh_command: bosh_command,
76
- environment_name: args.environment_name,
77
- logger: logger
78
- )
79
74
  Opsmgr::BoshCommandRunner.new(
80
- iaas_gateway: iaas_gateway,
81
75
  bosh_command: bosh_command,
82
76
  logger: logger
83
77
  ).run(args.command)
@@ -4,14 +4,14 @@ namespace :opsmgr do
4
4
 
5
5
  namespace :destroy do
6
6
  desc "- Clear our Resource Pool, deleting stemcells, all installed products' VMs (including Ops Mgr)"
7
- task :vms, [:environment] do |_, args|
7
+ task :vms, [:environment, :om_version] do |_, args|
8
8
  require 'opsmgr/cmd/ops_manager'
9
9
  require 'opsmgr/environments'
10
10
  require 'opsmgr/api/client'
11
11
 
12
12
  env = Opsmgr::Environments.for(args.environment)
13
13
  begin
14
- installation_settings = Opsmgr::Api::Client.new(env).installation_settings.as_hash
14
+ installation_settings = Opsmgr::Api::Client.new(env, args.om_version).installation_settings.as_hash
15
15
  rescue
16
16
  installation_settings = { 'infrastructure' => {} }
17
17
  end
@@ -4,7 +4,7 @@ namespace :opsmgr do
4
4
  task :host, [:environment] do |_, args|
5
5
  require 'opsmgr/environments'
6
6
  require 'uri'
7
- uri = URI(Opsmgr::Environments.for(args.environment).settings.ops_manager.url)
7
+ uri = URI(Opsmgr::Environments.for(args.environment).settings['ops_manager']['url'])
8
8
  puts uri.host
9
9
  end
10
10
  end
@@ -36,9 +36,18 @@ namespace :opsmgr do
36
36
  require 'opsmgr/api/client'
37
37
 
38
38
  environment_object = Opsmgr::Environments.for(args.environment)
39
- client = Opsmgr::Api::Client.new(environment_object)
39
+ client = Opsmgr::Api::Client.new(environment_object, args.om_version)
40
40
  opsmgr_cmd = Opsmgr::Cmd::OpsManager.new(environment_object)
41
41
  opsmgr_cmd.import_installation(client, args.import_file)
42
+
43
+ if Gem::Version.new(args.om_version) >= Gem::Version.new('1.7')
44
+ require 'opsmgr/ui_helpers/ui_spec_runner'
45
+
46
+ UiSpecRunner.new(
47
+ environment: args.environment,
48
+ om_version: args.om_version
49
+ ).post_import_configuration
50
+ end
42
51
  end
43
52
 
44
53
  desc 'Delete installation'
@@ -123,7 +132,7 @@ namespace :opsmgr do
123
132
  require 'opsmgr/environments'
124
133
 
125
134
  environment = Opsmgr::Environments.for(args.environment)
126
- client = Opsmgr::Api::Client.new(environment)
135
+ client = Opsmgr::Api::Client.new(environment, args.om_version)
127
136
  Opsmgr::Cmd::OpsManager.new(environment).delete_unused_products(client)
128
137
  end
129
138
 
@@ -156,13 +165,7 @@ namespace :opsmgr do
156
165
  env_name: args.environment_name,
157
166
  om_version: args.om_version
158
167
  )
159
- iaas_gateway = Opsmgr::Cmd::IaasGateway.new(
160
- bosh_command: bosh_command,
161
- environment_name: args.environment_name,
162
- logger: logger
163
- )
164
168
  Opsmgr::ErrandRunner.new(
165
- iaas_gateway: iaas_gateway,
166
169
  bosh_command: bosh_command,
167
170
  environment_name: args.environment_name,
168
171
  logger: logger,
@@ -1,35 +1,38 @@
1
1
  namespace :opsmgr do
2
2
  namespace :product do
3
3
  desc 'Upload a Pivotal Product'
4
- task :upload, [:environment, :_om_version, :product_path, :product_name] do |_, args|
4
+ task :upload, [:environment, :om_version, :product_path, :product_name] do |_, args|
5
5
  require 'opsmgr/product_upload_wrapper'
6
6
 
7
7
  ProductUploadWrapper.wrap_upload(
8
8
  environment: args.environment,
9
9
  product_path: args.product_path,
10
- product_name: args.product_name
10
+ product_name: args.product_name,
11
+ om_version: args.om_version
11
12
  )
12
13
  end
13
14
 
14
15
  desc 'Upload and Add a Pivotal Product'
15
- task :upload_add, [:environment, :_om_version, :product_path, :product_name] do |_, args|
16
+ task :upload_add, [:environment, :om_version, :product_path, :product_name] do |_, args|
16
17
  require 'opsmgr/product_upload_wrapper'
17
18
 
18
19
  ProductUploadWrapper.wrap_add(
19
20
  environment: args.environment,
20
21
  product_path: args.product_path,
21
- product_name: args.product_name
22
+ product_name: args.product_name,
23
+ om_version: args.om_version
22
24
  )
23
25
  end
24
26
 
25
27
  desc 'Upgrade a Generic Pivotal Product'
26
- task :upload_upgrade, [:environment, :_om_version, :product_path, :product_name] do |_, args|
28
+ task :upload_upgrade, [:environment, :om_version, :product_path, :product_name] do |_, args|
27
29
  require 'opsmgr/product_upload_wrapper'
28
30
 
29
31
  ProductUploadWrapper.wrap_upgrade(
30
32
  environment: args.environment,
31
33
  product_path: args.product_path,
32
- product_name: args.product_name
34
+ product_name: args.product_name,
35
+ om_version: args.om_version
33
36
  )
34
37
  end
35
38