class Prof::CloudFoundry
Attributes
api_url[R]
domain[R]
password[R]
retry_interval[R]
retry_timeout[R]
username[R]
Public Class Methods
new(opts = {})
click to toggle source
# File lib/prof/cloud_foundry.rb, line 46 def initialize(opts = {}) @domain = opts.fetch(:domain) @api_url = opts.fetch(:api_url) { "https://api.#{domain}" } @username = opts.fetch(:username) @password = opts.fetch(:password) @retry_interval = opts.fetch(:retry_interval) { 5 } @retry_timeout = opts.fetch(:retry_timeout) { 720 } @hula_cloud_foundry = opts.fetch(:hula_cloud_foundry) if opts.key?(:hula_cloud_foundry) end
Public Instance Methods
auth_token()
click to toggle source
# File lib/prof/cloud_foundry.rb, line 171 def auth_token hula_cloud_foundry.auth_token end
bind_service_and_keep_running(pushed_app_name, service_instance_name)
click to toggle source
# File lib/prof/cloud_foundry.rb, line 99 def bind_service_and_keep_running(pushed_app_name, service_instance_name) hula_cloud_foundry.bind_app_to_service(pushed_app_name, service_instance_name) hula_cloud_foundry.start_app(pushed_app_name) end
bind_service_and_run(pushed_app, service_instance) { || ... }
click to toggle source
# File lib/prof/cloud_foundry.rb, line 104 def bind_service_and_run(pushed_app, service_instance, &_block) hula_cloud_foundry.bind_app_to_service(pushed_app.name, service_instance.name) hula_cloud_foundry.start_app(pushed_app.name) yield ensure hula_cloud_foundry.unbind_app_from_service(pushed_app.name, service_instance.name) end
create_service_key(service_instance) { |service_key_name, service_key_data| ... }
click to toggle source
# File lib/prof/cloud_foundry.rb, line 130 def create_service_key(service_instance, &_block) service_key_name = "#{service_instance.name}-#{SecureRandom.hex(4)}" hula_cloud_foundry.create_service_key(service_instance.name, service_key_name) service_key_raw = hula_cloud_foundry.service_key(service_instance.name, service_key_name) service_key_data = JSON.parse( service_key_raw.split("\n").slice(2..-1).join ) yield service_key_name, service_key_data ensure hula_cloud_foundry.delete_service_key(service_instance.name, service_key_name) end
delete_service_instance_and_unbind(service_instance, options = {})
click to toggle source
# File lib/prof/cloud_foundry.rb, line 165 def delete_service_instance_and_unbind(service_instance, options = {}) hula_cloud_foundry.delete_service_instance_and_unbind(service_instance.name, options) wait_for_service_state(service_instance, "Service instance #{service_instance.name} not found", "delete failed") end
delete_service_key(service_instance, service_key)
click to toggle source
# File lib/prof/cloud_foundry.rb, line 144 def delete_service_key(service_instance, service_key) hula_cloud_foundry.delete_service_key(service_instance.name, service_key) end
enable_diego_and_start_app(app)
click to toggle source
# File lib/prof/cloud_foundry.rb, line 76 def enable_diego_and_start_app(app) hula_cloud_foundry.enable_diego_for_app(app.name) hula_cloud_foundry.start_app(app.name) end
list_service_keys(service_instance)
click to toggle source
# File lib/prof/cloud_foundry.rb, line 126 def list_service_keys(service_instance) hula_cloud_foundry.list_service_keys(service_instance.name) end
provision_and_create_service_key(service) { |service_instance, service_key, service_key_data| ... }
click to toggle source
# File lib/prof/cloud_foundry.rb, line 118 def provision_and_create_service_key(service, &_block) provision_service(service) do |service_instance| create_service_key(service_instance) do |service_key, service_key_data| yield service_instance, service_key, service_key_data end end end
provision_and_keep_service(service, service_instance = ServiceInstance.new)
click to toggle source
# File lib/prof/cloud_foundry.rb, line 148 def provision_and_keep_service(service, service_instance = ServiceInstance.new) hula_cloud_foundry.create_service_instance(service.name, service_instance.name, service.plan) wait_for_service_state(service_instance, "create succeeded", "create failed") service_instance.name end
provision_service(service, options = {}, service_instance = ServiceInstance.new) { |service_instance| ... }
click to toggle source
# File lib/prof/cloud_foundry.rb, line 154 def provision_service(service, options = {}, service_instance = ServiceInstance.new, &_block) hula_cloud_foundry.create_service_instance(service.name, service_instance.name, service.plan) wait_for_service_state(service_instance, "create succeeded", "create failed") yield service_instance if block_given? ensure options[:allow_failure] = false delete_service_instance_and_unbind(service_instance, options) end
push_and_keep_app(app, pushed_app_name = "cf-app-
click to toggle source
# File lib/prof/cloud_foundry.rb, line 58 def push_and_keep_app(app, pushed_app_name = "cf-app-#{SecureRandom.hex(4)}") deployed_app = PushedTestApp.new(name: pushed_app_name, url: hula_cloud_foundry.url_for_app(pushed_app_name)) hula_cloud_foundry.push_app(app.path, deployed_app.name) [deployed_app.name, deployed_app.url] end
push_app(app) { |deployed_app| ... }
click to toggle source
# File lib/prof/cloud_foundry.rb, line 65 def push_app(app, &_block) pushed_app_name = "cf-app-#{SecureRandom.hex(4)}" deployed_app = PushedTestApp.new(name: pushed_app_name, url: hula_cloud_foundry.url_for_app(pushed_app_name)) hula_cloud_foundry.push_app(app.path, deployed_app.name) yield deployed_app ensure hula_cloud_foundry.delete_app deployed_app.name end
push_app_and_bind_with_service(app, service) { |pushed_app, service_instance| ... }
click to toggle source
# File lib/prof/cloud_foundry.rb, line 81 def push_app_and_bind_with_service(app, service, &_block) push_app(app) do |pushed_app| provision_service(service) do |service_instance| bind_service_and_run(pushed_app, service_instance) do yield pushed_app, service_instance end end end end
push_app_and_bind_with_service_instance(app, service_instance) { |pushed_app, service_instance| ... }
click to toggle source
# File lib/prof/cloud_foundry.rb, line 91 def push_app_and_bind_with_service_instance(app, service_instance, &_block) push_app(app) do |pushed_app| bind_service_and_run(pushed_app, service_instance) do yield pushed_app, service_instance end end end
unbind_app_from_service(pushed_app, service_instance)
click to toggle source
# File lib/prof/cloud_foundry.rb, line 114 def unbind_app_from_service(pushed_app, service_instance) hula_cloud_foundry.unbind_app_from_service(pushed_app.name, service_instance.name) end
Private Instance Methods
hula_cloud_foundry()
click to toggle source
# File lib/prof/cloud_foundry.rb, line 188 def hula_cloud_foundry @hula_cloud_foundry ||= Hula::CloudFoundry.new( api_url: api_url, domain: domain, username: username, password: password ) end
wait_for_service_state(service_instance, expected_state, failure_state)
click to toggle source
# File lib/prof/cloud_foundry.rb, line 177 def wait_for_service_state(service_instance, expected_state, failure_state) Timeout::timeout(retry_timeout) do loop do status = hula_cloud_foundry.get_service_status(service_instance.name, {:allow_failure => true}) return if status.include? expected_state raise "Error #{failure_state} occured for service instance: #{service_instance.name}" if status.include? failure_state sleep retry_interval end end end