Class: OpsManager::ProductDeployment

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Logging
Defined in:
lib/ops_manager/product_deployment.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

#logger, logger, logger=

Constructor Details

#initialize(config_file, forced_deployment = false) ⇒ ProductDeployment

Returns a new instance of ProductDeployment.



18
19
20
21
# File 'lib/ops_manager/product_deployment.rb', line 18

def initialize(config_file, forced_deployment = false)
  @config_file = config_file
  @forced_deployment = forced_deployment
end

Class Method Details

.exists?(name, version) ⇒ Boolean

Returns:

  • (Boolean)


112
113
114
115
# File 'lib/ops_manager/product_deployment.rb', line 112

def self.exists?(name, version)
  res = JSON.parse(OpsManager::Api::Opsman.new.get_available_products.body)
  !!res.find{ |o| o['name'] == name && o['product_version'].include?(version) }
end

Instance Method Details

#add_to_installationObject



83
84
85
86
87
# File 'lib/ops_manager/product_deployment.rb', line 83

def add_to_installation
  unless installation
    add_staged_products(config[:name], config[:desired_version])
  end
end

#deployObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/ops_manager/product_deployment.rb', line 89

def deploy
  puts "====> Deploying #{config[:name]} version #{config[:desired_version]}...".green
  upload
  add_to_installation
  merge_product_installation_settings
  products = "all"
  if config[:selected_deployments]
    products = config[:selected_deployments]
  elsif config[:single_tile_deploy]
    products = [installation.guid]
  end
  OpsManager::InstallationRunner.trigger!(products).wait_for_result

  puts "====> Finish!".green
end

#installationObject



23
24
25
# File 'lib/ops_manager/product_deployment.rb', line 23

def installation
  OpsManager::ProductInstallation.find(config[:name])
end

#merge_product_installation_settingsObject



106
107
108
109
110
# File 'lib/ops_manager/product_deployment.rb', line 106

def merge_product_installation_settings
  get_installation_settings({write_to: '/tmp/is.yml'})
  puts `DEBUG=false DEFAULT_ARRAY_MERGE_KEY=identifier spruce merge /tmp/is.yml #{config[:installation_settings_file]} > /tmp/new_is.yml`
  upload_installation_settings('/tmp/new_is.yml')
end

#runObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ops_manager/product_deployment.rb', line 27

def run
  OpsManager.(config[:target], config[:username], config[:password])
  products = "all"
  if config[:selected_deployments]
    products = config[:selected_deployments]
  elsif config[:single_tile_deploy]
    products = [installation.guid]
  end

  import_stemcell(config[:stemcell], products)

  case
  when installation.nil? || forced_deployment?
    deploy
  when installation && installation.current_version < desired_version
    upgrade
  when installation && installation.current_version == desired_version
    deploy
  end
end

#upgradeObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/ops_manager/product_deployment.rb', line 62

def upgrade
  unless installation.prepared?
    puts "====> Skipping as this product has a pending installation!".red
    return
  end
  puts "====> Upgrading #{config[:name]} version from #{installation.current_version.to_s} to #{config[:desired_version]}...".green
  upload
  upgrade_product_installation(installation.guid, config[:desired_version])
  merge_product_installation_settings

  products = "all"
  if config[:selected_deployments]
    products = config[:selected_deployments]
  elsif config[:single_tile_deploy]
    products = [installation.guid]
  end
  OpsManager::InstallationRunner.trigger!(products).wait_for_result

  puts "====> Finish!".green
end

#uploadObject



52
53
54
55
56
57
58
59
60
# File 'lib/ops_manager/product_deployment.rb', line 52

def upload
  if ProductDeployment.exists?(config[:name], config[:desired_version])
    puts "====> Product already exists... skipping upload".green
  elsif config[:filepath]
    upload_product(config[:filepath])
  else
    puts "no filepath provided, skipping product upload.".green
  end
end