cloulu 0.0.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/{cloulu → cl} +0 -0
- data/lib/cc_api_stub/applications.rb +53 -0
- data/lib/cc_api_stub/domains.rb +16 -0
- data/lib/cc_api_stub/frameworks.rb +22 -0
- data/lib/cc_api_stub/helper.rb +131 -0
- data/lib/cc_api_stub/login.rb +21 -0
- data/lib/cc_api_stub/organization_users.rb +21 -0
- data/lib/cc_api_stub/organizations.rb +70 -0
- data/lib/cc_api_stub/routes.rb +26 -0
- data/lib/cc_api_stub/runtimes.rb +22 -0
- data/lib/cc_api_stub/service_bindings.rb +22 -0
- data/lib/cc_api_stub/service_instances.rb +22 -0
- data/lib/cc_api_stub/services.rb +25 -0
- data/lib/cc_api_stub/spaces.rb +49 -0
- data/lib/cc_api_stub/users.rb +84 -0
- data/lib/cc_api_stub.rb +17 -0
- data/lib/cfoundry/auth_token.rb +63 -0
- data/lib/cfoundry/baseclient.rb +201 -0
- data/lib/cfoundry/chatty_hash.rb +46 -0
- data/lib/cfoundry/client.rb +46 -0
- data/lib/cfoundry/concerns/login_helpers.rb +13 -0
- data/lib/cfoundry/errors.rb +160 -0
- data/lib/cfoundry/rest_client.rb +299 -0
- data/lib/cfoundry/test_support.rb +3 -0
- data/lib/cfoundry/trace_helpers.rb +40 -0
- data/lib/cfoundry/uaaclient.rb +112 -0
- data/lib/cfoundry/upload_helpers.rb +187 -0
- data/lib/cfoundry/v1/app.rb +363 -0
- data/lib/cfoundry/v1/base.rb +72 -0
- data/lib/cfoundry/v1/client.rb +193 -0
- data/lib/cfoundry/v1/framework.rb +21 -0
- data/lib/cfoundry/v1/model.rb +178 -0
- data/lib/cfoundry/v1/model_magic.rb +129 -0
- data/lib/cfoundry/v1/runtime.rb +24 -0
- data/lib/cfoundry/v1/service.rb +39 -0
- data/lib/cfoundry/v1/service_instance.rb +32 -0
- data/lib/cfoundry/v1/service_plan.rb +19 -0
- data/lib/cfoundry/v1/user.rb +22 -0
- data/lib/cfoundry/v2/app.rb +392 -0
- data/lib/cfoundry/v2/base.rb +83 -0
- data/lib/cfoundry/v2/client.rb +138 -0
- data/lib/cfoundry/v2/domain.rb +11 -0
- data/lib/cfoundry/v2/framework.rb +14 -0
- data/lib/cfoundry/v2/model.rb +148 -0
- data/lib/cfoundry/v2/model_magic.rb +449 -0
- data/lib/cfoundry/v2/organization.rb +16 -0
- data/lib/cfoundry/v2/route.rb +15 -0
- data/lib/cfoundry/v2/runtime.rb +12 -0
- data/lib/cfoundry/v2/service.rb +19 -0
- data/lib/cfoundry/v2/service_auth_token.rb +9 -0
- data/lib/cfoundry/v2/service_binding.rb +10 -0
- data/lib/cfoundry/v2/service_instance.rb +14 -0
- data/lib/cfoundry/v2/service_plan.rb +12 -0
- data/lib/cfoundry/v2/space.rb +18 -0
- data/lib/cfoundry/v2/user.rb +64 -0
- data/lib/cfoundry/validator.rb +39 -0
- data/lib/cfoundry/version.rb +4 -0
- data/lib/cfoundry/zip.rb +56 -0
- data/lib/cfoundry.rb +2 -0
- data/lib/manifests-vmc-plugin/errors.rb +21 -0
- data/lib/manifests-vmc-plugin/loader/builder.rb +34 -0
- data/lib/manifests-vmc-plugin/loader/normalizer.rb +149 -0
- data/lib/manifests-vmc-plugin/loader/resolver.rb +79 -0
- data/lib/manifests-vmc-plugin/loader.rb +31 -0
- data/lib/manifests-vmc-plugin/plugin.rb +145 -0
- data/lib/manifests-vmc-plugin/version.rb +3 -0
- data/lib/manifests-vmc-plugin.rb +313 -0
- data/lib/mothership/base.rb +99 -0
- data/lib/mothership/callbacks.rb +85 -0
- data/lib/mothership/command.rb +146 -0
- data/lib/mothership/errors.rb +38 -0
- data/lib/mothership/help/commands.rb +53 -0
- data/lib/mothership/help/printer.rb +170 -0
- data/lib/mothership/help.rb +64 -0
- data/lib/mothership/inputs.rb +189 -0
- data/lib/mothership/parser.rb +182 -0
- data/lib/mothership/version.rb +3 -0
- data/lib/mothership.rb +64 -0
- data/lib/tunnel-vmc-plugin/plugin.rb +178 -0
- data/lib/tunnel-vmc-plugin/tunnel.rb +308 -0
- data/lib/tunnel-vmc-plugin/version.rb +3 -0
- data/lib/uaa/http.rb +168 -0
- data/lib/uaa/misc.rb +121 -0
- data/lib/uaa/scim.rb +292 -0
- data/lib/uaa/token_coder.rb +196 -0
- data/lib/uaa/token_issuer.rb +255 -0
- data/lib/uaa/util.rb +235 -0
- data/lib/uaa/version.rb +19 -0
- data/lib/uaa.rb +18 -0
- data/lib/vmc/cli/app/app.rb +45 -0
- data/lib/vmc/cli/app/apps.rb +99 -0
- data/lib/vmc/cli/app/base.rb +90 -0
- data/lib/vmc/cli/app/crashes.rb +42 -0
- data/lib/vmc/cli/app/delete.rb +95 -0
- data/lib/vmc/cli/app/deprecated.rb +11 -0
- data/lib/vmc/cli/app/env.rb +78 -0
- data/lib/vmc/cli/app/files.rb +137 -0
- data/lib/vmc/cli/app/health.rb +26 -0
- data/lib/vmc/cli/app/instances.rb +53 -0
- data/lib/vmc/cli/app/logs.rb +76 -0
- data/lib/vmc/cli/app/push/create.rb +165 -0
- data/lib/vmc/cli/app/push/interactions.rb +94 -0
- data/lib/vmc/cli/app/push/sync.rb +64 -0
- data/lib/vmc/cli/app/push.rb +109 -0
- data/lib/vmc/cli/app/rename.rb +35 -0
- data/lib/vmc/cli/app/restart.rb +20 -0
- data/lib/vmc/cli/app/scale.rb +71 -0
- data/lib/vmc/cli/app/start.rb +143 -0
- data/lib/vmc/cli/app/stats.rb +67 -0
- data/lib/vmc/cli/app/stop.rb +27 -0
- data/lib/vmc/cli/help.rb +11 -0
- data/lib/vmc/cli/interactive.rb +105 -0
- data/lib/vmc/cli/route/base.rb +12 -0
- data/lib/vmc/cli/route/map.rb +82 -0
- data/lib/vmc/cli/route/routes.rb +25 -0
- data/lib/vmc/cli/route/unmap.rb +94 -0
- data/lib/vmc/cli/service/base.rb +8 -0
- data/lib/vmc/cli/service/bind.rb +44 -0
- data/lib/vmc/cli/service/create.rb +126 -0
- data/lib/vmc/cli/service/delete.rb +86 -0
- data/lib/vmc/cli/service/rename.rb +35 -0
- data/lib/vmc/cli/service/service.rb +42 -0
- data/lib/vmc/cli/service/services.rb +114 -0
- data/lib/vmc/cli/service/unbind.rb +38 -0
- data/lib/vmc/cli/start/base.rb +94 -0
- data/lib/vmc/cli/start/colors.rb +13 -0
- data/lib/vmc/cli/start/info.rb +126 -0
- data/lib/vmc/cli/start/login.rb +97 -0
- data/lib/vmc/cli/start/logout.rb +17 -0
- data/lib/vmc/cli/start/target.rb +60 -0
- data/lib/vmc/cli/start/target_interactions.rb +37 -0
- data/lib/vmc/cli/start/targets.rb +16 -0
- data/lib/vmc/cli/user/base.rb +29 -0
- data/lib/vmc/cli/user/create.rb +39 -0
- data/lib/vmc/cli/user/delete.rb +27 -0
- data/lib/vmc/cli/user/passwd.rb +50 -0
- data/lib/vmc/cli/user/register.rb +42 -0
- data/lib/vmc/cli/user/users.rb +32 -0
- data/lib/vmc/cli/v2_check_cli.rb +16 -0
- data/lib/vmc/cli.rb +474 -0
- data/lib/vmc/constants.rb +13 -0
- data/lib/vmc/detect.rb +129 -0
- data/lib/vmc/errors.rb +19 -0
- data/lib/vmc/plugin.rb +56 -0
- data/lib/vmc/spacing.rb +89 -0
- data/lib/vmc/spec_helper.rb +1 -0
- data/lib/vmc/test_support.rb +6 -0
- data/lib/vmc/version.rb +3 -0
- data/lib/vmc.rb +8 -0
- data/vendor/errors/v1.yml +189 -0
- data/vendor/errors/v2.yml +360 -0
- metadata +303 -190
@@ -0,0 +1,363 @@
|
|
1
|
+
require "cfoundry/upload_helpers"
|
2
|
+
require "cfoundry/chatty_hash"
|
3
|
+
|
4
|
+
require "cfoundry/v1/model"
|
5
|
+
|
6
|
+
module CFoundry::V1
|
7
|
+
class App < Model
|
8
|
+
include CFoundry::UploadHelpers
|
9
|
+
|
10
|
+
attribute :name, :string, :guid => true
|
11
|
+
attribute :instances, :integer
|
12
|
+
attribute :state, :string
|
13
|
+
attribute :created, :integer, :at => [:meta, :created], :read_only => true
|
14
|
+
attribute :version, :integer, :at => [:meta, :version], :read_only => true
|
15
|
+
attribute :framework, :string, :at => [:staging, :model]
|
16
|
+
attribute :runtime, :string, :at => [:staging, :stack]
|
17
|
+
attribute :command, :string, :at => [:staging, :command]
|
18
|
+
attribute :memory, :integer, :at => [:resources, :memory]
|
19
|
+
attribute :disk, :integer, :at => [:resources, :disk]
|
20
|
+
attribute :fds, :integer, :at => [:resources, :fds]
|
21
|
+
attribute :env, [:string], :default => []
|
22
|
+
attribute :uris, [:string], :default => []
|
23
|
+
attribute :services, [:string], :default => []
|
24
|
+
|
25
|
+
attribute :console, :boolean, :default => false,
|
26
|
+
:read => [:meta, :console], :write => :console
|
27
|
+
|
28
|
+
attribute :debug, :string, :default => nil, :read => [:meta, :debug],
|
29
|
+
:write => :debug
|
30
|
+
|
31
|
+
attribute :running_instances, :integer, :read => :runningInstances,
|
32
|
+
:read_only => true
|
33
|
+
|
34
|
+
|
35
|
+
define_client_methods
|
36
|
+
|
37
|
+
|
38
|
+
alias_method :total_instances, :instances
|
39
|
+
alias_method :total_instances=, :instances=
|
40
|
+
|
41
|
+
alias_method :debug_mode, :debug
|
42
|
+
alias_method :debug_mode=, :debug=
|
43
|
+
|
44
|
+
alias_method :framework_name, :framework
|
45
|
+
alias_method :framework_name=, :framework=
|
46
|
+
|
47
|
+
alias_method :runtime_name, :runtime
|
48
|
+
alias_method :runtime_name=, :runtime=
|
49
|
+
|
50
|
+
alias_method :service_names, :services
|
51
|
+
alias_method :service_names=, :services=
|
52
|
+
|
53
|
+
alias_method :status, :state
|
54
|
+
alias_method :status=, :state=
|
55
|
+
|
56
|
+
alias_method :urls, :uris
|
57
|
+
alias_method :urls=, :uris=
|
58
|
+
|
59
|
+
alias_method :env_array, :env
|
60
|
+
alias_method :env_array=, :env=
|
61
|
+
|
62
|
+
def framework
|
63
|
+
@client.framework(framework_name)
|
64
|
+
end
|
65
|
+
|
66
|
+
def framework=(obj)
|
67
|
+
set_named(:framework, obj)
|
68
|
+
end
|
69
|
+
|
70
|
+
def runtime
|
71
|
+
@client.runtime(runtime_name)
|
72
|
+
end
|
73
|
+
|
74
|
+
def runtime=(obj)
|
75
|
+
set_named(:runtime, obj)
|
76
|
+
end
|
77
|
+
|
78
|
+
def services
|
79
|
+
service_names.collect { |name| @client.service_instance(name) }
|
80
|
+
end
|
81
|
+
|
82
|
+
def services=(objs)
|
83
|
+
set_many_named(:service, objs)
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
# Retrieve all of the instances of the app, as Instance objects.
|
88
|
+
def instances
|
89
|
+
@client.base.instances(@guid).collect do |m|
|
90
|
+
Instance.new(self, m[:index].to_s, @client, m)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# Retrieve crashed instances
|
95
|
+
def crashes
|
96
|
+
@client.base.crashes(@guid).collect do |i|
|
97
|
+
Instance.new(self, i[:instance].to_s, @client, i)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# Retrieve application statistics, e.g. CPU load and memory usage.
|
102
|
+
def stats
|
103
|
+
stats = {}
|
104
|
+
|
105
|
+
@client.base.stats(@guid).each do |idx, info|
|
106
|
+
stats[idx.to_s] = info
|
107
|
+
end
|
108
|
+
|
109
|
+
stats
|
110
|
+
end
|
111
|
+
|
112
|
+
# Stop the application.
|
113
|
+
def stop!
|
114
|
+
self.state = "STOPPED"
|
115
|
+
update!
|
116
|
+
end
|
117
|
+
|
118
|
+
# Start the application.
|
119
|
+
def start!(async = false)
|
120
|
+
self.state = "STARTED"
|
121
|
+
update!
|
122
|
+
end
|
123
|
+
|
124
|
+
# Restart the application.
|
125
|
+
def restart!(async = false)
|
126
|
+
stop!
|
127
|
+
start!
|
128
|
+
end
|
129
|
+
|
130
|
+
def update!(async = false)
|
131
|
+
super()
|
132
|
+
end
|
133
|
+
|
134
|
+
# Determine application health.
|
135
|
+
#
|
136
|
+
# If all instances are running, returns "RUNNING". If only some are
|
137
|
+
# started, returns the precentage of them that are healthy.
|
138
|
+
#
|
139
|
+
# Otherwise, returns application's status.
|
140
|
+
def health
|
141
|
+
s = state
|
142
|
+
if s == "STARTED"
|
143
|
+
healthy_count = running_instances
|
144
|
+
expected = total_instances
|
145
|
+
|
146
|
+
if healthy_count && expected > 0
|
147
|
+
ratio = healthy_count / expected.to_f
|
148
|
+
if ratio == 1.0
|
149
|
+
"RUNNING"
|
150
|
+
else
|
151
|
+
"#{(ratio * 100).to_i}%"
|
152
|
+
end
|
153
|
+
else
|
154
|
+
"N/A"
|
155
|
+
end
|
156
|
+
else
|
157
|
+
s
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
# Check that all application instances are running.
|
162
|
+
def healthy?
|
163
|
+
# invalidate cache so the check is fresh
|
164
|
+
invalidate!
|
165
|
+
health == "RUNNING"
|
166
|
+
end
|
167
|
+
alias_method :running?, :healthy?
|
168
|
+
|
169
|
+
# Is the application stopped?
|
170
|
+
def stopped?
|
171
|
+
state == "STOPPED"
|
172
|
+
end
|
173
|
+
|
174
|
+
# Is the application started?
|
175
|
+
#
|
176
|
+
# Note that this does not imply that all instances are running. See
|
177
|
+
# #healthy?
|
178
|
+
def started?
|
179
|
+
state == "STARTED"
|
180
|
+
end
|
181
|
+
|
182
|
+
|
183
|
+
# Shortcut for uris[0]
|
184
|
+
def uri
|
185
|
+
uris[0]
|
186
|
+
end
|
187
|
+
|
188
|
+
# Shortcut for uris = [x]
|
189
|
+
def uri=(x)
|
190
|
+
self.uris = [x]
|
191
|
+
end
|
192
|
+
|
193
|
+
alias_method :url, :uri
|
194
|
+
alias_method :url=, :uri=
|
195
|
+
|
196
|
+
def env
|
197
|
+
e = env_array || []
|
198
|
+
|
199
|
+
env = {}
|
200
|
+
e.each do |pair|
|
201
|
+
name, val = pair.split("=", 2)
|
202
|
+
env[name] = val
|
203
|
+
end
|
204
|
+
|
205
|
+
CFoundry::ChattyHash.new(method(:env=), env)
|
206
|
+
end
|
207
|
+
|
208
|
+
def env=(hash)
|
209
|
+
unless hash.is_a?(Array)
|
210
|
+
hash = hash.collect { |k, v| "#{k}=#{v}" }
|
211
|
+
end
|
212
|
+
|
213
|
+
self.env_array = hash
|
214
|
+
end
|
215
|
+
|
216
|
+
def services
|
217
|
+
service_names.collect do |name|
|
218
|
+
@client.service_instance(name)
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
def services=(instances)
|
223
|
+
self.service_names = instances.collect(&:name)
|
224
|
+
end
|
225
|
+
|
226
|
+
|
227
|
+
# Bind services to application.
|
228
|
+
def bind(*instances)
|
229
|
+
self.services += instances
|
230
|
+
update!
|
231
|
+
end
|
232
|
+
|
233
|
+
# Unbind services from application.
|
234
|
+
def unbind(*instances)
|
235
|
+
self.services -= instances
|
236
|
+
update!
|
237
|
+
end
|
238
|
+
|
239
|
+
def binds?(instance)
|
240
|
+
services.include? instance
|
241
|
+
end
|
242
|
+
|
243
|
+
# Retrieve file listing under path for the first instance of the application.
|
244
|
+
#
|
245
|
+
# [path]
|
246
|
+
# A sequence of strings representing path segments.
|
247
|
+
#
|
248
|
+
# For example, <code>files("foo", "bar")</code> for +foo/bar+.
|
249
|
+
def files(*path)
|
250
|
+
Instance.new(self, "0", @client).files(*path)
|
251
|
+
end
|
252
|
+
|
253
|
+
# Retrieve file contents for the first instance of the application.
|
254
|
+
#
|
255
|
+
# [path]
|
256
|
+
# A sequence of strings representing path segments.
|
257
|
+
#
|
258
|
+
# For example, <code>files("foo", "bar")</code> for +foo/bar+.
|
259
|
+
def file(*path)
|
260
|
+
Instance.new(self, "0", @client).file(*path)
|
261
|
+
end
|
262
|
+
|
263
|
+
private
|
264
|
+
|
265
|
+
def set_named(attr, val)
|
266
|
+
res = send(:"#{attr}_name=", val.name)
|
267
|
+
|
268
|
+
if @changes.key?(attr)
|
269
|
+
old, new = @changes[attr]
|
270
|
+
@changes[attr] = [@client.send(attr, old), val]
|
271
|
+
end
|
272
|
+
|
273
|
+
res
|
274
|
+
end
|
275
|
+
|
276
|
+
def set_many_named(attr, vals)
|
277
|
+
res = send(:"#{attr}_names=", val.collect(&:name))
|
278
|
+
|
279
|
+
if @changes.key?(attr)
|
280
|
+
old, new = @changes[attr]
|
281
|
+
@changes[attr] = [old.collect { |o| @client.send(attr, o) }, vals]
|
282
|
+
end
|
283
|
+
|
284
|
+
vals
|
285
|
+
end
|
286
|
+
|
287
|
+
# Class represnting a running instance of an application.
|
288
|
+
class Instance
|
289
|
+
# The application this instance belongs to.
|
290
|
+
attr_reader :app
|
291
|
+
|
292
|
+
# Application instance number.
|
293
|
+
attr_reader :id
|
294
|
+
|
295
|
+
# Create an Instance object.
|
296
|
+
#
|
297
|
+
# You'll usually call App#instances instead
|
298
|
+
def initialize(app, id, client, manifest = {})
|
299
|
+
@app = app
|
300
|
+
@id = id
|
301
|
+
@client = client
|
302
|
+
@manifest = manifest
|
303
|
+
end
|
304
|
+
|
305
|
+
# Show string representing the application instance.
|
306
|
+
def inspect
|
307
|
+
"#<App::Instance '#{@app.name}' \##@id>"
|
308
|
+
end
|
309
|
+
|
310
|
+
# Instance state.
|
311
|
+
def state
|
312
|
+
@manifest[:state]
|
313
|
+
end
|
314
|
+
alias_method :status, :state
|
315
|
+
|
316
|
+
# Instance start time.
|
317
|
+
def since
|
318
|
+
Time.at(@manifest[:since])
|
319
|
+
end
|
320
|
+
|
321
|
+
# Instance debugger data. If instance is in debug mode, returns a hash
|
322
|
+
# containing :ip and :port keys.
|
323
|
+
def debugger
|
324
|
+
return unless @manifest[:debug_ip] and @manifest[:debug_port]
|
325
|
+
|
326
|
+
{ :ip => @manifest[:debug_ip],
|
327
|
+
:port => @manifest[:debug_port]
|
328
|
+
}
|
329
|
+
end
|
330
|
+
|
331
|
+
# Instance console data. If instance has a console, returns a hash
|
332
|
+
# containing :ip and :port keys.
|
333
|
+
def console
|
334
|
+
return unless @manifest[:console_ip] and @manifest[:console_port]
|
335
|
+
|
336
|
+
{ :ip => @manifest[:console_ip],
|
337
|
+
:port => @manifest[:console_port]
|
338
|
+
}
|
339
|
+
end
|
340
|
+
|
341
|
+
# True if instance is starting or running, false if it's down or
|
342
|
+
# flapping.
|
343
|
+
def healthy?
|
344
|
+
case state
|
345
|
+
when "STARTING", "RUNNING"
|
346
|
+
true
|
347
|
+
when "DOWN", "FLAPPING"
|
348
|
+
false
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
def files(*path)
|
353
|
+
@client.base.files(@app.name, @id, *path).split("\n").collect do |entry|
|
354
|
+
path + [entry.split(/\s+/, 2)[0]]
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
def file(*path)
|
359
|
+
@client.base.files(@app.name, @id, *path)
|
360
|
+
end
|
361
|
+
end
|
362
|
+
end
|
363
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require "multi_json"
|
2
|
+
|
3
|
+
require "cfoundry/baseclient"
|
4
|
+
require "cfoundry/uaaclient"
|
5
|
+
|
6
|
+
require "cfoundry/errors"
|
7
|
+
|
8
|
+
module CFoundry::V1
|
9
|
+
class Base < CFoundry::BaseClient
|
10
|
+
include BaseClientMethods
|
11
|
+
|
12
|
+
def system_services
|
13
|
+
get("services", "v1", "offerings", :content => :json, :accept => :json)
|
14
|
+
end
|
15
|
+
|
16
|
+
def system_runtimes
|
17
|
+
get("info", "runtimes", :accept => :json)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Users
|
21
|
+
def create_user(payload)
|
22
|
+
p payload
|
23
|
+
# no JSON response
|
24
|
+
post("users", :content => :json, :payload => payload)
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_token(payload, email)
|
28
|
+
post("users", email, "tokens", :content => :json, :accept => :json, :payload => payload)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Applications
|
32
|
+
def instances(name)
|
33
|
+
get("apps", name, "instances", :accept => :json)[:instances]
|
34
|
+
end
|
35
|
+
|
36
|
+
def crashes(name)
|
37
|
+
get("apps", name, "crashes", :accept => :json)[:crashes]
|
38
|
+
end
|
39
|
+
|
40
|
+
def files(name, instance, *path)
|
41
|
+
get("apps", name, "instances", instance, "files", *path)
|
42
|
+
end
|
43
|
+
alias :file :files
|
44
|
+
|
45
|
+
def stats(name)
|
46
|
+
get("apps", name, "stats", :accept => :json)
|
47
|
+
end
|
48
|
+
|
49
|
+
def resource_match(fingerprints)
|
50
|
+
post("resources", :content => :json, :accept => :json, :payload => fingerprints)
|
51
|
+
end
|
52
|
+
|
53
|
+
def upload_app(name, zipfile = nil, resources = [])
|
54
|
+
payload = {
|
55
|
+
:_method => "put",
|
56
|
+
:resources => MultiJson.dump(resources),
|
57
|
+
:application =>
|
58
|
+
UploadIO.new(
|
59
|
+
if zipfile.is_a? File
|
60
|
+
zipfile
|
61
|
+
elsif zipfile.is_a? String
|
62
|
+
File.new(zipfile, "rb")
|
63
|
+
end,
|
64
|
+
"application/zip")
|
65
|
+
}
|
66
|
+
|
67
|
+
post("apps", name, "application", :payload => payload)
|
68
|
+
rescue EOFError
|
69
|
+
retry
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,193 @@
|
|
1
|
+
require File.expand_path("../../concerns/login_helpers", __FILE__)
|
2
|
+
|
3
|
+
module CFoundry::V1
|
4
|
+
# The primary API entrypoint. Wraps a BaseClient to provide nicer return
|
5
|
+
# values. Initialize with the target and, optionally, an auth token. These
|
6
|
+
# are the only two internal states.
|
7
|
+
class Client
|
8
|
+
include ClientMethods, CFoundry::LoginHelpers
|
9
|
+
|
10
|
+
attr_reader :base
|
11
|
+
|
12
|
+
# Create a new Client for interfacing with the given target.
|
13
|
+
#
|
14
|
+
# A token may also be provided to skip the login step.
|
15
|
+
def initialize(target = "https://api.cloulu.com", token = nil)
|
16
|
+
@base = Base.new(target, token)
|
17
|
+
end
|
18
|
+
|
19
|
+
def version
|
20
|
+
1
|
21
|
+
end
|
22
|
+
|
23
|
+
# The current target URL of the client.
|
24
|
+
def target
|
25
|
+
@base.target
|
26
|
+
end
|
27
|
+
|
28
|
+
# Current authentication token.
|
29
|
+
def token
|
30
|
+
@base.token
|
31
|
+
end
|
32
|
+
|
33
|
+
# Set the authentication token.
|
34
|
+
def token=(token)
|
35
|
+
@base.token = token
|
36
|
+
end
|
37
|
+
|
38
|
+
# Current proxy user. Usually nil.
|
39
|
+
def proxy
|
40
|
+
@base.proxy
|
41
|
+
end
|
42
|
+
|
43
|
+
# Set the proxy user for the client. Must be authorized as an
|
44
|
+
# administrator for this to have any effect.
|
45
|
+
def proxy=(email)
|
46
|
+
@base.proxy = email
|
47
|
+
end
|
48
|
+
|
49
|
+
# Is the client tracing API requests?
|
50
|
+
def trace
|
51
|
+
@base.trace
|
52
|
+
end
|
53
|
+
|
54
|
+
# Set the tracing flag; if true, API requests and responses will be
|
55
|
+
# printed out.
|
56
|
+
def trace=(bool)
|
57
|
+
@base.trace = bool
|
58
|
+
end
|
59
|
+
|
60
|
+
# The current log. See +log=+.
|
61
|
+
def log
|
62
|
+
@base.log
|
63
|
+
end
|
64
|
+
|
65
|
+
# Set the logging mode. Mode can be one of:
|
66
|
+
#
|
67
|
+
# [+String+] Name of a file to log the last 10 requests to.
|
68
|
+
# [+Array+] Array to append with log data (a Hash).
|
69
|
+
# [+IO+] An IO object to write to.
|
70
|
+
# [+false+] No logging.
|
71
|
+
def log=(mode)
|
72
|
+
@base.log = mode
|
73
|
+
end
|
74
|
+
|
75
|
+
# The currently authenticated user.
|
76
|
+
def current_user
|
77
|
+
if user = info[:user]
|
78
|
+
user(user)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def current_space
|
83
|
+
nil
|
84
|
+
end
|
85
|
+
|
86
|
+
def current_organization
|
87
|
+
nil
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
# Retrieve target metadata.
|
92
|
+
def info
|
93
|
+
@base.info
|
94
|
+
end
|
95
|
+
|
96
|
+
# Retrieve available services.
|
97
|
+
def services(options = {})
|
98
|
+
services = []
|
99
|
+
|
100
|
+
@base.system_services.each do |type, vendors|
|
101
|
+
vendors.each do |vendor, providers|
|
102
|
+
providers.each do |provider, properties|
|
103
|
+
properties.each do |_, meta|
|
104
|
+
meta[:supported_versions].each do |ver|
|
105
|
+
state = meta[:version_aliases].find { |k, v| v == ver }
|
106
|
+
|
107
|
+
services <<
|
108
|
+
Service.new(vendor.to_s, ver.to_s, meta[:description],
|
109
|
+
type.to_s, provider.to_s, state && state.first,
|
110
|
+
generate_plans(meta))
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
services
|
118
|
+
end
|
119
|
+
|
120
|
+
def generate_plans(meta)
|
121
|
+
names = meta[:plans]
|
122
|
+
descriptions = meta[:plan_descriptions]
|
123
|
+
default_name = meta[:default_plan]
|
124
|
+
names.map { |name|
|
125
|
+
description = descriptions[name.to_sym] if descriptions
|
126
|
+
is_default = name == default_name || names.length == 1
|
127
|
+
ServicePlan.new(name, description, is_default)
|
128
|
+
}
|
129
|
+
end
|
130
|
+
|
131
|
+
# Retrieve available runtimes.
|
132
|
+
def runtimes(options = {})
|
133
|
+
runtimes = []
|
134
|
+
|
135
|
+
@base.system_runtimes.each do |name, meta|
|
136
|
+
runtimes <<
|
137
|
+
Runtime.new(name.to_s, meta[:version], meta[:debug_modes])
|
138
|
+
end
|
139
|
+
|
140
|
+
runtimes
|
141
|
+
end
|
142
|
+
|
143
|
+
def runtime(name)
|
144
|
+
Runtime.new(name)
|
145
|
+
end
|
146
|
+
|
147
|
+
def runtime_by_name(name)
|
148
|
+
runtimes.find { |r| r.name == name }
|
149
|
+
end
|
150
|
+
|
151
|
+
# Retrieve available frameworks.
|
152
|
+
def frameworks(options = {})
|
153
|
+
fs = info[:frameworks]
|
154
|
+
return unless fs
|
155
|
+
|
156
|
+
frameworks = []
|
157
|
+
fs.each do |name, meta|
|
158
|
+
runtimes = meta[:runtimes].collect do |r|
|
159
|
+
Runtime.new(r[:name], r[:description])
|
160
|
+
end
|
161
|
+
|
162
|
+
frameworks <<
|
163
|
+
Framework.new(name.to_s, nil, runtimes, meta[:detection])
|
164
|
+
end
|
165
|
+
|
166
|
+
frameworks
|
167
|
+
end
|
168
|
+
|
169
|
+
def framework(name)
|
170
|
+
Framework.new(name)
|
171
|
+
end
|
172
|
+
|
173
|
+
def framework_by_name(name)
|
174
|
+
frameworks.find { |f| f.name == name }
|
175
|
+
end
|
176
|
+
|
177
|
+
# Create a user on the target and return a User object representing them.
|
178
|
+
def register(email, password)
|
179
|
+
@base.create_user(:email => email, :password => password)
|
180
|
+
user(email)
|
181
|
+
end
|
182
|
+
|
183
|
+
# Clear client token. No requests are made for this.
|
184
|
+
def logout
|
185
|
+
@base.token = nil
|
186
|
+
end
|
187
|
+
|
188
|
+
# Is an authentication token set on the client?
|
189
|
+
def logged_in?
|
190
|
+
!!@base.token
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module CFoundry::V1
|
2
|
+
class Framework
|
3
|
+
attr_accessor :name, :description, :runtimes, :detection
|
4
|
+
|
5
|
+
def initialize(name, description = nil, runtimes = [], detection = nil)
|
6
|
+
@name = name
|
7
|
+
@description = description
|
8
|
+
@runtimes = runtimes
|
9
|
+
@detection = detection
|
10
|
+
end
|
11
|
+
|
12
|
+
def eql?(other)
|
13
|
+
other.is_a?(self.class) && other.name == @name
|
14
|
+
end
|
15
|
+
alias :== :eql?
|
16
|
+
|
17
|
+
def apps
|
18
|
+
[] # not supported by v1
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|