Module: Nucleus::Adapters::V1::CloudFoundryV2::Services
- Included in:
- Nucleus::Adapters::V1::CloudFoundryV2
- Defined in:
- lib/nucleus/adapters/v1/cloud_foundry_v2/services.rb
Overview
Cloud Foundry, operations for the application’s addons
Instance Method Summary collapse
- #add_service(application_name_or_id, service_entity, plan_entity) ⇒ Object
- #change_service(application_name_or_id, service_id, plan_entity) ⇒ Object
- #installed_service(application_name_or_id, service_id_or_name) ⇒ Object
- #installed_services(application_name_or_id) ⇒ Object
- #remove_service(application_name_or_id, service_id) ⇒ Object
- #service(service_id_or_name) ⇒ Object
- #service_plan(service_id_or_name, plan_id) ⇒ Object
- #service_plans(service_id_or_name) ⇒ Object
- #services ⇒ Object
Instance Method Details
#add_service(application_name_or_id, service_entity, plan_entity) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/nucleus/adapters/v1/cloud_foundry_v2/services.rb', line 55 def add_service(application_name_or_id, service_entity, plan_entity) app_guid = app_guid(application_name_or_id) service_guid = service_guid(service_entity[:id], Errors::SemanticAdapterRequestError) cf_service = load_allowed_service(service_entity, service_guid) # get the plan, throws 422 if the plan could not be found plan_guid = plan_guid(service_guid, plan_entity[:id]) # create new service instance instance_request_body = { space_guid: user_space_guid, service_plan_guid: plan_guid, name: "#{cf_service[:entity][:label]}-#{application_name_or_id}-nucleus" } cf_instance = post('/v2/service_instances', body: instance_request_body).body # bind the created service instance to the application binding_request_body = { service_instance_guid: cf_instance[:metadata][:guid], app_guid: app_guid } cf_binding = post('/v2/service_bindings', body: binding_request_body).body # created service presentation to_nucleus_installed_service(cf_binding, cf_service, cf_instance) end |
#change_service(application_name_or_id, service_id, plan_entity) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/nucleus/adapters/v1/cloud_foundry_v2/services.rb', line 77 def change_service(application_name_or_id, service_id, plan_entity) app_guid = app_guid(application_name_or_id) service_guid = service_guid(service_id) cf_service = get("/v2/services/#{service_guid}").body fail_with(:service_not_updateable, [service_id]) unless cf_service[:entity][:plan_updateable] cf_binding = binding(app_guid, service_guid) # get the plan, throws 422 if the plan could not be found plan_guid = plan_guid(service_guid, plan_entity[:id]) cf_instance = put("/v2/service_instances/#{cf_binding[:entity][:service_instance_guid]}", body: { service_plan_guid: plan_guid }).body to_nucleus_installed_service(cf_binding, cf_service, cf_instance) end |
#installed_service(application_name_or_id, service_id_or_name) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/nucleus/adapters/v1/cloud_foundry_v2/services.rb', line 44 def installed_service(application_name_or_id, service_id_or_name) app_guid = app_guid(application_name_or_id) service_guid = service_guid(service_id_or_name) cf_binding = binding(app_guid, service_guid) # make sure there is a binding fail Errors::AdapterResourceNotFoundError, "No such service '#{service_id_or_name}' for application '#{application_name_or_id}'" unless cf_binding to_nucleus_installed_service(cf_binding) end |
#installed_services(application_name_or_id) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/nucleus/adapters/v1/cloud_foundry_v2/services.rb', line 36 def installed_services(application_name_or_id) app_guid = app_guid(application_name_or_id) get("/v2/apps/#{app_guid}/service_bindings?inline-relations-depth=1").body[:resources].collect do |binding| to_nucleus_installed_service(binding) end end |
#remove_service(application_name_or_id, service_id) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/nucleus/adapters/v1/cloud_foundry_v2/services.rb', line 93 def remove_service(application_name_or_id, service_id) app_guid = app_guid(application_name_or_id) service_guid = service_guid(service_id) # sadly we can't resolve the binding and instance from the service_id with ease # we therefore setup a chain to resolve the binding and instance from the active pla binding = binding(app_guid, service_guid) # now remove the binding from the application delete("/v2/apps/#{app_guid}/service_bindings/#{binding[:metadata][:guid]}", expects: [201]) # and finally delete the service instance delete("/v2/service_instances/#{binding[:entity][:service_instance_guid]}") end |
#service(service_id_or_name) ⇒ Object
17 18 19 20 |
# File 'lib/nucleus/adapters/v1/cloud_foundry_v2/services.rb', line 17 def service(service_id_or_name) service_guid = service_guid(service_id_or_name) to_nucleus_service(get("/v2/services/#{service_guid}?inline-relations-depth=1").body) end |
#service_plan(service_id_or_name, plan_id) ⇒ Object
29 30 31 32 33 |
# File 'lib/nucleus/adapters/v1/cloud_foundry_v2/services.rb', line 29 def service_plan(service_id_or_name, plan_id) service_guid = service_guid(service_id_or_name) plan_guid = plan_guid(service_guid, plan_id, Errors::AdapterResourceNotFoundError) to_nucleus_plan(get("/v2/service_plans/#{plan_guid}").body) end |
#service_plans(service_id_or_name) ⇒ Object
23 24 25 26 |
# File 'lib/nucleus/adapters/v1/cloud_foundry_v2/services.rb', line 23 def service_plans(service_id_or_name) service_guid = service_guid(service_id_or_name) load_plans(service_guid).collect { |plan| to_nucleus_plan(plan) } end |
#services ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/nucleus/adapters/v1/cloud_foundry_v2/services.rb', line 8 def services get('/v2/services?inline-relations-depth=1').body[:resources].collect do |service| # show only services that are both, active and bindable next unless service[:entity][:active] && service[:entity][:bindable] to_nucleus_service(service) end.compact end |