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

#auth_tokenObject



158
159
160
# File 'lib/prof/cloud_foundry.rb', line 158

def auth_token
  hula_cloud_foundry.auth_token
end

#bind_service_and_keep_running(pushed_app_name, service_instance_name) ⇒ Object



93
94
95
96
# File 'lib/prof/cloud_foundry.rb', line 93

def bind_service_and_keep_running(pushed_app_name, service_instance_name)
  hula_cloud_foundry.bind_app_to_service(pushed_app_name, service_instance_name)
  hula_cloud_foundry.start_app(pushed_app_name)
end

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



98
99
100
101
102
103
104
105
# File 'lib/prof/cloud_foundry.rb', line 98

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)


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

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



136
137
138
# File 'lib/prof/cloud_foundry.rb', line 136

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



70
71
72
73
# File 'lib/prof/cloud_foundry.rb', line 70

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



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

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

#provision_and_create_service_key(service, &_block) ⇒ Object



111
112
113
114
115
116
117
# File 'lib/prof/cloud_foundry.rb', line 111

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_and_keep_service(service) ⇒ Object



140
141
142
143
144
145
# File 'lib/prof/cloud_foundry.rb', line 140

def provision_and_keep_service(service)
  service_instance = ServiceInstance.new

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

#provision_service(service, options = {}, &_block) ⇒ Object



147
148
149
150
151
152
153
154
155
156
# File 'lib/prof/cloud_foundry.rb', line 147

def provision_service(service, options = {}, &_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, options)
end

#push_and_keep_app(app) ⇒ Object



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

def push_and_keep_app(app)
  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)
  [deployed_app.name, deployed_app.url]
end

#push_app(app, &_block) ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/prof/cloud_foundry.rb', line 59

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



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

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



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

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

#unbind_app_from_service(pushed_app, service_instance) ⇒ Object



107
108
109
# File 'lib/prof/cloud_foundry.rb', line 107

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