Class: ProductUploadWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/opsmgr/product_upload_wrapper.rb

Class Method Summary collapse

Class Method Details

.find_latest_version(product_name, products_list) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# 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:) ⇒ Object



7
8
9
# 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) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 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:) ⇒ Object



11
12
13
# 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:) ⇒ Object



15
16
17
# 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