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



85
86
87
88
89
90
91
# File 'lib/opsmgr/api/client.rb', line 85

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

#delete_unused_productsObject



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

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

#download_staged_manifest(product_guid) ⇒ Object



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

def download_staged_manifest(product_guid)
  response = http_client.download_staged_manifest(product_guid)
  if response.code == '200'
    StagedManifestResult.new(response.body)
  else
    Error.new("Error downloading staged manifest for '#{product_guid}'", response)
  end
end

#import_installation(path, password) ⇒ Object



93
94
95
96
# File 'lib/opsmgr/api/client.rb', line 93

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



98
99
100
101
# File 'lib/opsmgr/api/client.rb', line 98

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



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

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



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

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

#root_ca_certificateObject



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

def root_ca_certificate
  response = http_client.root_ca_certificate
  if response.code == '200'
    JSON.parse(response.body)['root_ca_certificate_pem']
  else
    Error.new('Error retrieving the root ca certificate', response)
  end
end

#upgrade_product(product_guid, to_version) ⇒ Object



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

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