Module: Nucleus::Adapters::V1::CloudFoundryV2::Application
- Included in:
- Nucleus::Adapters::V1::CloudFoundryV2
- Defined in:
- lib/nucleus/adapters/v1/cloud_foundry_v2/application.rb
Instance Method Summary collapse
- #application(application_name_or_id) ⇒ Object
- #applications ⇒ Object
- #create_application(application) ⇒ Object
- #delete_application(application_name_or_id) ⇒ Object
- #update_application(application_name_or_id, application_form) ⇒ Object
Instance Method Details
#application(application_name_or_id) ⇒ Object
17 18 19 20 21 |
# File 'lib/nucleus/adapters/v1/cloud_foundry_v2/application.rb', line 17 def application(application_name_or_id) app_guid = app_guid(application_name_or_id) get_response = get("/v2/apps/#{app_guid}") to_nucleus_app(get_response.body) end |
#applications ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/nucleus/adapters/v1/cloud_foundry_v2/application.rb', line 7 def applications response = get('/v2/apps') apps = [] response.body[:resources].each do |application_resource| apps << to_nucleus_app(application_resource) end apps end |
#create_application(application) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/nucleus/adapters/v1/cloud_foundry_v2/application.rb', line 24 def create_application(application) if application.key? :region unless application[:region].casecmp('default') == 0 fail Errors::SemanticAdapterRequestError, "Region '#{application[:region]}' does not exist at the endpoint. "\ 'Please check which regions are actually available on this endpoint.' end # there is no region in Cloud Foundry --> remove from request application.delete :region end apply_buildpack(application) # apply default values, if not overridden by custom params default_params = { space_guid: user_space_guid } application = default_params.merge(application) # WORKAROUND: requires numeric input, but rack-test provides characters :/ application['memory'] = application['memory'].to_i if application.key?('memory') response = post('/v2/apps', body: application).body # now create the default route (similar to when using an UI, e.g. Pivotal, Stackato or Bluemix) == web_url create_cf_domain(response[:metadata][:guid], @endpoint_app_domain, response[:metadata][:guid]) # finally build the application response application(response[:metadata][:guid]) end |
#delete_application(application_name_or_id) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/nucleus/adapters/v1/cloud_foundry_v2/application.rb', line 63 def delete_application(application_name_or_id) app_guid = app_guid(application_name_or_id) # first delete all service bindings remove_all_services(app_guid) # then delete the default route (otherwise it would remain as orphaned route) routes = get("/v2/apps/#{app_guid}/routes?q=host:#{app_guid}&inline-relations-depth=1").body[:resources] default_route = routes.find { |route| route[:entity][:domain][:entity][:name] == @endpoint_app_domain } delete("/v2/routes/#{default_route[:metadata][:guid]}") if default_route # and finally delete the app delete("/v2/apps/#{app_guid}") end |
#update_application(application_name_or_id, application_form) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/nucleus/adapters/v1/cloud_foundry_v2/application.rb', line 54 def update_application(application_name_or_id, application_form) app_guid = app_guid(application_name_or_id) apply_buildpack(application_form) # update by guid update_response = put("/v2/apps/#{app_guid}", body: application_form) to_nucleus_app(update_response.body) end |