Class: Prof::CloudFoundry
- Inherits:
-
Object
- Object
- Prof::CloudFoundry
- Extended by:
- Forwardable
- Defined in:
- lib/prof/cloud_foundry.rb
Instance Attribute Summary collapse
-
#api_url ⇒ Object
readonly
Returns the value of attribute api_url.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#retry_interval ⇒ Object
readonly
Returns the value of attribute retry_interval.
-
#retry_timeout ⇒ Object
readonly
Returns the value of attribute retry_timeout.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #auth_token ⇒ Object
- #bind_service_and_keep_running(pushed_app_name, service_instance_name) ⇒ Object
- #bind_service_and_run(pushed_app, service_instance, &_block) ⇒ Object
- #create_service_key(service_instance, &_block) ⇒ Object
- #delete_service_instance_and_unbind(service_instance, options = {}) ⇒ Object
- #delete_service_key(service_instance, service_key) ⇒ Object
- #enable_diego_and_start_app(app) ⇒ Object
-
#initialize(opts = {}) ⇒ CloudFoundry
constructor
A new instance of CloudFoundry.
- #list_service_keys(service_instance) ⇒ Object
- #provision_and_create_service_key(service, &_block) ⇒ Object
- #provision_and_keep_service(service, service_instance = ServiceInstance.new) ⇒ Object
- #provision_service(service, options = {}, service_instance = ServiceInstance.new, &_block) ⇒ Object
- #push_and_keep_app(app, pushed_app_name = "cf-app-#{SecureRandom.hex(4)}") ⇒ Object
- #push_app(app, &_block) ⇒ Object
- #push_app_and_bind_with_service(app, service, &_block) ⇒ Object
- #push_app_and_bind_with_service_instance(app, service_instance, &_block) ⇒ Object
- #unbind_app_from_service(pushed_app, service_instance) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ CloudFoundry
Returns a new instance of CloudFoundry.
46 47 48 49 50 51 52 53 54 55 56 |
# 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 |
Instance Attribute Details
#api_url ⇒ Object (readonly)
Returns the value of attribute api_url.
22 23 24 |
# File 'lib/prof/cloud_foundry.rb', line 22 def api_url @api_url end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
22 23 24 |
# File 'lib/prof/cloud_foundry.rb', line 22 def domain @domain end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
22 23 24 |
# File 'lib/prof/cloud_foundry.rb', line 22 def password @password end |
#retry_interval ⇒ Object (readonly)
Returns the value of attribute retry_interval.
22 23 24 |
# File 'lib/prof/cloud_foundry.rb', line 22 def retry_interval @retry_interval end |
#retry_timeout ⇒ Object (readonly)
Returns the value of attribute retry_timeout.
22 23 24 |
# File 'lib/prof/cloud_foundry.rb', line 22 def retry_timeout @retry_timeout end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
22 23 24 |
# File 'lib/prof/cloud_foundry.rb', line 22 def username @username end |
Instance Method Details
#auth_token ⇒ Object
171 172 173 |
# 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) ⇒ Object
99 100 101 102 |
# 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, &_block) ⇒ Object
104 105 106 107 108 109 110 111 112 |
# 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, &_block) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 |
# 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 = {}) ⇒ Object
165 166 167 168 169 |
# File 'lib/prof/cloud_foundry.rb', line 165 def delete_service_instance_and_unbind(service_instance, = {}) hula_cloud_foundry.delete_service_instance_and_unbind(service_instance.name, ) wait_for_service_state(service_instance, "Service instance #{service_instance.name} not found", "delete failed") end |
#delete_service_key(service_instance, service_key) ⇒ Object
144 145 146 |
# 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) ⇒ Object
76 77 78 79 |
# 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) ⇒ Object
126 127 128 |
# 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, &_block) ⇒ Object
118 119 120 121 122 123 124 |
# 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) ⇒ Object
148 149 150 151 152 |
# 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, &_block) ⇒ Object
154 155 156 157 158 159 160 161 162 163 |
# File 'lib/prof/cloud_foundry.rb', line 154 def provision_service(service, = {}, 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 [:allow_failure] = false delete_service_instance_and_unbind(service_instance, ) end |
#push_and_keep_app(app, pushed_app_name = "cf-app-#{SecureRandom.hex(4)}") ⇒ Object
58 59 60 61 62 63 |
# 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, &_block) ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# 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, &_block) ⇒ Object
81 82 83 84 85 86 87 88 89 |
# 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, &_block) ⇒ Object
91 92 93 94 95 96 97 |
# 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) ⇒ Object
114 115 116 |
# 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 |