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.



16
17
18
19
# File 'lib/ops_manager/product_deployment.rb', line 16

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)


86
87
88
89
# File 'lib/ops_manager/product_deployment.rb', line 86

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



68
69
70
71
72
# File 'lib/ops_manager/product_deployment.rb', line 68

def add_to_installation
  unless installation
    add_staged_products(config.name, config.desired_version)
  end
end

#deployObject



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/ops_manager/product_deployment.rb', line 74

def deploy
  puts "====> Deploying #{config.name} version #{config.desired_version}...".green
  upload
  add_to_installation
  get_installation_settings({write_to: '/tmp/is.yml'})
  puts `DEBUG=false spruce merge /tmp/is.yml #{config.installation_settings_file} > /tmp/new_is.yml`
  upload_installation_settings('/tmp/new_is.yml')
  OpsManager::InstallationRunner.trigger!.wait_for_result

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

#installationObject



21
22
23
# File 'lib/ops_manager/product_deployment.rb', line 21

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

#runObject



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ops_manager/product_deployment.rb', line 25

def run
  OpsManager.(config.target, config.username, config.password)
  import_stemcell(config.stemcell)

  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



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ops_manager/product_deployment.rb', line 55

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)
  OpsManager::InstallationRunner.trigger!.wait_for_result

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

#uploadObject



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ops_manager/product_deployment.rb', line 43

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