Class: OpsmanagerClient::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/opsmanager_client/client.rb,
lib/opsmanager_client/version.rb

Defined Under Namespace

Modules: Internals

Constant Summary collapse

VERSION =
"0.8.5"

Instance Method Summary collapse

Constructor Details

#initialize(url, username, password) ⇒ Client

Returns a new instance of Client.



67
68
69
# File 'lib/opsmanager_client/client.rb', line 67

def initialize(url, username, password)
  @http_client = HTTPClient.new(url, username, password)
end

Instance Method Details

#add_product(product) ⇒ Object



75
76
77
78
79
80
81
82
# File 'lib/opsmanager_client/client.rb', line 75

def add_product(product)

  if product_added_or_installed?(product)
    return "Product #{product} has already been added to the installation"
  end

  @http_client.add_product(product)
end

#apply_changesObject



169
170
171
# File 'lib/opsmanager_client/client.rb', line 169

def apply_changes
  @http_client.apply_changes
end

#available_productsObject



115
116
117
# File 'lib/opsmanager_client/client.rb', line 115

def available_products
  @http_client.available_products
end

#cc_client_credentialsObject



198
199
200
201
202
203
# File 'lib/opsmanager_client/client.rb', line 198

def cc_client_credentials
  OpenStruct.new(
    :identity => "cloud_controller", #Bug in POM means it reports wrong identity cc_client.fetch("identity"),
    :password => uaa_job.properties.fetch("cc_client_credentials").fetch("password")
  )
end

#cf_admin_client_secretObject



186
187
188
# File 'lib/opsmanager_client/client.rb', line 186

def cf_admin_client_secret
  uaa_job.properties.fetch("admin_client_credentials").fetch("password")
end

#cf_admin_credentialsObject



173
174
175
# File 'lib/opsmanager_client/client.rb', line 173

def cf_admin_credentials
  cf_uaa_credentials("admin_credentials")
end

#cf_installed?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/opsmanager_client/client.rb', line 94

def cf_installed?
  !installed_products.find { |p| p.type == 'cf' }.nil?
end

#cf_uaa_credentials(credentials_key) ⇒ Object



177
178
179
180
181
182
183
184
# File 'lib/opsmanager_client/client.rb', line 177

def cf_uaa_credentials(credentials_key)
  cf_credentials = uaa_job.properties.fetch(credentials_key)

  OpenStruct.new(
    :username => cf_credentials.fetch("identity"),
    :password => cf_credentials.fetch("password")
  )
end

#delete_unused_productsObject



111
112
113
# File 'lib/opsmanager_client/client.rb', line 111

def delete_unused_products
  @http_client.delete_unused_products
end

#first_ip_of_product_job(product_name, job_type) ⇒ Object



190
191
192
# File 'lib/opsmanager_client/client.rb', line 190

def first_ip_of_product_job(product_name, job_type)
  product(product_name).job_of_type(job_type).ips.first
end

#product_added?(product) ⇒ Boolean

Returns:

  • (Boolean)


126
127
128
129
130
131
132
# File 'lib/opsmanager_client/client.rb', line 126

def product_added?(product)
  installed_or_configured_products.any? { |installed_product|
    installed_product.type == product.name &&
      installed_product.version == product.version &&
        !installed_product.prepared
  }
end

#product_added_or_installed?(product) ⇒ Boolean

Returns:

  • (Boolean)


119
120
121
122
123
124
# File 'lib/opsmanager_client/client.rb', line 119

def product_added_or_installed?(product)
  installed_or_configured_products.any? { |installed_product|
    installed_product.type == product.name &&
      installed_product.version == product.version
  }
end

#product_installed?(product) ⇒ Boolean

Returns:

  • (Boolean)


134
135
136
137
138
139
140
141
# File 'lib/opsmanager_client/client.rb', line 134

def product_installed?(product)
  installed_or_configured_products.any? { |installed_product|
    installed_product.type == product.name &&
      installed_product.version == product.version &&
        installed_product.prepared
  }

end

#product_type_installed?(product) ⇒ Boolean

Returns:

  • (Boolean)


143
144
145
146
147
# File 'lib/opsmanager_client/client.rb', line 143

def product_type_installed?(product)
  installed_or_configured_products.any? { |installed_product|
    installed_product.type == product.name
  }
end

#product_uploaded?(product) ⇒ Boolean

Returns:

  • (Boolean)


149
150
151
152
153
154
# File 'lib/opsmanager_client/client.rb', line 149

def product_uploaded?(product)
  available_products.include?(
    "name" => product.name,
    "product_version" => product.version
  )
end

#remove_product(product) ⇒ Object



84
85
86
87
88
89
90
91
92
# File 'lib/opsmanager_client/client.rb', line 84

def remove_product(product)

  if !product_added?(product)
    return "Product #{product} is not added to the installation"
  end

  guid = guid_for_currently_installed_product_of_type(product.name)
  @http_client.remove_product_with_guid(guid)
end

#system_domainObject



194
195
196
# File 'lib/opsmanager_client/client.rb', line 194

def system_domain
  product("cf").job_of_type('cloud_controller').properties.fetch("system_domain")
end

#uninstall_product_and_apply_changes(product_to_uninstall) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/opsmanager_client/client.rb', line 156

def uninstall_product_and_apply_changes(product_to_uninstall)
  installed_product = installed_or_configured_products.find { |product|
    product.type == product_to_uninstall.name
  }

  if installed_product
    @http_client.uninstall_product_with_guid(installed_product.guid)
    apply_changes
  else
    "Product not installed"
  end
end

#upgrade_product(product) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/opsmanager_client/client.rb', line 98

def upgrade_product(product)
  if !product_uploaded?(product)
    raise "Unable to find available product"
  end

  if !different_version_installed?(product)
    raise "No product available to upgrade from"
  end

  guid = guid_for_currently_installed_product_of_type(product.name)
  @http_client.upgrade_product(product, guid)
end

#upload_product(product) ⇒ Object



71
72
73
# File 'lib/opsmanager_client/client.rb', line 71

def upload_product(product)
  @http_client.upload_product_from_file(product.file) unless product_uploaded?(product)
end

#vms_for_job_type(job_type) ⇒ Object



205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/opsmanager_client/client.rb', line 205

def vms_for_job_type(job_type)
  product = product_that_has_job_of_type(job_type)
  job = product.job_of_type(job_type)
  vm_credentials = job.properties.fetch('vm_credentials')

  job.ips.map { |ip|
    OpenStruct.new(
      :hostname => ip,
      :username => vm_credentials.fetch("identity"),
      :password => vm_credentials.fetch("password")
    )
  }
end