Class: OpsmanagerClient::Client
- Inherits:
-
Object
- Object
- OpsmanagerClient::Client
- Defined in:
- lib/opsmanager_client/client.rb,
lib/opsmanager_client/client/version.rb
Defined Under Namespace
Modules: Internals
Constant Summary collapse
- VERSION =
"0.8.3"
Instance Method Summary collapse
- #add_product(product) ⇒ Object
- #apply_changes ⇒ Object
- #available_products ⇒ Object
- #cc_client_credentials ⇒ Object
- #cf_admin_client_secret ⇒ Object
- #cf_admin_credentials ⇒ Object
- #cf_installed? ⇒ Boolean
- #cf_uaa_credentials(credentials_key) ⇒ Object
- #delete_unused_products ⇒ Object
- #first_ip_of_product_job(product_name, job_type) ⇒ Object
-
#initialize(url, username, password) ⇒ Client
constructor
A new instance of Client.
- #product_added?(product) ⇒ Boolean
- #product_added_or_installed?(product) ⇒ Boolean
- #product_installed?(product) ⇒ Boolean
- #product_type_installed?(product) ⇒ Boolean
- #product_uploaded?(product) ⇒ Boolean
- #remove_product(product) ⇒ Object
- #system_domain ⇒ Object
- #uninstall_product_and_apply_changes(product_to_uninstall) ⇒ Object
- #upgrade_product(product) ⇒ Object
- #upload_product(product) ⇒ Object
- #vms_for_job_type(job_type) ⇒ Object
Constructor Details
#initialize(url, username, password) ⇒ Client
68 69 70 |
# File 'lib/opsmanager_client/client.rb', line 68 def initialize(url, username, password) @http_client = HTTPClient.new(url, username, password) end |
Instance Method Details
#add_product(product) ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/opsmanager_client/client.rb', line 76 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 ⇒ Object
170 171 172 |
# File 'lib/opsmanager_client/client.rb', line 170 def apply_changes @http_client.apply_changes end |
#available_products ⇒ Object
116 117 118 |
# File 'lib/opsmanager_client/client.rb', line 116 def available_products @http_client.available_products end |
#cc_client_credentials ⇒ Object
199 200 201 202 203 204 |
# File 'lib/opsmanager_client/client.rb', line 199 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 ⇒ Object
187 188 189 |
# File 'lib/opsmanager_client/client.rb', line 187 def cf_admin_client_secret uaa_job.properties.fetch("admin_client_credentials").fetch("password") end |
#cf_admin_credentials ⇒ Object
174 175 176 |
# File 'lib/opsmanager_client/client.rb', line 174 def cf_admin_credentials cf_uaa_credentials("admin_credentials") end |
#cf_installed? ⇒ Boolean
95 96 97 |
# File 'lib/opsmanager_client/client.rb', line 95 def cf_installed? !installed_products.find { |p| p.type == 'cf' }.nil? end |
#cf_uaa_credentials(credentials_key) ⇒ Object
178 179 180 181 182 183 184 185 |
# File 'lib/opsmanager_client/client.rb', line 178 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 ⇒ Object
112 113 114 |
# File 'lib/opsmanager_client/client.rb', line 112 def delete_unused_products @http_client.delete_unused_products end |
#first_ip_of_product_job(product_name, job_type) ⇒ Object
191 192 193 |
# File 'lib/opsmanager_client/client.rb', line 191 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
127 128 129 130 131 132 133 |
# File 'lib/opsmanager_client/client.rb', line 127 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
120 121 122 123 124 125 |
# File 'lib/opsmanager_client/client.rb', line 120 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
135 136 137 138 139 140 141 142 |
# File 'lib/opsmanager_client/client.rb', line 135 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
144 145 146 147 148 |
# File 'lib/opsmanager_client/client.rb', line 144 def product_type_installed?(product) installed_or_configured_products.any? { |installed_product| installed_product.type == product.name } end |
#product_uploaded?(product) ⇒ Boolean
150 151 152 153 154 155 |
# File 'lib/opsmanager_client/client.rb', line 150 def product_uploaded?(product) available_products.include?( "name" => product.name, "product_version" => product.version ) end |
#remove_product(product) ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'lib/opsmanager_client/client.rb', line 85 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 ⇒ Object
195 196 197 |
# File 'lib/opsmanager_client/client.rb', line 195 def system_domain product("cf").job_of_type('cloud_controller').properties.fetch("system_domain") end |
#uninstall_product_and_apply_changes(product_to_uninstall) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/opsmanager_client/client.rb', line 157 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
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/opsmanager_client/client.rb', line 99 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
72 73 74 |
# File 'lib/opsmanager_client/client.rb', line 72 def upload_product(product) @http_client.upload_product_from_file(product.file) unless product_uploaded?(product) end |
#vms_for_job_type(job_type) ⇒ Object
206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/opsmanager_client/client.rb', line 206 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 |