Class: OpsManager::ApplianceDeployment
- Inherits:
-
Object
- Object
- OpsManager::ApplianceDeployment
- Extended by:
- Forwardable
- Defined in:
- lib/ops_manager/appliance_deployment.rb
Instance Attribute Summary collapse
-
#config_file ⇒ Object
readonly
Returns the value of attribute config_file.
Instance Method Summary collapse
- #appliance ⇒ Object
- #create_first_user ⇒ Object
- #current_name ⇒ Object
- #current_version ⇒ Object
- #deploy ⇒ Object
- #desired_version ⇒ Object
-
#download_current_stemcells ⇒ Object
Lists all the available stemcells in the current installation_settings.
-
#find_stemcell_file(release_id, filename, product_name) ⇒ Object
Finds stemcell’s pivotal network release file.
-
#find_stemcell_release(version, product_name) ⇒ Object
Finds available stemcell’s pivotal network release.
-
#initialize(config_file) ⇒ ApplianceDeployment
constructor
A new instance of ApplianceDeployment.
- #list_current_stemcells ⇒ Object
- #new_vm_name ⇒ Object
- #provision_stemcells ⇒ Object
- #run ⇒ Object
- #upgrade ⇒ Object
- #wait_for_uaa ⇒ Object
Constructor Details
#initialize(config_file) ⇒ ApplianceDeployment
Returns a new instance of ApplianceDeployment.
19 20 21 |
# File 'lib/ops_manager/appliance_deployment.rb', line 19 def initialize(config_file) @config_file = config_file end |
Instance Attribute Details
#config_file ⇒ Object (readonly)
Returns the value of attribute config_file.
17 18 19 |
# File 'lib/ops_manager/appliance_deployment.rb', line 17 def config_file @config_file end |
Instance Method Details
#appliance ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/ops_manager/appliance_deployment.rb', line 54 def appliance @appliance ||= if config[:provider] =~/vsphere/i OpsManager::Appliance::Vsphere.new(config) else OpsManager::Appliance::AWS.new(config) end end |
#create_first_user ⇒ Object
62 63 64 65 66 67 |
# File 'lib/ops_manager/appliance_deployment.rb', line 62 def create_first_user puts '====> Creating initial user'.green until( create_user.code.to_i == 200) do print ' .'.green ; sleep 1 end end |
#current_name ⇒ Object
159 160 161 |
# File 'lib/ops_manager/appliance_deployment.rb', line 159 def current_name @current_name ||= "#{config[:name]}-#{current_version}" end |
#current_version ⇒ Object
155 156 157 |
# File 'lib/ops_manager/appliance_deployment.rb', line 155 def current_version @current_version ||= OpsManager::Semver.new(version_from_diagnostic_report) end |
#deploy ⇒ Object
69 70 71 72 |
# File 'lib/ops_manager/appliance_deployment.rb', line 69 def deploy appliance.deploy_vm wait_for_https_alive 300 end |
#desired_version ⇒ Object
163 164 165 |
# File 'lib/ops_manager/appliance_deployment.rb', line 163 def desired_version @desired_version ||= OpsManager::Semver.new(config[:desired_version]) end |
#download_current_stemcells ⇒ Object
Lists all the available stemcells in the current installation_settings. Downloads those stemcells.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/ops_manager/appliance_deployment.rb', line 132 def download_current_stemcells print "====> Downloading existing stemcells ...".green puts "no stemcells found".green if list_current_stemcells.empty? FileUtils.mkdir_p current_stemcell_dir list_current_stemcells.each do |stemcell_info| stemcell_version = stemcell_info[:version] product_name = stemcell_info[:product] release_id = find_stemcell_release(stemcell_version, product_name) accept_product_release_eula(product_name, release_id) stemcell_regex = /vsphere/ if config[:provider] == "AWS" stemcell_regex = /aws/ end file_id, file_name = find_stemcell_file(release_id, stemcell_regex, product_name) download_product_release_file(product_name, release_id, file_id, write_to: "#{current_stemcell_dir}/#{file_name}") end end |
#find_stemcell_file(release_id, filename, product_name) ⇒ Object
Finds stemcell’s pivotal network release file. #
124 125 126 127 128 |
# File 'lib/ops_manager/appliance_deployment.rb', line 124 def find_stemcell_file(release_id, filename, product_name) files = JSON.parse(get_product_release_files(product_name, 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, product_name) ⇒ 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. #
104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/ops_manager/appliance_deployment.rb', line 104 def find_stemcell_release(version, product_name) version = OpsManager::Semver.new(version) releases = stemcell_releases(product_name).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_stemcells ⇒ Object
89 90 91 92 93 94 95 96 97 |
# File 'lib/ops_manager/appliance_deployment.rb', line 89 def list_current_stemcells JSON.parse(installation_settings).fetch('products').inject([]) do |a, p| product_name = "stemcells" if p['stemcell'].fetch('os') =~ /windows/i product_name = "stemcells-windows-server" end a << { version: p['stemcell'].fetch('version'), product: product_name } end.uniq end |
#new_vm_name ⇒ Object
151 152 153 |
# File 'lib/ops_manager/appliance_deployment.rb', line 151 def new_vm_name @new_vm_name ||= "#{config[:name]}-#{config[:desired_version]}" end |
#provision_stemcells ⇒ Object
167 168 169 170 171 172 |
# File 'lib/ops_manager/appliance_deployment.rb', line 167 def provision_stemcells reset_access_token Dir.glob("#{current_stemcell_dir}/*").each do |stemcell_filepath| import_stemcell(stemcell_filepath) end end |
#run ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ops_manager/appliance_deployment.rb', line 23 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]) 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 if pending_changes? puts "OpsManager at #{config[:ip]} version has pending changes. Applying changes...".green if config[:single_tile_deploy] OpsManager::InstallationRunner.trigger!("none").wait_for_result else OpsManager::InstallationRunner.trigger!.wait_for_result end else puts "OpsManager at #{config[:ip]} version is already #{config[:desired_version]}. Skiping ...".green end end puts '====> Finish!'.green end |
#upgrade ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/ops_manager/appliance_deployment.rb', line 74 def upgrade get_installation_assets download_current_stemcells appliance.stop_current_vm(current_name) deploy upload_installation_assets wait_for_uaa provision_stemcells if config[:single_tile_deploy] OpsManager::InstallationRunner.trigger!("none").wait_for_result else OpsManager::InstallationRunner.trigger!.wait_for_result end end |
#wait_for_uaa ⇒ Object
174 175 176 177 178 179 |
# File 'lib/ops_manager/appliance_deployment.rb', line 174 def wait_for_uaa puts '====> Waiting for UAA to become available ...'.green while !uaa_available? sleep(5) end end |