class PcfPause::OpsManInfo
Attributes
token[R]
url[R]
Public Class Methods
new(url, username, password)
click to toggle source
# File lib/pcf_pause/ops_man_info.rb, line 19 def initialize(url, username, password) @url = url @token = auth_header(username, password) end
Public Instance Methods
get_director_manifest()
click to toggle source
# File lib/pcf_pause/ops_man_info.rb, line 46 def get_director_manifest get_info 'deployed/director/manifest' end
get_manifest(product_id)
click to toggle source
# File lib/pcf_pause/ops_man_info.rb, line 28 def get_manifest(product_id) get_info "deployed/products/#{product_id}/manifest" end
get_product_id(type)
click to toggle source
# File lib/pcf_pause/ops_man_info.rb, line 50 def get_product_id(type) get_products.detect { |product_info| product_info['type'] == type }['guid'] end
get_products()
click to toggle source
# File lib/pcf_pause/ops_man_info.rb, line 24 def get_products get_info 'deployed/products/' end
get_vm_credentials(product_id)
click to toggle source
# File lib/pcf_pause/ops_man_info.rb, line 32 def get_vm_credentials(product_id) get_info "deployed/products/#{product_id}/vm_credentials" end
get_vm_names(product_id)
click to toggle source
# File lib/pcf_pause/ops_man_info.rb, line 36 def get_vm_names(product_id) manifest = get_manifest(product_id) key = if manifest.has_key?('jobs') # 1.7 manifest 'jobs' else 'instance_groups' end manifest[key].map { |vm| vm['name'] } end
Private Instance Methods
auth_header(username, password)
click to toggle source
# File lib/pcf_pause/ops_man_info.rb, line 73 def auth_header(username, password) CF::UAA::TokenIssuer.new(URI.join(url, 'uaa'), 'opsman', '').tap do |issuer| issuer.skip_ssl_validation = true end.owner_password_grant(username, password).auth_header end
get_info(path)
click to toggle source
# File lib/pcf_pause/ops_man_info.rb, line 56 def get_info(path) get_request = Net::HTTP::Get.new(File.join('/api/v0/', path)) get_request['Authorization'] = token response = http_client.request(get_request) fail("Unexpected response: #{response.inspect}") unless response.code == '200' JSON.parse(response.body) end
http_client()
click to toggle source
# File lib/pcf_pause/ops_man_info.rb, line 64 def http_client uri = URI.parse(url) Net::HTTP.new(uri.host, uri.port).tap do |http| http.use_ssl = true if url =~ /https/ http.verify_mode = OpenSSL::SSL::VERIFY_NONE http.read_timeout = 300 end end