manifests-vmc-plugin 0.4.17 → 0.4.18

Sign up to get free protection for your applications and to get access to all the features.
@@ -78,6 +78,10 @@ module VMCManifests
78
78
  if app.key?("mem")
79
79
  app["memory"] = app.delete("mem")
80
80
  end
81
+
82
+ if app.key?("url") && app["url"].nil?
83
+ app["url"] = "none"
84
+ end
81
85
  end
82
86
 
83
87
  def toplevel_attributes(manifest)
@@ -104,6 +108,8 @@ module VMCManifests
104
108
  stringified
105
109
  when Array
106
110
  val.collect { |x| normalize_key_val(x) }
111
+ when nil
112
+ nil
107
113
  else
108
114
  val.to_s
109
115
  end
@@ -1,13 +1,16 @@
1
1
  module VMCManifests
2
2
  module Resolver
3
- def resolve!(manifest, resolver)
4
- manifest[:applications].each_value do |v|
5
- resolve_lexically(resolver, v, [manifest])
6
- end
3
+ def resolve(manifest, resolver)
4
+ new = {}
7
5
 
8
- resolve_lexically(resolver, manifest, [manifest])
6
+ new[:applications] = {}
9
7
 
10
- nil
8
+ manifest[:applications].each do |k, v|
9
+ new[:applications][k] =
10
+ resolve_lexically(resolver, v, [manifest])
11
+ end
12
+
13
+ resolve_lexically(resolver, new, [new])
11
14
  end
12
15
 
13
16
  private
@@ -16,24 +19,28 @@ module VMCManifests
16
19
  def resolve_lexically(resolver, val, ctx)
17
20
  case val
18
21
  when Hash
19
- val.each_value do |v|
20
- resolve_lexically(resolver, v, [val] + ctx)
22
+ new = {}
23
+
24
+ val.each do |k, v|
25
+ new[k] = resolve_lexically(resolver, v, [val] + ctx)
21
26
  end
27
+
28
+ new
22
29
  when Array
23
- val.each do |v|
30
+ val.collect do |v|
24
31
  resolve_lexically(resolver, v, ctx)
25
32
  end
26
33
  when String
27
- val.gsub!(/\$\{([^\}]+)\}/) do
28
- resolve(resolver, $1, ctx)
34
+ val.gsub(/\$\{([^\}]+)\}/) do
35
+ resolve_symbol(resolver, $1, ctx)
29
36
  end
37
+ else
38
+ val
30
39
  end
31
-
32
- nil
33
40
  end
34
41
 
35
42
  # resolve a symbol to its value, and then resolve that value
36
- def resolve(resolver, sym, ctx)
43
+ def resolve_symbol(resolver, sym, ctx)
37
44
  if found = find_symbol(sym.to_sym, ctx)
38
45
  resolve_lexically(resolver, found, ctx)
39
46
  found
@@ -16,8 +16,7 @@ module VMCManifests
16
16
  def manifest
17
17
  info = build(@file)
18
18
  normalize! info
19
- resolve! info, @resolver
20
- info
19
+ resolve info, @resolver
21
20
  end
22
21
 
23
22
  private
@@ -1,3 +1,3 @@
1
1
  module VMCManifests
2
- VERSION = "0.4.17"
2
+ VERSION = "0.4.18".freeze
3
3
  end
@@ -131,9 +131,9 @@ module VMCManifests
131
131
  in_manifest = []
132
132
 
133
133
  if names_or_paths.empty?
134
- specific = find_apps(Dir.pwd)
134
+ apps = find_apps(Dir.pwd)
135
135
 
136
- if !specific.empty?
136
+ if !apps.empty?
137
137
  in_manifest += apps
138
138
  else
139
139
  each_app(&blk)
@@ -167,6 +167,50 @@ module VMCManifests
167
167
  external
168
168
  end
169
169
 
