Class: Prof::CloudFoundry

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/prof/cloud_foundry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ CloudFoundry

Returns a new instance of CloudFoundry.



44
45
46
47
48
49
# File 'lib/prof/cloud_foundry.rb', line 44

def initialize(opts = {})
  @domain   = opts.fetch(:domain)
  @api_url  = opts.fetch(:api_url) { "https://api.#{domain}" }
  @username = opts.fetch(:username)
  @password = opts.fetch(:password)
end

Instance Attribute Details

#api_urlObject (readonly)

Returns the value of attribute api_url.



22
23
24
# File 'lib/prof/cloud_foundry.rb', line 22

def api_url
  @api_url
end

#domainObject (readonly)

Returns the value of attribute domain.



22
23
24
# File 'lib/prof/cloud_foundry.rb', line 22

def domain
  @domain
end

#passwordObject (readonly)

Returns the value of attribute password.



22
23
24
# File 'lib/prof/cloud_foundry.rb', line 22

def password
  @password
end

#usernameObject (readonly)

Returns the value of attribute username.



22
23
24
# File 'lib/prof/cloud_foundry.rb', line 22

def username
  @username
end

Instance Method Details

#bind_service_and_run(pushed_app, service_instance, &_block) ⇒ Object



85
86
87
88
89
90
91
92
# File 'lib/prof/cloud_foundry.rb', line 85

def bind_service_and_run(pushed_app, service_instance, &_block)
  hula_cloud_foundry.bind_app_to_service(pushed_app.name, service_instance.name)
  hula_cloud_foundry.start_app(pushed_app.name)

  yield

  hula_cloud_foundry.unbind_app_from_service(pushed_app.name, service_instance.name)
end

#create_service_key(service_instance) {|service_key_name, service_key_data| ... } ⇒ Object

Yields:

  • (service_key_name, service_key_data)


106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/prof/cloud_foundry.rb', line 106

def create_service_key(service_instance, &_block)
  service_key_name = "#{service_instance.name}-#{SecureRandom.hex(4)}"
  hula_cloud_foundry.create_service_key(service_instance.name, service_key_name)
  service_key_raw = hula_cloud_foundry.service_key(service_instance.name, service_key_name)
  service_key_data = JSON.parse(
    service_key_raw.split("\n").slice(2..-1).join
  )

  yield service_key_name, service_key_data

  hula_cloud_foundry.delete_service_key(service_instance.name, service_key_name)
end

#delete_service_key(service_instance, service_key) ⇒ Object



119
120
121
# File 'lib/prof/cloud_foundry.rb', line 119

def delete_service_key(service_instance, service_key)
  hula_cloud_foundry.delete_service_key(service_instance.name, service_key)
end

#enable_diego_and_start_app(app) ⇒ Object



62
63
64
65
# File 'lib/prof/cloud_foundry.rb', line 62

def enable_diego_and_start_app(app)
  hula_cloud_foundry.enable_diego_for_app(app.name)
  hula_cloud_foundry.start_app(app.name)
end

#list_service_keys(service_instance) ⇒ Object



102
103
104
# File 'lib/prof/cloud_foundry.rb', line 102

def list_service_keys(service_instance)
  hula_cloud_foundry.list_service_keys(service_instance.name)
end

#provision_and_create_service_key(service, &_block) ⇒ Object



94
95
96
97
98
99
100
# File 'lib/prof/cloud_foundry.rb', line 94

def provision_and_create_service_key(service, &_block)
  provision_service(service) do |service_instance|
    create_service_key(service_instance) do |service_key, service_key_data|
      yield service_instance, service_key, service_key_data
    end
  end
end

#provision_service(service, &_block) ⇒ Object



123
124
125
126
127
128
129
130
131
132
# File 'lib/prof/cloud_foundry.rb', line 123

def provision_service(service, &_block)
  service_instance = ServiceInstance.new

  hula_cloud_foundry.create_service_instance(service.name, service_instance.name, service.plan)

  yield service_instance if block_given?

ensure
  hula_cloud_foundry.delete_service_instance_and_unbind(service_instance.name)
end

#push_app(app, &_block) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/prof/cloud_foundry.rb', line 51

def push_app(app, &_block)
  pushed_app_name = "cf-app-#{SecureRandom.hex(4)}"
  deployed_app    = PushedTestApp.new(name: pushed_app_name, url: hula_cloud_foundry.url_for_app(pushed_app_name))

  hula_cloud_foundry.push_app(app.path, deployed_app.name)

  yield deployed_app
ensure
  hula_cloud_foundry.delete_app deployed_app.name
end

#push_app_and_bind_with_service(app, service, &_block) ⇒ Object



67
68
69
70
71
72
73
74
75
# File 'lib/prof/cloud_foundry.rb', line 67

def push_app_and_bind_with_service(app, service, &_block)
  push_app(app) do |pushed_app|
    provision_service(service) do |service_instance|
      bind_service_and_run(pushed_app, service_instance) do
        yield pushed_app, service_instance
      end
    end
  end
end

#push_app_and_bind_with_service_instance(app, service_instance, &_block) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/prof/cloud_foundry.rb', line 77

def push_app_and_bind_with_service_instance(app, service_instance, &_block)
  push_app(app) do |pushed_app|
    bind_service_and_run(pushed_app, service_instance) do
      yield pushed_app, service_instance
    end
  end
end