Module: Nucleus::Adapters::V1::CloudControl::Services

Included in:
Nucleus::Adapters::V1::CloudControl
Defined in:
lib/nucleus/adapters/v1/cloud_control/services.rb

Overview

cloud control, operations for the application’s addons

Instance Method Summary collapse

Instance Method Details

#add_service(application_id, service_entity, plan_entity) ⇒ Object

See Also:



53
54
55
56
57
58
# File 'lib/nucleus/adapters/v1/cloud_control/services.rb', line 53

def add_service(application_id, service_entity, plan_entity)
  plan_name = plan_name?(plan_entity[:id]) ? plan_entity[:id] : "#{service_entity[:id]}.#{plan_entity[:id]}"
  created = post("/app/#{application_id}/deployment/#{NUCLEUS_DEPLOYMENT}/addon",
                 body: { addon: plan_name }).body
  to_nucleus_installed_service(service(service_entity[:id]), created)
end

#change_service(application_id, service_id, plan_entity) ⇒ Object



61
62
63
64
65
66
67
68
69
70
# File 'lib/nucleus/adapters/v1/cloud_control/services.rb', line 61

def change_service(application_id, service_id, plan_entity)
  plan_name = active_plan(application_id, service_id)
  fail Errors::SemanticAdapterRequestError,
       "Plan '#{plan_entity[:id]}' is already active for service '#{service_id}' of application "\
       "'#{application_id}'" if plan_name == plan_entity[:id]

  updated = put("/app/#{application_id}/deployment/#{NUCLEUS_DEPLOYMENT}/addon/#{plan_name}",
                body: { addon: plan_entity[:id] }).body
  to_nucleus_installed_service(service(service_id), updated)
end

#installed_service(application_id, service_name) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/nucleus/adapters/v1/cloud_control/services.rb', line 44

def installed_service(application_id, service_name)
  # we also require the installed plan to retrieve the service, the list does not include all properties :(
  plan_name = active_plan(application_id, service_name)
  assignment = get("/app/#{application_id}/deployment/#{NUCLEUS_DEPLOYMENT}/addon/#{plan_name}").body
  installed_service = service(parse_service_name(assignment[:addon_option][:name]))
  to_nucleus_installed_service(installed_service, assignment)
end

#installed_services(application_id) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/nucleus/adapters/v1/cloud_control/services.rb', line 34

def installed_services(application_id)
  load_installed_addons(application_id).collect do |assignment|
    # ignore config and alias addons, for us they are core parts of the application
    next if %w(config.free alias.free).include?(assignment[:addon_option][:name])
    service = service(parse_service_name(assignment[:addon_option][:name]))
    to_nucleus_installed_service(service, assignment)
  end.compact
end

#remove_service(application_id, service_id) ⇒ Object



73
74
75
76
# File 'lib/nucleus/adapters/v1/cloud_control/services.rb', line 73

def remove_service(application_id, service_id)
  plan_name = active_plan(application_id, service_id)
  delete("/app/#{application_id}/deployment/#{NUCLEUS_DEPLOYMENT}/addon/#{plan_name}")
end

#service(service_name) ⇒ Object

See Also:



13
14
15
# File 'lib/nucleus/adapters/v1/cloud_control/services.rb', line 13

def service(service_name)
  to_nucleus_service(get("/addon/#{service_name}").body)
end

#service_plan(service_name, plan_name) ⇒ Object

See Also:



23
24
25
26
27
28
29
30
31
# File 'lib/nucleus/adapters/v1/cloud_control/services.rb', line 23

def service_plan(service_name, plan_name)
  plan_name = plan_name?(plan_name) ? plan_name : "#{service_name}.#{plan_name}"
  plan = get("/addon/#{service_name}").body[:options].find do |cc_plan|
    cc_plan[:name] == plan_name
  end
  fail Errors::AdapterResourceNotFoundError,
       "No such plan '#{plan_name}' for service '#{service_name}'" unless plan
  to_nucleus_plan(plan)
end

#service_plans(service_name) ⇒ Object

See Also:



18
19
20
# File 'lib/nucleus/adapters/v1/cloud_control/services.rb', line 18

def service_plans(service_name)
  get("/addon/#{service_name}").body[:options].collect { |plan| to_nucleus_plan(plan) }
end

#servicesObject

See Also:



8
9
10
# File 'lib/nucleus/adapters/v1/cloud_control/services.rb', line 8

def services
  get('/addon').body.collect { |cc_service| to_nucleus_service(cc_service) }
end