170
+ def create_manifest_for(app, path)
171
+ meta = {
172
+ "name" => app.name,
173
+ "framework" => app.framework.name,
174
+ "runtime" => app.runtime.name,
175
+ "memory" => human_size(app.memory * 1024 * 1024, 0),
176
+ "instances" => app.total_instances,
177
+ "url" => app.url ? app.url.sub(target_base, '${target-base}') : "none",
178
+ "path" => path
179
+ }
180
+
181
+ services = app.services
182
+
183
+ unless services.empty?
184
+ meta["services"] = {}
185
+
186
+ services.each do |i|
187
+ if v2?
188
+ p = i.service_plan
189
+ s = p.service
190
+
191
+ meta["services"][i.name] = {
192
+ "label" => s.label,
193
+ "provider" => s.provider,
194
+ "version" => s.version,
195
+ "plan" => p.name
196
+ }
197
+ else
198
+ meta["services"][i.name] = {
199
+ "vendor" => i.vendor,
200
+ "version" => i.version,
201
+ "tier" => i.tier
202
+ }
203
+ end
204
+ end
205
+ end
206
+
207
+ if cmd = app.command
208
+ meta["command"] = cmd
209
+ end
210
+
211
+ meta
212
+ end
213
+
170
214
  private
171
215
 
172
216
  def show_manifest_usage
@@ -230,46 +274,6 @@ module VMCManifests
230
274
  def ask_to_save(input, app)
231
275
  return if manifest_file
232
276
 
233
- service_instances = app.services
234
-
235
- meta = {
236
- "name" => app.name,
237
- "framework" => app.framework.name,
238
- "runtime" => app.runtime.name,
239
- "memory" => human_size(app.memory * 1024 * 1024, 0),
240
- "instances" => app.total_instances,
241
- "url" => app.url && app.url.sub(target_base, '${target-base}'),
242
- "path" => input[:path]
243
- }
244
-
245
- unless service_instances.empty?
246
- meta["services"] = {}
247
-
248
- service_instances.each do |i|
249
- if v2?
250
- p = i.service_plan
251
- s = p.service
252
-
253
- meta["services"][i.name] = {
254
- "label" => s.label,
255
- "provider" => s.provider,
256
- "version" => s.version,
257
- "plan" => p.name
258
- }
259
- else
260
- meta["services"][i.name] = {
261
- "vendor" => i.vendor,
262
- "version" => i.version,
263
- "tier" => i.tier
264
- }
265
- end
266
- end
267
- end
268
-
269
- if cmd = app.command
270
- meta["command"] = cmd
271
- end
272
-
273
277
  if ask("Save configuration?", :default => false)
274
278
  with_progress("Saving to #{c("manifest.yml", :name)}") do
275
279
  File.open("manifest.yml", "w") do |io|
@@ -22,6 +22,17 @@ describe VMCManifests::Normalizer do
22
22
  end
23
23
  end
24
24
 
25
+ context 'with a manifest where the url is nil' do
26
+ let(:manifest) { { "applications" => { "." => { "url" => nil } } } }
27
+
28
+ it "sets it to none" do
29
+ expect(subject).to eq(
30
+ :applications => {
31
+ :"." => { :path => ".", :url => "none" }
32
+ })
33
+ end
34
+ end
35
+
25
36
  context 'with a manifest with toplevel attributes' do
26
37
  context 'and properties' do
