cfoundry 0.6.1.rc3 → 0.6.1.rc4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cfoundry/client.rb +1 -0
- data/lib/cfoundry/v2/app.rb +15 -0
- data/lib/cfoundry/v2/model.rb +2 -2
- data/lib/cfoundry/v2/model_magic.rb +25 -12
- data/lib/cfoundry/v2/organization.rb +3 -0
- data/lib/cfoundry/v2/quota_definition.rb +12 -0
- data/lib/cfoundry/version.rb +1 -1
- data/spec/cfoundry/v2/app_spec.rb +78 -0
- data/spec/cfoundry/v2/model_spec.rb +34 -0
- data/spec/cfoundry/v2/organization_spec.rb +17 -2
- data/spec/cfoundry/v2/quota_definition_spec.rb +52 -0
- metadata +8 -3
data/lib/cfoundry/client.rb
CHANGED
data/lib/cfoundry/v2/app.rb
CHANGED
@@ -175,6 +175,21 @@ module CFoundry::V2
|
|
175
175
|
true
|
176
176
|
end
|
177
177
|
|
178
|
+
def stream_update_log(log_url)
|
179
|
+
offset = 0
|
180
|
+
|
181
|
+
while true
|
182
|
+
begin
|
183
|
+
@client.stream_url(log_url + "&tail&tail_offset=#{offset}") do |out|
|
184
|
+
offset += out.size
|
185
|
+
yield out
|
186
|
+
end
|
187
|
+
rescue Timeout::Error
|
188
|
+
end
|
189
|
+
end
|
190
|
+
rescue CFoundry::APIError
|
191
|
+
end
|
192
|
+
|
178
193
|
# Determine application health.
|
179
194
|
#
|
180
195
|
# If all instances are running, returns "RUNNING". If only some are
|
data/lib/cfoundry/v2/model.rb
CHANGED
@@ -58,27 +58,40 @@ module CFoundry::V2
|
|
58
58
|
|
59
59
|
define_base_client_methods do
|
60
60
|
define_method(singular) do |guid, *args|
|
61
|
-
get("v2", plural, guid,
|
62
|
-
|
61
|
+
get("v2", plural, guid,
|
62
|
+
:accept => :json,
|
63
|
+
:params => ModelMagic.params_from(args)
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
define_method(plural) do |*args|
|
68
|
+
all_pages(
|
69
|
+
get("v2", plural,
|
70
|
+
:accept => :json,
|
71
|
+
:params => ModelMagic.params_from(args)
|
72
|
+
)
|
73
|
+
)
|
63
74
|
end
|
64
75
|
|
65
76
|
define_method(:"create_#{singular}") do |payload|
|
66
|
-
post("v2", plural,
|
77
|
+
post("v2", plural,
|
78
|
+
:content => :json,
|
79
|
+
:accept => :json,
|
80
|
+
:payload => payload
|
81
|
+
)
|
67
82
|
end
|
68
83
|
|
69
|
-
define_method(:"delete_#{singular}") do |guid|
|
70
|
-
delete("v2", plural, guid)
|
84
|
+
define_method(:"delete_#{singular}") do |guid, params|
|
85
|
+
delete("v2", plural, guid, :params => params)
|
71
86
|
true
|
72
87
|
end
|
73
88
|
|
74
89
|
define_method(:"update_#{singular}") do |guid, payload|
|
75
|
-
put("v2", plural, guid,
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
get("v2", plural, :accept => :json,
|
81
|
-
:params => ModelMagic.params_from(args)))
|
90
|
+
put("v2", plural, guid,
|
91
|
+
:content => :json,
|
92
|
+
:accept => :json,
|
93
|
+
:payload => payload
|
94
|
+
)
|
82
95
|
end
|
83
96
|
end
|
84
97
|
|
@@ -10,6 +10,9 @@ module CFoundry::V2
|
|
10
10
|
to_many :billing_managers, :as => :user
|
11
11
|
to_many :auditors, :as => :user
|
12
12
|
|
13
|
+
to_one :quota_definition
|
14
|
+
attribute :billing_enabled, :boolean
|
15
|
+
|
13
16
|
queryable_by :name, :space_guid, :user_guid, :manager_guid,
|
14
17
|
:billing_manager_guid, :auditor_guid
|
15
18
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "cfoundry/v2/model"
|
2
|
+
|
3
|
+
module CFoundry::V2
|
4
|
+
class QuotaDefinition < Model
|
5
|
+
attribute :name, :string
|
6
|
+
attribute :non_basic_services_allowed, :boolean
|
7
|
+
attribute :total_services, :integer
|
8
|
+
attribute :memory_limit, :integer
|
9
|
+
|
10
|
+
queryable_by :name
|
11
|
+
end
|
12
|
+
end
|
data/lib/cfoundry/version.rb
CHANGED
@@ -141,4 +141,82 @@ describe CFoundry::V2::App do
|
|
141
141
|
end
|
142
142
|
end
|
143
143
|
end
|
144
|
+
|
145
|
+
describe "#stream_update_log" do
|
146
|
+
let(:client) { fake_client }
|
147
|
+
let(:base_url) { "http://example.com/log" }
|
148
|
+
|
149
|
+
subject { described_class.new(nil, client) }
|
150
|
+
|
151
|
+
def mock_log(url = anything)
|
152
|
+
mock(client).stream_url(url) do |_, blk|
|
153
|
+
blk.call(yield)
|
154
|
+
end.ordered
|
155
|
+
end
|
156
|
+
|
157
|
+
def stub_log(url = anything)
|
158
|
+
stub(client).stream_url(url) do |_, blk|
|
159
|
+
blk.call(yield)
|
160
|
+
end.ordered
|
161
|
+
end
|
162
|
+
|
163
|
+
it "yields chunks from the response to the block" do
|
164
|
+
mock_log { "a" }
|
165
|
+
mock_log { "b" }
|
166
|
+
mock_log { raise CFoundry::NotFound }
|
167
|
+
|
168
|
+
chunks = []
|
169
|
+
subject.stream_update_log(base_url) do |chunk|
|
170
|
+
chunks << chunk
|
171
|
+
end
|
172
|
+
|
173
|
+
expect(chunks).to eq(%w(a b))
|
174
|
+
end
|
175
|
+
|
176
|
+
it "retries when the connection times out" do
|
177
|
+
mock_log { raise Timeout::Error }
|
178
|
+
mock_log { "a" }
|
179
|
+
mock_log { raise Timeout::Error }
|
180
|
+
mock_log { "b" }
|
181
|
+
mock_log { raise Timeout::Error }
|
182
|
+
mock_log { raise CFoundry::NotFound }
|
183
|
+
|
184
|
+
chunks = []
|
185
|
+
subject.stream_update_log(base_url) do |chunk|
|
186
|
+
chunks << chunk
|
187
|
+
end
|
188
|
+
|
189
|
+
expect(chunks).to eq(%w(a b))
|
190
|
+
end
|
191
|
+
|
192
|
+
it "tracks the offset to stream from" do
|
193
|
+
url = "#{base_url}&tail&tail_offset="
|
194
|
+
|
195
|
+
mock_log("#{url}0") { "a" }
|
196
|
+
mock_log("#{url}1") { raise Timeout::Error }
|
197
|
+
mock_log("#{url}1") { "b" }
|
198
|
+
mock_log("#{url}2") { raise CFoundry::NotFound }
|
199
|
+
|
200
|
+
chunks = []
|
201
|
+
subject.stream_update_log(base_url) do |chunk|
|
202
|
+
chunks << chunk
|
203
|
+
end
|
204
|
+
|
205
|
+
expect(chunks).to eq(%w(a b))
|
206
|
+
end
|
207
|
+
|
208
|
+
it "stops when the endpoint disappears" do
|
209
|
+
mock_log { "a" }
|
210
|
+
mock_log { "b" }
|
211
|
+
mock_log { raise CFoundry::NotFound }
|
212
|
+
stub_log { "c" }
|
213
|
+
|
214
|
+
chunks = []
|
215
|
+
subject.stream_update_log(base_url) do |chunk|
|
216
|
+
chunks << chunk
|
217
|
+
end
|
218
|
+
|
219
|
+
expect(chunks).to eq(%w(a b))
|
220
|
+
end
|
221
|
+
end
|
144
222
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe CFoundry::V2::Model do
|
4
|
+
let(:client) { fake_client }
|
5
|
+
let(:guid) { random_string("my-object-guid") }
|
6
|
+
|
7
|
+
subject { described_class.new(guid, client) }
|
8
|
+
|
9
|
+
describe "#delete!" do
|
10
|
+
before { stub(client.base).delete_model }
|
11
|
+
|
12
|
+
context "without options" do
|
13
|
+
it "sends delete with the object guid and an empty hash" do
|
14
|
+
mock(client.base).delete_model(guid, {})
|
15
|
+
subject.delete!
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "with options" do
|
20
|
+
it "sends delete with the object guid and options" do
|
21
|
+
options = {:excellent => "billandted"}
|
22
|
+
mock(client.base).delete_model(guid, options)
|
23
|
+
|
24
|
+
subject.delete!(options)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it "clears its guid" do
|
29
|
+
subject.guid.should be_present
|
30
|
+
subject.delete!
|
31
|
+
subject.guid.should_not be_present
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -3,13 +3,28 @@ require "spec_helper"
|
|
3
3
|
describe CFoundry::V2::Organization do
|
4
4
|
let(:client) { fake_client }
|
5
5
|
|
6
|
-
|
6
|
+
subject { CFoundry::V2::Organization.new("organization-1", client) }
|
7
|
+
|
8
|
+
describe "summarization" do
|
7
9
|
let(:mymodel) { CFoundry::V2::Organization }
|
8
10
|
let(:myobject) { fake(:organization) }
|
9
11
|
let(:summary_attributes) { { :name => "fizzbuzz" } }
|
10
12
|
|
11
13
|
subject { myobject }
|
12
14
|
|
13
|
-
it_behaves_like
|
15
|
+
it_behaves_like "a summarizeable model"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "has quota_definition" do
|
19
|
+
quota = fake(:quota_definition)
|
20
|
+
subject.quota_definition = quota
|
21
|
+
expect(subject.quota_definition).to eq(quota)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "has billing_enabled" do
|
25
|
+
[true, false].each do |v|
|
26
|
+
subject.billing_enabled = v
|
27
|
+
expect(subject.billing_enabled).to eq(v)
|
28
|
+
end
|
14
29
|
end
|
15
30
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe CFoundry::V2::QuotaDefinition do
|
4
|
+
let(:client) { fake_client }
|
5
|
+
|
6
|
+
subject { CFoundry::V2::QuotaDefinition.new("quota-definition-1", client) }
|
7
|
+
|
8
|
+
it "has guid" do
|
9
|
+
expect(subject.guid).to eq("quota-definition-1")
|
10
|
+
end
|
11
|
+
|
12
|
+
it "has name" do
|
13
|
+
subject.name = "name"
|
14
|
+
expect(subject.name).to eq("name")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "has non_basic_services_allowed" do
|
18
|
+
[true, false].each do |v|
|
19
|
+
subject.non_basic_services_allowed = v
|
20
|
+
expect(subject.non_basic_services_allowed).to eq(v)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it "has total_services" do
|
25
|
+
[0, 1].each do |v|
|
26
|
+
subject.total_services = v
|
27
|
+
expect(subject.total_services).to eq(v)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it "has total_services" do
|
32
|
+
[0, 1].each do |v|
|
33
|
+
subject.total_services = v
|
34
|
+
expect(subject.total_services).to eq(v)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "querying" do
|
39
|
+
let(:foo) { fake(:quota_definition, :name => "foo") }
|
40
|
+
let(:bar) { fake(:quota_definition, :name => "bar") }
|
41
|
+
let(:baz) { fake(:quota_definition, :name => "baz") }
|
42
|
+
|
43
|
+
let(:quota_definitions) { [foo, bar, baz] }
|
44
|
+
|
45
|
+
let(:client) { fake_client :quota_definitions => quota_definitions }
|
46
|
+
|
47
|
+
it "is queryable by name" do
|
48
|
+
quota = quota_definitions.last
|
49
|
+
expect(client.quota_definition_by_name("bar")).to eq(bar)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cfoundry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.1.
|
4
|
+
version: 0.6.1.rc4
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-04-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: multipart-post
|
@@ -225,6 +225,7 @@ files:
|
|
225
225
|
- lib/cfoundry/v2/model.rb
|
226
226
|
- lib/cfoundry/v2/model_magic.rb
|
227
227
|
- lib/cfoundry/v2/organization.rb
|
228
|
+
- lib/cfoundry/v2/quota_definition.rb
|
228
229
|
- lib/cfoundry/v2/route.rb
|
229
230
|
- lib/cfoundry/v2/service.rb
|
230
231
|
- lib/cfoundry/v2/service_auth_token.rb
|
@@ -270,7 +271,9 @@ files:
|
|
270
271
|
- spec/cfoundry/v2/client_spec.rb
|
271
272
|
- spec/cfoundry/v2/domain_spec.rb
|
272
273
|
- spec/cfoundry/v2/model_magic_spec.rb
|
274
|
+
- spec/cfoundry/v2/model_spec.rb
|
273
275
|
- spec/cfoundry/v2/organization_spec.rb
|
276
|
+
- spec/cfoundry/v2/quota_definition_spec.rb
|
274
277
|
- spec/cfoundry/v2/space_spec.rb
|
275
278
|
- spec/fakes/app_fake.rb
|
276
279
|
- spec/fakes/domain_fake.rb
|
@@ -349,7 +352,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
349
352
|
version: '0'
|
350
353
|
segments:
|
351
354
|
- 0
|
352
|
-
hash:
|
355
|
+
hash: 163727160375400133
|
353
356
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
354
357
|
none: false
|
355
358
|
requirements:
|
@@ -392,7 +395,9 @@ test_files:
|
|
392
395
|
- spec/cfoundry/v2/client_spec.rb
|
393
396
|
- spec/cfoundry/v2/domain_spec.rb
|
394
397
|
- spec/cfoundry/v2/model_magic_spec.rb
|
398
|
+
- spec/cfoundry/v2/model_spec.rb
|
395
399
|
- spec/cfoundry/v2/organization_spec.rb
|
400
|
+
- spec/cfoundry/v2/quota_definition_spec.rb
|
396
401
|
- spec/cfoundry/v2/space_spec.rb
|
397
402
|
- spec/fakes/app_fake.rb
|
398
403
|
- spec/fakes/domain_fake.rb
|