Module: Nucleus::Adapters::V1::OpenshiftV2::Services
- Included in:
- Nucleus::Adapters::V1::OpenshiftV2
- Defined in:
- lib/nucleus/adapters/v1/openshift_v2/services.rb
Overview
Openshift V2, operations for the application’s addons
Instance Method Summary collapse
- #add_service(application_id, service_entity, plan_entity) ⇒ Object
- #installed_service(application_id, service_id) ⇒ Object
- #installed_services(application_id) ⇒ Object
- #remove_service(application_id, service_id) ⇒ Object
- #service(service_id) ⇒ Object
- #service_plan(service_id, plan_id) ⇒ Object
- #service_plans(service_id) ⇒ Object
- #services ⇒ Object
Instance Method Details
#add_service(application_id, service_entity, plan_entity) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/nucleus/adapters/v1/openshift_v2/services.rb', line 53 def add_service(application_id, service_entity, plan_entity) # make sure dependencies are installed app_id = app_id_by_name(application_id) begin service_to_add = (service_entity[:id]) rescue Errors::AdapterResourceNotFoundError raise Errors::SemanticAdapterRequestError, "Invalid service: '#{service_entity[:id]}' could not be found" end # verify dependencies are installed, throws error if not verify_cartridge_dependencies(app_id, service_entity[:id], service_to_add) # check plan (if there are some) # no plans, chosen plan must be 'default' plan_name = service_to_add[:usage_rates].find { |plan| plan[:plan_id] == plan_entity[:id] } if (service_to_add[:usage_rates].empty? && plan_entity[:id] != 'default') || (!service_to_add[:usage_rates].empty? && plan_name.nil?) fail Errors::SemanticAdapterRequestError, "No such service plan name '#{plan_entity[:id]}' for service "\ "'#{service_entity[:id]}' and application '#{application_id}'" end # TODO: if a different plan than 'default' is chosen, we can't use it yet :/ # However, only 'standalone' cartridges showed different plans as of April, 15th 2015 to_nucleus_installed_service(post("/application/#{app_id}/cartridges", body: { cartridge: service_entity[:id] }).body[:data]) end |
#installed_service(application_id, service_id) ⇒ Object
47 48 49 50 |
# File 'lib/nucleus/adapters/v1/openshift_v2/services.rb', line 47 def installed_service(application_id, service_id) installed = get("/application/#{app_id_by_name(application_id)}/cartridge/#{service_id}").body[:data] to_nucleus_installed_service(installed) end |
#installed_services(application_id) ⇒ Object
40 41 42 43 44 |
# File 'lib/nucleus/adapters/v1/openshift_v2/services.rb', line 40 def installed_services(application_id) installed_cartridges(application_id).collect do |installed| to_nucleus_installed_service(installed) end end |
#remove_service(application_id, service_id) ⇒ Object
80 81 82 |
# File 'lib/nucleus/adapters/v1/openshift_v2/services.rb', line 80 def remove_service(application_id, service_id) delete("/application/#{app_id_by_name(application_id)}/cartridge/#{service_id}") end |
#service(service_id) ⇒ Object
13 14 15 |
# File 'lib/nucleus/adapters/v1/openshift_v2/services.rb', line 13 def service(service_id) to_nucleus_service((service_id)) end |
#service_plan(service_id, plan_id) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/nucleus/adapters/v1/openshift_v2/services.rb', line 26 def service_plan(service_id, plan_id) cartridge = (service_id) if (cartridge[:usage_rates].empty? && plan_id != 'default') || (!cartridge[:usage_rates].empty? && !cartridge[:usage_rates].any? { |rate| rate[:plan_id] == plan_id }) # Currently there are no plans, implement when required... fail Errors::AdapterResourceNotFoundError, "No such service plan name '#{plan_id}' for service "\ "'#{service_id}'" end return default_plan(cartridge) if cartridge[:usage_rates].empty? to_nucleus_plan(cartridge, cartridge[:usage_rates].find { |rate| rate[:plan_id] == plan_id }) end |
#service_plans(service_id) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/nucleus/adapters/v1/openshift_v2/services.rb', line 18 def service_plans(service_id) cartridge = (service_id) # Currently there are no plans, implement when required... return [default_plan(cartridge)] if cartridge[:usage_rates].empty? cartridge[:usage_rates].collect { |usage_rate| to_nucleus_plan(cartridge, usage_rate) } end |
#services ⇒ Object
8 9 10 |
# File 'lib/nucleus/adapters/v1/openshift_v2/services.rb', line 8 def services .collect { |cartridge| to_nucleus_service(cartridge) } end |