27
38
  let(:manifest) {
@@ -1,13 +1,22 @@
1
1
  require 'spec_helper'
2
2
  require 'manifests-vmc-plugin'
3
3
 
4
+ require 'cfoundry/spec_helper'
5
+
4
6
  describe VMCManifests do
5
7
  let(:cmd) do
6
- manifest = Object.new
8
+ manifest = VMC::App::Push.new
7
9
  manifest.extend VMCManifests
8
10
  manifest
9
11
  end
10
12
 
13
+ let(:target_base) { "some-cloud.com" }
14
+
15
+ before do
16
+ stub(cmd).target_base { target_base }
17
+ stub(cmd).v2? { true }
18
+ end
19
+
11
20
  describe '#find_apps' do
12
21
  subject { cmd.find_apps(nil) }
13
22
 
@@ -16,4 +25,111 @@ describe VMCManifests do
16
25
  it { should eq [] }
17
26
  end
18
27
  end
19
- end
28
+
29
+ describe '#create_manifest_for' do
30
+ let(:app) {
31
+ FactoryGirl.build(
32
+ :app,
33
+ :framework => FactoryGirl.build(:framework),
34
+ :runtime => FactoryGirl.build(:runtime),
35
+ :memory => 2048,
36
+ :instances => 2,
37
+ :command => "ruby main.rb",
38
+ :routes => [
39
+ FactoryGirl.build(
40
+ :route,
41
+ :host => "some-app-name",
42
+ :domain => FactoryGirl.build(:domain, :name => target_base))
43
+ ],
44
+ :service_bindings => [
45
+ FactoryGirl.build(
46
+ :service_binding,
47
+ :service_instance =>
48
+ FactoryGirl.build(
49
+ :service_instance,
50
+ :name => "service-1",
51
+ :service_plan =>
52
+ FactoryGirl.build(
53
+ :service_plan,
54
+ :name => "P200",
55
+ :service => FactoryGirl.build(:service))))
56
+ ])
57
+ }
58
+
59
+ subject { cmd.create_manifest_for(app, "some-path") }
60
+
61
+ its(["name"]) { should eq app.name }
62
+ its(["framework"]) { should eq app.framework.name }
63
+ its(["runtime"]) { should eq app.runtime.name }
64
+ its(["memory"]) { should eq "2G" }
65
+ its(["instances"]) { should eq 2 }
66
+ its(["path"]) { should eq "some-path" }
67
+ its(["url"]) { should eq "some-app-name.${target-base}" }
68
+ its(["command"]) { should eq "ruby main.rb" }
69
+
70
+ it "contains the service information" do
71
+ manifest = subject
72
+ expect(manifest["services"]).to be_a Hash
73
+
74
+ services = manifest["services"]
75
+ app.service_bindings.each do |b|
76
+ service = b.service_instance
77
+
78
+ expect(services).to include service.name
79
+
80
+ info = services[service.name]
81
+
82
+ plan = service.service_plan
83
+ offering = plan.service
84
+
85
+ { "plan" => plan.name,
86
+ "label" => offering.label,
87
+ "provider" => offering.provider,
88
+ "version" => offering.version
89
+ }.each do |attr, val|
90
+ expect(info).to include attr
91
+ expect(info[attr]).to eq val
92
+ end
93
+ end
94
+ end
95
+
96
+ context 'when there is no url' do
97
+ let(:app) {
98
+ FactoryGirl.build(
99
+ :app,
100
+ :framework => FactoryGirl.build(:framework),
101
+ :runtime => FactoryGirl.build(:runtime),
102
+ :memory => 2048,
103
+ :instances => 2)
104
+ }
105
+
106
+ its(["url"]) { should eq "none" }
107
+ end
108
+
109
+ context 'when there is no command' do
110
+ let(:app) {
111
+ FactoryGirl.build(
112
+ :app,
113
+ :framework => FactoryGirl.build(:framework),
114
+ :runtime => FactoryGirl.build(:runtime),
115
+ :memory => 2048,
116
+ :instances => 2)
117
+ }
118
+
119
+ it { should_not include "command" }
120
+ end
121
+
122
+ context 'when there are no service bindings' do
123
+ let(:app) {
124
+ FactoryGirl.build(
125
+ :app,
126
+ :framework => FactoryGirl.build(:framework),
127
+ :runtime => FactoryGirl.build(:runtime),
128
+ :memory => 2048,
129
+ :instances => 2)
130
+ }
131
+
132
+ it { should_not include "services" }
133
+ end
134
+ end
135
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: manifests-vmc-plugin
3
3
  version: !ruby/object:Gem::Version
4
- hash: 45
4
+ hash: 43
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 17
10
- version: 0.4.17
9
+ - 18
10
+ version: 0.4.18
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex Suraci
@@ -15,7 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-12-05 00:00:00 Z
18
+ date: 2012-12-14 00:00:00 -08:00
19
+ default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: cfoundry
@@ -34,50 +35,111 @@ dependencies:
34
35
  type: :runtime
35
36
  version_requirements: *id001
36
37
  - !ruby/object:Gem::Dependency
37
- name: rake
38
+ name: vmc
38
39
  prerelease: false
39
40
  requirement: &id002 !ruby/object:Gem::Requirement
40
41
  none: false
41
42
  requirements:
42
- - - ">="
43
+ - - ~>
43
44
  - !ruby/object:Gem::Version
44
- hash: 3
45
+ hash: 1
45
46
  segments:
46
47
  - 0
47
- version: "0"
48
+ - 4
49
+ - 7
50
+ version: 0.4.7
48
51
  type: :development
49
52
  version_requirements: *id002
50
53
  - !ruby/object:Gem::Dependency
51
- name: rspec
54
+ name: rake
52
55
  prerelease: false
53
56
  requirement: &id003 !ruby/object:Gem::Requirement
54
57
  none: false
55
58
  requirements:
56
59
  - - ~>
57
60
  - !ruby/object:Gem::Version
58
- hash: 3
61
+ hash: 25
59
62
  segments:
60
- - 2
61
63
  - 0
62
- version: "2.0"
64
+ - 9
65
+ version: "0.9"
63
66
  type: :development
64
67
  version_requirements: *id003
65
68
  - !ruby/object:Gem::Dependency
66
- name: vmc
69
+ name: rspec
67
70
  prerelease: false
68
71
  requirement: &id004 !ruby/object:Gem::Requirement
69
72
  none: false
70
73
  requirements:
71
- - - ">="
74
+ - - ~>
72
75
  - !ruby/object:Gem::Version
73
- hash: 15
76
+ hash: 21
77
+ segments:
78
+ - 2
79
+ - 11
80
+ version: "2.11"
81
+ type: :development
82
+ version_requirements: *id004
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ prerelease: false
86
+ requirement: &id005 !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ~>
90
+ - !ruby/object:Gem::Version
91
+ hash: 7
74
92
  segments:
75
93
  - 0
76
- - 4
94
+ - 6
95
+ version: "0.6"
96
+ type: :development
97
+ version_requirements: *id005
98
+ - !ruby/object:Gem::Dependency
99
+ name: webmock
100
+ prerelease: false
101
+ requirement: &id006 !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ~>
105
+ - !ruby/object:Gem::Version
106
+ hash: 29
107
+ segments:
108
+ - 1
109
+ - 9
110
+ version: "1.9"
111
+ type: :development
112
+ version_requirements: *id006
113
+ - !ruby/object:Gem::Dependency
114
+ name: rr
115
+ prerelease: false
116
+ requirement: &id007 !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ~>
120
+ - !ruby/object:Gem::Version
121
+ hash: 15
122
+ segments:
123
+ - 1
77
124
  - 0
78
- version: 0.4.0
125
+ version: "1.0"
79
126
  type: :development
80
- version_requirements: *id004
127
+ version_requirements: *id007
128
+ - !ruby/object:Gem::Dependency
129
+ name: factory_girl
130
+ prerelease: false
131
+ requirement: &id008 !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ~>
135
+ - !ruby/object:Gem::Version
136
+ hash: 15
137
+ segments:
138
+ - 2
139
+ - 6
140
+ version: "2.6"
141
+ type: :development
142
+ version_requirements: *id008
81
143
  description:
82
144
  email:
83
145
  - asuraci@vmware.com
@@ -89,17 +151,18 @@ extra_rdoc_files: []
89
151
 
90
152
  files:
91
153
  - Rakefile
154
+ - lib/manifests-vmc-plugin/version.rb
92
155
  - lib/manifests-vmc-plugin/errors.rb
93
- - lib/manifests-vmc-plugin/loader/builder.rb
156
+ - lib/manifests-vmc-plugin/plugin.rb
157
+ - lib/manifests-vmc-plugin/loader.rb
94
158
  - lib/manifests-vmc-plugin/loader/normalizer.rb
95
159
  - lib/manifests-vmc-plugin/loader/resolver.rb
96
- - lib/manifests-vmc-plugin/loader.rb
97
- - lib/manifests-vmc-plugin/plugin.rb
98
- - lib/manifests-vmc-plugin/version.rb
160
+ - lib/manifests-vmc-plugin/loader/builder.rb
99
161
  - lib/manifests-vmc-plugin.rb
100
- - spec/loader/normalizer_spec.rb
101
- - spec/manifests-vmc-plugin_spec.rb
102
162
  - spec/spec_helper.rb
163
+ - spec/manifests-vmc-plugin_spec.rb
164
+ - spec/loader/normalizer_spec.rb
165
+ has_rdoc: true
103
166
  homepage: http://cloudfoundry.com/
104
167
  licenses: []
105
168
 
@@ -129,11 +192,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
192
  requirements: []
130
193
 
131
194
  rubyforge_project: manifests-vmc-plugin
132
- rubygems_version: 1.8.24
195
+ rubygems_version: 1.6.2
133
196
  signing_key:
134
197
  specification_version: 3
135
198
  summary: Cloud Foundry automation via manifest documents.
136
199
  test_files:
137
- - spec/loader/normalizer_spec.rb
138
- - spec/manifests-vmc-plugin_spec.rb
139
200
  - spec/spec_helper.rb
201
+ - spec/manifests-vmc-plugin_spec.rb
202
+ - spec/loader/normalizer_spec.rb