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) ⇒ Client

Returns a new instance of Client.



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

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

Instance Attribute Details

#environment_nameObject (readonly)

Returns the value of attribute environment_name.



9
10
11
# File 'lib/opsmgr/api/client.rb', line 9

def environment_name
  @environment_name
end

Instance Method Details

#add_product(product_name, version) ⇒ Object



31
32
33
34
# File 'lib/opsmgr/api/client.rb', line 31

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



64
65
66
67
68
69
70
# File 'lib/opsmgr/api/client.rb', line 64

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

#delete_unused_productsObject



59
60
61
62
# File 'lib/opsmgr/api/client.rb', line 59

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

#installation_settingsObject



16
17
18
19
20
21
22
23
# File 'lib/opsmgr/api/client.rb', line 16

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



50
51
52
53
54
55
56
57
# File 'lib/opsmgr/api/client.rb', line 50

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



41
42
43
44
45
46
47
48
# File 'lib/opsmgr/api/client.rb', line 41

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



36
37
38
39
# File 'lib/opsmgr/api/client.rb', line 36

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”



26
27
28
29
# File 'lib/opsmgr/api/client.rb', line 26

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