class OpsmanagerClient::Client
Constants
- VERSION
Public Class Methods
new(url, username, password)
click to toggle source
# File lib/opsmanager_client/client.rb, line 67 def initialize(url, username, password) @http_client = HTTPClient.new(url, username, password) end
Public Instance Methods
add_product(product)
click to toggle source
# 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_changes()
click to toggle source
# File lib/opsmanager_client/client.rb, line 169 def apply_changes @http_client.apply_changes end
available_products()
click to toggle source
# File lib/opsmanager_client/client.rb, line 115 def available_products @http_client.available_products end
cc_client_credentials()
click to toggle source
# 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_secret()
click to toggle source
# 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_credentials()
click to toggle source
# File lib/opsmanager_client/client.rb, line 173 def cf_admin_credentials cf_uaa_credentials("admin_credentials") end
cf_installed?()
click to toggle source
# 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)
click to toggle source
# 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_products()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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_domain()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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
Private Instance Methods
different_version_installed?(product)
click to toggle source
# File lib/opsmanager_client/client.rb, line 227 def different_version_installed?(product) installed_or_configured_products.select { |installed_product| installed_product.type == product.name && installed_product.version != product.version }.any? end
guid_for_currently_installed_product_of_type(type)
click to toggle source
# File lib/opsmanager_client/client.rb, line 221 def guid_for_currently_installed_product_of_type(type) installed_or_configured_products.find { |installed_product| installed_product.type == type }.guid end
installation()
click to toggle source
# File lib/opsmanager_client/client.rb, line 245 def installation @http_client.installation end
installed_or_configured_products()
click to toggle source
# File lib/opsmanager_client/client.rb, line 237 def installed_or_configured_products installation.fetch('products').map { |product_options| Internals::Product.new(product_options) } end
installed_products()
click to toggle source
# File lib/opsmanager_client/client.rb, line 241 def installed_products installed_or_configured_products.reject { |product| product.ips.empty? } end
product(product_name)
click to toggle source
# File lib/opsmanager_client/client.rb, line 249 def product(product_name) installed_or_configured_products.find { |product| product.type == product_name } end
product_that_has_job_of_type(job_type)
click to toggle source
# File lib/opsmanager_client/client.rb, line 233 def product_that_has_job_of_type(job_type) installed_or_configured_products.find { |product| product.has_job_of_type?(job_type) } end
uaa_job()
click to toggle source
# File lib/opsmanager_client/client.rb, line 255 def uaa_job product("cf").job_of_type('uaa') end