Class: Opsmgr::Api::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(environment, om_version) ⇒ Client

Returns a new instance of Client.



14
15
16
17
# File 'lib/opsmgr/api/client.rb', line 14

def initialize(environment, om_version)
  @http_client = HttpClient.build(environment, om_version)
  @environment_name = environment.settings.dig('name').freeze
end

Instance Attribute Details

#environment_nameObject (readonly)

Returns the value of attribute environment_name.



12
13
14
# File 'lib/opsmgr/api/client.rb', line 12

def environment_name
  @environment_name
end

Instance Method Details

#add_product(product_name, version) ⇒ Object



34
35
36
37
# File 'lib/opsmgr/api/client.rb', line 34

def add_product(product_name, version)
  response = http_client.add_product(product_name, version)
  basic_success_or_error("Error adding '#{product_name} #{version}'", response)
end

#basic_success_or_error(message, response) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/opsmgr/api/client.rb', line 67

def basic_success_or_error(message, response)
  if response.code == '200'
    Result.new
  else
    Error.new(message, response)
  end
end

#delete_unused_productsObject



62
63
64
65
# File 'lib/opsmgr/api/client.rb', line 62

def delete_unused_products
  response = http_client.delete_unused_products
  basic_success_or_error('There was an error deleting the unused products:', response)
end

#import_installation(path, password) ⇒ Object



75
76
77
78
# File 'lib/opsmgr/api/client.rb', line 75

def import_installation(path, password)
  response = http_client.import_installation(path, password)
  basic_success_or_error("Error importing #{path}", response)
end

#import_stemcell(path) ⇒ Object



80
81
82
83
# File 'lib/opsmgr/api/client.rb', line 80

def import_stemcell(path)
  response = http_client.import_stemcell(path)
  basic_success_or_error("Error importing stemcell #{path}", response)
end

#installation_settingsObject



19
20
21
22
23
24
25
26
# File 'lib/opsmgr/api/client.rb', line 19

def installation_settings
  response = http_client.installation_settings
  if response.code == '200'
    InstallationSettingsResult.new(JSON.parse(response.body))
  else
    Error.new('Error viewing current installation settings', response)
  end
end

#installed_productsObject



53
54
55
56
57
58
59
60
# File 'lib/opsmgr/api/client.rb', line 53

def installed_products
  response = http_client.installed_products
  if response.code == '200'
    InstalledProductsResult.new(Opsmgr::Settings::Microbosh::ProductList.new(JSON.parse(response.body)))
  else
    Error.new('Error listing installed products', response)
  end
end

#list_productsObject



44
45
46
47
48
49
50
51
# File 'lib/opsmgr/api/client.rb', line 44

def list_products
  response = http_client.list_products
  if response.code == '200'
    ListProductsResult.new(JSON.parse(response.body))
  else
    Error.new('Error listing products', response)
  end
end

#upgrade_product(product_guid, to_version) ⇒ Object



39
40
41
42
# File 'lib/opsmgr/api/client.rb', line 39

def upgrade_product(product_guid, to_version)
  response = http_client.upgrade_product(product_guid, to_version)
  basic_success_or_error("Error upgrading '#{product_guid}' to '#{to_version}'", response)
end

#upload_component(path) ⇒ Object

.pivotal file is referred to as a “product” but the Tempest developers call it a “component”



29
30
31
32
# File 'lib/opsmgr/api/client.rb', line 29

def upload_component(path)
  response = http_client.upload_component(path)
  basic_success_or_error("Error uploading #{path}", response)
end