class ProductUploadWrapper

Public Class Methods

find_latest_version(product_name, products_list) click to toggle source
# File lib/opsmgr/product_upload_wrapper.rb, line 46
def self.find_latest_version(product_name, products_list)
  stored_version = nil

  products_list.products.each do |p|
     if p['name'] != product_name
       next
     end

     if stored_version.nil?
       stored_version = p['product_version']
     elsif Gem::Version.new(p['product_version']) > Gem::Version.new(stored_version)
       stored_version = p['product_version']
     end
  end

  stored_version
end
wrap_add(environment:, product_path:, product_name:, om_version:) click to toggle source
# File lib/opsmgr/product_upload_wrapper.rb, line 7
def self.wrap_add(environment:, product_path:, product_name:, om_version:)
  wrap_operation(environment, product_path, product_name, 'add', om_version)
end
wrap_operation(environment, product_path, product_name, operation, om_version) click to toggle source
# File lib/opsmgr/product_upload_wrapper.rb, line 19
def self.wrap_operation(environment, product_path, product_name, operation, om_version)
  unless %w(add upgrade upload).include?(operation)
    fail "Operation '#{operation}' is not available"
  end

  environment_object = Opsmgr::Environments.for(environment)
  client = Opsmgr::Api::Client.new(environment_object, om_version)
  opsmgr_cmd = Opsmgr::Cmd::OpsManager.new(environment_object)
  opsmgr_cmd.upload_product(client, product_path)

  products_list = opsmgr_cmd.list_products(client)

  stored_version = find_latest_version(product_name, products_list)

  fail "#{product_name} is not available" if stored_version.nil?

  return if operation == 'upload'

  if operation == 'add'
    opsmgr_cmd.add_product(client, product_name, stored_version)
  else
    installed_products = opsmgr_cmd.installed_products(client)
    product_guid = installed_products.guid_for(product_name)
    opsmgr_cmd.upgrade_product(client, product_guid, stored_version)
  end
end
wrap_upgrade(environment:, product_path:, product_name:, om_version:) click to toggle source
# File lib/opsmgr/product_upload_wrapper.rb, line 11
def self.wrap_upgrade(environment:, product_path:, product_name:, om_version:)
  wrap_operation(environment, product_path, product_name, 'upgrade', om_version)
end
wrap_upload(environment:, product_path:, product_name:, om_version:) click to toggle source
# File lib/opsmgr/product_upload_wrapper.rb, line 15
def self.wrap_upload(environment:, product_path:, product_name:, om_version:)
  wrap_operation(environment, product_path, product_name, 'upload', om_version)
end