Class: OpsManager::ApplianceDeployment

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_file) ⇒ ApplianceDeployment

Returns a new instance of ApplianceDeployment.



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

def initialize(config_file)
  @config_file = config_file
end

Instance Attribute Details

#config_fileObject (readonly)

Returns the value of attribute config_file.



14
15
16
# File 'lib/ops_manager/appliance_deployment.rb', line 14

def config_file
  @config_file
end

Instance Method Details

#create_first_userObject



53
54
55
56
57
58
# File 'lib/ops_manager/appliance_deployment.rb', line 53

def create_first_user
  puts '====> Creating initial user'.green
  until( create_user.code.to_i == 200) do
    print ' .'.green ; sleep 1
  end
end

#current_versionObject



124
125
126
# File 'lib/ops_manager/appliance_deployment.rb', line 124

def current_version
  @current_version ||= OpsManager::Semver.new(version_from_diagnostic_report)
end

#deployObject



43
44
45
# File 'lib/ops_manager/appliance_deployment.rb', line 43

def deploy
  deploy_vm(desired_vm_name , config.ip)
end

#desired_versionObject



128
129
130
# File 'lib/ops_manager/appliance_deployment.rb', line 128

def desired_version
  @desired_version ||= OpsManager::Semver.new(config.desired_version)
end

#download_current_stemcellsObject

Lists all the available stemcells in the current installation_settings. Downloads those stemcells.



109
110
111
112
113
114
115
116
117
118
# File 'lib/ops_manager/appliance_deployment.rb', line 109

def download_current_stemcells
  puts "Downloading existing stemcells ...".green
  FileUtils.mkdir_p current_stemcell_dir
  list_current_stemcells.each do |stemcell_version|
    release_id = find_stemcell_release(stemcell_version)
    accept_product_release_eula('stemcells', release_id )
    file_id, file_name = find_stemcell_file(release_id, /vsphere/)
    download_product_release_file('stemcells', release_id, file_id, write_to: "#{current_stemcell_dir}/#{file_name}")
  end
end

#find_stemcell_file(release_id, filename) ⇒ Object

Finds stemcell’s pivotal network release file. #

Parameters:

  • release_id (String)

    the version number, eg: ‘2362.17’

  • filename (Regex)

    the version number, eg: /vsphere/

Returns:

  • id and name [Array] the pivotal network file ID and Filename for the matching stemcell.



101
102
103
104
105
# File 'lib/ops_manager/appliance_deployment.rb', line 101

def find_stemcell_file(release_id, filename)
  files = JSON.parse(get_product_release_files('stemcells', release_id).body).fetch('product_files')
  file = files.select{ |r| r.fetch('aws_object_key') =~ filename }.first
  return file['id'], file['aws_object_key'].split('/')[-1]
end

#find_stemcell_release(version) ⇒ Object

Finds available stemcell’s pivotal network release. If it can not find the exact version it will try to find the newest minor version available. #

Parameters:

  • version (String)

    the version number, eg: ‘2362.17’



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/ops_manager/appliance_deployment.rb', line 81

def find_stemcell_release(version)
  version  = OpsManager::Semver.new(version)
  releases = stemcell_releases.collect do |r|
    {
      release_id:  r['id'],
      version:     OpsManager::Semver.new(r['version']),
    }
  end
  releases.keep_if{ |r| r[:version].major == version.major }
  exact_version = releases.select {|r| r[:version] == version }
  return exact_version.first[:release_id] unless exact_version.empty?
  releases_sorted_by_version = releases.sort_by{ |r| r[:version].minor }.reverse
  return releases_sorted_by_version.first[:release_id] unless releases_sorted_by_version.empty?
end

#list_current_stemcellsObject



70
71
72
73
74
# File 'lib/ops_manager/appliance_deployment.rb', line 70

def list_current_stemcells
  JSON.parse(installation_settings).fetch('products').inject([]) do |a, p|
    a << p['stemcell'].fetch('version')
  end
end

#new_vm_nameObject



120
121
122
# File 'lib/ops_manager/appliance_deployment.rb', line 120

def new_vm_name
  @new_vm_name ||= "#{config.name}-#{config.desired_version}"
end

#provision_stemcellsObject



132
133
134
135
136
# File 'lib/ops_manager/appliance_deployment.rb', line 132

def provision_stemcells
  Dir.glob("#{current_stemcell_dir}/*").each do |stemcell_filepath|
    import_stemcell(stemcell_filepath)
  end
end

#runObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ops_manager/appliance_deployment.rb', line 20

def run
  OpsManager.set_conf(:target, config.ip)
  OpsManager.set_conf(:username, config.username)
  OpsManager.set_conf(:password, config.password)
  OpsManager.set_conf(:pivnet_token, config.pivnet_token)

  self.extend(OpsManager::Deployments::Vsphere)

  case
  when current_version.empty?
    puts "No OpsManager deployed at #{config.ip}. Deploying ...".green
    deploy
    create_first_user
  when current_version < desired_version then
    puts "OpsManager at #{config.ip} version is #{current_version}. Upgrading to #{desired_version} .../".green
    upgrade
  when current_version == desired_version then
    puts "OpsManager at #{config.ip} version is already #{config.desired_version}. Skiping ...".green
  end

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

#upgradeObject



60
61
62
63
64
65
66
67
68
# File 'lib/ops_manager/appliance_deployment.rb', line 60

def upgrade
  get_installation_assets
  download_current_stemcells
  stop_current_vm(current_vm_name)
  deploy
  upload_installation_assets
  provision_stemcells
  OpsManager::InstallationRunner.trigger!.wait_for_result
end