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.
-
#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) {|service_key_name, service_key_data| ... } ⇒ 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) ⇒ Object
- #provision_service(service, options = {}, &_block) ⇒ Object
- #push_and_keep_app(app) ⇒ 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.
45 46 47 48 49 50 |
# File 'lib/prof/cloud_foundry.rb', line 45 def initialize(opts = {}) @domain = opts.fetch(:domain) @api_url = opts.fetch(:api_url) { "https://api.#{domain}" } @username = opts.fetch(:username) @password = opts.fetch(:password) 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 |
#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
163 164 165 |
# File 'lib/prof/cloud_foundry.rb', line 163 def auth_token hula_cloud_foundry.auth_token end |
#bind_service_and_keep_running(pushed_app_name, service_instance_name) ⇒ Object
94 95 96 97 |
# File 'lib/prof/cloud_foundry.rb', line 94 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
99 100 101 102 103 104 105 106 |
# File 'lib/prof/cloud_foundry.rb', line 99 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 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| ... } ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/prof/cloud_foundry.rb', line 124 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 hula_cloud_foundry.delete_service_key(service_instance.name, service_key_name) end |
#delete_service_instance_and_unbind(service_instance, options = {}) ⇒ Object
159 160 161 |
# File 'lib/prof/cloud_foundry.rb', line 159 def delete_service_instance_and_unbind(service_instance, = {}) hula_cloud_foundry.delete_service_instance_and_unbind(service_instance.name, ) end |
#delete_service_key(service_instance, service_key) ⇒ Object
137 138 139 |
# File 'lib/prof/cloud_foundry.rb', line 137 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
71 72 73 74 |
# File 'lib/prof/cloud_foundry.rb', line 71 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
120 121 122 |
# File 'lib/prof/cloud_foundry.rb', line 120 def list_service_keys(service_instance) hula_cloud_foundry.list_service_keys(service_instance.name) end |
#provision_and_create_service_key(service, &_block) ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/prof/cloud_foundry.rb', line 112 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) ⇒ Object
141 142 143 144 145 146 |
# File 'lib/prof/cloud_foundry.rb', line 141 def provision_and_keep_service(service) service_instance = ServiceInstance.new hula_cloud_foundry.create_service_instance(service.name, service_instance.name, service.plan) service_instance.name end |
#provision_service(service, options = {}, &_block) ⇒ Object
148 149 150 151 152 153 154 155 156 157 |
# File 'lib/prof/cloud_foundry.rb', line 148 def provision_service(service, = {}, &_block) service_instance = ServiceInstance.new hula_cloud_foundry.create_service_instance(service.name, service_instance.name, service.plan) yield service_instance if block_given? ensure hula_cloud_foundry.delete_service_instance_and_unbind(service_instance.name, ) end |
#push_and_keep_app(app) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/prof/cloud_foundry.rb', line 52 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
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/prof/cloud_foundry.rb', line 60 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
76 77 78 79 80 81 82 83 84 |
# File 'lib/prof/cloud_foundry.rb', line 76 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
86 87 88 89 90 91 92 |
# File 'lib/prof/cloud_foundry.rb', line 86 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
108 109 110 |
# File 'lib/prof/cloud_foundry.rb', line 108 def unbind_app_from_service(pushed_app, service_instance) hula_cloud_foundry.unbind_app_from_service(pushed_app.name, service_instance.name) end |