Module: Nucleus::Adapters::V1::CloudControl::Application

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

Overview

cloud control, CRUD operations for the application object

Instance Method Summary collapse

Instance Method Details

#application(application_id) ⇒ Object

See Also:



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

def application(application_id)
  response = get("/app/#{application_id}").body
  to_nucleus_app(response, default_deployment(response[:name]))
end

#applicationsObject

See Also:



8
9
10
11
12
13
14
15
# File 'lib/nucleus/adapters/v1/cloud_control/application.rb', line 8

def applications
  response = get('/app')
  apps = []
  response.body.each do |application|
    apps << to_nucleus_app(application, default_deployment(application[:name]))
  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
52
53
# File 'lib/nucleus/adapters/v1/cloud_control/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 cloudControl --> remove from request
    application.delete :region
  end

  apply_buildpack(application)

  # force the use of repository type 'git', unless overridden by the params
  default_params = { repository_type: 'git' }
  cc_application = default_params.merge(application)

  create_app_response = post('/app', body: cc_application).body

  # create the default deployment, name will automatically become 'default'
  created_deployment = post("/app/#{create_app_response[:name]}/deployment", body: { name: 'nucleus' }).body

  # activate the variables addon. However, the activation explicitly requires an initial key value pair...
  post("/app/#{create_app_response[:name]}/deployment/#{NUCLEUS_DEPLOYMENT}/addon",
       body: { addon: 'config.free', options: "{\"nucleus-initialized\": \"true\"}" }).body
  # ...now delete the initial key value pair to have the desired clean setup
  delete_env_var(create_app_response[:name], 'nucleus-initialized')

  to_nucleus_app(create_app_response, created_deployment)
end

#delete_application(application_id) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/nucleus/adapters/v1/cloud_control/application.rb', line 56

def delete_application(application_id)
  # delete all deployments first
  deployments = get("/app/#{application_id}/deployment").body
  deployments.each do |deployment|
    deployment_name = %r{(\w+)\/(\w+)}.match(deployment[:name])[2]
    delete("/app/#{application_id}/deployment/#{deployment_name}")
  end
  delete("/app/#{application_id}")
end